:root {
  color-scheme: light;
  font-family: var(--app-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
  color: #202a38;
  background: #f3f5f8;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

html[data-theme="dark"] {
  color-scheme: dark;
  color: #e2e8f0;
  background: #151a22;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: #f3f5f8; }
a { color: #185ba4; text-decoration: none; }
a:hover { text-decoration: underline; }
.auth-topbar {
  min-height: 60px;
  padding: 0 max(20px, calc((100% - 1500px) / 2));
  display: flex;
  align-items: center;
  background: #172b4d;
  color: #fff;
}
.auth-topbar .theme-toggle { margin-left: auto; color: #e7edf7; }
.brand { color: #fff; font-size: 19px; font-weight: 800; letter-spacing: .07em; }
.brand:hover { text-decoration: none; }
.workspace-body { min-height: 100vh; }
.workspace { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex: 0 0 248px;
  flex-direction: column;
  height: 100vh;
  padding: 22px 14px 14px;
  background: #172b4d;
  color: #dce5f2;
}
.sidebar .brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 26px; font-size: 16px; }
.brand-mark { display: grid; width: 36px; height: 36px; place-items: center; border: 1px solid #7189a8; border-radius: 10px; color: #fff; font-size: 18px; letter-spacing: 0; }
.sidebar .brand small { display: block; margin-top: 3px; color: #9db0ca; font-size: 9px; font-weight: 650; letter-spacing: .12em; }
.sidebar-caption { padding: 0 11px 8px; color: #91a5c2; font-size: 10px; font-weight: 750; letter-spacing: .12em; }
.sidebar-caption-spaced { margin-top: 25px; }
.sidebar-nav { display: grid; gap: 4px; }
.nav-item { display: flex; min-height: 42px; align-items: center; gap: 11px; padding: 8px 11px; border-radius: 7px; color: #dce5f2; font-size: 13px; font-weight: 580; }
.nav-item:hover { background: #ffffff12; color: #fff; text-decoration: none; }
.nav-item.active { background: #2f4d73; color: #fff; box-shadow: inset 3px 0 #83b9eb; }
.nav-icon { display: grid; width: 20px; place-items: center; color: #aac0dc; font-size: 17px; }
.nav-item.active .nav-icon { color: #fff; }
.sidebar-bottom { display: flex; align-items: center; gap: 8px; margin-top: auto; padding: 13px 10px 4px; border-top: 1px solid #ffffff20; color: #a8b8ce; font-size: 11px; }
.connection-indicator { width: 7px; height: 7px; border-radius: 50%; background: #69c48a; box-shadow: 0 0 0 3px #69c48a20; }
.workspace-main { display: flex; min-width: 0; flex: 1; flex-direction: column; }
.workspace-topbar { position: sticky; top: 0; z-index: 5; display: flex; min-height: 60px; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 26px; border-bottom: 1px solid #e1e6ed; background: #fff; }
.workspace-location { display: flex; align-items: center; gap: 9px; color: #8490a0; font-size: 12px; font-weight: 600; }
.workspace-location strong { color: #29364a; font-size: 13px; }
.location-separator { color: #c1c9d3; }
.workspace-actions, .workspace-actions form { display: flex; align-items: center; gap: 8px; }
.workspace-actions .button { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.appearance-menu { position: relative; }
.appearance-menu summary { list-style: none; }
.appearance-menu summary::-webkit-details-marker { display: none; }
.appearance-menu summary::after { content: " ▾"; font-size: 10px; }
.appearance-panel { position: absolute; z-index: 10; top: calc(100% + 9px); right: 0; display: grid; width: 220px; gap: 12px; padding: 14px; border: 1px solid #d5dde7; border-radius: 9px; background: #fff; box-shadow: 0 10px 28px #172b4d24; }
.appearance-panel label { gap: 6px; }
.appearance-panel input[type="color"] { min-height: 38px; padding: 4px; cursor: pointer; }
.appearance-panel .button { width: 100%; }
.auth-topbar .appearance-menu { margin-left: 10px; }
.auth-topbar .appearance-panel { color: #202a38; text-align: left; }
.user-name { margin-left: 8px; color: #4a586b; font-size: 13px; font-weight: 650; }
.page { width: min(1600px, 100%); margin: 0 auto; padding: 24px 26px 32px; flex: 1; }
.footer { padding: 12px 20px; text-align: center; font-size: 11px; color: #8a94a2; }
.auth-layout { min-height: calc(100vh - 60px); display: flex; flex-direction: column; }
.auth-layout .page { width: min(1500px, 100%); flex: 1; }
.page-heading { display: flex; gap: 16px; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.heading-actions { display: flex; flex-wrap: wrap; gap: 8px; }
h1 { margin: 0; font-size: clamp(24px, 3vw, 32px); }
.eyebrow { color: #718096; font-size: 11px; font-weight: 750; letter-spacing: .12em; margin: 0 0 6px; }
.muted { color: #697587; line-height: 1.5; }
.button { display: inline-flex; min-height: 38px; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 8px; padding: 8px 13px; font: inherit; font-size: 14px; font-weight: 650; cursor: pointer; text-decoration: none; }
.button:hover { text-decoration: none; filter: brightness(.97); }
.button-primary { background: #1769aa; color: #fff; }
.button-secondary { background: #e8eef5; border-color: #d3dce8; color: #253852; }
.button-quiet { background: transparent; color: inherit; }
.button-danger { background: #fff0ef; border-color: #f2c9c5; color: #a22d25; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.summary-card { display: flex; flex-direction: column; gap: 7px; background: #fff; border: 1px solid #e1e6ed; border-radius: 10px; padding: 14px 16px; box-shadow: 0 2px 6px #20304708; }
.summary-card span { font-size: 13px; color: #6a7688; }
.summary-card strong { font-size: 20px; }
.filters { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; background: #fff; border: 1px solid #e1e6ed; border-radius: 10px; padding: 12px; margin-bottom: 12px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: #465469; }
input, select, textarea { min-height: 38px; width: 100%; padding: 8px 10px; border: 1px solid #cbd4df; border-radius: 7px; background: #fff; color: #202a38; font: inherit; font-size: 14px; }
input:focus, select:focus, textarea:focus { outline: 3px solid #c5e1fa; border-color: #438fc8; }
.search-label { flex: 1 1 280px; max-width: 520px; }
.bulk-bar { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; padding: 10px 12px; background: #eaf0f6; border: 1px solid #dce4ee; border-bottom: 0; border-radius: 10px 10px 0 0; font-size: 13px; color: #445267; }
.bulk-select { min-width: 190px; }
.table-wrap { width: 100%; overflow: auto; background: #fff; border: 1px solid #dfe5ec; border-radius: 0 0 10px 10px; }
table { width: 100%; min-width: 1380px; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 9px; border-bottom: 1px solid #e9edf2; text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 1; background: #f4f6f9; color: #4a586b; font-size: 12px; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f7faff; }
.sort-link { color: inherit; }
.sort-link:hover { color: #1769aa; text-decoration: none; }
.check-cell { width: 38px; text-align: center; }
.check-cell input { width: 16px; min-height: 16px; height: 16px; margin: 0; accent-color: #1769aa; }
.part-name { min-width: 250px; max-width: 350px; font-weight: 650; }
.external-link { display: block; margin-top: 4px; font-size: 11px; font-weight: 500; }
.numeric { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.status-label { display: inline-block; border-radius: 20px; padding: 4px 8px; white-space: nowrap; font-size: 11px; font-weight: 700; }
td .status-label { color: #34516e; background: #edf2f7; }
.table-action { white-space: nowrap; }
.empty-state { padding: 36px; text-align: center; color: #758195; }
.table-hint { color: #748093; font-size: 12px; margin: 9px 2px; }
.flash-list { display: grid; gap: 8px; margin-bottom: 14px; }
.flash { border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.flash-success { color: #205a3a; background: #e3f4e9; }
.flash-error { color: #8c2823; background: #fde9e7; }
.flash-info { color: #35536e; background: #e8f1fa; }
.auth-card { width: min(460px, 100%); margin: 6vh auto; padding: 28px; background: #fff; border: 1px solid #e1e6ed; border-radius: 14px; box-shadow: 0 12px 35px #172b4d12; }
.auth-card h1 { margin-bottom: 10px; }
.form-stack { display: grid; gap: 15px; margin-top: 18px; }
.form-stack .button { width: 100%; margin-top: 3px; }
.setup-card { width: min(600px, 100%); margin-top: 2vh; }
.setup-user { display: grid; gap: 12px; padding: 15px; background: #f7f9fb; border: 1px solid #e6ebf0; border-radius: 9px; }
.setup-user h2 { margin: 0; font-size: 16px; }
.part-form { padding: 20px; background: #fff; border: 1px solid #e1e6ed; border-radius: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.form-grid .wide { grid-column: 1 / -1; }
.field-hint { color: #788496; font-size: 11px; font-weight: 450; line-height: 1.4; }
textarea { resize: vertical; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.compact-table { min-width: 720px; }
.section-title { margin: 24px 0 10px; font-size: 19px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.sale-entry-table { min-width: 760px; }
.sale-entry-table input, .sale-entry-table select { min-width: 125px; }
.sale-entry-table td:first-child { min-width: 300px; }
.sale-entry-table .sale-part-search { margin-bottom: 5px; }
.nikita-card { margin-top: 12px; width: min(420px, 100%); }
.sale-meta { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.sale-meta .summary-card strong { font-size: 16px; overflow-wrap: anywhere; }

html[data-theme="dark"] body { color: #e2e8f0; background: #151a22; }
html[data-theme="dark"] .workspace-topbar,
html[data-theme="dark"] .summary-card,
html[data-theme="dark"] .filters,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .part-form,
html[data-theme="dark"] .auth-card,
html[data-theme="dark"] .appearance-panel { background: #202733; border-color: #394454; }
html[data-theme="dark"] .workspace-topbar { border-bottom-color: #394454; }
html[data-theme="dark"] .workspace-location strong,
html[data-theme="dark"] .user-name,
html[data-theme="dark"] label { color: #d7dfeb; }
html[data-theme="dark"] .summary-card span,
html[data-theme="dark"] .muted,
html[data-theme="dark"] .table-hint,
html[data-theme="dark"] .footer,
html[data-theme="dark"] .field-hint { color: #a4afbf; }
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea { color: #e2e8f0; background: #171d26; border-color: #4a5668; }
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #8793a4; }
html[data-theme="dark"] input:focus,
html[data-theme="dark"] select:focus,
html[data-theme="dark"] textarea:focus { outline-color: #315a7c; border-color: #63a8df; }
html[data-theme="dark"] th { color: #c4cfdd; background: #28313e; }
html[data-theme="dark"] th,
html[data-theme="dark"] td { border-bottom-color: #343e4c; }
html[data-theme="dark"] tbody tr:hover { background: #283444; }
html[data-theme="dark"] td .status-label { color: #d2deeb; background: #344253; }
html[data-theme="dark"] .button-secondary { color: #dce5f2; background: #303b4a; border-color: #465366; }
html[data-theme="dark"] .button-quiet { color: #dce5f2; }
html[data-theme="dark"] .bulk-bar { color: #d5deea; background: #252f3c; border-color: #3a4656; }
html[data-theme="dark"] .bulk-bar label { color: #d5deea; }
html[data-theme="dark"] .bulk-bar .button-quiet { color: #c7d8eb; }
html[data-theme="dark"] .bulk-bar .button-quiet:hover { background: #344356; }
html[data-theme="dark"] .auth-card h1,
html[data-theme="dark"] h1,
html[data-theme="dark"] .section-title { color: #edf2f8; }
html[data-theme="dark"] .setup-user { background: #252e3a; border-color: #3c4858; }
html[data-theme="dark"] .flash-success { color: #a6e2b9; background: #1d3a2b; }
html[data-theme="dark"] .flash-error { color: #ffc0ba; background: #482b2c; }
html[data-theme="dark"] .flash-info { color: #b7d7f4; background: #26394d; }
html[data-theme="dark"] .auth-topbar { background: #121f35; }
html[data-theme="dark"] .status-label { border: 1px solid #536278; }
html[data-theme="dark"] .empty-state { color: #a4afbf; }
html[data-theme="dark"] .appearance-panel { color: #e2e8f0; }
.page { color: var(--app-font-color, #202a38); }
.page :is(h1, h2, h3, p, label, th, td, strong, span):not(.eyebrow):not(.status-label) { color: var(--app-font-color, #202a38); }
.footer { color: var(--app-font-color, #8a94a2); }

@media (max-width: 700px) {
  .auth-topbar { min-height: 54px; padding: 0 14px; }
  .workspace { display: block; }
  .sidebar { position: sticky; z-index: 6; top: 0; width: 100%; height: auto; padding: 9px 12px 8px; }
  .sidebar .brand { padding: 0 3px 8px; font-size: 14px; }
  .brand-mark { width: 29px; height: 29px; font-size: 15px; }
  .sidebar .brand small, .sidebar-caption, .sidebar-bottom { display: none; }
  .sidebar-nav { display: flex; gap: 5px; overflow-x: auto; padding-bottom: 1px; }
  .sidebar-caption-spaced { display: none; }
  .nav-item { min-height: 34px; flex: 0 0 auto; gap: 6px; padding: 6px 9px; font-size: 11px; }
  .nav-icon { width: auto; font-size: 14px; }
  .workspace-topbar { position: static; min-height: 48px; gap: 8px; padding: 7px 12px; }
  .workspace-location { font-size: 10px; }
  .workspace-location strong { font-size: 11px; }
  .workspace-actions { flex-wrap: wrap; gap: 4px; }
  .workspace-actions .button { min-height: 31px; padding: 5px 7px; font-size: 10px; }
  .workspace-actions .theme-toggle { padding-right: 5px; padding-left: 5px; }
  .appearance-panel { right: 0; width: min(220px, calc(100vw - 24px)); }
  .user-name { display: none; }
  .page { padding: 18px 12px 24px; }
  .page-heading { align-items: flex-start; }
  .page-heading > .button { padding: 8px 10px; font-size: 12px; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .sale-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-card { padding: 11px; }
  .summary-card strong { font-size: 18px; }
  .filters { align-items: stretch; }
  .filters > label, .filters > .button { flex: 1 1 100%; max-width: none; }
  .bulk-bar > * { flex: 1 1 100%; }
  .bulk-select { min-width: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .part-form { padding: 14px; }
  .auth-card { margin: 4vh auto; padding: 21px; }
}

@media (min-width: 701px) and (max-width: 980px) {
  .sidebar { flex-basis: 210px; padding-right: 10px; padding-left: 10px; }
  .workspace-topbar { padding-right: 16px; padding-left: 16px; }
  .page { padding-right: 16px; padding-left: 16px; }
  .user-name { display: none; }
}
