:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --border: #e1e6e4;
  --text: #17201c;
  --muted: #5f6b66;
  --accent: #128c5e;
  --accent-strong: #0d6e49;
  --accent-soft: #e5f4ed;
  --danger: #c0392b;
  --danger-soft: #fbeceb;
  --warn: #9a6700;
  --warn-soft: #fff6dd;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 20, 0.06), 0 4px 16px rgba(16, 24, 20, 0.05);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.5; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- Form ---------- */
label { display: block; font-weight: 500; margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
input[type='text'], input[type='email'], input[type='password'], input[type='search'], input[type='date'], select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  color: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.pw-field { position: relative; }
.pw-field input { padding-right: 42px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; display: grid; place-items: center;
  background: none; border: 0; border-radius: 6px; color: var(--muted); cursor: pointer;
}
.pw-toggle:hover { color: var(--text); background: var(--surface-2); }
.pw-toggle:focus-visible { outline: 2px solid var(--accent); }
.pw-toggle svg { width: 18px; height: 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--accent); color: #fff;
}
.btn:hover { background: var(--accent-strong); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: #efc5c0; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }

.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13.5px; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.success { background: var(--accent-soft); color: var(--accent-strong); }
.alert.info { background: var(--warn-soft); color: var(--warn); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 12.5px; }

/* ---------- Layout aplikasi ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 4px;
}
.sidebar .brand { padding: 0 8px; margin-bottom: 18px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { background: var(--accent-soft); color: var(--accent-strong); }
.nav-link svg { width: 18px; height: 18px; flex: none; }
button.nav-link { width: 100%; background: none; border: 0; font: inherit; cursor: pointer; text-align: left; }
button.nav-link:hover { color: var(--danger); background: var(--danger-soft); }
.sidebar-footer { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; }
.user-chip { padding: 4px 10px 10px; }
.user-chip .name { font-weight: 600; }
.user-chip .role { color: var(--muted); font-size: 12.5px; }

.main { padding: 28px 32px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin: 4px 0 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card h2 { font-size: 15px; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid-2 > .card { margin-top: 0; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .value.sm { font-size: 15px; padding-top: 5px; }

.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600; }
.status-pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-pill.connected { background: var(--accent-soft); color: var(--accent-strong); }
.status-pill.qr, .status-pill.connecting { background: var(--warn-soft); color: var(--warn); }
.status-pill.idle { background: #eef0ef; color: var(--muted); }

.qr-box { display: grid; place-items: center; padding: 12px; background: var(--surface-2); border: 1px dashed var(--border); border-radius: var(--radius); min-height: 220px; }
.qr-box img { width: 260px; max-width: 100%; height: auto; image-rendering: pixelated; background: #fff; padding: 8px; border-radius: 8px; }
.steps { margin: 0; padding-left: 18px; color: var(--muted); }
.steps li { margin-bottom: 4px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin-bottom: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; word-break: break-all; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Tabel ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.toolbar input[type='search'] { flex: 1 1 220px; width: auto; }
.toolbar input[type='date'] { width: auto; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.nowrap { white-space: nowrap; }
td.msg-text { white-space: pre-wrap; word-break: break-word; min-width: 260px; }
.muted { color: var(--muted); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: #eef0ef; color: var(--muted); }
.tag.green { background: var(--accent-soft); color: var(--accent-strong); }
.tag.red { background: var(--danger-soft); color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; color: var(--muted); gap: 8px; flex-wrap: wrap; }

.group-list { max-height: 340px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.group-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.group-item:last-child { border-bottom: 0; }
.group-item.selected { background: var(--accent-soft); }
.group-item .gname { font-weight: 500; }

/* ---------- Dialog ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(16, 24, 20, 0.4); }
.dialog-body { padding: 22px; }
.dialog-body h2 { font-size: 16px; margin-bottom: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }

.form-narrow { max-width: 420px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar .brand { margin: 0 auto 0 0; padding: 0; }
  .sidebar-footer { margin: 0; border: 0; padding: 0; display: flex; align-items: center; }
  .user-chip { display: none; }
  .nav-link span { display: none; }
  .main { padding: 20px 16px; }
  .grid-2, .stats { grid-template-columns: 1fr; }
}

/* ---------- Sakelar & sub-judul (kartu "Yang direkam") ---------- */
.sub-head { font-size: 13px; color: var(--muted); font-weight: 600; margin: 18px 0 8px; display: flex; align-items: center; gap: 6px; }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; margin: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch input:disabled { cursor: not-allowed; }
.slider { position: absolute; inset: 0; background: #cfd6d3; border-radius: 99px; transition: background .15s; }
.slider::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .slider { opacity: .6; }
.tag.blue { background: #e6eefb; color: #2456a6; }
