/* Mithmill client portal. Visual language matches the MithMill commission
   portal: navy sidebar, light page, white rounded cards, slate text. */
:root {
  /* brand (navy) */
  --brand-50: #eef0f9;
  --brand-100: #dce0f3;
  --brand-200: #b9c1e7;
  --brand-500: #3d47a8;
  --brand-600: #2d3192;
  --brand-700: #262a7a;
  --brand-800: #211c5c;
  --brand-900: #1a1748;
  --brand-950: #110f30;
  --gold: #e8b23e;
  --gold-50: #fdf8ec;
  --gold-600: #bd7722;

  /* surfaces + text (slate) */
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-soft: #f1f5f9;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;

  /* semantic */
  --accent: var(--brand-800);
  --accent-hover: var(--brand-700);
  --accent-soft: var(--brand-50);
  --link: var(--brand-600);
  --green: #059669;
  --green-700: #047857;
  --green-soft: #ecfdf5;
  --amber: #92400e;
  --amber-soft: #fef3c7;
  --amber-line: #fcd34d;
  --red: #e11d48;
  --red-700: #be123c;
  --red-soft: #fff1f2;
  --red-line: #fda4af;

  --radius: 16px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px 0 rgb(16 24 40 / 0.04), 0 1px 3px 0 rgb(16 24 40 / 0.06);
  --sidebar: 256px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
a { color: var(--link); }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.012em; color: var(--text); }
h1 { font-size: 20px; font-weight: 700; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.boot { padding: 48px; text-align: center; color: var(--muted); }
.ico { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- app shell: sidebar + content */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); z-index: 30;
  display: flex; flex-direction: column; background: var(--brand-900);
}
.sb-logo { display: flex; align-items: center; gap: 10px; padding: 20px; text-decoration: none; }
.sb-logo img { height: 26px; width: auto; }
.sb-name { font-weight: 700; color: #fff; font-size: 16px; letter-spacing: -0.01em; line-height: 1.2; }
.sb-sub { font-size: 10px; color: rgb(185 193 231 / .7); text-transform: uppercase; letter-spacing: .06em; }
.sb-close { display: none; margin-left: auto; background: none; border: 0; color: rgb(255 255 255 / .7); cursor: pointer; padding: 6px; }
.sb-sep { height: 1px; background: rgb(255 255 255 / .1); margin: 0 16px 12px; }
.sb-nav { flex: 1; padding: 0 12px; display: grid; align-content: start; gap: 4px; overflow-y: auto; }
.sb-nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
  color: rgb(220 224 243 / .7); text-decoration: none; font-weight: 500; transition: background .15s, color .15s;
}
.sb-nav a:hover { color: #fff; background: rgb(255 255 255 / .05); }
.sb-nav a.active { color: #fff; background: rgb(255 255 255 / .1); }
.sb-nav a.active .ico { color: var(--brand-200); }
.sb-nav .label { flex: 1; }
.sb-badge { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--red); color: #fff; font-weight: 600; }
.sb-user { margin: 0 12px 16px; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: rgb(255 255 255 / .05); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-500); color: #fff; display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.sb-user-info { flex: 1; min-width: 0; }
.sb-user-info .email { color: #fff; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-info .role { font-size: 11px; color: rgb(185 193 231 / .6); }
.sb-icon-btn { display: grid; place-items: center; padding: 6px; border-radius: 8px; border: 0; background: none; color: rgb(220 224 243 / .6); cursor: pointer; }
.sb-icon-btn:hover { color: #fff; background: rgb(255 255 255 / .1); }
.sb-icon-btn .ico { width: 16px; height: 16px; }

.mobilebar { display: none; }
.sb-backdrop { display: none; }

.content { margin-left: var(--sidebar); min-width: 0; }
.header {
  position: sticky; top: 0; z-index: 20;
  background: rgb(245 247 246 / .9); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgb(226 232 240 / .7);
}
.header-inner { max-width: 1280px; margin: 0 auto; padding: 16px 32px; }
.header-inner:empty { display: none; }
.main { max-width: 1280px; margin: 0 auto; padding: 24px 32px 64px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.main > .page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 20px; }
.page-head p { margin: 2px 0 0; font-size: 12px; }
.stack { display: grid; gap: 24px; }
.stack > * { min-width: 0; }

/* ---- welcome banner */
.welcome {
  border-radius: var(--radius); padding: 28px; color: #fff; box-shadow: var(--shadow);
  background: linear-gradient(120deg, #211c5c 0%, #2d3192 100%);
  display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap;
}
.welcome .eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: rgb(185 193 231 / .8); }
.welcome .name { font-size: 34px; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; }
.welcome .wstats { display: flex; flex-wrap: wrap; gap: 32px; }
.welcome .wstat { text-align: right; }
.welcome .wv { font-size: 28px; font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; }
.welcome .wl { font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: rgb(185 193 231 / .7); margin-top: 2px; }

/* ---- cards & stats */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat { padding: 18px 20px; }
.stat .label { font-size: 11px; color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; color: var(--text); }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.note {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 14px 16px; border-radius: 12px;
  background: var(--gold-50); color: var(--text-2); border: 1px solid #faedc9;
}
.note strong { color: var(--gold-600); }
.note-icon { font-size: 16px; line-height: 1.3; }
.note-info { background: var(--brand-50); border-color: var(--brand-100); }
.note-info strong { color: var(--brand-700); }

/* ---- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 20px; text-align: left; vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); font-weight: 600; padding-top: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border-soft); }
td { border-bottom: 1px solid var(--border-soft); color: var(--text-2); }
tbody tr:hover td { background: rgb(248 250 252 / .6); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 40px 20px; text-align: center; color: var(--faint); }

/* status pills (commission portal StatusPill) */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: .02em; white-space: nowrap; border: 1px solid transparent; }
.b-active, .b-paid { background: var(--green); border-color: var(--green); color: #fff; }
.b-pending { background: #fff; color: var(--faint); border: 1px dashed #cbd5e1; }
.b-in_progress, .b-unpaid { background: var(--amber-soft); color: var(--amber); border-color: var(--amber-line); }
.b-cancelled { background: #ffe4e6; color: var(--red-700); border-color: var(--red-line); text-decoration: line-through; }
.b-void { background: var(--surface-2); color: var(--faint); border-color: var(--border); text-decoration: line-through; }
.b-overdue { background: var(--red-soft); color: var(--red); border: 1px dashed var(--red-line); }

/* ---- forms */
label { display: block; font-weight: 500; font-size: 13px; margin-bottom: 6px; color: var(--text-2); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
input, select, textarea {
  width: 100%; padding: 9px 12px; font: inherit; font-size: 14px; color: var(--text);
  background: #fff; border: 1px solid #cbd5e1; border-radius: var(--radius-sm);
}
input:disabled { background: var(--surface-2); color: var(--muted); }
textarea { min-height: 96px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-500); outline-offset: -1px; border-color: transparent; }
.field { margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: #fff; color: var(--text-2); font: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--border-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-danger { color: var(--red); border-color: #fecdd3; }
.btn-danger:hover { background: var(--red-soft); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; justify-self: start; }
.btn-success:hover { background: var(--green-700); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.error { color: var(--red); font-size: 13px; margin-top: 8px; min-height: 1em; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; margin: 0; }
.check input { width: auto; }

/* ---- auth (login / invite) */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--brand-950); }
.auth .card { width: 100%; max-width: 384px; padding: 24px; border-radius: 12px; border: 0; box-shadow: 0 20px 25px -5px rgb(0 0 0 / .25), 0 8px 10px -6px rgb(0 0 0 / .2); }
.auth-logo { display: flex; justify-content: center; margin-bottom: 8px; }
.auth-logo img { width: 100%; max-width: 260px; height: auto; display: block; }
.auth h1 { margin: 16px 0 4px; font-size: 18px; }
.auth p { margin: 0 0 20px; }
.auth .btn-primary { padding: 10px 16px; font-weight: 600; }

/* ---- order wizard */
.steps { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 8px; color: var(--faint); font-weight: 500; }
.step .n { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--border); color: var(--muted); font-size: 12px; font-weight: 600; }
.step.on { color: var(--text); }
.step.on .n { background: var(--accent); color: #fff; }
.step + .step::before { content: ""; width: 24px; height: 1px; background: #cbd5e1; }
.types { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.type {
  text-align: left; padding: 18px; border-radius: 14px; cursor: pointer;
  border: 1.5px solid var(--border); background: #fff; color: var(--text); font: inherit; transition: border-color .15s, background .15s;
}
.type:hover { border-color: var(--brand-200); }
.type.sel { border-color: var(--brand-600); background: var(--brand-50); }
.type .t-name { font-weight: 600; font-size: 15px; }
.type .t-price { color: var(--brand-600); font-size: 13px; font-weight: 600; margin-top: 4px; }
.type .t-desc { color: var(--muted); font-size: 12px; margin-top: 8px; }
.section-title { margin: 8px 0 12px; padding-top: 8px; }
.review dl { display: grid; grid-template-columns: 200px 1fr; gap: 8px 16px; margin: 0; }
.review dt { color: var(--muted); }
.review dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.total { display: flex; justify-content: space-between; align-items: baseline; padding: 16px 20px; border-top: 1px solid var(--border-soft); font-weight: 600; }
.total .amt { font-size: 22px; color: var(--brand-800); }
.csv-box { border: 1.5px dashed #cbd5e1; border-radius: 14px; padding: 16px; margin-bottom: 20px; display: grid; gap: 12px; background: var(--surface-2); }
.csv-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.csv-head h3 { margin-bottom: 4px; }
.file-btn { margin: 0; }
.csv-err:empty { display: none; }

/* ---- notifications */
.notif { padding: 14px 20px; border-bottom: 1px solid var(--border-soft); }
.notif:last-child { border-bottom: 0; }
.notif.unread { background: var(--brand-50); }
.notif .when { font-size: 11px; color: var(--faint); }

/* ---- admin order list */
details.order { border-bottom: 1px solid var(--border-soft); }
details.order:last-child { border-bottom: 0; }
details.order summary { list-style: none; cursor: pointer; padding: 14px 20px; display: grid; grid-template-columns: 70px 1.4fr 1fr 90px 110px 120px; gap: 12px; align-items: center; color: var(--text-2); }
details.order summary:hover { background: rgb(248 250 252 / .6); }
details.order summary::-webkit-details-marker { display: none; }
details.order summary strong { color: var(--text); }
details.order[open] summary { background: var(--surface-2); }
.order-body { padding: 16px 20px 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.order-body pre { margin: 4px 0 0; white-space: pre-wrap; word-break: break-word; font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); border: 1px solid var(--border-soft); padding: 10px 12px; border-radius: 10px; color: var(--text-2); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; color: var(--text-2); }
.complete-box { padding: 14px; border-radius: 12px; background: var(--green-soft); border: 1px solid #d1fae5; margin-bottom: 16px; display: grid; gap: 8px; }
.price-row td { background: var(--surface-2); }

/* ---- invoice editor */
table.lines td { padding: 8px 6px; vertical-align: middle; }
table.lines td:first-child, table.lines th:first-child { padding-left: 20px; }
table.lines input, table.lines select { padding: 7px 10px; }
input.num { text-align: right; }
.totals { display: grid; gap: 8px; justify-content: end; padding: 16px 20px; border-top: 1px solid var(--border-soft); }
.totals > div { display: grid; grid-template-columns: 140px 160px; align-items: center; gap: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.totals label { margin: 0; font-weight: 400; }
.totals input { text-align: right; }
.totals .grand { font-weight: 700; font-size: 18px; padding-top: 8px; border-top: 1px solid var(--border); color: var(--brand-800); }

/* ---- invoice page */
.invoice-sheet { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 32px; display: grid; gap: 24px; }
.invoice-sheet .table-wrap { border: 1px solid var(--border); border-radius: 12px; }
.inv-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.inv-logo { height: 60px; width: auto; }
.inv-title { text-align: right; display: grid; gap: 4px; justify-items: end; }
.inv-word { font-size: 24px; font-weight: 700; letter-spacing: .12em; color: var(--brand-800); }
.inv-num { color: var(--muted); font-weight: 600; }
.inv-meta { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.inv-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); font-weight: 600; margin-bottom: 4px; }
.inv-dates { display: grid; gap: 6px; }
.inv-dates > div { display: flex; justify-content: space-between; gap: 12px; }
.inv-dates .inv-label { margin: 0; }
.inv-totals { border-top: 0; padding: 0; }
.inv-notes div:last-child { white-space: pre-wrap; }

/* ---- dialog + toast */
dialog.modal { width: min(640px, calc(100% - 32px)); border: 0; border-radius: var(--radius); background: #fff; color: var(--text); padding: 20px; box-shadow: 0 20px 25px -5px rgb(0 0 0 / .15); }
dialog.modal::backdrop { background: rgb(0 0 0 / .4); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { font-size: 16px; }
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); z-index: 60;
  background: var(--brand-900); color: #fff; padding: 10px 18px; border-radius: 10px; box-shadow: 0 10px 15px -3px rgb(0 0 0 / .2);
  font-weight: 500; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- responsive */
@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; z-index: 50; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .sb-backdrop { display: block; position: fixed; inset: 0; background: rgb(0 0 0 / .4); z-index: 40; }
  .sb-close { display: grid; }
  .mobilebar {
    display: flex; position: sticky; top: 0; z-index: 30; align-items: center; justify-content: space-between;
    background: var(--brand-900); color: #fff; padding: 12px 16px;
  }
  .mobilebar img { height: 24px; width: auto; }
  .mobilebar button { background: none; border: 0; color: #fff; padding: 8px; border-radius: 8px; cursor: pointer; display: grid; }
  .content { margin-left: 0; }
  .header { top: 52px; }
  .header-inner, .main { padding-left: 20px; padding-right: 20px; }
}
@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .order-body { grid-template-columns: 1fr; }
  details.order summary { grid-template-columns: 1fr auto; }
  details.order summary .hide-sm { display: none; }
  .welcome .wstat { text-align: left; }
}
@media (max-width: 600px) {
  .header-inner, .main { padding-left: 16px; padding-right: 16px; }
  .main { padding-top: 20px; padding-bottom: 48px; }
  .grid-2, .types { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .review dl, .kv { grid-template-columns: 1fr; }
  .review dt { margin-top: 8px; }
  .stat .value { font-size: 22px; }
  th, td { padding: 10px 12px; }
  .welcome { padding: 22px; }
  .welcome .name { font-size: 26px; }
  .welcome .wstats { gap: 20px; }
  .welcome .wv { font-size: 20px; }
}
@media (max-width: 700px) {
  .invoice-sheet { padding: 20px 16px; }
  .inv-meta { grid-template-columns: 1fr; }
  .totals > div { grid-template-columns: 1fr 130px; }
  .totals { justify-content: stretch; }
}

/* ---- print (invoices) */
@page { margin: 16mm; }
@media print {
  body { background: #fff; }
  .sidebar, .mobilebar, .header, .sb-backdrop, .no-print, #toast { display: none !important; }
  .content { margin-left: 0; }
  .main { padding: 0; max-width: none; }
  .invoice-sheet { border: 0; padding: 0; box-shadow: none; }
  .badge { border: 1px solid currentColor; }
}
dialog.modal.modal-wide { width: min(760px, calc(100% - 32px)); max-height: calc(100vh - 32px); }
[hidden] { display: none !important; }
.batch-opt { padding: 14px; border-radius: 12px; background: var(--brand-50); border: 1px solid var(--brand-100); margin-bottom: 14px; }
details.order { scroll-margin-top: 150px; }
