/* ==========================================================================
   Page compositions — arrangement of components for specific screens.
   ========================================================================== */

/* ---------- Home: hero ---------- */
.hero { position: relative; background: var(--navy-900); color: #fff; padding-block: var(--space-16) var(--space-20); overflow: hidden; }
.hero::before { content: ""; position: absolute; inset: auto -10% -45% auto; width: 620px; height: 620px; border-radius: 50%; background: radial-gradient(circle, rgba(59, 124, 240, 0.32), transparent 65%); pointer-events: none; }
.hero__grid { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 520px); gap: var(--space-12); align-items: start; }
.hero__copy { display: grid; gap: var(--space-6); padding-top: var(--space-8); }
.hero h1 { color: #fff; font-size: var(--text-display); line-height: 1.08; letter-spacing: -0.03em; }
.highlight--dark { color: var(--navy-950); background: var(--sun-400); padding: 0 0.18em; border-radius: 6px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.eyebrow--on-dark { color: var(--sun-400); }
.hero__lead { font-size: var(--text-lg); color: rgba(255, 255, 255, 0.82); max-width: 46ch; }
.hero__points { display: grid; gap: var(--space-3); margin: 0; padding: 0; list-style: none; }
.hero__points li { display: flex; align-items: center; gap: var(--space-3); color: rgba(255, 255, 255, 0.92); }
.hero__points .icon { color: var(--sun-400); }
.hero__facts { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.hero__facts > div { padding: var(--space-3) var(--space-4); border: 1px solid rgba(255, 255, 255, 0.16); border-radius: var(--radius-md); background: rgba(255, 255, 255, 0.04); }
.hero__facts dt { font-size: var(--text-xs); color: rgba(255, 255, 255, 0.68); text-transform: uppercase; letter-spacing: 0.06em; }
.hero__facts dd { font-weight: var(--weight-semibold); color: #fff; }
.hero :focus-visible { outline-color: var(--sun-400); }
.hero .upload-card :focus-visible { outline-color: var(--focus-ring); }

.upload-card { color: var(--text); box-shadow: var(--shadow-lg); border: 0; }
.upload-card__head { display: grid; gap: var(--space-4); padding: var(--space-6) var(--space-6) 0; }
.upload-card__title { font-size: var(--text-xl); }
.upload-card__panel { padding: var(--space-5) var(--space-6) var(--space-6); }
.upload-card__panel:focus-visible { outline-offset: -3px; }
.js .upload-card__panel[hidden] { display: none !important; }
.privacy-note { display: flex; gap: var(--space-2); align-items: flex-start; font-size: var(--text-xs); color: var(--text-muted); }
.privacy-note .icon { width: 16px; height: 16px; color: var(--success); margin-top: 1px; }
.selection { display: grid; gap: var(--space-3); }
kbd { display: inline-block; padding: 0 6px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--surface); font-size: 0.8em; font-family: var(--font-sans); color: var(--ink); }

@media (max-width: 1024px) {
  .hero__grid { grid-template-columns: minmax(0, 1fr); gap: var(--space-8); }
  .hero__copy { padding-top: 0; }
  .upload-card { max-width: 640px; width: 100%; }
}
@media (max-width: 600px) {
  .hero { padding-block: var(--space-8) var(--space-10); }
  .hero__lead { font-size: var(--text-base); }
  .hero__points { display: none; }
  .upload-card__head { padding: var(--space-5) var(--space-4) 0; }
  .upload-card__panel { padding: var(--space-4); }
  .dropzone { padding: var(--space-6) var(--space-4); }
  .dropzone .btn-row { width: 100%; }
  .dropzone .btn-row .btn { flex: 1; }
  .dropzone__paste { display: none; }
}

/* ---------- Home: results ---------- */
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); gap: var(--space-6); }
.result-card { display: grid; grid-template-rows: auto 1fr; overflow: hidden; min-width: 0; }
.result-card__media { aspect-ratio: 16 / 9; background: var(--surface-sunken) repeating-conic-gradient(#eef2f6 0 25%, #f8fafc 0 50%) 0 0 / 20px 20px; display: grid; place-items: center; border-bottom: 1px solid var(--border); }
.result-card__media { position: relative; overflow: hidden; }
.result-card__media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.result-card__locked { display: grid; justify-items: center; gap: var(--space-2); padding: var(--space-4); color: var(--text-muted); font-size: var(--text-sm); text-align: center; }
.result-card__locked .icon { width: 28px; height: 28px; }
.result-card__body { display: grid; gap: var(--space-5); padding: var(--space-5); align-content: start; }
.result-card__head { display: grid; gap: var(--space-2); }
.result-card__name { font-size: var(--text-base); overflow-wrap: anywhere; }
.result-card__links, .result-card__more { display: grid; gap: var(--space-4); }

/* ---------- Home: history ---------- */
.history-list { display: grid; gap: var(--space-3); margin: 0; padding: 0; list-style: none; }
.history-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-4); padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.history-item__icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--radius-md); background: var(--primary-soft); color: var(--primary); }
.history-item__text { display: grid; min-width: 0; }
.history-item__name { font-weight: var(--weight-semibold); color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item__meta { font-size: var(--text-xs); color: var(--text-muted); overflow-wrap: anywhere; }
.history-item__actions { justify-content: flex-end; }
@media (max-width: 900px) {
  .history-item { grid-template-columns: auto minmax(0, 1fr); }
  .history-item__actions { grid-column: 1 / -1; justify-content: flex-start; }
}

/* ---------- Home: features ---------- */
.feature-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-5); }
.feature { display: grid; gap: var(--space-3); align-content: start; padding: var(--space-6); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.feature__icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: var(--radius-md); background: var(--navy-900); color: var(--sun-400); }
.feature h3 { font-size: var(--text-base); }
.feature p { font-size: var(--text-sm); color: var(--text-muted); }
.feature__code { display: block; padding: var(--space-2) var(--space-3); font-size: var(--text-xs); }
@media (max-width: 1200px) { .feature-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) { .feature-grid { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Console: lists, tables, popovers ---------- */
.media-list { display: grid; margin: 0; padding: 0; list-style: none; }
.media-list__item { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-4) var(--space-6); border-bottom: var(--border-width) solid var(--border); }
.media-list__item:last-child { border-bottom: 0; }
.media-list__item > :last-child:not(.media-list__text) { margin-left: auto; }
.media-list__icon { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: var(--radius-md); background: var(--primary-soft); color: var(--primary); }
.media-list__text, .media-cell__text { display: grid; gap: 2px; min-width: 0; flex: 1; }
.media-cell { display: flex; align-items: flex-start; gap: var(--space-3); min-width: 240px; }
.media-cell .chip-list:empty { display: none; }
.table__code { font-size: var(--text-xs); color: var(--text-muted); background: transparent; padding: 0; overflow-wrap: anywhere; }
.table__lines { display: grid; gap: 2px; white-space: nowrap; }
.btn-row--tight { gap: var(--space-2); flex-wrap: wrap; }
.btn-row--end { justify-content: flex-end; }
.toolbar--full { width: 100%; }
.toolbar--full .toolbar__search { flex: 1; max-width: 460px; }
.result-count { font-size: var(--text-sm); color: var(--text-muted); white-space: nowrap; }
.library-table .actions { width: 1%; white-space: nowrap; }

.popover { position: relative; display: inline-block; }
.popover > summary { list-style: none; cursor: pointer; }
.popover > summary::-webkit-details-marker { display: none; }
.popover[open] > summary { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.popover__panel { position: absolute; right: 0; top: calc(100% + var(--space-2)); z-index: var(--z-popover); width: min(320px, 86vw); padding: var(--space-4); background: var(--surface); border: var(--border-width) solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); text-align: left; white-space: normal; }
.input--file { padding: var(--space-2); min-height: auto; font-size: var(--text-sm); }
.input--file::file-selector-button { margin-right: var(--space-3); padding: 6px 12px; border: var(--border-width) solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font: inherit; font-weight: var(--weight-medium); cursor: pointer; }
.input--file::file-selector-button:hover { background: var(--canvas); }

.action-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-4) 0; border-bottom: var(--border-width) solid var(--border); }
.action-row:last-child { border-bottom: 0; padding-bottom: 0; }
.action-row:first-child { padding-top: 0; }
.action-row__title { display: block; font-size: var(--text-sm); color: var(--ink); }
.action-row__desc { display: block; font-size: var(--text-xs); color: var(--text-muted); }

.check-list { display: grid; gap: var(--space-2); margin: 0; padding: 0; list-style: none; font-size: var(--text-sm); }
.check-list li { display: flex; gap: var(--space-2); align-items: flex-start; }
.check-list .icon { width: 18px; height: 18px; color: var(--success); margin-top: 1px; }
.check-list--muted { color: var(--text-muted); }
.check-list--muted .icon { color: var(--text-subtle); }
hr { border: 0; border-top: var(--border-width) solid var(--border); margin: var(--space-2) 0; }

.kv--grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); column-gap: var(--space-8); }
.kv--grid .kv__row:last-child { border-bottom: var(--border-width) solid var(--border); }
.grid-2--wide-left { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.nav-link--button { width: 100%; border: 0; background: transparent; font: inherit; font-size: var(--text-sm); font-weight: var(--weight-medium); text-align: left; cursor: pointer; }
.auth__note { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: rgba(255,255,255,0.7); }
.icon--flip { transform: scaleX(-1); }
body.has-drawer { overflow: hidden; }

@media (max-width: 900px) {
  .grid-2--wide-left { grid-template-columns: minmax(0, 1fr); }
  .table--stack .media-cell { min-width: 0; }
  .table--stack .table__lines { white-space: normal; }
  .library-table .actions { width: auto; }
  .popover__panel { right: auto; left: 0; }
}
@media (max-width: 600px) {
  .media-list__item { padding: var(--space-4) var(--space-5); }
  .action-row { flex-wrap: wrap; }
}

/* ---------- Shared image viewer ---------- */
.state-card { max-width: 480px; margin: var(--space-10) auto; padding: var(--space-10) var(--space-8); display: grid; justify-items: center; gap: var(--space-4); text-align: center; }
.state-card__icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); }
.state-card__icon .icon { width: 28px; height: 28px; }
.state-card__icon--danger { background: var(--danger-soft); color: var(--danger); }
.state-card__icon--warning { background: var(--warning-soft); color: var(--warning); }
.state-card__title { font-size: var(--text-2xl); }
.state-card__text { color: var(--text-muted); max-width: 40ch; }
.state-card__form { width: 100%; text-align: left; margin-top: var(--space-2); }
.viewer { display: grid; gap: var(--space-6); }
.viewer__head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-4); }
.viewer__heading { display: grid; gap: var(--space-2); min-width: 0; }
.viewer__title { font-size: var(--text-2xl); overflow-wrap: anywhere; }
.viewer__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); margin: 0; padding: 0; list-style: none; font-size: var(--text-sm); color: var(--text-muted); }
.viewer__stage { margin: 0; display: grid; place-items: center; min-height: 280px; padding: var(--space-6); border: var(--border-width) solid var(--border); border-radius: var(--radius-lg); background: var(--surface-sunken) repeating-conic-gradient(#eef2f6 0 25%, #f8fafc 0 50%) 0 0 / 24px 24px; }
.viewer__stage img { max-width: 100%; max-height: 72vh; width: auto; height: auto; border-radius: var(--radius-sm); box-shadow: var(--shadow-md); }
@media (max-width: 600px) {
  .state-card { margin: var(--space-4) auto; padding: var(--space-8) var(--space-5); }
  .viewer__head .btn-row, .viewer__head .btn-row .btn { width: 100%; }
  .viewer__stage { padding: var(--space-3); min-height: 200px; }
}

/* ---------- Setup ---------- */
.setup-steps-hint { font-size: var(--text-sm); color: rgba(255,255,255,0.75); }
.setup-done { display: flex; gap: var(--space-4); align-items: flex-start; }
.state-card__icon--success { background: var(--success-soft); color: var(--success); flex: none; }
.server-checks { overflow: hidden; }
.server-checks > summary.server-checks__summary { justify-content: flex-start; gap: var(--space-4); padding: var(--space-4) var(--space-5); min-height: auto; border-radius: 0; }
.server-checks__icon { display: grid; place-items: center; flex: none; }
.server-checks__icon--ok { color: var(--success); }
.server-checks__icon--warn { color: var(--warning); }
.server-checks__icon--fail { color: var(--danger); }
.server-checks__text { display: grid; gap: 2px; flex: 1; min-width: 0; }
.server-checks__text > span { font-weight: var(--weight-regular); color: var(--text-muted); font-size: var(--text-xs); }
.server-checks__list { padding: 0 var(--space-5) var(--space-5); }
.setup-form fieldset { margin: 0; border: 0; min-width: 0; }
.setup-form legend { padding: 0; }
.setup-form .form-section { padding-block: var(--space-6); }
.setup-form .form-section:first-of-type { padding-top: 0; }
.setup-form .form-section:last-of-type { padding-bottom: 0; }
.step-no { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--navy-900); color: var(--sun-400); font-size: var(--text-sm); font-weight: var(--weight-bold); }
@media (max-width: 600px) { .setup-steps-hint { display: none; } .setup-done { flex-direction: column; } }

/* Programmatic focus targets (view headings, main) keep focus without a ring. */
h1[tabindex="-1"]:focus, main[tabindex="-1"]:focus { outline: none; }
.library-table .actions .btn-row { flex-wrap: nowrap; }
@media (min-width: 1025px) { .console-header__title { visibility: hidden; } }
@media (max-width: 900px) {
  .library-table td[data-label="Image"]::before { display: none; }
  .library-table .actions .btn-row { flex-wrap: wrap; }
}
fieldset.form-section > legend { margin-bottom: var(--space-4); }
@media (max-width: 600px) { .hide-sm { display: none; } }

/* ---------- Home: remove with delete key ---------- */
.remove-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 520px); gap: var(--space-10); align-items: start; }
@media (max-width: 900px) { .remove-grid { grid-template-columns: minmax(0, 1fr); gap: var(--space-6); } }
