:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #16202c;
  --muted: #6b7789;
  --line: #e3e8ef;
  --nav: #12263f;
  --nav-ink: #c8d4e3;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --ok: #16794c;
  --warn: #a35c00;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.shell { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--nav);
  color: var(--nav-ink);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, #1f6feb, #2ea3a3);
  color: #fff; font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { color: #fff; font-size: 13.5px; }
.brand-text span { color: #8fa3ba; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.nav a {
  color: var(--nav-ink);
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 13.5px;
}
.nav a:hover { background: rgba(255, 255, 255, .07); text-decoration: none; }
.nav a.active { background: rgba(255, 255, 255, .12); color: #fff; font-weight: 600; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.badge-ro {
  font-size: 11px; text-align: center; padding: 4px 8px;
  border: 1px solid #3a5573; border-radius: 999px; color: #9db4cd;
}
.user-chip { display: flex; align-items: center; gap: 9px; padding: 6px; }
.avatar {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 50%;
  background: #243b58; color: #fff; font-size: 12px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.user-meta strong { color: #fff; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { color: #8fa3ba; font-size: 11px; }
.logout-form button { width: 100%; }

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 26px 10px;
}
.topbar-title h1 { font-size: 20px; margin: 0; font-weight: 650; }
.topbar-title p { margin: 2px 0 0; font-size: 13px; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.topbar > .btn { margin-left: auto; }
.menu-btn {
  display: none; border: 1px solid var(--line); background: #fff;
  border-radius: 9px; padding: 6px 10px; font-size: 16px; cursor: pointer;
}

.content { padding: 8px 26px 34px; display: flex; flex-direction: column; gap: 16px; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head h2 { font-size: 15px; margin: 0; font-weight: 650; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.block { display: block; }
.empty { text-align: center; padding: 22px 0 !important; }
.strong { font-weight: 650; }
.danger { color: var(--danger); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpis-3 { grid-template-columns: repeat(3, 1fr); }
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi.compact { padding: 12px 16px; }
.kpi-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.kpi-value { font-size: 23px; font-weight: 680; letter-spacing: -.4px; }
.kpi.compact .kpi-value { font-size: 19px; }
.kpi-foot { color: var(--muted); font-size: 12px; }
.kpi-foot em { font-style: normal; margin-left: 6px; }
.kpi-foot .up { color: var(--ok); }
.kpi-foot .down { color: var(--danger); }

/* ---------- grid ---------- */
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
.detail-top { grid-template-columns: 1fr 1fr; }

/* ---------- chart ---------- */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 8px; }
.chart-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; }
.chart-bar {
  width: 100%; max-width: 26px; min-height: 2px;
  background: linear-gradient(180deg, #2ea3a3, #1f6feb);
  border-radius: 5px 5px 2px 2px;
}
.chart-x { font-size: 10px; color: var(--muted); }

/* ---------- lists ---------- */
.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.rank li { display: flex; align-items: center; gap: 10px; }
.rank-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-value { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 10px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line);
}
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tfoot td { padding: 9px 10px; font-size: 13.5px; border-top: 1px solid var(--line); }
.table .total-row td { font-size: 15px; }

/* ---------- filters ---------- */
.filters { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; padding: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 140px; }
.field.grow { flex: 1; min-width: 220px; }
.field span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.field input, .field select, .form input {
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px;
  font: inherit; background: #fff; color: var(--ink); min-height: 36px;
}
.field input:focus, .field select:focus, .form input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 111, 235, .12);
}
.filter-actions { display: flex; gap: 8px; margin-left: auto; }
.check { display: flex; align-items: center; gap: 7px; padding-bottom: 9px; color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: inherit; font-weight: 550;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; background: #f6f8fb; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #1a61cf; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn.disabled { opacity: .45; pointer-events: none; }

/* ---------- pager ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; }
.pager-buttons { display: flex; gap: 8px; }

/* ---------- pills & facts ---------- */
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  background: #eef3f8; color: #41536b; font-size: 11.5px; font-weight: 600;
}
.pill-warn { background: #fff3e0; color: var(--warn); }

.facts { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
.facts dt { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.facts dd { margin: 2px 0 0; font-size: 14px; }

/* ---------- login ---------- */
.login-wrap { min-height: calc(100vh - 150px); display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 380px; padding: 26px; }
.login-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-head h2 { margin: 0; font-size: 17px; }
.login-head p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 5px; }
.form label span { font-size: 12px; color: var(--muted); }
.alert { padding: 10px 12px; border-radius: 9px; margin-bottom: 14px; font-size: 13px; }
.alert-error { background: #fdecea; color: #922b21; border: 1px solid #f5c6c0; }

/* ---------- data entry ---------- */
.badge-live {
  font-size: 11px; text-align: center; padding: 4px 8px;
  border: 1px solid #2c6b4d; border-radius: 999px;
  color: #a8e6c4; background: rgba(34, 139, 87, .16);
}

.entry-form { display: flex; flex-direction: column; gap: 16px; }
.form-grid {
  display: grid; gap: 12px 16px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.form-grid .span-2 { grid-column: span 2; }
.form-grid .field input, .form-grid .field select {
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px;
  font: inherit; background: #fff; color: var(--ink); min-height: 36px; width: 100%;
}
.form-grid .field input:focus, .form-grid .field select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 111, 235, .12);
}
.form-grid .check { align-self: end; padding-bottom: 8px; }

.total-field .entry-total { font-size: 19px; font-weight: 680; padding-top: 4px; }

.entry-table td { padding: 7px 6px; }
.entry-table input {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px;
  font: inherit; background: #fff; color: var(--ink); width: 100%; min-height: 34px;
}
.entry-table input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 111, 235, .12);
}
.entry-table .grow-cell { min-width: 220px; }
.entry-table .line-desc { margin-top: 4px; font-size: 12px; }
.entry-table .w-qty { width: 84px; }
.entry-table .w-unit { width: 74px; }
.entry-table .w-price { width: 110px; }
.entry-table .w-disc { width: 78px; }
.entry-table .w-total { width: 110px; }
.entry-table .line-total { color: var(--muted); }

.entry-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 4px 2px 8px;
}

.alert-ok { background: #e8f6ee; color: #17603f; border: 1px solid #bfe4cf; }

.pill-ok { background: #e6f4ec; color: var(--ok); }
.pill-danger { background: #fdecea; color: var(--danger); }

.steps { margin: 0 0 10px; padding-left: 20px; display: flex; flex-direction: column; gap: 7px; }
.steps li { line-height: 1.45; }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .kpis, .kpis-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .detail-top { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .sidebar {
    position: fixed; z-index: 20; left: -240px; transition: left .2s ease;
    height: 100vh; box-shadow: 0 0 0 100vmax rgba(0,0,0,0);
  }
  .sidebar.open { left: 0; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
  .menu-btn { display: inline-block; }
  .content { padding: 8px 14px 28px; }
  .topbar { padding: 14px 14px 8px; }
  .kpis, .kpis-3 { grid-template-columns: 1fr; }
  .filter-actions { margin-left: 0; width: 100%; }
  .facts { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .entry-actions { flex-direction: column-reverse; }
  .entry-actions .btn { width: 100%; }
}
