/* ================= Tokens ================= */
:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --panel-2: #f8f9fc;
  --hover: #f2f3f8;
  --border: #e5e7ef;
  --border-strong: #d3d7e2;
  --text: #11131c;
  --text-2: #3d4356;
  --muted: #6c7287;
  --accent: #5b5bd6;
  --accent-hover: #4b4bc4;
  --accent-soft: #eeeefc;
  --accent-text: #ffffff;
  --danger: #e5484d;
  --danger-soft: #fdeded;
  --success: #2f9e6a;
  --success-soft: #e7f7ef;
  --warn: #c98a12;
  --sidebar: #ffffff;
  --shadow-sm: 0 1px 2px rgba(16, 19, 35, .05);
  --shadow: 0 1px 3px rgba(16, 19, 35, .06), 0 8px 24px rgba(16, 19, 35, .06);
  --shadow-lg: 0 20px 60px rgba(16, 19, 35, .18);
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0e14;
    --panel: #13161e;
    --panel-2: #171b25;
    --hover: #1b2030;
    --border: #232838;
    --border-strong: #303749;
    --text: #eef0f6;
    --text-2: #c4c9d6;
    --muted: #8a91a5;
    --accent: #7272ec;
    --accent-hover: #8585f2;
    --accent-soft: #1d1f3d;
    --accent-text: #ffffff;
    --danger: #f2555a;
    --danger-soft: #2c1517;
    --success: #3dbb83;
    --success-soft: #11291f;
    --sidebar: #10131a;
    --shadow-sm: none;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 24px 70px rgba(0, 0, 0, .55);
  }
}

/* ================= Base ================= */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
code { font-family: var(--mono); font-size: .92em; background: var(--panel-2); border: 1px solid var(--border); padding: 0 5px; border-radius: 5px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.spacer { flex: 1; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ic.xl { width: 40px; height: 40px; stroke-width: 1.5; opacity: .5; }

/* ================= Buttons & inputs ================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; font-size: 13.5px; white-space: nowrap;
  border: 1px solid var(--border-strong); background: var(--panel); color: var(--text);
  cursor: pointer; transition: background .12s, border-color .12s, color .12s, transform .05s;
  text-decoration: none;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); box-shadow: var(--shadow-sm); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn.danger-ghost:hover { background: var(--danger-soft); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.95); }
.btn.icon { width: 36px; padding: 0; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn.icon.sm { width: 30px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  height: 38px; padding: 0 12px; width: 100%; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder { color: var(--muted); opacity: .8; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field em { font-style: normal; font-weight: 400; }
.input-group { display: flex; align-items: center; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--panel); transition: border-color .12s, box-shadow .12s; }
.input-group:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-group input, .input-group select { border: 0; box-shadow: none !important; background: transparent; }
.input-group .btn { height: 34px; margin-right: 2px; }
.addr-input .at { color: var(--muted); padding: 0 2px; }
.addr-input select { width: auto; max-width: 55%; padding-right: 8px; color: var(--text-2); }
.grid-2 { display: grid; grid-template-columns: 110px 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; cursor: pointer; }
.form-error { color: var(--danger); font-size: 13px; min-height: 0; }
.form-error:empty { display: none; }
.hint { margin-top: -6px; }

/* ================= Auth ================= */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(800px 400px at 20% -10%, var(--accent-soft), transparent 70%), var(--bg); }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow); }
.auth-card h1 { margin-top: 24px; }
.auth-card > .muted { margin: 4px 0 22px; }

/* ================= Brand ================= */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.02em; }
.brand b { color: var(--accent); font-weight: 700; }
.logo { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), #9b6bf2); box-shadow: 0 4px 12px rgba(91, 91, 214, .35); }
.logo .ic { width: 17px; height: 17px; }
.brand-lg { font-size: 19px; }
.brand-lg .logo { width: 38px; height: 38px; border-radius: 11px; }

/* ================= Shell ================= */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100%; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 24px;
  padding: 20px 14px; background: var(--sidebar); border-right: 1px solid var(--border);
}
.sidebar .brand { padding: 0 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 550; cursor: pointer; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item .count { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--muted); }
.nav-item.active .count { color: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); padding-top: 14px; }
.who { display: flex; align-items: center; gap: 10px; padding: 0 6px; min-width: 0; }
.who-text { min-width: 0; }
.who-email { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-role { font-size: 12px; color: var(--muted); }
.sidebar-foot .btn { justify-content: flex-start; }
.scrim { display: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 22px 32px 6px; }
.topbar-title { min-width: 0; flex: 1; }
.topbar-title .muted { font-size: 13px; margin-top: 2px; }
.topbar-actions { display: flex; gap: 8px; }
.menu-btn { display: none; }
.page { padding: 16px 32px 40px; display: flex; flex-direction: column; gap: 16px; max-width: 1280px; width: 100%; }

/* ================= Avatar ================= */
.avatar { width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #fff; background: var(--accent); text-transform: uppercase; }
.avatar.lg { width: 42px; height: 42px; font-size: 16px; }

/* ================= Panels ================= */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.panel.pad { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--hover); color: var(--muted); }
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge:empty { display: none; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hide-sm { display: none; }
}
.stat { display: flex; align-items: center; gap: 14px; padding: 16px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.stat-ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--hover); color: var(--text-2); }
.stat-ic.accent { background: var(--accent-soft); color: var(--accent); }
.stat-ic .ic { width: 19px; height: 19px; }
.stat-num { font-size: 22px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12.5px; color: var(--muted); }

/* Toolbar + search */
.toolbar { display: flex; align-items: center; gap: 12px; padding: 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.search-box { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
.search-box .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-box input { padding-left: 34px; }
.search-hero { position: relative; }
.search-hero .ic { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--muted); }
.search-hero input { height: 52px; padding-left: 48px; font-size: 16px; border-radius: var(--radius); box-shadow: var(--shadow-sm); }

/* Table */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 14px; background: var(--panel-2); border-bottom: 1px solid var(--border); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--panel-2); }
.table .num { width: 1%; white-space: nowrap; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.table .right { text-align: right; }
.cell-addr { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-addr .mono { font-family: var(--mono); font-size: 13px; white-space: nowrap; }
.table td { white-space: nowrap; }
.pill { white-space: nowrap; }
.cell-addr .btn { opacity: 0; }
.table tr:hover .cell-addr .btn, .cell-addr .btn:focus-visible { opacity: 1; }
.actions { display: flex; gap: 4px; justify-content: flex-end; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.count-cell { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; color: var(--text-2); padding: 40px 16px; }
.more { display: flex; justify-content: center; padding: 10px; }
.more:has(.hidden:only-child) { display: none; }

/* Search results */
.results { display: flex; flex-direction: column; gap: 10px; }
.result { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: start; padding: 14px 16px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); transition: border-color .12s; }
.result:hover { border-color: var(--border-strong); }
.result-no { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 22px; text-align: right; padding-top: 2px; }
.result-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.result-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.result-acc { font-family: var(--mono); font-size: 12px; color: var(--accent); background: var(--accent-soft); padding: 1px 7px; border-radius: 6px; }
.result-subj { font-weight: 650; word-break: break-word; }
.result-from, .result-snip { font-size: 13px; color: var(--muted); word-break: break-word; }
.result-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.code-tag { font: 700 14px var(--mono); color: var(--accent); background: var(--accent-soft); padding: 3px 9px; border-radius: 7px; letter-spacing: .04em; }

/* API */
.key-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.key-box { flex: 1; min-width: 240px; padding: 9px 12px; font-size: 13px; word-break: break-all; border-radius: var(--radius-sm); }
.api-examples { display: flex; flex-direction: column; gap: 14px; }
.api-ex h3 { font-size: 13.5px; font-weight: 650; margin-bottom: 6px; }
.api-ex .code-wrap { position: relative; }
.api-ex pre { margin: 0; padding: 11px 70px 11px 13px; overflow-x: auto; border-radius: var(--radius-sm); background: var(--panel-2); border: 1px solid var(--border); font: 12.5px/1.55 var(--mono); }
.api-ex .btn { position: absolute; top: 5px; right: 5px; }
.api-ex p { margin-top: 5px; }

/* ================= Inbox ================= */
.page-inbox { max-width: none; height: calc(100vh - 82px); padding-bottom: 20px; }
.inbox-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.addr-wrap { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.addr { font: 600 17px var(--mono); word-break: break-all; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--success); background: var(--success-soft); padding: 3px 10px; border-radius: 99px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.inbox { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); gap: 16px; }
.mail-list { overflow-y: auto; min-height: 0; }
.list-search { position: sticky; top: 0; z-index: 1; background: var(--panel); padding: 10px 10px 8px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.list-search .search-box { max-width: none; min-width: 0; }
.list-search .muted:empty { display: none; }
.list { list-style: none; margin: 0; padding: 6px; }
.list li { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; padding: 11px 12px; border-radius: 10px; cursor: pointer; position: relative; transition: background .1s; }
.list li + li { margin-top: 2px; }
.list li:hover { background: var(--hover); }
.list li.active { background: var(--accent-soft); }
.list li .avatar { grid-row: span 3; width: 34px; height: 34px; }
.li-top { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.li-from { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.li-subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.li-bottom { display: flex; align-items: center; gap: 8px; min-width: 0; }
.li-preview { flex: 1; min-width: 0; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li.unseen .li-from, .list li.unseen .li-subj { font-weight: 700; color: var(--text); }
.list li.unseen::before { content: ""; position: absolute; left: 3px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--accent); }
.code-chip { font: 700 12.5px var(--mono); color: var(--accent); background: var(--accent-soft); border: 1px solid transparent; padding: 1px 8px; border-radius: 6px; cursor: copy; white-space: nowrap; }
.code-chip:hover { border-color: var(--accent); }
.list li.active .code-chip { background: var(--panel); }

.reader { min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.reader-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--muted); }
.reader-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.reader-head { padding: 18px 20px 14px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 12px; }
.reader-back { display: none; align-self: flex-start; margin-left: -8px; }
.subject { font-size: 19px; font-weight: 700; word-break: break-word; }
.from-row { display: flex; align-items: center; gap: 10px; }
.from-name { font-weight: 600; }
.reader iframe { flex: 1; min-height: 300px; width: 100%; border: 0; background: #fff; border-radius: 0 0 var(--radius) var(--radius); }

/* ================= Dialog ================= */
.dialog { width: min(480px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 16px; padding: 22px; background: var(--panel); color: var(--text); box-shadow: var(--shadow-lg); }
.dialog.sm { width: min(400px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(10, 12, 20, .45); backdrop-filter: blur(2px); }
.dialog[open] { animation: pop .16s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.dialog > p { margin: 6px 0 12px; }
.creds { margin: 0; padding: 12px 14px; max-height: 260px; overflow: auto; border-radius: var(--radius-sm); background: var(--panel-2); border: 1px solid var(--border); font: 13px/1.7 var(--mono); white-space: pre-wrap; word-break: break-all; }

/* ================= Toast ================= */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 9px; padding: 10px 14px; border-radius: 10px; background: #1b1e2b; color: #f2f3f8; font-weight: 550; font-size: 13.5px; box-shadow: var(--shadow-lg); animation: toast-in .18s ease-out; max-width: 360px; }
.toast .ic { color: #6ee7a8; }
.toast.err .ic { color: #ff8a8e; }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ================= Responsive ================= */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; left: 0; top: 0; width: 264px; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .shell.nav-open .sidebar { transform: none; }
  .shell.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(10, 12, 20, .4); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 14px 16px 4px; }
  .page { padding: 12px 16px 32px; }
  .hide-sm { display: none; }
  .cell-addr .btn { opacity: 1; }
  .page-inbox { height: auto; }
  .inbox { grid-template-columns: 1fr; }
  .mail-list { overflow: visible; }
  .reader { display: none; min-height: 70vh; }
  .inbox.reading .reader { display: flex; }
  .inbox.reading .mail-list { display: none; }
  .reader-back { display: inline-flex; }
  .result { grid-template-columns: 1fr; }
  .result-no { display: none; }
  .result-side { flex-direction: row; align-items: center; justify-content: space-between; }
}
@media (max-width: 640px) {
  /* Tabel akun jadi kartu bertumpuk biar tombol aksi kelihatan tanpa geser */
  .table thead { display: none; }
  .table, .table tbody { display: block; }
  .table tr { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; grid-template-areas: "num addr count" "num act act"; gap: 8px 10px; padding: 12px; border-bottom: 1px solid var(--border); }
  .table tbody tr:last-child { border-bottom: 0; }
  .table td { padding: 0; border: 0; min-width: 0; }
  .table td:nth-child(1) { grid-area: num; padding-top: 6px; }
  .table td:nth-child(2) { grid-area: addr; }
  .table td:nth-child(3) { grid-area: count; align-self: center; }
  .table td:nth-child(5) { grid-area: act; }
  .table .actions { justify-content: flex-start; padding-left: 42px; }
  .cell-addr .mono { overflow: hidden; text-overflow: ellipsis; }
  .toolbar .search-box { max-width: none; }
}
@media (max-width: 520px) {
  .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat { padding: 12px; gap: 10px; }
  .stat-ic { width: 34px; height: 34px; }
}
