/* Printman visual refinement — Ledger Authority, screen only.
   Deep indigo structure, porcelain paper, hairline rules, amber used only as signal. */

@media screen {
  :root {
    --state-hover: color-mix(in oklch, var(--primary) 7%, var(--surface));
    --state-active: color-mix(in oklch, var(--primary) 13%, var(--surface));
    --focus-ring: color-mix(in oklch, var(--primary) 78%, black);
    --shadow-sheet: 0 2px 4px oklch(0.20 0.04 263 / 0.10), 0 24px 60px oklch(0.20 0.04 263 / 0.20);
    --shadow-menu: 0 10px 28px oklch(0.20 0.04 263 / 0.18);
    --rule: color-mix(in oklch, var(--primary) 18%, var(--border));
  }

  body {
    background: var(--bg);
  }

  /* Controls: precise state feedback, no lifted-card theatrics. */
  .button {
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 -1px 0 oklch(0.20 0.04 263 / 0.07);
    transition: background-color var(--state-change), border-color var(--state-change), color var(--state-change), transform var(--state-change);
  }

  .button:hover {
    background: var(--state-hover);
    border-color: var(--border-strong);
  }

  .button-primary:hover,
  .button-danger:hover {
    filter: brightness(1.08);
  }

  .button:active,
  .icon-button:active,
  .chip:active {
    transform: translateY(1px);
  }

  .button:disabled:hover {
    background: var(--surface);
    transform: none;
    filter: none;
  }

  .button-primary:disabled:hover {
    background: var(--primary);
  }

  .icon-button:hover {
    background: var(--state-hover);
    border-color: var(--border-strong);
    color: var(--primary);
  }

  input:hover:not(:disabled),
  select:hover:not(:disabled),
  textarea:hover:not(:disabled) {
    border-color: var(--border-strong);
  }

  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 0;
    border-color: var(--primary);
    background: var(--surface);
  }

  /* Navigation: a ruled spine with amber thread marks. */
  .sidebar-head {
    position: relative;
  }

  .sidebar-head::after {
    content: "";
    position: absolute;
    right: var(--space-4);
    bottom: -1px;
    width: 24px;
    height: 2px;
    background: var(--warning);
  }

  .side-nav::before,
  .sidebar-foot::before {
    content: "Sections";
    padding: 0 var(--space-3) 6px;
    color: var(--rail-muted);
    font-size: 0.625rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
  }

  .sidebar-foot::before { content: "Workspace"; }

  .nav-item {
    letter-spacing: 0.005em;
  }

  .nav-item:hover {
    background: var(--rail-active);
    color: var(--rail-ink);
  }

  .nav-item:active {
    background: color-mix(in oklch, var(--rail-active) 80%, white);
  }

  .nav-item.is-active {
    background: var(--rail-active);
    color: var(--rail-ink);
  }

  .nav-item.is-active svg { color: var(--rail-ink); }

  .topbar {
    border-bottom-color: var(--rule);
  }

  .topbar h1 {
    font-family: var(--font-display);
    letter-spacing: -0.02em;
  }

  .sync-status {
    border-color: var(--rule);
    border-radius: var(--radius-sm);
  }

  /* Metrics: ledger tape, not a wall of KPI cards. */
  .stat-strip {
    background: color-mix(in oklch, var(--surface) 55%, transparent);
  }

  button.stat {
    width: 100%;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
  }

  button.stat:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: -2px;
    background: var(--state-hover);
  }

  button.stat[data-value="cash"]:focus-visible {
    outline-color: var(--success);
    box-shadow: inset 3px 0 0 var(--success);
  }

  button.stat[data-value="production"]:focus-visible {
    outline-color: var(--primary);
    box-shadow: inset 3px 0 0 var(--primary);
  }

  button.stat[data-value="pipeline"]:focus-visible {
    outline-color: var(--info);
    box-shadow: inset 3px 0 0 var(--info);
  }

  button.stat[data-value="documents"]:focus-visible {
    outline-color: var(--danger);
    box-shadow: inset 3px 0 0 var(--danger);
  }

  button.stat[data-value="goals"]:focus-visible {
    outline-color: var(--warning-ink);
    box-shadow: inset 3px 0 0 var(--warning);
  }

  .stat-label {
    color: var(--muted);
  }

  .stat-value {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.03em;
  }

  .stat-note {
    color: var(--muted);
  }

  .stat.is-danger .stat-value { color: var(--danger); }
  .stat.is-success .stat-value { color: var(--success); }

  .overview-grid.is-focused {
    grid-template-columns: minmax(0, 1fr);
  }

  .overview-main > .panel:first-child .panel-head,
  .overview-side > .panel:first-child .panel-head,
  .page-stack > .panel:first-of-type .panel-head {
    box-shadow: inset 3px 0 0 var(--primary);
  }

  .panel {
    background: var(--surface);
    border-color: var(--border);
  }

  .panel-head {
    background: color-mix(in oklch, var(--surface) 88%, var(--bg));
  }

  .panel-head h2 { font-family: var(--font-display); }

  .data-table thead th {
    position: sticky;
    top: 57px;
    z-index: 1;
    background: var(--surface-strong);
    border-bottom: 1px solid var(--border-strong);
  }

  .data-table tbody tr:hover {
    background: var(--state-hover);
  }

  .data-table tbody tr:last-child td { border-bottom: 0; }

  .list-title { font-weight: 680; }
  .list-meta { color: var(--muted); }

  .badge { letter-spacing: 0.04em; }

  .progress {
    background: var(--surface-strong);
  }

  .progress > span {
    background: var(--primary);
  }

  .insight-grid .alert {
    border-left-width: 3px;
  }

  .alert-mark {
    background: var(--ink);
    color: var(--surface);
  }

  .chip.is-active {
    box-shadow: inset 0 -2px 0 oklch(0.20 0.04 263 / 0.28);
  }

  /* Decision layer: compact, ruled insight bands rather than KPI cards. */
  .insight-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    border-top: 1px solid var(--border-strong);
    border-bottom: 1px solid var(--border-strong);
    background: color-mix(in oklch, var(--surface) 60%, transparent);
  }

  .insight-cell {
    display: grid;
    gap: 3px;
    min-width: 0;
    padding: 0.75rem 1rem;
    border-right: 1px solid var(--border);
  }

  .insight-cell:first-child { padding-left: 0; }
  .insight-cell:last-child { border-right: 0; }

  .insight-label {
    color: var(--muted);
    font-size: 0.625rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }

  .insight-value {
    min-width: 0;
    overflow: hidden;
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .insight-note {
    overflow: hidden;
    color: var(--muted);
    font-size: var(--text-xs);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .insight-cell.is-danger .insight-value { color: var(--danger); }
  .insight-cell.is-warning .insight-value { color: var(--warning-ink); }
  .insight-cell.is-success .insight-value { color: var(--success); }

  .decision-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 0.75rem 1rem;
    border: 1px solid var(--rule);
    background: var(--surface);
    color: var(--muted);
    font-size: var(--text-sm);
  }

  .decision-line strong { color: var(--ink); }
  .decision-line .button { min-height: 34px; }

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

  .rank-row {
    display: grid;
    gap: 5px;
    min-width: 0;
  }

  .rank-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    min-width: 0;
  }

  .rank-name {
    min-width: 0;
    overflow: hidden;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .rank-value {
    flex: 0 0 auto;
    font-variant-numeric: tabular-nums;
  }

  .rank-value.is-warning { color: var(--warning-ink); }

  .rank-track {
    height: 5px;
    overflow: hidden;
    background: var(--surface-strong);
  }

  .rank-fill {
    display: block;
    height: 100%;
    background: var(--primary);
    transition: width 160ms var(--ease-out);
  }

  .rank-fill.is-warning { background: var(--warning); }

  .rank-note {
    color: var(--muted);
    font-size: var(--text-xs);
  }

  /* Dialogs and menus: one elevation, one dark top rule. */
  .sheet-dialog {
    box-shadow: var(--shadow-sheet);
    animation: sheet-enter 180ms var(--ease-out) both;
  }

  .sheet-dialog[open] {
    animation: sheet-enter 180ms var(--ease-out) both;
  }

  .sheet-dialog::backdrop {
    background: oklch(0.18 0.035 263 / 0.58);
    animation: backdrop-enter 140ms ease-out both;
  }

  .sheet-head {
    border-bottom-color: var(--rule);
  }

  .more-menu {
    box-shadow: var(--shadow-menu);
    border-color: var(--border-strong);
    animation: menu-enter 140ms var(--ease-out) both;
  }

  .more-menu button:hover {
    background: var(--state-hover);
    color: var(--primary);
  }

  .more-menu button:active {
    background: var(--state-active);
  }

  .toast {
    border-color: var(--rail-edge);
  }

  /* Typography rhythm: dense controls, authoritative display figures. */
  body { line-height: 1.48; }
  h1, h2 { text-wrap: balance; }
  h1 { font-weight: 600; }
  h2 { font-weight: 600; }
  p, li, small { font-kerning: normal; }
  input, select, textarea, .stat-value, .doc-total-row, .line-items td, .money {
    font-variant-numeric: lining-nums tabular-nums;
  }
  .eyebrow { letter-spacing: 0.1em; }
  .badge { letter-spacing: 0.04em; }

  /* Mobile navigation: current tab marker and clear pressed state. */
  .bottom-nav {
    background: var(--rail);
    border-top-color: var(--rail-edge);
  }

  .bottom-item.is-active { color: var(--rail-ink); }
  .bottom-item:active { background: var(--rail-active); }

  /* Auth: indigo folio on the left, porcelain account card on the right. */
  .auth-panel { position: relative; }

  .auth-intro h1 {
    color: var(--rail-ink);
    font-weight: 600;
  }

  .auth-intro p:last-child {
    color: var(--rail-muted);
  }

  .auth-footer { color: var(--muted); }

  .auth-tab {
    border-bottom-color: transparent;
    color: var(--muted);
  }

  .auth-tab.is-active {
    border-bottom-color: var(--primary);
    color: var(--ink);
  }

  .auth-tab:hover { color: var(--ink); }

  @keyframes sheet-enter {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
  }

  @keyframes backdrop-enter {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  @keyframes menu-enter {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* Data visualisations: quiet, measurable, never celebratory. */
  .money-flow {
    position: relative;
    margin-top: var(--space-3);
  }

  .money-flow svg {
    width: 100%;
    height: clamp(28px, 4vw, 40px);
    display: block;
  }

  .money-flow-labels {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    margin-top: var(--space-2);
    font-size: 0.6875rem;
    color: var(--muted);
  }

  .flow-label {
    display: grid;
    gap: 2px;
    justify-items: center;
  }

  .flow-date { font-weight: 700; color: var(--ink); }
  .flow-dir { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .margin-viz-header {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
    margin-top: var(--space-3);
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

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

  .margin-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: var(--space-3);
    align-items: center;
  }

  .margin-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    min-width: 0;
  }

  .margin-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .margin-amount { font-variant-numeric: tabular-nums; }

  .margin-track {
    position: relative;
    grid-column: 1 / -1;
    height: 5px;
    border-radius: 0;
    background: var(--surface-strong);
    overflow: hidden;
  }

  .margin-track::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 1px;
    background: var(--border-strong);
  }

  .margin-fill {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 0;
    border-radius: 0;
    transition: width 140ms var(--ease-out);
  }

  .margin-fill.is-positive { background: var(--success); }
  .margin-fill.is-negative { right: 50%; left: auto; background: var(--danger); }

  .alert[data-action] { cursor: pointer; }
  .alert[data-action]:hover { background: var(--surface-strong); }

  .doc-search {
    min-width: 180px;
    border-radius: var(--radius-sm);
  }

  .sync-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid color-mix(in oklch, var(--danger) 30%, var(--border));
    border-left: 3px solid var(--danger);
    background: var(--danger-soft);
    color: var(--danger);
    font-size: var(--text-sm);
    font-weight: 650;
  }

  .sync-banner.is-warning {
    background: var(--warning-soft);
    border-bottom-color: color-mix(in oklch, var(--warning) 40%, var(--border));
    border-left-color: var(--warning);
    color: var(--warning-ink);
  }

  .sync-banner-actions { display: flex; gap: var(--space-2); }

  @media (min-width: 768px) {
    .overview-side {
      padding-left: var(--space-5);
      border-left: 1px solid var(--border);
    }

    .overview-grid.is-focused .overview-side {
      padding-left: 0;
      border-left: 0;
    }
  }

  @media (max-width: 767px) {
    .auth-screen { background: var(--bg); }
    .auth-intro,
    .auth-intro p:last-child { color: var(--ink); }
    .auth-kicker { color: var(--primary); }
  }

  @media (max-width: 700px) {
    .topbar { padding-inline: var(--space-3); }
    .stat-strip { border-radius: 0; }
    .stat { padding: 0.75rem 0.875rem; }
    .stat:first-child { padding-left: 0.875rem; }
    .stat-value { font-size: 1.5rem; }
    .data-table thead th { position: static; }

    .insight-strip { grid-template-columns: 1fr 1fr; }
    .insight-cell { padding: 0.625rem 0.75rem; }
    .insight-cell:nth-child(2n) { border-right: 0; }
    .insight-cell:nth-last-child(-n + 2) { border-bottom: 0; }
    .insight-value { font-size: 1rem; }
    .decision-line { padding: 0.625rem 0.75rem; }
    .decision-line .button { width: 100%; }
  }

  @media (max-width: 420px) {
    .insight-strip { grid-template-columns: 1fr; }
    .insight-cell { border-right: 0; border-bottom: 1px solid var(--border); }
    .insight-cell:last-child { border-bottom: 0; }
  }

  @media (max-width: 360px) {
    .stat-value { font-size: 1.25rem; overflow-wrap: anywhere; }
    .insight-value { font-size: 1rem; }
  }

  @media (prefers-reduced-motion: reduce) {
    .sheet-dialog,
    .sheet-dialog[open],
    .sheet-dialog::backdrop,
    .more-menu { animation: none; }
    .button:active,
    .icon-button:active,
    .chip:active { transform: none; }
  }
}
