:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #6b7686;
  --line: #e3e7ee;
  --brand: #1f6feb;
  --brand-ink: #ffffff;
  --ok: #1a7f4b;
  --ok-bg: #e5f6ec;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --bad: #b42318;
  --bad-bg: #fde9e7;
  --info: #175cd3;
  --info-bg: #e7f0ff;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --card: #171e27;
    --text: #e6ebf2;
    --muted: #93a0b2;
    --line: #273241;
    --brand: #4d8ff5;
    --ok-bg: #12301f;
    --ok: #5fd08f;
    --warn-bg: #3a2c0b;
    --warn: #f0c35a;
    --bad-bg: #3b1513;
    --bad: #ff8a80;
    --info-bg: #13284a;
    --info: #8ab4ff;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
small, .muted { color: var(--muted); }
code { background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-size: 13px; word-break: break-all; }

/* ===== layout ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 16px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { display: none; background: none; border: 0; font-size: 22px; color: var(--text); cursor: pointer; padding: 4px 6px; }
.shell { display: flex; min-height: calc(100vh - 56px); }
.side {
  width: 220px; flex: 0 0 220px; padding: 14px 10px;
  background: var(--card); border-right: 1px solid var(--line);
}
.side a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin-bottom: 2px; border-radius: 8px;
  color: var(--text); font-weight: 500;
}
.side a:hover { background: var(--bg); text-decoration: none; }
.side a.on { background: var(--brand); color: var(--brand-ink); }
.ico { width: 18px; text-align: center; opacity: .85; }
.main { flex: 1; min-width: 0; padding: 22px 24px 60px; max-width: 1150px; }

@media (max-width: 820px) {
  .menu-btn { display: block; }
  .side {
    position: fixed; top: 56px; left: 0; bottom: 0; z-index: 15;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 0 8px 30px rgba(0,0,0,.15);
  }
  .side.open { transform: none; }
  .main { padding: 16px 16px 60px; }
}

/* ===== auth ===== */
.auth { max-width: 400px; margin: 8vh auto; padding: 0 16px; }
.auth h1 { text-align: center; }

/* ===== cards & grid ===== */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px;
}
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 980px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

/* ===== forms ===== */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 5px; font-size: 14px; }
.field small { display: block; margin-top: 4px; font-size: 12.5px; }
.field.check label { font-weight: 500; display: flex; gap: 8px; align-items: center; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=search], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13.5px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters > * { width: auto; flex: 1 1 140px; }
.filters .btn { flex: 0 0 auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn-danger { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
form.inline { display: inline; }

/* ===== tables ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

/* ===== misc ===== */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.flash { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--bad-bg); color: var(--bad); }
.flash-info { background: var(--info-bg); color: var(--info); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 14px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.progress { height: 10px; background: var(--bg); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.progress > div { height: 100%; background: var(--brand); width: 0; transition: width .4s; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; }
@media (max-width: 560px) { .kv { grid-template-columns: 1fr; } .kv dt { margin-top: 6px; } }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; word-break: break-word; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* utilitas (pengganti style inline, karena CSP melarang style="...") */
.mb { margin-bottom: 14px; }
.grow { flex: 1 1 200px; width: auto; }
.w-sm { width: 110px !important; flex: 0 0 110px; }
.btn-block { width: 100%; }
.center { text-align: center; }
label.btn input[type=file] { display: none; }

/* rapikan jarak kartu di dalam grid */
.grid { margin-bottom: 16px; }
.grid > .card { margin-bottom: 0; }
@media (max-width: 560px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .stat { padding: 14px; }
  .stat .value { font-size: 18px; }
}
