/* ==========================================================================
   GilClean
   Design note: colour is reserved for meaning. Nothing in the chrome is
   tinted, so when something turns green or amber it is always a statement
   about a file, never decoration. Primary actions are ink, not brand blue.
   ========================================================================== */

/* 1. Design tokens ------------------------------------------------------- */

:root {
  --canvas:       #f2f1ee;
  --surface:      #ffffff;
  --surface-2:    #f8f7f4;
  --surface-3:    #edebe6;

  --ink:          #16181c;
  --ink-2:        #565b66;
  --ink-3:        #7c8390;

  --line:         #e2dfd8;
  --line-strong:  #cbc7be;

  --accent:       #2a52be;
  --accent-soft:  #eaeffb;

  --good:         #1a6b45;
  --good-bg:      #e2f0e8;
  --warn:         #855312;
  --warn-bg:      #f8eeda;
  --bad:          #a32c22;
  --bad-bg:       #fbe8e6;

  --btn-ink:      #16181c;
  --btn-ink-hi:   #2b2f36;
  --btn-on-ink:   #ffffff;

  --shadow-sm:    0 1px 2px rgba(28, 26, 22, .06),
                  0 1px 1px rgba(28, 26, 22, .04);
  --shadow-md:    0 4px 12px rgba(28, 26, 22, .08),
                  0 1px 3px rgba(28, 26, 22, .05);
  --shadow-lg:    0 12px 32px rgba(28, 26, 22, .12),
                  0 2px 8px rgba(28, 26, 22, .06);

  --font-body:    system-ui, -apple-system, "Segoe UI", Roboto,
                  "Helvetica Neue", Arial, sans-serif;
  --font-mono:    ui-monospace, SFMono-Regular, "SF Mono", "Cascadia Mono",
                  Menlo, Consolas, monospace;

  --text-xs:      12px;
  --text-sm:      13px;
  --text-base:    15px;
  --text-md:      17px;
  --text-lg:      clamp(19px, 1.4vw, 21px);
  --text-xl:      clamp(24px, 3vw, 32px);

  --space-1: 4px;   --space-2: 8px;   --space-3: 12px;  --space-4: 16px;
  --space-5: 20px;  --space-6: 24px;  --space-8: 32px;  --space-10: 40px;
  --space-12: 48px; --space-16: 64px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --fast: 140ms cubic-bezier(.2, .0, .2, 1);
  --std:  260ms cubic-bezier(.2, .0, .2, 1);

  --shell: 1080px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas:       #131417;
    --surface:      #1a1c20;
    --surface-2:    #202328;
    --surface-3:    #2a2e34;

    --ink:          #eae9e5;
    --ink-2:        #a5a9b2;
    --ink-3:        #868c96;

    --line:         #2c3036;
    --line-strong:  #3d424a;

    --accent:       #94aaff;
    --accent-soft:  #1d2438;

    --good:         #6fca9b;
    --good-bg:      #162c21;
    --warn:         #e0b062;
    --warn-bg:      #2f2513;
    --bad:          #ef8f84;
    --bad-bg:       #33191a;

    --btn-ink:      #eae9e5;
    --btn-ink-hi:   #ffffff;
    --btn-on-ink:   #14161a;

    --shadow-sm:    0 1px 2px rgba(0, 0, 0, .5);
    --shadow-md:    0 4px 12px rgba(0, 0, 0, .45);
    --shadow-lg:    0 14px 34px rgba(0, 0, 0, .55);
  }
}

/* 2. Reset & base -------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body.centered {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.015em; line-height: 1.25; }
p { margin: 0; }
img { max-width: 100%; display: block; }

a { color: var(--accent); text-underline-offset: 2px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.skip {
  position: absolute; left: -9999px; top: var(--space-2);
  background: var(--surface); color: var(--ink);
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); z-index: 50;
}
.skip:focus { left: var(--space-4); }

.muted { color: var(--ink-2); }
.num { font-family: var(--font-mono); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }

/* 3. Layout primitives --------------------------------------------------- */

.shell {
  max-width: var(--shell);
  margin: 0 auto;
  padding: var(--space-8) var(--space-5) var(--space-16);
}

@media (min-width: 768px) {
  .shell { padding: var(--space-12) var(--space-8) var(--space-16); }
}

/* 4. Top bar ------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
@supports not (backdrop-filter: blur(8px)) {
  .topbar { background: var(--surface); }
}

.topbar-inner {
  max-width: var(--shell);
  margin: 0 auto;
  padding: var(--space-3) var(--space-5);
  display: flex; align-items: center; gap: var(--space-5);
}
@media (min-width: 768px) { .topbar-inner { padding: var(--space-3) var(--space-8); } }

.wordmark {
  display: inline-flex; align-items: center; gap: var(--space-2);
  color: var(--ink); text-decoration: none;
  font-weight: 600; letter-spacing: -.02em; font-size: var(--text-md);
}
.mark { width: 26px; height: 26px; flex: none; }
.mark rect { fill: none; stroke: currentColor; stroke-width: 1.6; opacity: .35; }
.mark-tick {
  fill: none; stroke: currentColor; stroke-width: 2.4;
  stroke-linecap: round; stroke-linejoin: round;
}
.wordmark-lg { font-size: var(--text-lg); gap: var(--space-3); }
.wordmark-lg .mark { width: 34px; height: 34px; }

.tabs { display: flex; gap: var(--space-1); }
.tab {
  display: inline-flex; align-items: center; min-height: 40px;
  padding: 0 var(--space-3);
  color: var(--ink-2); text-decoration: none;
  font-size: var(--text-sm); font-weight: 500;
  border-radius: var(--radius-sm);
  transition: color var(--fast), background var(--fast);
}
.tab:hover { color: var(--ink); background: var(--surface-2); }
.tab.is-current { color: var(--ink); background: var(--surface-3); }

.topbar-end { margin-left: auto; display: flex; align-items: center; gap: var(--space-3); }
.inline-form { display: contents; }

/* 5. Page heads ---------------------------------------------------------- */

.page-head { margin-bottom: var(--space-8); }
.page-head h1 { font-size: var(--text-xl); }
.lede {
  margin-top: var(--space-3);
  color: var(--ink-2);
  max-width: 62ch;
  font-size: var(--text-md);
  line-height: 1.55;
}

.page-head-row {
  display: flex; flex-wrap: wrap; gap: var(--space-6);
  align-items: flex-start; justify-content: space-between;
}

.stats { display: flex; gap: var(--space-6); margin: 0; }
.stats div { display: flex; flex-direction: column; gap: 2px; }
.stats dt {
  font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: .06em; color: var(--ink-3);
}
.stats dd {
  margin: 0; font-family: var(--font-mono);
  font-size: var(--text-md); font-variant-numeric: tabular-nums;
}

/* 6. Dropzone ------------------------------------------------------------ */

.dropzone {
  display: grid; justify-items: center; gap: var(--space-1);
  padding: var(--space-12) var(--space-6);
  background: var(--surface);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  text-align: center; cursor: pointer;
  transition: border-color var(--fast), background var(--fast), transform var(--fast);
}
.dropzone:hover { border-color: var(--ink-3); }
.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  border-style: solid;
}
.dz-icon {
  width: 34px; height: 34px; margin-bottom: var(--space-3);
  fill: none; stroke: var(--ink-3); stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}
.dropzone.is-over .dz-icon { stroke: var(--accent); }
.dz-title { font-size: var(--text-md); font-weight: 600; }
.dz-sub { color: var(--ink-2); font-size: var(--text-sm); }
.dz-link { color: var(--accent); text-decoration: underline; }
.dz-note {
  margin-top: var(--space-3); color: var(--ink-3);
  font-size: var(--text-xs); letter-spacing: .01em;
}

/* 7. Queue --------------------------------------------------------------- */

.queue { margin-top: var(--space-6); }
.queue-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-3);
}
.queue-head h2 { font-size: var(--text-sm); color: var(--ink-2); font-weight: 600; }

.thumbs {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: var(--space-3);
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
}
.thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-3);
  border: 1px solid var(--line);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-name {
  position: absolute; inset: auto 0 0 0;
  padding: 14px var(--space-2) var(--space-2);
  font-size: 11px; color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, .72));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thumb-drop {
  position: absolute; top: var(--space-1); right: var(--space-1);
  width: 26px; height: 26px; padding: 0;
  display: grid; place-items: center;
  border: 0; border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, .62); color: #fff;
  font-size: 15px; line-height: 1; cursor: pointer;
  opacity: 0; transition: opacity var(--fast);
}
.thumb:hover .thumb-drop, .thumb-drop:focus-visible { opacity: 1; }

/* 8. Panel & controls ---------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.controls {
  margin-top: var(--space-5);
  padding: var(--space-5);
  display: grid; gap: var(--space-5);
}
@media (min-width: 860px) {
  .controls {
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: var(--space-8);
  }
}

.field { display: grid; gap: var(--space-2); }
.field label {
  font-size: var(--text-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3);
}
.field select, .field input[type="text"], .field input[type="password"] {
  font: inherit; color: var(--ink);
  min-height: 44px; padding: 0 var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}
.field select { min-width: 170px; }

.switches { display: grid; gap: var(--space-3); }

.switch {
  display: grid; grid-template-columns: auto 1fr;
  gap: var(--space-3); align-items: start;
  cursor: pointer; min-height: 44px; align-content: center;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-body {
  margin-top: 2px;
  width: 38px; height: 22px; flex: none;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  position: relative;
  transition: background var(--fast), border-color var(--fast);
}
.switch-dot {
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow-sm);
  transition: transform var(--fast);
}
.switch input:checked + .switch-body {
  background: var(--btn-ink); border-color: var(--btn-ink);
}
.switch input:checked + .switch-body .switch-dot {
  transform: translateX(16px); background: var(--btn-on-ink);
}
.switch input:focus-visible + .switch-body {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.switch-label { font-size: var(--text-sm); line-height: 1.4; }
.switch-label em {
  display: block; font-style: normal;
  color: var(--ink-3); font-size: var(--text-xs);
}

.actions { display: flex; gap: var(--space-3); flex-wrap: wrap; }
@media (min-width: 860px) { .actions { justify-content: flex-end; } }

/* 9. Buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  min-height: 44px; padding: 0 var(--space-5);
  font: inherit; font-size: var(--text-sm); font-weight: 600;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background var(--fast), border-color var(--fast),
              color var(--fast), transform var(--fast);
}
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-busy { opacity: .55; cursor: default; }
.btn[disabled]:active, .btn.is-busy:active { transform: none; }

.btn-primary { background: var(--btn-ink); color: var(--btn-on-ink); }
.btn-primary:hover:not([disabled]) { background: var(--btn-ink-hi); }

.btn-quiet {
  background: var(--surface); color: var(--ink);
  border-color: var(--line-strong);
}
.btn-quiet:hover:not([disabled]) { background: var(--surface-2); border-color: var(--ink-3); }

.btn-danger { background: transparent; color: var(--bad); border-color: var(--line-strong); }
.btn-danger:hover:not([disabled]) { background: var(--bad-bg); border-color: var(--bad); }

.btn-sm { min-height: 40px; padding: 0 var(--space-4); font-size: var(--text-xs); }
.btn-block { width: 100%; }

.btn-spinner { display: none; width: 14px; height: 14px; flex: none; }
.btn.is-busy .btn-spinner {
  display: block;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 10. Status & summary --------------------------------------------------- */

.status {
  margin-top: var(--space-5);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ink-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}
.status.is-info { border-left-color: var(--accent); }
.status.is-good { border-left-color: var(--good); }
.status.is-bad  { border-left-color: var(--bad); color: var(--bad); }

.summary {
  margin-top: var(--space-6);
  display: grid; gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: var(--space-4);
}
.stat-value {
  font-family: var(--font-mono); font-size: 24px;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.stat-label {
  font-size: var(--text-xs); color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .06em; margin-top: 2px;
}
.stat.is-good .stat-value { color: var(--good); }
.stat.is-bad  .stat-value { color: var(--bad); }

/* 11. Results ------------------------------------------------------------ */

.results { margin-top: var(--space-6); display: grid; gap: var(--space-2); }

.result {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.result > summary {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  cursor: pointer; list-style: none; min-height: 56px;
}
.result > summary::-webkit-details-marker { display: none; }
.result > summary:hover { background: var(--surface-2); }
.result-name {
  font-weight: 600; font-size: var(--text-sm);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.result-facts {
  margin-left: auto; display: flex; align-items: center;
  gap: var(--space-3); flex: none;
}
.chev {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: var(--ink-3); stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
  transition: transform var(--fast);
}
.result[open] .chev { transform: rotate(180deg); }

.result-body {
  padding: 0 var(--space-4) var(--space-4);
  border-top: 1px solid var(--line);
  padding-top: var(--space-4);
}

.pill {
  display: inline-flex; align-items: center;
  padding: 3px var(--space-2);
  font-size: 11px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
  border-radius: var(--radius-pill); white-space: nowrap;
}
.pill-good { background: var(--good-bg); color: var(--good); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-bad  { background: var(--bad-bg);  color: var(--bad); }

.findings { list-style: none; margin: var(--space-2) 0 0; padding: 0; }
.findings li {
  display: flex; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--text-sm); color: var(--ink-2);
}
.findings li:last-child { border-bottom: 0; }
.findings b { color: var(--ink); font-weight: 600; }
.findings span:last-child { font-family: var(--font-mono); font-size: var(--text-xs); white-space: nowrap; }

.result-label {
  font-size: var(--text-xs); font-weight: 600; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .06em;
}
.notes { margin-top: var(--space-3); font-size: var(--text-sm); color: var(--ink-2); }

/* 12. Library ------------------------------------------------------------ */

.library-bar {
  display: flex; flex-wrap: wrap; gap: var(--space-3);
  align-items: center; justify-content: space-between;
  margin: var(--space-6) 0 var(--space-3);
}
.library-bar-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.library { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }

.lib-item {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: var(--space-4);
  align-items: center;
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  transition: opacity var(--std), border-color var(--fast);
}
.lib-item.is-going { opacity: .35; }
@media (min-width: 780px) {
  .lib-item { grid-template-columns: 68px 1fr auto; }
}

.lib-thumb {
  width: 68px; height: 68px; border-radius: var(--radius-sm);
  overflow: hidden; background: var(--surface-3);
  display: grid; place-items: center; flex: none;
}
.lib-thumb img { width: 100%; height: 100%; object-fit: cover; }
.lib-thumb-empty { color: var(--ink-3); font-family: var(--font-mono); }

.lib-body { min-width: 0; }
.lib-name {
  font-size: var(--text-sm); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lib-meta {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: var(--space-2); margin-top: var(--space-1);
}
.lib-sub { font-size: var(--text-xs); color: var(--ink-2); margin-top: var(--space-1); }

.lib-actions {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: var(--space-2);
  flex-wrap: wrap;
}
@media (min-width: 780px) {
  .lib-actions { grid-column: auto; justify-content: flex-end; }
}
.lib-age {
  font-size: var(--text-xs); color: var(--ink-3);
  font-variant-numeric: tabular-nums; margin-right: var(--space-2);
}

/* 13. Empty state & scope note ------------------------------------------- */

.empty {
  display: grid; justify-items: center; gap: var(--space-3);
  padding: var(--space-16) var(--space-6);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  text-align: center;
  margin-top: var(--space-6);
}
.empty-icon {
  width: 38px; height: 38px;
  fill: none; stroke: var(--ink-3); stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
}
.empty h2 { font-size: var(--text-md); }
.empty p { color: var(--ink-2); font-size: var(--text-sm); max-width: 44ch; }
.empty .btn { margin-top: var(--space-3); }

.scope-note {
  margin-top: var(--space-12);
  padding: var(--space-5) var(--space-6);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}
.scope-note h2 {
  font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: .06em; color: var(--ink-3);
}
.scope-note p {
  margin-top: var(--space-2); color: var(--ink-2);
  font-size: var(--text-sm); max-width: 74ch;
}

/* 14. Auth --------------------------------------------------------------- */

.auth { width: 100%; padding: var(--space-6); display: grid; place-items: center; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-8);
}
.auth-sub {
  margin-top: var(--space-2); margin-bottom: var(--space-6);
  color: var(--ink-2); font-size: var(--text-sm);
}
.auth-form { display: grid; gap: var(--space-4); margin-top: var(--space-5); }
.auth .status { margin-top: var(--space-4); }

/* 15. Footer ------------------------------------------------------------- */

.footer {
  border-top: 1px solid var(--line);
  padding: var(--space-6) var(--space-5);
}
.footer p {
  max-width: var(--shell); margin: 0 auto;
  color: var(--ink-3); font-size: var(--text-xs);
}
@media (min-width: 768px) { .footer { padding: var(--space-6) var(--space-8); } }

/* 16. Motion ------------------------------------------------------------- */

@media (prefers-reduced-motion: no-preference) {
  .result, .lib-item, .stat {
    animation: rise var(--std) both;
  }
  @keyframes rise {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
