:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #e6e1d8;
  --accent: #7a1f3d;
  --accent-ink: #ffffff;
  --accent-soft: #f4e4ea;
  --ok: #1f7a4d;
  --warn: #b7791f;
  --bad: #b42318;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .06), 0 6px 20px rgba(20, 20, 30, .05);
}
[data-theme="dark"] {
  --bg: #14161b;
  --surface: #1c1f26;
  --surface-2: #232730;
  --ink: #eceef2;
  --muted: #9aa1ae;
  --line: #2d323d;
  --accent: #e07a9b;
  --accent-ink: #1a0f14;
  --accent-soft: #3a2230;
  --ok: #5fd39a;
  --warn: #f0b955;
  --bad: #ff8a80;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}
h1, h2, h3 { margin: 0; }
a { color: var(--accent); }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.hidden { display: none !important; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--bad); margin: 0; font-size: 14px; }
.brand-title { font-family: Fraunces, Georgia, serif; font-weight: 600; letter-spacing: .2px; }

/* ---------- Cards / login ---------- */
.center-screen { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.card.narrow { width: 100%; max-width: 390px; display: grid; gap: 14px; }
.logo { width: 52px; height: 52px; border-radius: 14px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 26px; }
.logo.sm { width: 34px; height: 34px; font-size: 18px; border-radius: 10px; }
.card.narrow h1 { font-size: 26px; }

/* ---------- Forms ---------- */
label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; width: 100%;
}
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.form { display: grid; gap: 12px; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 14px; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.icon { padding: 6px 10px; font-size: 18px; }
.btn[disabled] { opacity: .6; cursor: wait; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; align-items: center; gap: 10px; font-size: 18px; padding: 0 6px; }
.sidebar nav { display: grid; gap: 4px; }
.sidebar nav a {
  text-decoration: none; color: var(--ink); padding: 9px 12px; border-radius: 9px; font-weight: 500;
}
.sidebar nav a:hover { background: var(--surface-2); }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); }
.side-foot { margin-top: auto; display: grid; gap: 8px; word-break: break-all; }
.main-wrap { min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 24px;
  border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.topbar h2 { font-family: Fraunces, Georgia, serif; font-size: 22px; }
main { padding: 24px; max-width: 1200px; }
.only-mobile { display: none; }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-family: Fraunces, Georgia, serif; font-size: 30px; margin-top: 4px; }
.stat.warn .value { color: var(--warn); }
.stat.bad .value { color: var(--bad); }
.stat.ok .value { color: var(--ok); }

/* ---------- Tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 22px; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h3 { font-size: 16px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input { max-width: 280px; }
.toolbar select { max-width: 190px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--line); }
.badge.Received   { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }
.badge.Cutting    { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.badge.Sewing     { background: #fefce8; color: #854d0e; border-color: #fde68a; }
.badge.Fitting    { background: #f0f9ff; color: #075985; border-color: #bae6fd; }
.badge.Alteration { background: #faf5ff; color: #6b21a8; border-color: #e9d5ff; }
.badge.Ready      { background: #ecfdf3; color: #067647; border-color: #a6f4c5; }
.badge.Delivered  { background: #f2f4f7; color: #475467; border-color: #d0d5dd; }
.badge.Cancelled  { background: #fef3f2; color: #b42318; border-color: #fecdca; }
[data-theme="dark"] .badge { filter: brightness(.92) saturate(1.1); }
.due-over { color: var(--bad); font-weight: 600; }
.due-soon { color: var(--warn); font-weight: 600; }

/* ---------- Modal / drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 17, 23, .5); display: grid; place-items: center; padding: 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 680px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal-head h3 { font-family: Fraunces, Georgia, serif; font-size: 20px; flex: 1; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.status-steps { display: flex; gap: 6px; flex-wrap: wrap; }
.status-steps button.current { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); display: grid; gap: 12px; }
.timeline li { position: relative; padding-left: 12px; }
.timeline li::before { content: ""; position: absolute; left: -21px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }

/* ---------- Settings ---------- */
.settings-grid { display: grid; gap: 22px; max-width: 760px; }
.settings-grid .panel { margin: 0; }
.panel-body { padding: 18px 16px; display: grid; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; padding: 4px 6px 4px 12px; font-size: 13px; }
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; padding: 2px 6px; }
.chip button:hover { color: var(--bad); }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 100; box-shadow: var(--shadow); font-size: 14px; }

/* ---------- Tracking page ---------- */
.track-result { display: grid; gap: 14px; margin-top: 6px; }
.progress { display: flex; gap: 4px; }
.progress span { flex: 1; height: 8px; border-radius: 99px; background: var(--line); }
.progress span.done { background: var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; width: 240px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .only-mobile { display: inline-block; }
  main { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .grid3, .grid4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}

/* ---------- Print: order slip ---------- */
@media print {
  body * { visibility: hidden; }
  #printSlip, #printSlip * { visibility: visible; }
  #printSlip { position: absolute; inset: 0; padding: 24px; color: #000; background: #fff; }
}
#printSlip { display: none; }
@media print { #printSlip { display: block; } }
