/* =====================================================================
   KINGSTON AI — application styles
   Intelligence for Kingston Branding

   Everything is driven by the CSS variables in the :root blocks below.
   Rebranding the app is a matter of changing those values; no component
   hard-codes a colour, radius or shadow.
   ===================================================================== */

/* ---------------------------------------------------------------------
   1. Design tokens — light (default)
   --------------------------------------------------------------------- */
:root {
  --bg:                #f5f6f8;
  --surface:           #ffffff;
  --surface-secondary: #f1f2f5;
  --surface-hover:     #ebedf1;
  --surface-sunken:    #fafbfc;

  --text:        #14161a;
  --text-muted:  #656b76;
  --text-subtle: #6f757f;

  --border:        #e4e6eb;
  --border-strong: #d2d6dd;

  --accent:        #2f56e6;
  --accent-hover:  #2545c4;
  --accent-text:   #ffffff;
  --accent-soft:   rgba(47, 86, 230, 0.09);
  --accent-border: rgba(47, 86, 230, 0.22);

  --success:      #12805a;
  --success-soft: rgba(18, 128, 90, 0.10);
  --warning:      #a76a08;
  --warning-soft: rgba(167, 106, 8, 0.11);
  --danger:       #c23b3b;
  --danger-soft:  rgba(194, 59, 59, 0.10);
  --info:         #2b6ba8;
  --info-soft:    rgba(43, 107, 168, 0.10);
  --neutral-soft: rgba(20, 22, 26, 0.05);

  --shadow-sm: 0 1px 2px rgba(17, 21, 30, 0.05), 0 1px 3px rgba(17, 21, 30, 0.04);
  --shadow-md: 0 2px 4px rgba(17, 21, 30, 0.04), 0 6px 16px rgba(17, 21, 30, 0.07);
  --shadow-lg: 0 8px 24px rgba(17, 21, 30, 0.10), 0 2px 6px rgba(17, 21, 30, 0.05);

  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-pill: 999px;

  --sidebar-w: 250px;
  --topbar-h:  62px;
  --content-max: 1120px;

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

  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
  --speed: 160ms;

  color-scheme: light;
}

/* ---------------------------------------------------------------------
   2. Design tokens — dark
   Applied both by system preference and by the explicit toggle.
   --------------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:                #0d0e11;
    --surface:           #15171b;
    --surface-secondary: #1b1e23;
    --surface-hover:     #22262c;
    --surface-sunken:    #101216;

    --text:        #eceef2;
    --text-muted:  #98a0ad;
    --text-subtle: #8b93a1;

    --border:        #262a31;
    --border-strong: #343a43;

    --accent:        #7d97ff;
    --accent-hover:  #94a9ff;
    --accent-text:   #0d0e11;
    --accent-soft:   rgba(125, 151, 255, 0.13);
    --accent-border: rgba(125, 151, 255, 0.30);

    --success:      #3fbd8b;
    --success-soft: rgba(63, 189, 139, 0.13);
    --warning:      #e0a03c;
    --warning-soft: rgba(224, 160, 60, 0.13);
    --danger:       #ee6b6b;
    --danger-soft:  rgba(238, 107, 107, 0.13);
    --info:         #62a8dd;
    --info-soft:    rgba(98, 168, 221, 0.13);
    --neutral-soft: rgba(236, 238, 242, 0.06);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.4), 0 8px 20px rgba(0, 0, 0, 0.32);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg:                #0d0e11;
  --surface:           #15171b;
  --surface-secondary: #1b1e23;
  --surface-hover:     #22262c;
  --surface-sunken:    #101216;

  --text:        #eceef2;
  --text-muted:  #98a0ad;
  --text-subtle: #8b93a1;

  --border:        #262a31;
  --border-strong: #343a43;

  --accent:        #7d97ff;
  --accent-hover:  #94a9ff;
  --accent-text:   #0d0e11;
  --accent-soft:   rgba(125, 151, 255, 0.13);
  --accent-border: rgba(125, 151, 255, 0.30);

  --success:      #3fbd8b;
  --success-soft: rgba(63, 189, 139, 0.13);
  --warning:      #e0a03c;
  --warning-soft: rgba(224, 160, 60, 0.13);
  --danger:       #ee6b6b;
  --danger-soft:  rgba(238, 107, 107, 0.13);
  --info:         #62a8dd;
  --info-soft:    rgba(98, 168, 221, 0.13);
  --neutral-soft: rgba(236, 238, 242, 0.06);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.4), 0 8px 20px rgba(0, 0, 0, 0.32);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);

  color-scheme: dark;
}

/* ---------------------------------------------------------------------
   3. Reset and base
   --------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv05" 1, "ss01" 1;
}

h1, h2, h3, h4 { margin: 0; font-weight: 620; letter-spacing: -0.018em; line-height: 1.25; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0; }

a { color: inherit; text-decoration: none; }

button, input, select, textarea { font: inherit; color: inherit; }

code, kbd, .mono { font-family: var(--font-mono); font-size: 0.86em; }

svg.icon, svg.nav-icon, svg.search-icon { width: 18px; height: 18px; flex: none; }

::selection { background: var(--accent-soft); }

/* Visually hidden but still read by screen readers. NOT the same as the
   HTML hidden attribute, which removes an element from the a11y tree. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

/* ---------------------------------------------------------------------
   4. App shell
   --------------------------------------------------------------------- */
.app { display: flex; min-height: 100vh; }

.main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.content {
  flex: 1 1 auto;
  padding: 30px 34px 72px;
  max-width: calc(var(--content-max) + 68px);
  width: 100%;
  margin: 0 auto;
}

/* --- sidebar --------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 22px;
}

.brand-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--text);
  color: var(--surface);
  display: grid; place-items: center;
  font-weight: 700; font-size: 16px;
  letter-spacing: -0.02em;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text strong { font-size: 13.5px; font-weight: 680; letter-spacing: 0.09em; }
.brand-text span   { font-size: 13.5px; font-weight: 500; letter-spacing: 0.22em; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 570; }
.nav-item.is-active svg { color: var(--accent); }

.sidebar-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }

.avatar {
  width: 32px; height: 32px; flex: none;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 650; letter-spacing: 0.02em;
}

.user-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.user-text strong { font-size: 13.5px; font-weight: 570; }
.user-text span { font-size: 12px; color: var(--text-subtle); }

.logout {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 13.5px;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.logout:hover { background: var(--surface-hover); color: var(--text); }

/* --- topbar ---------------------------------------------------------- */
.topbar {
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 34px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}

.global-search {
  position: relative;
  flex: 1 1 auto;
  max-width: 460px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  height: 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.global-search:focus-within {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.global-search svg { color: var(--text-subtle); }
.global-search input {
  flex: 1; min-width: 0;
  border: 0; background: none; outline: none;
  font-size: 14px;
}
.global-search input::placeholder { color: var(--text-subtle); }
.global-search kbd {
  flex: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 11px;
  color: var(--text-subtle);
  background: var(--surface-secondary);
}

.icon-btn {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

.theme-toggle { margin-left: auto; }
.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun  { display: none; }
  :root:not([data-theme="light"]) .icon-moon { display: block; }
}

.menu-btn { display: none; }
.scrim { display: none; }

/* --- global search dropdown ------------------------------------------ */
.search-results {
  position: absolute;
  top: calc(100% + 8px); left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  max-height: 62vh;
  overflow-y: auto;
  z-index: 50;
}
.search-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-subtle); font-weight: 600;
  padding: 9px 10px 5px;
}
.search-hit {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer;
}
.search-hit:hover, .search-hit.is-highlighted { background: var(--surface-hover); }
.search-hit-body { min-width: 0; flex: 1; }
.search-hit-title { font-size: 13.5px; font-weight: 540; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-hit-meta  { font-size: 12px; color: var(--text-subtle); display: block; }
.search-hit code  { font-size: 11.5px; color: var(--accent); }
.search-empty { padding: 16px 12px; color: var(--text-muted); font-size: 13.5px; text-align: center; }

/* ---------------------------------------------------------------------
   5. Common building blocks
   --------------------------------------------------------------------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 20px; flex-wrap: wrap; margin-bottom: 24px;
}
.eyebrow {
  font-size: 11.5px; font-weight: 620; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-subtle); margin-bottom: 7px;
}
.page-sub { color: var(--text-muted); margin-top: 6px; font-size: 14.5px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px 22px; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 14.5px; font-weight: 600; }
.card-head a  { font-size: 13px; color: var(--accent); font-weight: 520; }

.section { margin-bottom: 28px; }
.section-title {
  font-size: 12px; font-weight: 620; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-subtle); margin-bottom: 12px;
}

.grid { display: grid; gap: 14px; }
.grid-1 { grid-template-columns: minmax(0, 1fr); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }

/* --- stats ----------------------------------------------------------- */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px;
  display: flex; flex-direction: column; gap: 3px;
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 520; }
.stat-value { font-size: 1.42rem; font-weight: 640; letter-spacing: -0.024em; font-variant-numeric: tabular-nums; }
.stat-meta  { font-size: 12px; color: var(--text-subtle); }
.stat-success .stat-value { color: var(--success); }
.stat-danger  .stat-value { color: var(--danger); }
.stat-accent  .stat-value { color: var(--accent); }

/* --- pills and badges ------------------------------------------------ */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: var(--radius-pill);
  font-size: 11.5px; font-weight: 560; letter-spacing: 0.01em;
  white-space: nowrap;
}
.pill-success { background: var(--success-soft); color: var(--success); }
.pill-warning { background: var(--warning-soft); color: var(--warning); }
.pill-danger  { background: var(--danger-soft);  color: var(--danger); }
.pill-info    { background: var(--info-soft);    color: var(--info); }
.pill-neutral { background: var(--neutral-soft); color: var(--text-muted); }

/* --- buttons --------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px; font-weight: 540;
  cursor: pointer;
  transition: background var(--speed) var(--ease), border-color var(--speed) var(--ease),
              transform var(--speed) var(--ease);
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: none; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

/* --- forms ----------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 540; color: var(--text-muted); }
.input, select.input, textarea.input {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.input:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select.input { appearance: none; padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) 18px, calc(100% - 11px) 18px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  padding: 16px 18px; margin-bottom: 18px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
/* A filter that wraps onto its own row must not stretch across the card. */
.filters .field { flex: 1 1 160px; min-width: 140px; max-width: 300px; }
.filters .field-wide { flex: 2 1 260px; max-width: 460px; }

/* --- tables ---------------------------------------------------------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; min-width: 640px; }
table.data th {
  text-align: left;
  font-size: 11.5px; font-weight: 620; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-subtle);
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunken);
  white-space: nowrap;
}
table.data td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 13.8px;
  vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background var(--speed) var(--ease); }
table.data tbody tr:hover { background: var(--surface-secondary); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* The reference-and-date line under a row title must never wrap: it used to
   orphan the year onto its own line and make the row two lines taller. */
table.data td .subtle { white-space: nowrap; }

/* Tables carrying many columns (Jobs, client Recent jobs) get more room and
   scroll inside .table-scroll rather than crushing every column. */
table.data.data-wide  { min-width: 1020px; }
/* The indexed-files table carries ten columns; give them room so client
   names do not wrap to three lines and treble the row height. */
table.data.data-xwide { min-width: 1240px; }
table.data.data-xwide td { white-space: nowrap; }
table.data.data-xwide td:first-child { white-space: normal; }
table.data .strong { font-weight: 570; }
table.data a.row-link { color: var(--text); font-weight: 550; }
table.data a.row-link:hover { color: var(--accent); }
table.data code { color: var(--accent); font-size: 12.5px; }

.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.nowrap { white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }

/* --- empty / loading / error states ---------------------------------- */
.empty {
  text-align: center;
  padding: 54px 24px;
  color: var(--text-muted);
}
.empty-icon {
  width: 46px; height: 46px; margin: 0 auto 14px;
  display: grid; place-items: center;
  border-radius: var(--radius);
  background: var(--surface-secondary);
  color: var(--text-subtle);
}
.empty h3 { font-size: 15px; margin-bottom: 5px; color: var(--text); }
.empty p  { font-size: 13.5px; max-width: 380px; margin: 0 auto; }

.alert {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 13px 16px; border-radius: var(--radius);
  font-size: 13.5px; margin-bottom: 18px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.alert svg { flex: none; margin-top: 1px; }
.alert-danger  { background: var(--danger-soft);  border-color: transparent; color: var(--danger); }
.alert-warning { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.alert-info    { background: var(--info-soft);    border-color: transparent; color: var(--info); }

.skeleton {
  background: linear-gradient(90deg, var(--surface-secondary) 25%, var(--surface-hover) 37%, var(--surface-secondary) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------------------------------------------------------------------
   6. Ask Kingston
   --------------------------------------------------------------------- */
.ask {
  max-width: 780px;
  margin: 0 auto;
  padding-top: 8px;
}

.ask-hero { text-align: center; padding: 26px 0 30px; }
.ask-wordmark {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 12px; font-weight: 640; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--text-subtle);
  margin-bottom: 20px;
}
.ask-wordmark svg { width: 15px; height: 15px; color: var(--accent); }
.ask-hero h1 { font-size: 2rem; letter-spacing: -0.03em; }
.ask-hero p  { color: var(--text-muted); font-size: 1.03rem; margin-top: 8px; }

.ask-form {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  padding: 14px 14px 12px;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.ask-form:focus-within {
  border-color: var(--accent-border);
  box-shadow: var(--shadow-md), 0 0 0 4px var(--accent-soft);
}
.ask-form textarea {
  width: 100%;
  border: 0; background: none; outline: none; resize: none;
  font-size: 15.5px; line-height: 1.55;
  min-height: 56px; max-height: 220px;
  padding: 4px 6px;
}
.ask-form textarea::placeholder { color: var(--text-subtle); }
.ask-form-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-top: 6px;
}
.ask-hint { font-size: 12px; color: var(--text-subtle); }
.ask-send { padding: 8px 16px; }

.ask-examples {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center; margin-top: 20px;
}
.chip {
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: all var(--speed) var(--ease);
}
.chip:hover {
  border-color: var(--accent-border);
  color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

/* --- conversation ---------------------------------------------------- */
.thread { margin-top: 34px; display: flex; flex-direction: column; gap: 30px; }

.turn { animation: rise 300ms var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.turn-question {
  display: flex; gap: 12px; align-items: flex-start;
  margin-bottom: 16px;
}
.turn-question .avatar { width: 28px; height: 28px; font-size: 11px; margin-top: 1px; }
.turn-question p { font-size: 15.5px; font-weight: 540; }

.answer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.answer-body { padding: 22px 24px; }

.answer-headline {
  font-size: 1.55rem; font-weight: 650; letter-spacing: -0.028em;
  margin-bottom: 8px;
}
.answer-summary { font-size: 15px; line-height: 1.6; color: var(--text); }
.answer-summary.no-evidence { color: var(--text-muted); }

.confidence {
  display: inline-flex; align-items: center; gap: 7px;
  margin-top: 16px;
  font-size: 12px; color: var(--text-subtle);
}
.confidence .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-subtle); }
.confidence-high .dot   { background: var(--success); }
.confidence-medium .dot { background: var(--warning); }
.confidence-low .dot    { background: var(--text-subtle); }
.confidence strong { font-weight: 560; color: var(--text-muted); }

/* --- answer blocks --------------------------------------------------- */
.block { margin-top: 20px; }
.block-title {
  font-size: 11.5px; font-weight: 620; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-subtle); margin-bottom: 10px;
}

.fin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.fin-cell { background: var(--surface); padding: 13px 15px; }
.fin-cell span { display: block; font-size: 11.5px; color: var(--text-muted); margin-bottom: 2px; }
.fin-cell strong { font-size: 1.16rem; font-weight: 620; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.fin-cell.is-profit strong { color: var(--success); }
.fin-cell.is-emphasis { background: var(--accent-soft); }
.fin-cell.is-emphasis strong { color: var(--accent); }

.job-block {
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px;
  background: var(--surface-sunken);
  transition: border-color var(--speed) var(--ease), background var(--speed) var(--ease);
}
.job-block:hover { border-color: var(--accent-border); background: var(--surface); }
.job-block-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.job-block-title { font-size: 15px; font-weight: 590; }
.job-block-meta {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  margin-top: 9px; font-size: 12.5px; color: var(--text-muted);
}
.job-block-meta b { font-weight: 560; color: var(--text); }
.job-block-spec {
  margin-top: 11px; padding-top: 11px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-muted);
}

.mini-list { display: flex; flex-direction: column; gap: 6px; }
.mini-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  transition: border-color var(--speed) var(--ease), background var(--speed) var(--ease);
}
.mini-row:hover { border-color: var(--accent-border); background: var(--surface); }
.mini-row-body { flex: 1; min-width: 0; }
.mini-row-title { font-size: 13.8px; font-weight: 545; display: block; }
/* Long file paths must wrap inside the row rather than sliding under
   the pill on its right. */
.mini-row-meta { font-size: 12px; color: var(--text-subtle); display: block; margin-top: 1px;
                 overflow-wrap: anywhere; }
.mini-row .pill { flex: none; align-self: center; }
.mini-row-value { font-size: 13.5px; font-weight: 570; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mini-row-icon {
  width: 30px; height: 30px; flex: none;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  background: var(--surface-secondary); color: var(--text-muted);
}

/* --- sources --------------------------------------------------------- */
.sources {
  border-top: 1px solid var(--border);
  background: var(--surface-sunken);
  padding: 18px 24px 20px;
}
.sources-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px; font-weight: 620; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-subtle); margin-bottom: 12px;
}
.sources-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: 10px; }

.source-card {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 12px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease), transform var(--speed) var(--ease);
}
.source-card:hover {
  border-color: var(--accent-border);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.source-icon {
  width: 32px; height: 32px; flex: none;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  background: var(--surface-secondary);
  color: var(--text-muted);
}
.source-body { min-width: 0; flex: 1; }
.source-type {
  font-size: 10.5px; font-weight: 640; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--text-subtle);
}
.source-title {
  display: block; font-size: 13.4px; font-weight: 545;
  margin-top: 1px; line-height: 1.35;
}
.source-meta { font-size: 11.5px; color: var(--text-subtle); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 8px; }
.source-meta code { color: var(--accent); }
.source-action {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 7px; font-size: 12px; font-weight: 540; color: var(--accent);
}
.source-action svg { width: 13px; height: 13px; }

/* type accents on document icons */
.doc-supplier_invoice, .source-card[data-type="supplier_invoice"] .source-icon { background: var(--warning-soft); color: var(--warning); }
.doc-customer_invoice, .source-card[data-type="customer_invoice"] .source-icon { background: var(--success-soft); color: var(--success); }
.doc-artwork,          .source-card[data-type="artwork"] .source-icon          { background: var(--accent-soft);  color: var(--accent); }
.doc-email,            .source-card[data-type="email"] .source-icon            { background: var(--info-soft);    color: var(--info); }

/* --- follow-ups ------------------------------------------------------ */
.followups { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.followups .chip { font-size: 12.5px; padding: 6px 12px; }

/* --- thinking state -------------------------------------------------- */
.thinking {
  display: flex; align-items: center; gap: 11px;
  padding: 20px 24px; color: var(--text-muted); font-size: 14px;
}
.dots { display: inline-flex; gap: 4px; }
.dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-subtle);
  animation: pulse 1.2s var(--ease) infinite;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 60%, 100% { opacity: 0.25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }

/* ---------------------------------------------------------------------
   7. Documents, clients, jobs
   --------------------------------------------------------------------- */
.doc-card {
  display: flex; align-items: center; gap: 13px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  transition: background var(--speed) var(--ease);
}
.doc-card:last-child { border-bottom: 0; }
.doc-card:hover { background: var(--surface-secondary); }
.doc-icon {
  width: 36px; height: 36px; flex: none;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  background: var(--surface-secondary); color: var(--text-muted);
}
.doc-body { flex: 1; min-width: 0; }
.doc-type { font-size: 10.5px; font-weight: 640; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-subtle); }
.doc-title { display: block; font-size: 14px; font-weight: 540; margin-top: 1px; }
.doc-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--text-subtle); margin-top: 3px; }
.doc-meta code { color: var(--accent); }
.doc-source { color: var(--text-subtle); }
.doc-amount { font-size: 14px; font-weight: 570; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc-open { color: var(--text-subtle); display: flex; }

.entity-card {
  display: flex; flex-direction: column; gap: 12px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease), transform var(--speed) var(--ease);
}
.entity-card:hover { border-color: var(--accent-border); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.entity-head { display: flex; align-items: center; gap: 12px; }
.entity-name { font-size: 15.5px; font-weight: 590; }
.entity-sub { font-size: 12.5px; color: var(--text-subtle); }
.entity-stats { display: flex; gap: 22px; flex-wrap: wrap; }
.entity-stat span { display: block; font-size: 11.5px; color: var(--text-muted); }
.entity-stat strong { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }

.detail-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 20px; flex-wrap: wrap; margin-bottom: 22px;
}
.detail-title { font-size: 1.75rem; letter-spacing: -0.03em; font-weight: 650; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; font-size: 13px; color: var(--text-muted); align-items: center; }
.detail-meta code { color: var(--accent); }

/* Canonical source paths are long and unbroken. */
.spec-box.mono { overflow-wrap: anywhere; }

.spec-box {
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  font-size: 14px; line-height: 1.65;
  color: var(--text);
  white-space: pre-line;
}

.definition { display: grid; grid-template-columns: 150px 1fr; gap: 10px 18px; font-size: 13.8px; }
.definition dt { color: var(--text-muted); }
.definition dd { margin: 0; font-weight: 520; }

.file-preview {
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  font-family: var(--font-mono);
  font-size: 12.6px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 620px;
  overflow: auto;
  color: var(--text-muted);
}

/* ---------------------------------------------------------------------
   8. Connectors
   --------------------------------------------------------------------- */
.connector-card {
  display: flex; flex-direction: column; gap: 14px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  height: 100%;   /* equal-height cards in the grid */
}
.connector-top { display: flex; align-items: flex-start; gap: 13px; }
.connector-icon {
  width: 40px; height: 40px; flex: none;
  border-radius: var(--radius);
  display: grid; place-items: center;
  background: var(--surface-secondary); color: var(--text-muted);
}
.connector-name { font-size: 15px; font-weight: 590; }
.connector-desc { font-size: 12.8px; color: var(--text-muted); margin-top: 2px; }
.connector-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding-top: 13px; border-top: 1px solid var(--border);
  margin-top: auto;   /* aligns the status line and button across the row */
}
.connector-sync { font-size: 12px; color: var(--text-subtle); }

/* ---------------------------------------------------------------------
   9. Login
   --------------------------------------------------------------------- */
.login-page {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 24px;
  background: var(--bg);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 34px 32px 28px;
}
.login-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 26px; }
.login-card h1 { font-size: 1.32rem; margin-bottom: 5px; }
.login-card .page-sub { margin-bottom: 22px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form .btn { width: 100%; padding: 10px; margin-top: 4px; }
.login-note {
  margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-subtle); line-height: 1.7;
}
.login-note code { color: var(--accent); }

/* ---------------------------------------------------------------------
   10. Responsive
   --------------------------------------------------------------------- */
@media (max-width: 1080px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform 220ms var(--ease);
    box-shadow: var(--shadow-lg);
  }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .scrim {
    display: block; position: fixed; inset: 0; z-index: 35;
    background: rgba(8, 10, 14, 0.4);
  }
  .menu-btn { display: grid; }
  .topbar { padding: 0 16px; }
  .content { padding: 22px 16px 60px; }
  .global-search kbd { display: none; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .definition { grid-template-columns: 1fr; gap: 2px 0; }
  .definition dd { margin-bottom: 10px; }
  .ask-hero h1 { font-size: 1.62rem; }
  .answer-headline { font-size: 1.32rem; }
  .answer-body { padding: 18px; }
  .sources { padding: 16px 18px; }
}

@media (max-width: 520px) {
  .ask-examples { flex-direction: column; }
  .chip { text-align: left; }
  .page-head { align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  .sidebar, .topbar, .ask-form, .ask-examples, .followups { display: none !important; }
  .content { padding: 0; }
}

/* --- Sign-in alternatives (magic link) ------------------------------ */
.btn-block { display: flex; width: 100%; justify-content: center; }
.login-alt { margin-top: 18px; }
.login-alt-rule { display: flex; align-items: center; gap: 10px; margin: 0 0 12px;
  color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.login-alt-rule::before, .login-alt-rule::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.login-alt .btn-ghost { border: 1px solid var(--border); }
.login-alt .btn-ghost:hover { border-color: var(--border-strong, var(--border)); }

/* --- Two-factor setup ---------------------------------------------- */
.tfa-grid { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: start; }
@media (max-width: 720px) { .tfa-grid { grid-template-columns: 1fr; } }
.tfa-qr { background: #fff; padding: 12px; border-radius: 10px; border: 1px solid var(--border);
  line-height: 0; display: inline-block; }
.tfa-secret { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px;
  letter-spacing: .08em; background: var(--surface-hover); padding: 10px 12px;
  border-radius: 8px; display: inline-block; user-select: all; }
.tfa-codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 14px 0; }
.tfa-code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px;
  background: var(--surface-hover); padding: 10px 12px; border-radius: 8px; text-align: center;
  letter-spacing: .06em; user-select: all; }
.tfa-code.is-used { opacity: .45; text-decoration: line-through; }

.btn-danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
