:root {
  --brand: #007998; --brand-2: #005f78; --brand-soft: #e3f3f7;
  --ink: #101828; --muted: #667085; --line: #e4e7ec; --bg: #f6f7f9; --card: #fff;
  --red: #d92d20; --red-soft: #fef3f2; --amber: #b54708; --amber-soft: #fffaeb; --blue: #2563eb; --blue-soft: #eff4ff;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06);
  font-family: Inter, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); }
h2, h3 { margin: 0; }
h3 { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

/* layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 232px; background: #062a35; color: #d3e6ec; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { display: flex; flex-direction: column; gap: 6px; padding: 16px 14px 12px; text-decoration: none; }
.brand-logo { background: #fff; border-radius: 10px; padding: 9px 10px; display: flex; justify-content: center; }
.brand-logo img { display: block; width: 100%; max-width: 176px; height: auto; }
.brand-sub { color: #9cc9d6; font-size: 12px; font-weight: 600; letter-spacing: .02em; text-align: center; }
.login-logo { display: flex; justify-content: center; margin-bottom: 6px; }
.login-logo img { width: 236px; max-width: 100%; height: auto; }
.login-title { font-size: 17px; text-align: center; margin: 4px 0 2px; color: var(--ink); }
.login-card .muted { text-align: center; }
.brand-mark { background: var(--brand); color: #fff; border-radius: 8px; width: 30px; height: 30px; display: grid; place-items: center; font-size: 13px; }
.brand.big { font-size: 18px; color: var(--ink); padding: 0 0 8px; }
#nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; overflow-y: auto; flex: 1; }
#nav a { color: #c2dbe3; text-decoration: none; padding: 9px 10px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
#nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
#nav a.active { background: var(--brand); color: #fff; }
#nav .ico { width: 18px; text-align: center; opacity: .9; }
#nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #79a6b3; padding: 14px 10px 4px; }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.08); padding: 14px 18px; display: flex; flex-direction: column; gap: 6px; }
.sidebar-foot .me { display: flex; flex-direction: column; color: #fff; }
.sidebar-foot .muted { color: #8db6c2; font-size: 12px; }
.sidebar-foot .btn.link { color: #b5d5df; padding: 0; text-align: left; }
.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 16px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h2 { font-size: 18px; flex: 1; }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.menu-btn { display: none; }
.view { padding: 20px 24px 60px; max-width: 1400px; }

/* controls */
.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--brand); padding: 4px 0; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; width: 36px; height: 36px; font-size: 18px; cursor: pointer; }
input, select, textarea { font: inherit; border: 1px solid #d0d5dd; border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(0,121,152,.25); border-color: var(--brand); }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: #344054; font-weight: 500; }
.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.rangebar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.rangebar .dates { display: flex; gap: 6px; align-items: center; }
.rangebar .dates input { width: 150px; padding: 6px 8px; }
.rangebar .label { color: var(--muted); font-size: 13px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters label { min-width: 160px; }
.filters .grow { flex: 1; min-width: 200px; }

/* cards & kpis */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kpi.accent { background: var(--brand); border-color: var(--brand); color: #fff; }
.kpi.accent .label, .kpi.accent .sub { color: #cde8ef; }
.delta { font-weight: 600; font-size: 12px; }
.delta.up { color: #067647; } .delta.down { color: var(--red); }
.kpi.accent .delta.up { color: #b7f0d3; } .kpi.accent .delta.down { color: #ffd2cc; }
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; margin-bottom: 12px; }
.grid2.even { grid-template-columns: 1fr 1fr; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px; }
.chart { position: relative; height: 260px; }
.chart.sm { height: 200px; }
.legend-list { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.legend-list li { display: flex; justify-content: space-between; gap: 8px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; vertical-align: -1px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 10px; gap: 10px; flex-wrap: wrap; }
.section-title h3 { margin: 0; }

/* tables */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #fafbfc; }
tr.total td { font-weight: 700; background: #f3f9fb; }
.name { font-weight: 600; }
.sub { color: var(--muted); font-size: 12px; }
.art { display: flex; gap: 10px; align-items: flex-start; max-width: 520px; }
.art img { width: 64px; height: 42px; object-fit: cover; border-radius: 6px; flex-shrink: 0; background: #eee; }
.art a { color: var(--ink); text-decoration: none; font-weight: 600; }
.art a:hover { color: var(--brand); text-decoration: underline; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #f2f4f7; color: #344054; white-space: nowrap; }
.badge.green { background: var(--brand-soft); color: var(--brand); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 8px; flex-wrap: wrap; }
.pager .btns { display: flex; gap: 8px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.loading { padding: 30px; text-align: center; color: var(--muted); }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.bar-cell { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.bar-cell .bar { height: 6px; background: var(--brand); border-radius: 3px; }

/* alerts, toast, modal */
.alert { border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 10px 0; }
.alert.error { background: var(--red-soft); color: var(--red); }
.alert.info { background: var(--blue-soft); color: #1d4ed8; }
.alert.warn { background: var(--amber-soft); color: var(--amber); }
.alert.ok { background: var(--brand-soft); color: var(--brand); }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #101828; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; font-size: 13px; max-width: 90vw; }
.modal-bg { position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 40; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 40px rgba(0,0,0,.2); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; }
.modal .body { padding: 16px 18px; display: grid; gap: 12px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.preview { display: flex; gap: 12px; align-items: center; background: #f9fafb; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.preview img { width: 90px; height: 58px; object-fit: cover; border-radius: 6px; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; background: #f2f4f7; padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, #eef0f3, #f7f8fa, #eef0f3); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; background: linear-gradient(160deg, #062a35, #00607a); }
.login-card { background: #fff; border-radius: 16px; padding: 28px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.stack { display: grid; gap: 12px; margin-top: 14px; }

/* mobile */
@media (max-width: 900px) {
  .grid2, .grid2.even, .grid3 { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; z-index: 30; transition: left .2s; }
  .sidebar.open { left: 0; }
  .menu-btn { display: inline-block; }
  .view { padding: 14px 12px 60px; }
  .topbar { padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  table.cards thead { display: none; }
  table.cards tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 4px; }
  table.cards td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 10px; text-align: right; }
  table.cards td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; }
  table.cards td.first { display: block; text-align: left; }
  table.cards td.first::before { content: none; }
  .kpi .value { font-size: 20px; }
}
