:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --border: #e4e7ef;
    --text: #1b2033;
    --muted: #6b7189;
    --primary: #4f46e5;
    --primary-soft: #eef0ff;
    --sidebar: #141a2e;
    --sidebar-text: #aab1cc;
    --green: #15803d;
    --green-soft: #e7f6ec;
    --red: #b91c1c;
    --red-soft: #fdecec;
    --amber: #b45309;
    --amber-soft: #fff4e0;
    --blue: #1d4ed8;
    --blue-soft: #e6eeff;
    --gray-soft: #eef0f4;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(20, 26, 46, .04), 0 4px 16px rgba(20, 26, 46, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2 { margin: 0; }
h2 { font-size: 15px; font-weight: 600; }
small { font-size: 12px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.link { color: var(--primary); font-weight: 500; }
.link:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
    display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 4px 8px 22px; }
.brand-mark {
    display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
    background: linear-gradient(135deg, #6366f1, #22d3ee); color: #fff; font-weight: 700;
}
.brand-mark.big { width: 56px; height: 56px; font-size: 26px; border-radius: 16px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; font-weight: 500;
    transition: background .15s, color .15s;
}
.sidebar nav a svg { width: 18px; height: 18px; fill: currentColor; opacity: .85; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar nav a.active { background: rgba(99, 102, 241, .22); color: #fff; }
.sidebar-footer { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, .08); padding-top: 14px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.user-chip:hover, .user-chip.active { background: rgba(255, 255, 255, .06); }
.user-chip strong { display: block; color: #fff; font-size: 13px; }
.user-chip small { color: var(--sidebar-text); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #2b3352; color: #fff; display: grid; place-items: center; font-weight: 600; }
.logout { display: block; margin-top: 6px; padding: 8px; font-size: 13px; border-radius: 8px; }
.logout:hover { color: #fff; background: rgba(255, 255, 255, .06); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; gap: 12px; padding: 18px 28px; background: var(--surface);
    border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 20px; font-weight: 700; }
.topbar-right { margin-left: auto; color: var(--muted); font-size: 13px; }
.menu-btn { display: none; background: none; border: 0; padding: 4px; cursor: pointer; }
.menu-btn svg { width: 24px; height: 24px; fill: var(--text); }
.content { padding: 24px 28px; display: flex; flex-direction: column; gap: 20px; flex: 1; }
.page-footer { padding: 16px 28px; color: var(--muted); font-size: 12px; }
.sidebar-backdrop { display: none; }

/* ---------- Cards & grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { display: flex; align-items: center; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-2-1 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.kpi-grid.three { grid-template-columns: repeat(3, 1fr); }
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi-label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi-value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: 12px; color: var(--muted); }
.delta { font-weight: 600; margin-right: 4px; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.delta.flat { color: var(--muted); }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toolbar p { margin: 0; }
.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.segmented a { padding: 6px 14px; border-radius: 7px; font-weight: 600; font-size: 13px; color: var(--muted); }
.segmented a.active { background: var(--primary); color: #fff; }

.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 300px; }
.legend-list { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 6px; }
.legend-list li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend-list i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend-list span:last-child { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted); font-weight: 600; padding: 10px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { border-top: 1px solid var(--border); border-bottom: 0; padding: 8px 10px; }
.table tfoot .grand td { font-weight: 700; font-size: 15px; }
.table.compact td { padding: 8px 10px; }
.table .num { text-align: right; }
.table tr.inactive { opacity: .55; }
.cell-title { font-weight: 500; }
.empty { text-align: center; color: var(--muted); padding: 28px !important; }
.bar { height: 4px; background: var(--gray-soft); border-radius: 4px; margin-top: 6px; max-width: 220px; }
.bar span { display: block; height: 100%; background: var(--primary); border-radius: 4px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-pending { background: var(--amber-soft); color: var(--amber); }
.badge-processing { background: var(--blue-soft); color: var(--blue); }
.badge-shipped { background: var(--primary-soft); color: var(--primary); }
.badge-delivered { background: var(--green-soft); color: var(--green); }
.badge-cancelled { background: var(--gray-soft); color: var(--muted); }
.badge-refunded { background: var(--red-soft); color: var(--red); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--gray-soft); font-size: 12px; font-weight: 600; }
.pill.warn { background: var(--amber-soft); color: var(--amber); }
.pill.accent { background: var(--primary-soft); color: var(--primary); }

.status-list, .stock-list { list-style: none; padding: 0; margin: 0; }
.status-list li, .stock-list li { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.status-list li:last-child, .stock-list li:last-child { border-bottom: 0; }
.stock-list small { display: block; color: var(--muted); }
.stock-num { font-weight: 600; color: var(--amber); white-space: nowrap; }
.stock-num.crit { color: var(--red); }

/* ---------- Forms ---------- */
input, select, button { font: inherit; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input[type=date], input:not([type]), select {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; background: #fff; color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 13px; }
label.inline { flex-direction: row; align-items: center; gap: 8px; white-space: nowrap; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form.narrow { max-width: 720px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 16px; }
.filters input[type=search] { flex: 1 1 240px; width: auto; }
.filters select { width: auto; }
.filters input[type=date] { width: auto; }
.push-right { margin-left: auto; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 9px;
    border: 1px solid transparent; font-weight: 600; cursor: pointer; white-space: nowrap; font-size: 13.5px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #4338ca; }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }

.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-reset { display: flex; gap: 6px; }
.inline-reset input { width: 140px; padding: 5px 8px; font-size: 12.5px; }
.status-form { display: flex; gap: 10px; align-items: flex-end; margin-top: 16px; }
.status-form label { flex: 1; }

.details { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; margin: 0 0 12px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; font-weight: 500; word-break: break-word; }

.alert { padding: 11px 14px; border-radius: 10px; font-weight: 500; }
.alert-success { background: var(--green-soft); color: var(--green); }
.alert-error { background: var(--red-soft); color: var(--red); }
.alert-info { background: var(--blue-soft); color: var(--blue); }

.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; padding-top: 16px; }
.pagination a, .pagination .disabled { padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; font-weight: 500; }
.pagination a:hover { background: var(--surface-2); }
.pagination .disabled { color: var(--muted); opacity: .5; }
.page-info { color: var(--muted); }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px;
    background: radial-gradient(circle at 15% 20%, #e0e7ff 0, transparent 40%), radial-gradient(circle at 85% 80%, #cffafe 0, transparent 40%), var(--bg); }
.login-wrap { display: grid; grid-template-columns: 1fr 1fr; width: 100%; max-width: 880px; background: var(--surface);
    border-radius: 20px; overflow: hidden; box-shadow: 0 20px 60px rgba(20, 26, 46, .15); }
.login-art { background: linear-gradient(150deg, #141a2e, #312e81); color: #c7cbe0; padding: 48px; display: flex; align-items: center; }
.login-art h2 { color: #fff; font-size: 26px; margin: 18px 0 10px; }
.login-art p { line-height: 1.6; margin: 0; }
.login-card { padding: 48px 44px; display: flex; flex-direction: column; gap: 16px; }
.login-card h1 { font-size: 24px; }
.login-card .muted { margin: -10px 0 4px; }
.demo-box { background: var(--surface-2); border: 1px dashed var(--border); border-radius: 10px; padding: 12px 14px; font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.demo-box strong { color: var(--text); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .grid-2-1, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
    .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
    .sidebar.open { transform: none; }
    .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 20; }
    .menu-btn { display: block; }
    .topbar { padding: 14px 16px; }
    .topbar-right { display: none; }
    .content { padding: 16px; }
    .grid-2, .kpi-grid.three { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .login-wrap { grid-template-columns: 1fr; }
    .login-art { display: none; }
    .login-card { padding: 32px 24px; }
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .filters > * { flex: 1 1 100%; }
    .filters select, .filters input[type=date] { width: 100%; }
    .push-right { margin-left: 0; }
}
