:root {
  --bg: #0d1117;
  --bg-2: #131a24;
  --panel: #161e2b;
  --panel-2: #1c2636;
  --line: #263246;
  --text: #e6edf3;
  --muted: #8b98ab;
  --accent: #5b8cff;
  --accent-2: #7aa2ff;
  --accent-ink: #ffffff;
  --danger: #ef5b5b;
  --warn: #e8b04a;
  --ok: #3fbf7f;
  --radius: 12px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f9;
    --bg-2: #eaeef5;
    --panel: #ffffff;
    --panel-2: #f6f8fb;
    --line: #dde3ec;
    --text: #18202c;
    --muted: #5d6b80;
    --accent: #3a6df0;
    --accent-2: #2c5cd9;
    --shadow: 0 10px 40px rgba(20, 30, 50, .15);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.noscript { padding: 2rem; text-align: center; }

svg.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- form controls ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); font-weight: 500; }
input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  width: 100%;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=range] { padding: 0; accent-color: var(--accent); background: none; border: 0; box-shadow: none; }
input[type=file] { padding: 8px; }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 44px; }
.pw-wrap .reveal { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: .9rem;
  padding: 10px 16px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  cursor: pointer; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost-danger { color: var(--danger); }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 8px;
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.on { color: var(--warn); }

.meter { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; transition: width .2s, background .2s; }
.meter[data-score="1"] span { width: 25%; background: var(--danger); }
.meter[data-score="2"] span { width: 50%; background: var(--warn); }
.meter[data-score="3"] span { width: 75%; background: var(--accent); }
.meter[data-score="4"] span { width: 100%; background: var(--ok); }

.callout { display: flex; gap: 10px; padding: 10px 12px; border-radius: 9px; margin: 0; }
.callout.warn { background: color-mix(in srgb, var(--warn) 12%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); }
.callout.warn svg { color: var(--warn); margin-top: 2px; }
.form-error { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); border-radius: 8px; padding: 9px 12px; margin: 14px 0 0; font-size: .9rem; }

.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.busy { display: flex; gap: 10px; align-items: center; justify-content: center; color: var(--muted); font-size: .9rem; margin-top: 14px; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 1.1rem; letter-spacing: .2px; }
.brand svg { width: 26px; height: 26px; color: var(--accent); }
.brand-lg { justify-content: center; font-size: 1.5rem; margin-bottom: 22px; }
.brand-lg svg { width: 36px; height: 36px; }

/* ---------- auth ---------- */
.auth { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 18px;
  background: radial-gradient(1200px 600px at 50% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent); }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 30px 28px; box-shadow: var(--shadow); }
.auth-foot { display: flex; align-items: center; gap: 6px; }
.auth-foot svg { width: 14px; height: 14px; }

/* ---------- vault layout ---------- */
.vault { height: 100%; display: grid; grid-template-columns: 230px minmax(260px, 360px) 1fr; grid-template-rows: 60px 1fr; grid-template-areas: "top top top" "side list detail"; }
.topbar { grid-area: top; display: flex; align-items: center; gap: 16px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar .brand { width: 198px; }
.search { flex: 1; max-width: 520px; position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 11px; color: var(--muted); }
.search input { padding-left: 36px; }
.top-actions { margin-left: auto; display: flex; gap: 4px; }

.sidebar { grid-area: side; padding: 16px 12px; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.filters { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.filters button { width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; border: 0; background: none; color: var(--muted); font: inherit; font-size: .92rem; cursor: pointer; text-align: left; }
.filters button:hover { background: var(--panel-2); color: var(--text); }
.filters button.active { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--text); }
.filters .count { margin-left: auto; font-size: .8rem; opacity: .8; }
.filters .sep { height: 1px; background: var(--line); margin: 8px 4px; }
.sidebar-foot { margin-top: auto; padding: 0 6px; word-break: break-all; }

.list-pane { grid-area: list; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.list-head { display: flex; align-items: baseline; justify-content: space-between; padding: 16px 16px 10px; }
.item-list { list-style: none; margin: 0; padding: 0 8px 16px; overflow-y: auto; flex: 1; }
.item-list:empty { display: none; }
.item-list li button { width: 100%; display: flex; gap: 12px; align-items: center; padding: 10px; border: 0; border-radius: 10px; background: none; color: inherit; font: inherit; cursor: pointer; text-align: left; }
.item-list li button:hover { background: var(--panel); }
.item-list li button.active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.avatar { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex: none; font-weight: 700; color: #fff; font-size: 1rem; }
.avatar svg { width: 18px; height: 18px; }
.item-text { min-width: 0; flex: 1; }
.item-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; align-items: center; }
.item-name svg { width: 13px; height: 13px; color: var(--warn); fill: var(--warn); }
.item-sub { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 40px 24px; text-align: center; color: var(--muted); }

.detail-pane { grid-area: detail; overflow-y: auto; padding: 28px 32px; min-width: 0; }
.detail-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.detail-head .avatar { width: 52px; height: 52px; font-size: 1.3rem; border-radius: 14px; }
.detail-head h2 { font-size: 1.35rem; word-break: break-word; }
.detail-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.back { display: none; }
.fields { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.field { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.field:first-child { border-top: 0; }
.field-main { flex: 1; min-width: 0; }
.field-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.field-value { word-break: break-all; white-space: pre-wrap; }
.field-value.mono { font-family: var(--mono); font-size: .95rem; }
.field-value .masked { letter-spacing: 2px; }
.field-actions { display: flex; gap: 2px; }
.section-title { margin: 24px 0 10px; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.meta { margin-top: 22px; color: var(--muted); font-size: .82rem; display: flex; flex-direction: column; gap: 2px; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.badge.weak { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.badge.reused { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.badges { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }

/* ---------- dialogs ---------- */
.dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--panel); color: var(--text); width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 32px); box-shadow: var(--shadow); }
.dialog.wide { width: min(620px, calc(100vw - 32px)); }
.dialog.narrow { width: min(380px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(5, 8, 14, .6); backdrop-filter: blur(2px); }
.dialog > .stack, .dialog > form { gap: 0; max-height: calc(100vh - 34px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog-body { padding: 20px; overflow-y: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.type-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.type-picker button { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); color: var(--muted); font: inherit; font-size: .8rem; cursor: pointer; }
.type-picker button.active { border-color: var(--accent); color: var(--text); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.inline-btns { display: flex; gap: 6px; }
.inline-btns input { flex: 1; }
.custom-field { display: grid; grid-template-columns: 1fr 1.4fr auto auto; gap: 8px; align-items: center; }
.check-inline { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-weight: 400; font-size: .9rem; }

.gen-out { display: flex; gap: 8px; align-items: center; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 8px 12px 14px; }
.gen-out output { flex: 1; font-family: var(--mono); font-size: 1.05rem; word-break: break-all; }
.checks { display: flex; flex-direction: column; gap: 8px; }
.checks label { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-weight: 400; font-size: .92rem; }

.tabs { display: flex; gap: 4px; padding: 10px 16px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { background: none; border: 0; color: var(--muted); font: inherit; font-weight: 600; font-size: .88rem; padding: 10px 12px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.qr { display: flex; justify-content: center; padding: 12px; background: #fff; border-radius: 12px; width: fit-content; margin: 0 auto; }
.qr img { display: block; width: 180px; height: 180px; image-rendering: pixelated; }
.secret-code { font-family: var(--mono); text-align: center; word-break: break-all; background: var(--bg-2); padding: 8px; border-radius: 8px; }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: .88rem; }
.activity li:first-child { border-top: 0; }
.activity .ev { font-weight: 600; min-width: 130px; }
.activity .ev.bad { color: var(--danger); }
.activity .where { color: var(--muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.row-between.wrap { flex-wrap: wrap; gap: 10px; }
.devices { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.devices li { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-2); }
.devices .dev-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--panel-2); color: var(--muted); flex: none; }
.devices .dev-main { flex: 1; min-width: 0; }
.devices .dev-name { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.devices .dev-sub { color: var(--muted); font-size: .82rem; }
.badge.this { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent-2); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.status.on { color: var(--ok); font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); opacity: .6; flex: none; }
.status.on .dot { background: var(--ok); opacity: 1; animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); } 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .status.on .dot { animation: none; } }
.remember-note { margin: -6px 0 0; }
.badge.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge.off { background: var(--panel-2); color: var(--muted); }
.invite-key { font-family: var(--mono); font-size: 1.25rem; letter-spacing: 1px; text-align: center; padding: 14px; background: var(--bg-2); border: 1px dashed var(--accent); border-radius: 10px; word-break: break-all; }
.optional { font-weight: 400; opacity: .7; }
.menu-wrap { position: relative; }
.account-btn { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border: 1px solid var(--line); border-radius: 99px; background: var(--panel-2); color: var(--text); font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; }
.account-btn:hover, .account-btn[aria-expanded="true"] { border-color: var(--muted); }
.account-btn svg { width: 14px; height: 14px; color: var(--muted); }
.account-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar-sm { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; font-weight: 700; font-size: .85rem; flex: none; }
.avatar-sm.lg { width: 42px; height: 42px; font-size: 1.1rem; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); width: 260px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 60; }
.menu-head { display: flex; gap: 12px; align-items: center; padding: 10px; }
.menu-head div { display: flex; flex-direction: column; min-width: 0; }
.menu-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu button[role="menuitem"] { width: 100%; display: flex; align-items: center; gap: 12px; padding: 9px 10px; border: 0; border-radius: 8px; background: none; color: var(--text); font: inherit; font-size: .92rem; cursor: pointer; text-align: left; }
.menu button[role="menuitem"]:hover, .menu button[role="menuitem"]:focus-visible { background: var(--panel-2); outline: none; }
.menu button[role="menuitem"] svg { color: var(--muted); }
.menu button.danger, .menu button.danger svg { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: .8rem; }
#tab-2fa { display: flex; flex-direction: column; gap: 14px; }
.captcha { display: flex; flex-direction: column; align-items: center; gap: 8px; min-height: 86px; }
.acct-title { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.acct-group { border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--bg-2); display: flex; flex-direction: column; gap: 14px; }
.callout .btn { margin-left: auto; flex: none; }
.item-when { color: var(--muted); font-size: .75rem; white-space: nowrap; align-self: flex-start; margin-top: 3px; }
.toast { display: flex; align-items: center; }
.list-head { flex-wrap: wrap; gap: 8px; }
.dialog-foot { flex-wrap: wrap; }
.toast-action { margin-left: 14px; background: none; border: 0; color: var(--accent-2); font: inherit; font-weight: 700; cursor: pointer; }
.callout.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); }
.callout.ok svg { color: var(--ok); margin-top: 2px; }
.sec { border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.sec h3 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.codes { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.codes li { font-family: var(--mono); padding: 9px 10px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; text-align: center; letter-spacing: 1px; }
@media print {
  body > *:not(#dlg-codes) { display: none !important; }
  #dlg-codes { position: static; border: 0; box-shadow: none; width: auto; color: #000; background: #fff; }
  #dlg-codes .dialog-foot, #dlg-codes .dialog-head button { display: none; }
  .codes li { border-color: #000; background: #fff; color: #000; }
}
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel-2); color: var(--text); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: .9rem; z-index: 100; max-width: calc(100vw - 32px); }
.toast.error { border-color: var(--danger); }

.only-mobile { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .vault { grid-template-columns: 210px 1fr; grid-template-areas: "top top" "side list"; }
  .topbar .brand { width: auto; }
  .detail-pane { grid-area: list; background: var(--bg); padding: 20px 16px; display: none; }
  .vault.show-detail .detail-pane { display: block; }
  .vault.show-detail .list-pane { display: none; }
  .back { display: inline-grid; }
}
@media (max-width: 700px) {
  .vault { grid-template-columns: 1fr; grid-template-areas: "top" "list"; grid-template-rows: auto 1fr; }
  .topbar { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .topbar .brand span { display: none; }
  .account-name { display: none; }
  .account-btn { padding-right: 8px; }
  .search { order: 5; flex-basis: 100%; max-width: none; }
  .only-mobile { display: inline-grid; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .vault.show-menu .sidebar { transform: none; }
  .detail-head { flex-wrap: wrap; }
  .detail-actions { margin-left: 0; width: 100%; justify-content: flex-start; }
  .grid-2, .custom-field { grid-template-columns: 1fr; }
  .type-picker { grid-template-columns: repeat(2, 1fr); }
  .auth-card { padding: 24px 18px; }
}
