:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #171a26;
  --muted: #6b7185;
  --soft: #9aa0b2;
  --line: #e7e9f0;
  --primary: #5b5bd6;
  --primary-soft: #eeeefc;
  --green: #1a9f5b;
  --green-soft: #e6f6ed;
  --red: #e5484d;
  --red-soft: #fdecec;
  --amber: #c27c0e;
  --amber-soft: #fdf3e1;
  --blue: #2f7ae5;
  --blue-soft: #e7f0fd;
  --violet: #8a4fd9;
  --violet-soft: #f2eafc;
  --grey-soft: #eef0f4;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Manrope", "Inter", "Segoe UI", Roboto, "Liberation Sans", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.4;
  display: grid; grid-template-columns: 248px 1fr; min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, select { font: inherit; color: inherit; }
i[data-ic] { display: inline-flex; width: 18px; height: 18px; flex: none; }
i[data-ic] svg { width: 100%; height: 100%; }

/* ---------- Sidebar ---------- */
.sidebar { position: sticky; top: 0; height: 100vh; background: #fff; border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 6px; }
.logo { display: flex; align-items: center; gap: 10px; padding: 2px 8px 18px; }
.logo-mark { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #6e6ef0, #4a3fc4); color: #fff; font-weight: 800; display: grid; place-items: center; font-size: 18px; }
.logo b { display: block; font-size: 17px; }
.logo small { color: var(--muted); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px; color: #3c4152; font-weight: 600; cursor: pointer; user-select: none; }
.nav a:hover { background: #f5f6fa; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav-badge { margin-left: auto; background: var(--primary); color: #fff; font-size: 11.5px; font-weight: 700; border-radius: 10px; padding: 1px 8px; }
.nav-badge.soft { background: var(--grey-soft); color: var(--muted); }
.side-card { margin-top: auto; background: #f7f7fc; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.side-card b { display: block; font-size: 13px; }
.side-card small { color: var(--muted); font-size: 12px; }
.sync-bar { height: 5px; border-radius: 3px; background: #e4e4f3; margin-top: 9px; overflow: hidden; }
.sync-bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #6e6ef0, #22b07d); }
.nav-bottom { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.me { display: flex; gap: 10px; align-items: center; padding: 10px 8px 0; }
.ava { width: 36px; height: 36px; border-radius: 50%; background: #ffe2cc; color: #b85a12; font-weight: 800; font-size: 13px; display: grid; place-items: center; flex: none; }
.me b { display: block; font-size: 13.5px; }
.me small { color: var(--muted); font-size: 12px; }

/* ---------- Main ---------- */
.main { padding: 0 28px 28px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 14px; height: 76px; position: sticky; top: 0; background: var(--bg); z-index: 10; }
.topbar h1 { font-size: 22px; margin: 0; }
.topbar .sub { color: var(--muted); font-size: 13px; }
.gsearch { margin-left: auto; display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; height: 40px; width: 340px; color: var(--soft); }
.gsearch input { border: 0; outline: 0; flex: 1; background: transparent; color: var(--text); }
kbd { font-family: inherit; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; background: #fafbfc; }
.seg { display: flex; background: #e9eaf1; border-radius: 10px; padding: 3px; }
.seg button { padding: 7px 12px; border-radius: 8px; font-weight: 600; color: var(--muted); font-size: 13px; }
.seg button.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(20,20,50,.12); }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; background: #fff; border: 1px solid var(--line); display: grid; place-items: center; position: relative; color: #3c4152; }
.icon-btn .dot { position: absolute; top: 9px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); border: 2px solid #fff; }
.btn { height: 40px; padding: 0 14px; border-radius: 10px; font-weight: 700; display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: #fff; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: #4b4bc4; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; margin: 0; }
.card-head small { color: var(--muted); font-size: 12.5px; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.kpi { padding: 16px 18px 12px; position: relative; overflow: hidden; }
.kpi .k-top { display: flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 600; font-size: 13px; }
.kpi .k-ic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; }
.kpi .k-ic i { width: 17px; height: 17px; }
.kpi .k-val { font-size: 26px; font-weight: 800; margin: 10px 0 4px; letter-spacing: -.3px; }
.kpi .k-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.delta { font-weight: 700; padding: 2px 7px; border-radius: 7px; font-size: 12px; }
.delta.up { color: var(--green); background: var(--green-soft); }
.delta.down { color: var(--red); background: var(--red-soft); }
.kpi svg.spark { position: absolute; right: 16px; top: 14px; width: 104px; height: 36px; }

/* Chart */
.row2 { display: grid; grid-template-columns: 2.15fr 1fr; gap: 16px; margin-bottom: 16px; }
.chart-card { padding-bottom: 10px; }
.legend { display: flex; gap: 16px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.lg-line { width: 16px; height: 3px; border-radius: 2px; background: var(--primary); display: inline-block; }
.lg-bar { width: 10px; height: 10px; border-radius: 3px; background: #cdd5e4; display: inline-block; }
.chart { height: 252px; position: relative; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .axis text { fill: var(--soft); font-size: 11px; }
.chart .grid line { stroke: #eef0f5; }
.tooltip { position: fixed; pointer-events: none; background: #1d2030; color: #fff; padding: 9px 12px; border-radius: 10px; font-size: 12.5px; opacity: 0; transition: opacity .12s; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.18); white-space: nowrap; }
.tooltip b { display: block; margin-bottom: 4px; font-size: 12px; color: #c6c9db; font-weight: 600; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; }
.tooltip .t-row i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* Donut */
.donut-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.donut-wrap svg { width: 160px; height: 160px; }
.donut-legend { width: 100%; display: flex; flex-direction: column; gap: 9px; }
.donut-legend div { display: grid; grid-template-columns: 12px 1fr auto 52px; align-items: center; gap: 10px; font-size: 13px; }
.donut-legend i { width: 10px; height: 10px; border-radius: 3px; }
.donut-legend b { text-align: right; }
.donut-legend span.pc { text-align: right; color: var(--muted); }

/* Table */
.table-card { padding-bottom: 8px; }
.tsearch { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; height: 38px; padding: 0 6px 0 10px; width: 330px; color: var(--soft); }
.tsearch:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.tsearch input { border: 0; outline: 0; flex: 1; background: transparent; color: var(--text); }
.tsearch button { width: 24px; height: 24px; border-radius: 6px; color: var(--muted); font-size: 18px; line-height: 1; visibility: hidden; }
.tsearch.has button { visibility: visible; }
.tsearch button:hover { background: var(--grey-soft); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 0 -20px; padding: 0 20px; }
.tabs button { padding: 10px 12px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; gap: 7px; align-items: center; }
.tabs button span { font-size: 11.5px; background: var(--grey-soft); color: var(--muted); border-radius: 8px; padding: 1px 7px; font-weight: 700; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs button.active span { background: var(--primary-soft); color: var(--primary); }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; color: var(--soft); font-weight: 600; padding: 12px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none; }
.tbl th[data-sort] { cursor: pointer; }
.tbl th[data-sort]:hover { color: var(--text); }
.tbl th.sorted::after { content: " ↓"; color: var(--primary); }
.tbl th.sorted.asc::after { content: " ↑"; }
.tbl td { padding: 11px 10px; border-bottom: 1px solid #f0f1f5; white-space: nowrap; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: #fafaff; }
.tbl .r { text-align: right; }
.tbl .oid { font-weight: 700; }
.tbl .oid small { display: block; color: var(--soft); font-weight: 500; font-size: 12px; }
.client { display: flex; align-items: center; gap: 10px; }
.client .ava { width: 32px; height: 32px; font-size: 12px; }
.client b { display: block; font-weight: 700; }
.client small { color: var(--muted); font-size: 12px; }
.items-cell { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.items-cell .em { width: 26px; height: 26px; border-radius: 7px; background: #f5f5fa; display: grid; place-items: center; font-size: 14px; }
.sum { font-weight: 800; }
.pay { color: var(--muted); }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 8px; font-weight: 700; font-size: 12.5px; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-new { color: var(--blue); background: var(--blue-soft); }
.st-processing { color: var(--amber); background: var(--amber-soft); }
.st-shipping { color: var(--violet); background: var(--violet-soft); }
.st-done { color: var(--green); background: var(--green-soft); }
.st-cancelled { color: #6b7185; background: var(--grey-soft); }
.chev { color: var(--soft); font-size: 18px; }
mark { background: #fff1a8; color: inherit; border-radius: 3px; padding: 0 1px; }
.tfoot { display: flex; justify-content: space-between; align-items: center; padding: 12px 2px 6px; color: var(--muted); font-size: 13px; }
.pager { display: flex; gap: 4px; }
.pager button { min-width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); font-weight: 600; background: #fff; padding: 0 8px; }
.pager button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager button:disabled { opacity: .4; cursor: default; }
.empty-row td { text-align: center; color: var(--muted); padding: 40px 0; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20, 22, 40, .42); display: grid; place-items: center; z-index: 40; animation: fade .15s; backdrop-filter: blur(2px); }
.modal-bg[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 760px; max-height: calc(100vh - 60px); overflow: auto; background: #fff; border-radius: 18px; box-shadow: 0 30px 80px rgba(10, 10, 40, .3); animation: rise .2s cubic-bezier(.2,.9,.3,1.1); }
@keyframes rise { from { transform: translateY(14px) scale(.98); opacity: 0; } }
.m-head { display: flex; align-items: center; gap: 12px; padding: 20px 24px 16px; border-bottom: 1px solid var(--line); }
.m-head h3 { margin: 0; font-size: 19px; }
.m-head small { color: var(--muted); }
.m-close { margin-left: auto; width: 34px; height: 34px; border-radius: 9px; font-size: 22px; color: var(--muted); }
.m-close:hover { background: var(--grey-soft); }
.m-body { padding: 18px 24px; display: grid; grid-template-columns: 1.25fr 1fr; gap: 22px; }
.m-sec h4 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--soft); }
.m-items { display: flex; flex-direction: column; }
.m-item { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid #f0f1f5; }
.m-item .em { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 20px; flex: none; }
.m-item .grow { flex: 1; }
.m-item small { color: var(--muted); }
.m-tot { display: flex; justify-content: space-between; padding: 6px 0; color: var(--muted); }
.m-tot.big { color: var(--text); font-weight: 800; font-size: 17px; padding-top: 10px; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 7px 10px; font-size: 13.5px; margin-bottom: 18px; }
.kv span { color: var(--muted); }
.steps { display: flex; flex-direction: column; gap: 0; }
.step { display: flex; gap: 10px; position: relative; padding-bottom: 12px; font-size: 13px; }
.step .d { width: 12px; height: 12px; border-radius: 50%; background: #dfe2ea; margin-top: 3px; flex: none; z-index: 1; }
.step.on .d { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.step.cur .d { background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.step:not(:last-child)::after { content: ""; position: absolute; left: 5px; top: 15px; bottom: 0; width: 2px; background: #eceef3; }
.step small { display: block; color: var(--muted); }
.m-foot { display: flex; align-items: center; gap: 10px; padding: 14px 24px 20px; border-top: 1px solid var(--line); background: #fafbfd; }
.m-foot label { color: var(--muted); font-weight: 600; }
.m-foot select { height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: #fff; min-width: 190px; font-weight: 600; }
.m-foot .sp { flex: 1; }

.toast { position: fixed; bottom: 28px; left: 50%; transform: translate(-50%, 20px); background: #1d2030; color: #fff; padding: 11px 18px; border-radius: 12px; font-weight: 600; opacity: 0; transition: .25s; z-index: 60; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.view-orders .kpis, .view-orders .row2 { display: none; }
