:root {
  --bg: #f4f5f8; --panel: #ffffff; --side: #eef0f4; --line: #e2e5eb; --line2: #d3d8e0;
  --text: #1b1f27; --muted: #667085; --faint: #98a2b3;
  --accent: #1e6ff0; --accent-2: #155ad0; --accent-soft: #e6effe;
  --danger: #d92d20; --danger-soft: #fdecea; --warn: #dc6803; --warn-soft: #fef4e6; --ok: #079455; --ok-soft: #e5f6ee;
  --digit: #1e6ff0; --symbol: #d92d20;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --font: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, "Leelawadee UI", "Noto Sans Thai", sans-serif;
  --mono: "Cascadia Mono", "JetBrains Mono", Consolas, ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --panel: #181c24; --side: #14171e; --line: #262c37; --line2: #323a47;
    --text: #e8ebf1; --muted: #98a2b3; --faint: #667085;
    --accent: #4b8dff; --accent-2: #6aa1ff; --accent-soft: #1b2a44;
    --danger: #ff6b5e; --danger-soft: #3a1f1d; --warn: #f5a524; --warn-soft: #3a2c14; --ok: #3ccb7f; --ok-soft: #15301f;
    --digit: #6aa1ff; --symbol: #ff7a6e; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 15px; height: 15px; }
svg.i.lg { width: 22px; height: 22px; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line2); background: var(--panel); cursor: pointer; font-weight: 600; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--side); }
.btn:focus-visible, .ibtn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--side); }
.btn.block { width: 100%; height: 40px; }
.btn:disabled { opacity: .55; cursor: default; }
.ibtn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 8px; border: 0;
  background: transparent; color: var(--muted); cursor: pointer; }
.ibtn:hover { background: var(--side); color: var(--text); }
.ibtn.on { color: #f5b301; }
input.in, select.in, textarea.in { width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--line2); border-radius: 8px; background: var(--panel); }
textarea.in { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; }
input.in::placeholder, textarea.in::placeholder { color: var(--faint); }
label.lbl { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; text-transform: none; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.seg { display: inline-flex; background: var(--side); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
input[type=range] { accent-color: var(--accent); width: 100%; }

/* ---------- auth screens ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, rgba(30,111,240,.16), transparent 60%), radial-gradient(900px 500px at 110% 110%, rgba(21,70,184,.14), transparent 60%), var(--bg); }
.auth-card { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); }
.auth-card.wide { width: min(640px, 100%); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: -.01em; margin-bottom: 22px; }
.brand img { width: 34px; height: 34px; }
.auth h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: -.01em; }
.auth p.sub { margin: 0 0 22px; color: var(--muted); }
.auth .links { margin-top: 18px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.auth .links button { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-weight: 600; }
.acct-chip { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 18px; }
.err { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: 9px 12px; font-size: 13px; }
.meter { height: 6px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 7px; }
.meter > i { display: block; height: 100%; width: 0; border-radius: 4px; transition: width .2s, background .2s; }
.meter-label { font-size: 12px; margin-top: 4px; color: var(--muted); }
.s0 { background: var(--danger); } .s1 { background: #f97066; } .s2 { background: var(--warn); } .s3 { background: #32d583; } .s4 { background: var(--ok); }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- emergency kit ---------- */
.kit { border: 2px dashed var(--line2); border-radius: 14px; padding: 22px; margin: 18px 0; background: var(--bg); }
.kit h2 { margin: 0 0 4px; font-size: 18px; }
.kit .kv { display: grid; grid-template-columns: 140px 1fr; gap: 10px 14px; margin-top: 16px; align-items: center; }
.kit .kv b { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kit .sk { font-family: var(--mono); font-size: 17px; font-weight: 600; letter-spacing: .02em; word-break: break-all; color: var(--accent); }
.kit .blank { border-bottom: 1px solid var(--line2); height: 26px; }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-columns: 236px 340px 1fr; grid-template-rows: 56px 1fr; height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar .brand { margin: 0; font-size: 17px; width: 210px; }
.topbar .brand img { width: 28px; height: 28px; }
.search { position: relative; flex: 1; max-width: 560px; }
.search svg { position: absolute; left: 11px; top: 9px; color: var(--faint); }
.search input { padding-left: 36px; background: var(--side); border-color: transparent; }
.search input:focus { background: var(--panel); border-color: var(--line2); }
.kbd { font-size: 11px; color: var(--faint); border: 1px solid var(--line2); border-radius: 5px; padding: 1px 5px; position: absolute; right: 10px; top: 9px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 13px; flex: none; }

.sidebar { background: var(--side); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px 10px 20px; }
.nav-sec { font-size: 11px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; padding: 14px 10px 6px; display: flex; align-items: center; }
.nav-sec .ibtn { width: 22px; height: 22px; margin-left: auto; }
.nav { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; border-radius: 8px; background: none; cursor: pointer;
  text-align: left; color: var(--text); font-weight: 500; }
.nav:hover { background: rgba(127,127,127,.1); }
.nav.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav svg { color: var(--muted); }
.nav.on svg { color: var(--accent); }
.nav .count { margin-left: auto; font-size: 12px; color: var(--faint); font-weight: 500; }
.nav .badge { margin-left: auto; font-size: 11px; background: var(--danger); color: #fff; border-radius: 10px; padding: 0 7px; font-weight: 700; }
.vault-ico { width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 700; flex: none; }

.list { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.list-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.list-head h2 { margin: 0; font-size: 15px; }
.list-items { overflow-y: auto; flex: 1; padding: 6px; }
.li { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 9px; cursor: pointer; }
.li:hover { background: var(--side); }
.li.on { background: var(--accent-soft); }
.li .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .s { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .meta { min-width: 0; flex: 1; }
.li .flags { display: flex; gap: 4px; color: var(--faint); }
.item-ico { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; flex: none; }
.item-ico.lg { width: 56px; height: 56px; border-radius: 14px; font-size: 24px; }
.item-ico svg { stroke: #fff; }
.group-h { font-size: 11px; font-weight: 700; color: var(--faint); padding: 10px 10px 4px; text-transform: uppercase; letter-spacing: .06em; }
.empty { text-align: center; color: var(--muted); padding: 60px 24px; }
.empty svg { width: 42px; height: 42px; color: var(--faint); margin-bottom: 8px; }

.detail { overflow-y: auto; background: var(--bg); min-width: 0; }
.detail-inner { max-width: 760px; margin: 0 auto; padding: 26px 30px 60px; }
.d-head { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.d-head h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; word-break: break-word; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 9px; border-radius: 20px; background: var(--side); color: var(--muted); font-weight: 600; }
.chip.blue { background: var(--accent-soft); color: var(--accent); }
.chip.red { background: var(--danger-soft); color: var(--danger); }
.chip.amber { background: var(--warn-soft); color: var(--warn); }
.chip.green { background: var(--ok-soft); color: var(--ok); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 14px; box-shadow: 0 1px 1px rgba(16,24,40,.03); }
.card-h { padding: 12px 16px 0; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.field { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-bottom: 1px solid var(--line); min-height: 58px; }
.field:last-child { border-bottom: 0; }
.field .fl { font-size: 12px; color: var(--accent); font-weight: 600; margin-bottom: 2px; }
.field .fv { word-break: break-all; white-space: pre-wrap; }
.field .fv.pw { font-family: var(--mono); font-size: 14.5px; }
.field .acts { display: flex; gap: 2px; opacity: .2; transition: opacity .12s; }
.field:hover .acts, .field:focus-within .acts { opacity: 1; }
.pwc .d { color: var(--digit); } .pwc .y { color: var(--symbol); }
.totp { display: flex; align-items: center; gap: 12px; }
.totp .code { font-family: var(--mono); font-size: 22px; font-weight: 600; letter-spacing: .04em; }
.ring { width: 22px; height: 22px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3; }
.ring .bgc { stroke: var(--line); } .ring .fgc { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .9s linear; }
.ring.low .fgc { stroke: var(--danger); }
.passkey-box { display: flex; align-items: center; gap: 12px; }
.passkey-box .pk-ico { width: 38px; height: 38px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.notes { padding: 14px 16px; white-space: pre-wrap; word-break: break-word; }
.foot { font-size: 12px; color: var(--muted); margin-top: 18px; display: flex; flex-direction: column; gap: 3px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; padding: 14px 16px; }

/* ---------- edit form ---------- */
.ef { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.ef:last-child { border-bottom: 0; }
.title-in { font-size: 20px; font-weight: 700; height: 46px !important; }
.inline-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.gen-pop { margin-top: 10px; padding: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.gen-out { font-family: var(--mono); font-size: 18px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; word-break: break-all; min-height: 54px; }
.gen-out.big { font-size: 24px; padding: 22px; text-align: center; }
.custom-row { display: grid; grid-template-columns: 1fr 1.6fr auto auto; gap: 6px; margin-bottom: 6px; }

/* ---------- watchtower ---------- */
.score { display: flex; align-items: center; gap: 22px; padding: 22px; }
.score .num { font-size: 52px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.score .bar { height: 10px; border-radius: 6px; background: var(--line); overflow: hidden; margin-top: 10px; }
.score .bar i { display: block; height: 100%; border-radius: 6px; }
.wt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 18px; }
.wt-card { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; cursor: pointer; display: flex; gap: 12px; align-items: flex-start; }
.wt-card:hover { border-color: var(--line2); box-shadow: var(--shadow); }
.wt-card.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.wt-card .n { font-size: 26px; font-weight: 800; line-height: 1.1; }
.wt-card .lab { font-weight: 600; }
.wt-card .desc { font-size: 12px; color: var(--muted); }
.wt-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.wt-ico.red { background: var(--danger-soft); color: var(--danger); } .wt-ico.amber { background: var(--warn-soft); color: var(--warn); }
.wt-ico.blue { background: var(--accent-soft); color: var(--accent); } .wt-ico.green { background: var(--ok-soft); color: var(--ok); }

/* ---------- settings ---------- */
.set-row { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.set-row:last-child { border-bottom: 0; }
.set-row .k { font-weight: 600; }
.set-row .v { color: var(--muted); font-size: 13px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl td, table.tbl th { padding: 9px 16px; border-bottom: 1px solid var(--line); text-align: left; }
table.tbl th { font-size: 11px; text-transform: uppercase; color: var(--faint); letter-spacing: .05em; }
table.tbl tr:last-child td { border-bottom: 0; }

/* ---------- modal & toast & menu ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10,14,22,.45); display: grid; place-items: center; z-index: 50; padding: 20px; animation: fade .12s; }
.modal { background: var(--panel); border-radius: 14px; width: min(480px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); border: 1px solid var(--line); }
.modal.wide { width: min(620px, 100%); }
.modal-h { display: flex; align-items: center; padding: 18px 20px 6px; }
.modal-h h3 { margin: 0; font-size: 17px; flex: 1; }
.modal-b { padding: 10px 20px 20px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 18px; }
.cat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.cat-btn { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); cursor: pointer; font-weight: 600; text-align: left; }
.cat-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; align-items: center; }
.toast { background: #1b1f27; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px; font-weight: 500; animation: fade .15s; }
.toast.err { background: var(--danger); }
.menu { position: fixed; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.18); padding: 5px; z-index: 55; min-width: 200px; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px 10px; border: 0; background: none; border-radius: 7px; cursor: pointer; text-align: left; }
.menu button:hover { background: var(--side); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

@media (max-width: 1100px) { .app { grid-template-columns: 210px 290px 1fr; } .topbar .brand { width: 186px; } }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 56px auto 1fr; }
  .sidebar { display: none; } .list { max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .topbar .brand span { display: none; } .topbar .brand { width: auto; }
  .detail-inner { padding: 18px 16px 40px; }
}
@media print {
  body * { visibility: hidden; }
  .printable, .printable * { visibility: visible; }
  .printable { position: absolute; left: 0; top: 0; width: 100%; }
  .overlay { background: none; }
}
