:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --line: #e1e6ee;
  --text: #121821;
  --muted: #5f6b7a;
  --accent: #1a73e8;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0fd;
  --ok: #138a4b;
  --ok-soft: #e3f5ea;
  --warn: #a35b00;
  --warn-soft: #fff1dc;
  --bad: #c62828;
  --bad-soft: #fde8e8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0f13;
    --surface: #151a21;
    --surface-2: #1c232c;
    --line: #2a333e;
    --text: #e8edf3;
    --muted: #93a0af;
    --accent: #5aa2ff;
    --accent-ink: #0b1220;
    --accent-soft: #15263d;
    --ok: #4cc38a;
    --ok-soft: #13291f;
    --warn: #f0a845;
    --warn-soft: #2d2213;
    --bad: #ff7a7a;
    --bad-soft: #321a1c;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 10px 16px; color: var(--text); }
.brand img { width: 28px; height: 28px; }
.brand span { font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 2px 6px; border-radius: 6px; }
.nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
  font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav .count { font-size: 11px; background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 0 7px; font-weight: 600; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 14px 10px 4px; }
.side-foot { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); font-size: 12px; }
.side-foot b { display: block; font-size: 13px; }
.main { padding: 26px 32px 60px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 4px 8px; }
  .nav { display: flex; overflow-x: auto; gap: 2px; width: 100%; }
  .nav a { white-space: nowrap; }
  .nav-sep { display: none; }
  .side-foot { margin: 0; border: 0; width: 100%; display: flex; justify-content: space-between; align-items: center; }
  .main { padding: 18px 16px 50px; }
}

/* ---------- Komponen ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.grid > .card + .card { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat .num { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn.ghost { border-color: transparent; background: transparent; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.badge { display: inline-block; font-size: 11px; font-weight: 600; border-radius: 6px; padding: 1px 7px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }

.alert { border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; background: var(--accent-soft); color: var(--text); border: 1px solid var(--line); }
.alert.warn { background: var(--warn-soft); }
.alert.bad { background: var(--bad-soft); }
.alert.ok { background: var(--ok-soft); }

/* ---------- Form ---------- */
label.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.field > small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="number"], input[type="search"], textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 11px;
  font: inherit;
}
textarea { resize: vertical; min-height: 84px; line-height: 1.55; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check:last-child { border-bottom: 0; }
.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); }
.check b { display: block; }
.err { color: var(--bad); font-size: 13px; margin: 0 0 12px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters input[type="search"] { max-width: 260px; }
.filters select { width: auto; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Tabel ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
td .title { font-weight: 600; }
td .ref { font-size: 12px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.empty { text-align: center; color: var(--muted); padding: 34px 10px; }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: 1fr 300px; gap: 18px; align-items: start; }
.editor-side { position: sticky; top: 16px; }
@media (max-width: 1240px) { .editor { grid-template-columns: 1fr; } .editor-side { position: static; order: -1; } }
@media (max-width: 640px) {
  .rows-head { display: none; }
  .rows .row { grid-template-columns: 1fr 34px !important; padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
  .rows .row input { grid-column: 1; }
  .rows .row .x { grid-column: 2; grid-row: 1; }
}
.rows .row { display: grid; gap: 6px; grid-template-columns: var(--cols, 1fr) 34px; margin-bottom: 6px; }
.rows .row input { padding: 7px 9px; font-size: 13px; }
.rows-head { display: grid; gap: 6px; grid-template-columns: var(--cols, 1fr) 34px; font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.x { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 8px; cursor: pointer; font-size: 16px; line-height: 1; }
.x:hover { color: var(--bad); background: var(--bad-soft); }
.section-box { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: var(--surface-2); }
.section-box .actions { justify-content: space-between; margin-bottom: 8px; }
fieldset { border: 0; padding: 0; margin: 0 0 6px; }
legend { font-weight: 700; font-size: 13px; padding: 0; margin-bottom: 8px; }
.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 22px 0 10px; font-weight: 700; }

/* ---------- Pratinjau ---------- */
.modal { position: fixed; inset: 0; background: rgba(10, 14, 20, 0.55); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal-box { background: var(--surface); border-radius: 14px; max-width: 720px; width: 100%; padding: 22px; }
.preview h2 { font-size: 20px; margin-bottom: 8px; }
.preview .lead { font-size: 15px; color: var(--muted); }
.preview h3 { margin: 16px 0 6px; }
.preview p { margin: 0 0 10px; }
.preview img { max-width: 100%; border-radius: 10px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 26px; }
.login .brand { padding: 0 0 18px; justify-content: center; }
.login h1 { font-size: 18px; text-align: center; margin-bottom: 6px; }
.login p { text-align: center; margin: 0 0 18px; }
.qr { display: block; margin: 0 auto 10px; border-radius: 10px; background: #fff; padding: 6px; width: 200px; height: 200px; }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: var(--surface-2); border-radius: 8px; padding: 8px; text-align: center; word-break: break-all; margin-bottom: 14px; user-select: all; }
.code-input { text-align: center; font-size: 22px !important; letter-spacing: 0.3em; font-family: ui-monospace, Consolas, monospace; }
.btn.block { width: 100%; justify-content: center; padding: 10px; }

.token-box { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); border-radius: 8px; padding: 10px; word-break: break-all; user-select: all; margin: 8px 0; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(30px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s;
  z-index: 60;
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.bad { background: var(--bad); color: #fff; }
.mt { margin-top: 14px; }
