:root {
  color-scheme: light;
  --ink: #203846;
  --muted: #556a79;
  --navy: #182e3f;
  --primary: #2f526b;
  --gold: #c49b53;
  --line: #d6e1e8;
  --input-line: #bfced9;
  --paper: #fff;
  --bg: #eef3f7;
  --subtle: #f6f9fb;
  --table-head: #eaf0f4;
  --pale: #fff8ed;
  --red: #963f34;
  --radius: 6px;
  color: var(--ink);
  background: var(--bg);
  font: 14px/1.5 "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box }
body { margin: 0 }
body:has(dialog[open]) { overflow: hidden }
button, input, select, textarea { font: inherit }
a { color: var(--primary); text-underline-offset: 3px }
button { cursor: pointer }
button:disabled { cursor: default }
[hidden] { display: none !important }
:focus-visible { outline: 2px solid #49738c; outline-offset: 2px }

.top {
  position: sticky;
  top: 0;
  z-index: 4;
  background: var(--navy);
  border-bottom: 2px solid #a78448;
  color: #fff;
}
.top-inner {
  display: flex;
  align-items: center;
  gap: 28px;
  min-height: 73px;
  max-width: 1440px;
  margin: auto;
  padding: 9px clamp(14px, 3vw, 32px);
}
.brand { display: flex; align-items: center; gap: 12px; flex: none }
.brand img { display: block; object-fit: contain; width: 45px; height: 45px }
.brand strong, .brand span { display: block }
.brand strong { font-size: 17px; letter-spacing: .05em; line-height: 1.25 }
.brand span { margin-top: 3px; color: #cddae4; font-size: 12px }
nav, .actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap }
.top nav { flex: 1; flex-wrap: nowrap; min-width: 0; gap: 3px; overflow-x: auto; scrollbar-width: thin }
.top nav button {
  flex: none;
  display: block;
  min-height: 44px;
  color: #d2dee7;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 9px 13px 7px;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
}
.top nav button:hover { color: #fff; background: #294558 }
.top nav button[aria-current="page"] { color: #fff; background: #233f53; border-bottom-color: var(--gold) }
.top button:focus-visible { outline-color: var(--gold); outline-offset: -3px }
#identity { flex: none; min-width: 0; max-width: 180px; font-size: 13px; text-align: right }
.identity-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.identity-role { color: #d8c49d; font-size: 11px }

main { max-width: 1440px; margin: auto; padding: 25px clamp(12px, 3vw, 32px) 45px }
.heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 17px;
}
.heading > div { min-width: 0 }
.heading h1 { margin: 0; overflow-wrap: anywhere }
.heading p { margin: 4px 0 0; overflow-wrap: anywhere }
h1 { color: var(--navy); font-size: 28px; font-weight: 700; line-height: 1.24 }
h2, h3 { color: var(--navy); line-height: 1.3 }
h2 { font-size: 17px; margin: 0 0 12px }
h3 { font-size: 14px; margin: 10px 0 6px }
.muted { color: var(--muted) }
.small { font-size: 12px }
.eyebrow { color: var(--primary); font-size: 12px; font-weight: 700; letter-spacing: .05em }
.badge {
  display: inline-block;
  vertical-align: baseline;
  padding: 2px 6px;
  border: 1px solid #d5e0e7;
  border-radius: 3px;
  background: var(--subtle);
  color: #36556a;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}
.badge.success { background: #f0f7f2; color: #26603f; border-color: #cfe1d5 }
.badge.pending { background: var(--pale); color: #764d1c; border-color: #eedcc3 }
.badge.inactive { color: #535f68 }
.warning { background: var(--pale); color: #70471f; border: 1px solid #ebd6b9; border-left: 3px solid var(--gold); border-radius: 3px; padding: 10px 13px }

.panel {
  min-width: 0;
  margin: 0 0 14px;
  padding: clamp(12px, 1.6vw, 20px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}
.login { max-width: 420px; margin: 28px auto; padding: 26px }
.login h1 { font-size: 23px; margin: 0 0 4px }
.login > p { margin: 0 0 18px }
.login form .btn { width: 100% }
.stack { display: grid; gap: 12px }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(155px, 100%), 1fr)); align-items: end }
.two { grid-template-columns: repeat(2, minmax(0, 1fr)) }
#project { grid-template-columns: repeat(3, minmax(0, 1fr)) }
.wide { grid-column: 1 / -1 }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 12px }
.panel-head h2 { margin: 0 }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 37px;
  padding: 7px 12px;
  border: 1px solid var(--primary);
  border-radius: 5px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}
.btn:not(:disabled):hover { background: #234257 }
.btn.secondary, .btn.ghost { color: #2b4f66; border-color: var(--input-line); background: #fff }
.btn.ghost { border-color: var(--line); background: var(--subtle) }
.btn.secondary:not(:disabled):hover, .btn.ghost:not(:disabled):hover { background: #ebf2f6; border-color: #adbfcc }
.btn.danger { color: var(--red) }
.btn.mini { min-height: 30px; padding: 4px 8px; font-size: 12px }
.btn:disabled { color: #667985; border-color: var(--line); background: #e9eff3 }

label { display: grid; gap: 5px; min-width: 0; color: #3d5668; font-size: 12px; font-weight: 600 }
label.checkbox { display: flex; align-items: center; gap: 8px }
input, select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 37px;
  padding: 7px 9px;
  border: 1px solid var(--input-line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 400;
}
input::placeholder, textarea::placeholder { color: #647784 }
input:disabled, select:disabled { opacity: .65; background: #f3f6f8 }
input[type="checkbox"] { width: 16px; min-width: 16px; height: 16px; min-height: 16px; margin: 0; accent-color: var(--primary) }
input[type="file"] { padding: 5px }
textarea { resize: vertical; min-height: 70px }

.table-wrap { max-width: 100%; overflow: auto }
table { border-collapse: collapse; width: 100%; font-size: 13px }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle }
thead th { background: var(--table-head); color: #365165; font-size: 12px; text-align: left; white-space: nowrap }
tbody tr:last-child > * { border-bottom: 0 }
td .small { display: block; margin-top: 1px }
.amount { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums }
.no-wrap { white-space: nowrap }
.quote-table { min-width: 830px }
.compact th, .compact td { padding: 6px 8px }
.entry {
  grid-template-columns: 1.25fr 1.15fr 1.7fr .85fr .85fr;
  padding: 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--subtle);
}
.entry .swatch { display: flex; align-items: center; gap: 8px; min-height: 34px }
.entry > button[type="submit"] { grid-column: 1 / -1; justify-self: end }
.thumb { width: 32px; height: 32px; object-fit: cover; border-radius: 3px; border: 1px solid var(--line) }
.swatch-preview { max-height: 60vh; max-width: 100%; object-fit: contain }
.totals-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px }
.total { padding: 12px 14px; border: 1px solid var(--line); border-radius: 4px; background: var(--subtle) }
.total strong { display: block; color: var(--navy); font-size: 23px; font-variant-numeric: tabular-nums }
.total small { color: var(--muted) }

dialog {
  width: min(800px, calc(100% - 24px));
  max-height: 88vh;
  max-height: 88dvh;
  padding: 0;
  border: 1px solid var(--input-line);
  border-radius: var(--radius);
  color: var(--ink);
  box-shadow: 0 14px 38px #1426383d;
}
dialog::backdrop { background: #12293970 }
#dialog-body { padding: 18px }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px }
.dialog-head h2 { margin: 0 }
.dialog-footer { margin-top: 13px }
.editor { min-height: 165px; font: 13px/1.5 Consolas, monospace }
.checkbox-list { display: grid; gap: 8px }
#toast {
  position: fixed;
  z-index: 5;
  right: 16px;
  bottom: 15px;
  max-width: min(440px, calc(100vw - 32px));
  padding: 10px 13px;
  border-radius: 4px;
  background: var(--navy);
  color: #fff;
}
#toast.error { background: #8d3834 }
.empty { padding: 21px 8px; color: var(--muted); text-align: center }

.setup-page main { max-width: 750px }
.setup-page .panel > p { margin: 0 0 12px }
.setup-page fieldset > p { margin: 0 0 10px }
.setup-page summary { color: var(--primary); font-weight: 600; cursor: pointer }
.setup-page details .grid { margin-top: 8px }
.print-page main { max-width: 1000px }
.document { padding: 29px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-top: 12px }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; padding-bottom: 14px; border-bottom: 2px solid var(--gold) }
.doc-head h1, .doc-head p { margin: 4px 0 }
.doc-totals { max-width: 360px; margin: 18px 0 18px auto }
.doc-totals p { display: flex; justify-content: space-between; gap: 12px; margin: 0; padding: 8px; border-bottom: 1px solid var(--line) }
.doc-totals .grand { font-size: 16px; background: var(--table-head) }
.notes { white-space: pre-wrap }

@media (max-width: 920px) {
  .top-inner { gap: 12px }
  .top nav button { padding-inline: 8px }
  .entry { grid-template-columns: repeat(3, minmax(0, 1fr)) }
  .entry .swatch { grid-column: span 2 }
}

@media (max-width: 760px) {
  .top-inner { flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; min-height: 0; padding-bottom: 0 }
  .top nav { order: 3; flex-basis: 100%; flex-wrap: wrap; gap: 0; overflow: visible }
  .top nav button { min-height: 38px }
  .top nav:empty { display: none }
  .top-inner:has(nav:empty) { padding-bottom: 9px }
  .brand img { width: 37px; height: 37px }
  .brand strong { font-size: 15px }
  #identity { max-width: 42% }
  main { padding-top: 19px }
  h1 { font-size: 23px }
  .heading { align-items: flex-start }
}

@media (max-width: 540px) {
  .two, .totals-layout, #project { grid-template-columns: 1fr }
  .entry { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 10px }
  .entry > label:has(select[name="fabric"]), .entry > label:has(input[name="note"]), .entry .swatch { grid-column: 1 / -1 }
  .entry .swatch:empty { display: none }
  input, select, textarea { font-size: 16px }
  .document { padding: 12px }
  .doc-head { flex-direction: column }
  .quote-table { min-width: 0 }
  .quote-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(100%) }
  .quote-table tbody, .quote-table td { display: block }
  .quote-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 4px; margin: 0 0 8px; padding: 4px }
  .quote-table td { border: 0; text-align: left; overflow-wrap: anywhere }
  .quote-table td[data-caption]::before { content: attr(data-caption); display: block; color: var(--muted); font-size: 11px }
  .quote-table td:first-child, .quote-table td:last-child { grid-column: 1 / -1 }
}

@media (pointer: coarse) {
  .btn, .btn.mini, input, select { min-height: 42px }
  input[type="checkbox"] { width: 20px; min-width: 20px; height: 20px; min-height: 20px }
}

@media print {
  :root, body { background: #fff }
  .top, .no-print { display: none !important }
  main, .document { padding: 0; margin: 0; max-width: none }
  .document { border: 0 }
  .table-wrap { overflow: visible }
  tr, .doc-totals { break-inside: avoid }
  thead { display: table-header-group }
}
