:root {
  --navy: #1f3a5f; --navy-2: #2b4f7e; --teal: #0e8a8a; --bg: #f4f6f9; --card: #fff; --line: #e2e7ee; --text: #1d2430; --muted: #687385;
  --red: #c62828; --green: #2e7d32; --orange: #e67e22; --yellow: #f2c230; --blue: #2f6fd6; --purple: #7b4bc4; --pink: #c2477f;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px; color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--navy-2); }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; }
code { font-size: .8rem; background: #eef1f5; padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.text-red { color: var(--red); } .text-green { color: var(--green); } .text-purple { color: var(--purple); }
.loading { padding: 3rem; text-align: center; color: var(--muted); }
[hidden] { display: none !important; }

/* Layout */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 232px; background: var(--navy); color: #fff; position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 30; }
.brand { display: flex; gap: .6rem; align-items: center; padding: 1rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand span { display: flex; flex-direction: column; line-height: 1.2; }
.brand small { opacity: .7; font-size: .78rem; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; background: #fff; color: var(--navy); display: grid; place-items: center; font-weight: 800; }
.brand-logo { width: 36px; height: 36px; object-fit: contain; background: #fff; border-radius: 9px; padding: 2px; }
.sidebar nav { padding: .5rem; overflow-y: auto; flex: 1; }
.nav-link { display: flex; gap: .7rem; align-items: center; padding: .6rem .75rem; border-radius: 8px; color: rgba(255,255,255,.82); text-decoration: none; margin-bottom: 2px; }
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { background: #fff; color: var(--navy); font-weight: 600; }
.nav-icon { width: 1.3rem; text-align: center; }
.sidebar-foot { padding: .75rem 1rem; opacity: .65; font-size: .8rem; word-break: break-all; }
.shell { flex: 1; margin-left: 232px; min-width: 0; }
.topbar { display: flex; justify-content: flex-end; align-items: center; gap: .5rem; padding: .6rem 1.5rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.menu-btn { display: none; margin-right: auto; }
main { padding: 1.5rem; max-width: 1400px; outline: none; }
.scrim { display: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .shell { margin-left: 0; }
  .menu-btn { display: inline-grid; }
  main { padding: 1rem; }
}

/* Page */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-actions, .actions-bar, .row-actions, .badges, .report-links { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions-bar { margin: 0 0 1rem; }
.actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.section { margin: 1.5rem 0 .75rem; }
.grid-2, .grid-3, .grid-4 { display: grid; gap: .75rem 1rem; }
.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-side { display: grid; grid-template-columns: minmax(260px, 360px) 1fr; gap: 1rem; }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4, .grid-side { grid-template-columns: 1fr; } }
.error-card { border-left: 4px solid var(--red); }
.empty { color: var(--muted); padding: 1rem 0; }
.summary { margin: .25rem 0 .75rem; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; display: flex; flex-direction: column; gap: .2rem; text-decoration: none; color: inherit; border-top: 3px solid var(--navy); }
a.stat:hover { box-shadow: 0 4px 12px rgba(16,24,40,.12); }
.queue .stat { border-top-color: var(--teal); }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 1.45rem; font-weight: 700; }
.stat-sub { color: var(--muted); font-size: .8rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .9rem; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 8px; font: inherit; font-size: .92rem; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #c5ccd8; background: #f8fafc; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger-ghost { color: var(--red); border-color: #f1c4c4; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: .3rem .6rem; font-size: .82rem; }
.btn.xs { padding: .15rem .4rem; font-size: .75rem; }
.btn.lg { padding: .7rem 1.2rem; font-size: 1rem; width: 100%; justify-content: center; }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 1rem; padding: .35rem .5rem; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: #eef1f5; color: var(--text); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.label { font-size: .82rem; font-weight: 600; color: #3b4555; }
.hint { color: var(--muted); font-size: .78rem; }
input, select, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid #cdd4de; border-radius: 8px; background: #fff; width: 100%; min-width: 0; color: inherit; }
input[type=checkbox] { width: auto; }
input:disabled, select:disabled, textarea:disabled { background: #f1f3f6; color: var(--muted); }
textarea { resize: vertical; }
.inline { display: inline-flex; align-items: center; gap: .4rem; font-size: .9rem; white-space: nowrap; }
.inline input[type=date] { width: auto; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; align-items: center; }
.filters > input[type=search] { flex: 1 1 260px; }
.filters > select { width: auto; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: .55rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.num { text-align: right; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7f9fc; }
.edit-grid td { padding: .3rem; }
.edit-grid input, .edit-grid select { padding: .4rem .45rem; }
.small-stack { display: flex; flex-direction: column; gap: 2px; }
@media (max-width: 700px) {
  .table-wrap table:not(.edit-grid) thead { display: none; }
  .table-wrap table:not(.edit-grid) tr { display: block; border-bottom: 1px solid var(--line); padding: .4rem 0; }
  .table-wrap table:not(.edit-grid) td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .25rem .4rem; text-align: right; }
  .table-wrap table:not(.edit-grid) td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; text-align: left; }
  .table-wrap table:not(.edit-grid) td[data-label=""]::before { content: none; }
}

/* Badges & pills */
.badge { display: inline-block; padding: .18rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; color: #fff; background: #8a94a6; }
.b-green { background: var(--green); } .b-green-dark { background: #1b5e20; } .b-red { background: var(--red); } .b-orange { background: var(--orange); }
.b-yellow { background: var(--yellow); color: #3d3000; } .b-blue { background: var(--blue); } .b-teal { background: var(--teal); }
.b-purple { background: var(--purple); } .b-pink { background: var(--pink); } .b-grey { background: #d5dae2; color: #333; }
.badges.big .badge { font-size: .85rem; padding: .3rem .75rem; }
.pill { display: inline-block; font-size: .78rem; padding: .2rem .55rem; border-radius: 6px; margin: .15rem .3rem .15rem 0; }
.pill.ok { background: #e6f4ea; color: #1e5b26; } .pill.warn { background: #fff1e0; color: #8a4b00; } .pill.info { background: #e7eefb; color: #1d4b9c; } .pill.plain { background: #eef1f5; }
.callout { padding: .7rem .9rem; border-radius: 8px; background: #fff8e6; border: 1px solid #f5dfa8; margin: .5rem 0; display: flex; gap: .75rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.callout.info { background: #eef4ff; border-color: #c9d9f7; }
.callout.warn { background: #fff1e0; border-color: #f6cf9f; }
.note { white-space: pre-wrap; background: #f7f9fc; padding: .5rem .7rem; border-radius: 6px; }

/* Thumbs & gallery */
.thumb { display: inline-grid; place-items: center; object-fit: cover; border-radius: 6px; background: #eef1f5; flex: none; }
.thumb.xs { width: 30px; height: 30px; font-size: .8rem; } .thumb.sm { width: 44px; height: 44px; } .thumb.placeholder { color: #9aa5b5; }
.main-img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #f7f9fc; border-radius: 8px; display: grid; place-items: center; color: var(--muted); }
.thumbs { display: flex; flex-wrap: wrap; gap: .5rem; margin: .75rem 0; }
.thumb-tile { width: 96px; display: flex; flex-direction: column; gap: 4px; }
.thumb-tile img { width: 96px; height: 96px; object-fit: cover; border-radius: 6px; border: 2px solid transparent; }
.thumb-tile img.selected { border-color: var(--navy); }
.tile-actions { display: flex; gap: 3px; flex-wrap: wrap; font-size: .75rem; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1rem; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.logo-preview img { max-height: 70px; max-width: 200px; }

/* Order form */
.order-form { display: grid; grid-template-columns: 1fr 300px; gap: 1rem; align-items: start; }
.form-side .sticky { position: sticky; top: 70px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; display: flex; flex-direction: column; gap: .6rem; }
@media (max-width: 1100px) { .order-form { grid-template-columns: 1fr; } .form-side .sticky { position: static; } }
.line-card { border: 1px solid var(--line); border-radius: 8px; padding: .8rem; margin-bottom: .75rem; background: #fbfcfe; display: flex; flex-direction: column; gap: .6rem; }
.line-top { display: flex; gap: .6rem; align-items: center; }
.line-top select { max-width: 320px; }
.line-no { font-weight: 700; color: var(--muted); }
.line-total { font-size: 1.05rem; padding: .45rem 0; }
.picked { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; background: #f7f9fc; padding: .7rem .9rem; border-radius: 8px; }
.cust-results { display: flex; flex-direction: column; gap: 2px; margin-top: .3rem; }
.cust-option { text-align: left; border: 1px solid var(--line); background: #fff; padding: .45rem .6rem; border-radius: 6px; cursor: pointer; font: inherit; }
.cust-option:hover { background: #eef4ff; }
.or { text-align: center; margin: .75rem 0 .5rem; font-size: .85rem; }
.summary-box dl, .money-box dl { display: grid; grid-template-columns: 1fr auto; gap: .35rem 1rem; margin: 0 0 .5rem; }
.summary-box dd, .money-box dd { margin: 0; text-align: right; }
.grand { font-weight: 700; font-size: 1.1rem; border-top: 1px solid var(--line); padding-top: .35rem; }
.order-head { display: grid; grid-template-columns: 1fr 300px; gap: 1rem; }
@media (max-width: 800px) { .order-head { grid-template-columns: 1fr; } }
.money-box { background: #f7f9fc; padding: .8rem 1rem; border-radius: 8px; }

/* Picker */
.picker { position: relative; }
.picker-list { display: none; position: absolute; z-index: 40; left: 0; right: 0; top: 100%; max-height: 320px; overflow-y: auto; margin: 2px 0 0; padding: 4px; list-style: none; background: #fff; border: 1px solid #cdd4de; border-radius: 8px; box-shadow: 0 8px 24px rgba(16,24,40,.15); min-width: 320px; }
.picker-list.open { display: block; }
.picker-list li { display: flex; gap: .55rem; align-items: center; padding: .4rem .5rem; border-radius: 6px; cursor: pointer; font-size: .88rem; }
.picker-list li:hover, .picker-list li.active { background: #eef4ff; }
.picker-list .grow { flex: 1; min-width: 0; }
.stock { color: var(--green); white-space: nowrap; } .stock.none { color: var(--red); }

/* Tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tab { border: 0; background: transparent; padding: .6rem .9rem; font: inherit; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--navy); border-bottom-color: var(--navy); font-weight: 600; }

/* Modal & toast */
dialog.modal { border: 0; border-radius: 12px; padding: 0; width: min(560px, 94vw); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog.modal.wide { width: min(920px, 96vw); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 1rem 1.1rem 1.1rem; max-height: 78vh; overflow-y: auto; }
.modal-body form > * + * { margin-top: .6rem; }
#toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; max-width: min(420px, 92vw); }
.toast { background: #1d2430; color: #fff; padding: .7rem 1rem; border-radius: 8px; box-shadow: var(--shadow); transition: opacity .4s; }
.toast.error { background: var(--red); }
.toast.hide { opacity: 0; }
.small-note { font-size: .8rem; }
@media (max-width: 700px) {
  .table-wrap table:not(.edit-grid), .table-wrap table:not(.edit-grid) tbody { display: block; width: 100%; }
  .filters > *, .filters > input[type=search] { flex: 1 1 100%; width: 100%; }
  .filters .inline { justify-content: space-between; }
  .filters .inline input[type=date] { width: auto; flex: 1; }
  .page-head h1 { width: 100%; }
  .topbar { padding: .5rem .75rem; }
  main { overflow-x: hidden; }
}
