:root {
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --primary-soft: #dbeafe;
  --primary-tint: #eff6ff;
  --accent: #0ea5e9;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --green: #15803d; --green-bg: #dcfce7;
  --amber: #b45309; --amber-bg: #fef3c7;
  --red: #b91c1c; --red-bg: #fee2e2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14.5px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; }
.boot, .loading { padding: 48px; text-align: center; color: var(--muted); }
[hidden] { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none !important; white-space: nowrap;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(255,255,255,.12); }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.danger:hover { background: var(--red-bg); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: none; cursor: pointer; font-size: 18px; color: var(--muted); padding: 2px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--red-bg); color: var(--red); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Top bar & layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; color: #fff;
  background: linear-gradient(100deg, var(--primary-dark), var(--primary) 70%, #2563eb);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 38px; height: 38px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-weight: 700; letter-spacing: .5px;
  background: linear-gradient(135deg, #fbbf24, #f59e0b); color: var(--primary-dark);
}
/* Logo image (falls back to initials badge when the file is missing) */
.logo-wrap { display: inline-flex; flex: none; }
.logo-wrap .logo { display: none; }
.logo-wrap.no-img .logo { display: grid; }
.logo-wrap.no-img .logo-img { display: none; }
.logo-img { display: block; object-fit: contain; background: #fff; border-radius: 10px; }
.logo-wrap.top .logo-img { height: 40px; width: auto; max-width: 160px; padding: 4px 8px; }
@media (max-width: 760px) { .logo-wrap.top .logo-img { height: 34px; max-width: 120px; } }
.logo-wrap.login { justify-content: center; margin: 0 auto 10px; }
.logo-wrap.login .logo-img { height: 72px; max-width: 220px; padding: 0; }
.logo-wrap.login .logo { margin: 0; }
.brand-name { font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand-sub { font-size: 12px; opacity: .8; }
.top-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top-right .btn.ghost { color: #fff; border-color: rgba(255,255,255,.35); }
.who { font-size: 13px; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.demo-pill { font-size: 11px; font-weight: 600; background: #fbbf24; color: #422006; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }

.layout { display: flex; min-height: calc(100vh - 58px); }
.sidenav {
  width: 220px; flex: none; padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
}
.sidenav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px;
  color: var(--muted); font-weight: 500; text-decoration: none;
}
.sidenav a:hover { background: var(--primary-tint); color: var(--primary); }
.sidenav a.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.sidenav svg, .ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sidenav .badge-count { margin-left: auto; background: var(--red); color: #fff; font-size: 11px; border-radius: 99px; padding: 0 7px; }
.main { flex: 1; min-width: 0; padding: 24px; max-width: 1180px; }

/* Page header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; margin-bottom: 8px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid.side { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
.stack > * + * { margin-top: 16px; }
.section { margin-top: 24px; }
.section > h2 { margin-bottom: 12px; }

.hero {
  border-radius: var(--radius); padding: 22px; color: #fff;
  background: linear-gradient(120deg, var(--primary-dark), var(--primary) 60%, var(--accent));
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: center;
}
.hero .hello { font-size: 20px; font-weight: 700; }
.hero .sub { opacity: .85; margin-top: 2px; }
.hero .amount { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hero .label { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; opacity: .85; }
.hero .btn { background: #fff; color: var(--primary-dark); border-color: #fff; margin-top: 8px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-top: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); text-decoration: none !important; color: inherit; display: block; }
a.stat:hover { border-color: #93c5fd; }
.stat .k { font-size: 12.5px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .v.red { color: var(--red); }
.stat .v.green { color: var(--green); }

/* Badges */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap; background: #f1f5f9; color: var(--muted); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.blue { background: var(--primary-soft); color: var(--primary-dark); }

/* Order cards */
.order-list { display: grid; gap: 12px; }
.order-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: inherit; text-decoration: none !important; }
.order-card:hover { border-color: #93c5fd; }
.oc-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.oc-no { font-weight: 700; }
.oc-meta { font-size: 12.5px; color: var(--muted); }
.oc-bottom { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.progress { height: 7px; background: #e2e8f0; border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 99px; }
.progress.done > span { background: var(--green); }
.stage-label { font-size: 13px; font-weight: 600; color: var(--primary-dark); margin-top: 6px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 6px 14px; cursor: pointer; font: inherit; font-size: 13px; color: var(--muted); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; display: flex; gap: 12px; padding-bottom: 18px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before { content: ''; position: absolute; left: 13px; top: 28px; bottom: 0; width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline li.done::before { background: var(--primary); }
.timeline .dot {
  width: 28px; height: 28px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; background: #f1f5f9; color: var(--muted); border: 2px solid var(--border); position: relative; z-index: 1;
}
.timeline li.done .dot { background: var(--primary); color: #fff; border-color: var(--primary); }
.timeline li.current .dot { background: #fff; color: var(--primary); border-color: var(--primary); box-shadow: 0 0 0 5px var(--primary-soft); }
.timeline li.done.current .dot { background: var(--green); border-color: var(--green); color: #fff; box-shadow: 0 0 0 5px var(--green-bg); }
.timeline .t-name { font-weight: 600; padding-top: 3px; }
.timeline li.todo .t-name { color: var(--muted); font-weight: 500; }
.timeline .t-meta { font-size: 12.5px; color: var(--muted); }

/* Key-value lists */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; font-weight: 500; word-break: break-word; }
.copyable { display: inline-flex; align-items: center; gap: 6px; }
.copy-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; font-size: 11px; padding: 1px 7px; cursor: pointer; color: var(--muted); }
.copy-btn:hover { color: var(--primary); border-color: #93c5fd; }

.bank-card { background: linear-gradient(135deg, var(--primary-tint), #fff); border-color: #bfdbfe; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--primary-tint); }
.table tfoot td { font-weight: 600; border-top: 1px solid var(--border); }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; color: #334155; }
input, select, textarea {
  font: inherit; color: var(--text); background: #fff; border: 1px solid #cbd5e1; border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input:disabled { background: #f8fafc; color: var(--muted); }
textarea { resize: vertical; min-height: 70px; }
.input-prefix { display: flex; }
.input-prefix span { border: 1px solid #cbd5e1; border-right: 0; border-radius: 8px 0 0 8px; padding: 9px 10px; background: #f8fafc; color: var(--muted); }
.input-prefix input { border-radius: 0 8px 8px 0; }
.file-cur { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; background: var(--primary-tint); border: 1px solid #bfdbfe; border-radius: 8px; font-size: 13px; }
.file-cur .file-name { font-weight: 600; word-break: break-all; }
.form-error { color: var(--red); background: var(--red-bg); border-radius: 8px; padding: 8px 12px; font-size: 13px; }
.note { background: var(--primary-tint); border: 1px solid #bfdbfe; border-radius: 10px; padding: 10px 14px; font-size: 13px; color: #1e3a8a; }
.note.amber { background: var(--amber-bg); border-color: #fde68a; color: #78350f; }
.search { max-width: 280px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1000px 500px at 10% -10%, #3b82f6 0, transparent 60%), linear-gradient(160deg, var(--primary-dark), #1e40af 55%, #0369a1); }
.login-card { width: min(400px, 100%); background: #fff; border-radius: 16px; padding: 28px; box-shadow: 0 20px 50px rgba(2, 6, 23, .35); }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand .logo { width: 56px; height: 56px; font-size: 20px; margin: 0 auto 10px; border-radius: 14px; }
.login-brand h1 { font-size: 20px; }
.login-card form > * + * { margin-top: 14px; }
.demo-box { margin-top: 18px; font-size: 12.5px; background: #fffbeb; border: 1px dashed #f59e0b; border-radius: 10px; padding: 10px 12px; color: #78350f; }
.login-foot { text-align: center; margin-top: 16px; font-size: 13px; }

/* Modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 24px 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: min(560px, 100%); box-shadow: 0 20px 50px rgba(2, 6, 23, .35); }
.modal.wide { width: min(900px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.modal-body { padding: 18px; }
.modal-body img { max-width: 100%; border-radius: 8px; }
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow); animation: pop .2s ease-out; }
.toast.error { background: var(--red); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Order form (admin) & documents list (client) */
.order-form { max-width: 860px; }
.step-no { display: inline-grid; place-items: center; width: 24px; height: 24px; margin-right: 8px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 12px; font-weight: 700; vertical-align: 1px; }
.form-grid > .full { grid-column: 1 / -1; }
.save-bar { position: sticky; bottom: 12px; z-index: 5; }
.doc-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.doc-line:first-child { border-top: 0; padding-top: 0; }
/* Responsive */
.pay-line { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
@media (max-width: 980px) {
  .grid.side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .topbar { padding: 10px 16px; }
  .who { display: none; }
  .brand-sub { display: none; }
  .layout { display: block; min-height: 0; }
  .sidenav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; width: auto; height: 64px;
    flex-direction: row; justify-content: space-around; padding: 6px 4px; border-right: 0; border-top: 1px solid var(--border);
    box-shadow: 0 -4px 12px rgba(15, 23, 42, .06);
  }
  .sidenav a { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 11px; flex: 1; text-align: center; }
  .sidenav .badge-count { position: absolute; margin: 0 0 0 18px; font-size: 10px; }
  .main { padding: 16px 16px 88px; }
  .grid.two { grid-template-columns: minmax(0, 1fr); }
  .hero .amount { font-size: 24px; }
  h1 { font-size: 19px; }
  .card { padding: 14px; }
  .search { max-width: none; }
}
@media (max-width: 760px) { .save-bar { bottom: 76px; } }
@media (max-width: 760px) { .logo-wrap.top:not(.no-img) + div { display: none; } }
