/* ============================================================
   Account Manager — "autosecure"-style dark glass UI
   ============================================================ */
:root {
  --bg: #060912;
  --bg-2: #0a0f1d;
  --surface: rgba(255, 255, 255, 0.035);
  --surface-2: rgba(255, 255, 255, 0.06);
  --surface-solid: #0e1524;
  --glass-border: rgba(255, 255, 255, 0.09);
  --fg: #e8eef8;
  --muted: #8a99b5;
  --border: rgba(255, 255, 255, 0.08);
  --accent: #38bdf8;
  --accent-2: #6366f1;
  --accent-grad: linear-gradient(135deg, #38bdf8 0%, #6366f1 100%);
  --accent-soft: rgba(56, 189, 248, 0.14);
  --danger: #f43f5e;
  --ok: #34d399;
  --warn: #fbbf24;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: "Inter", "Segoe UI", system-ui, sans-serif; font-size: 15px;
  line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; transition: color .15s; }
a:hover { color: #7dd3fc; }

/* ---- animated background: aurora blobs + starfield ---- */
.bg-aurora, .bg-stars { position: fixed; inset: 0; z-index: -2; pointer-events: none; }
.bg-aurora {
  background:
    radial-gradient(600px 400px at 12% -5%, rgba(99, 102, 241, 0.28), transparent 60%),
    radial-gradient(700px 500px at 100% 0%, rgba(56, 189, 248, 0.20), transparent 55%),
    radial-gradient(600px 600px at 60% 110%, rgba(139, 92, 246, 0.16), transparent 60%),
    var(--bg);
}
.bg-stars {
  z-index: -1; opacity: .5;
  background-image:
    radial-gradient(1px 1px at 20% 30%, rgba(255,255,255,.7), transparent),
    radial-gradient(1px 1px at 70% 60%, rgba(255,255,255,.5), transparent),
    radial-gradient(1px 1px at 40% 80%, rgba(255,255,255,.6), transparent),
    radial-gradient(1px 1px at 90% 20%, rgba(255,255,255,.5), transparent),
    radial-gradient(1px 1px at 55% 15%, rgba(255,255,255,.45), transparent),
    radial-gradient(1px 1px at 15% 70%, rgba(255,255,255,.5), transparent);
  background-size: 700px 700px, 600px 600px, 800px 800px, 500px 500px, 650px 650px, 720px 720px;
  animation: drift 90s linear infinite;
}
@keyframes drift { to { background-position: 700px 700px, -600px 600px, 800px -800px, -500px 500px, 650px -650px, -720px 720px; } }

/* ============================ layout ============================ */
.app-shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.auth-shell { display: block; }

.sidebar {
  position: sticky; top: 0; align-self: start; height: 100vh;
  display: flex; flex-direction: column; gap: 6px;
  padding: 20px 14px; background: rgba(8, 12, 22, 0.72);
  backdrop-filter: blur(18px); border-right: 1px solid var(--border);
}
.side-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 18px; color: var(--fg); font-weight: 800; font-size: 1.15rem;
}
.side-brand:hover { color: var(--fg); }
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px; object-fit: cover; flex: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px; font-size: 18px;
  background: var(--accent-grad); color: #051018;
  box-shadow: 0 6px 18px rgba(56, 189, 248, 0.4);
}
.brand-dot { color: var(--accent); }

.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 12px; color: var(--muted);
  font-weight: 600; font-size: 14px; position: relative; transition: all .15s;
}
.side-link:hover { background: var(--surface-2); color: var(--fg); }
.side-link.active {
  color: var(--fg);
  background: linear-gradient(90deg, var(--accent-soft), transparent);
}
.side-link.active::before {
  content: ""; position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 3px; border-radius: 3px; background: var(--accent-grad);
}
.side-ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.side-link.active .side-ic { stroke: var(--accent); }

.side-foot {
  display: flex; align-items: center; gap: 8px;
  padding-top: 14px; margin-top: 6px; border-top: 1px solid var(--border);
}
.side-user { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; color: var(--fg); }
.side-user:hover { color: var(--fg); }
.side-user-info { display: flex; flex-direction: column; min-width: 0; }
.side-user-name { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-role { color: var(--muted); font-size: 12px; }
.side-logout { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; padding: 0; background: var(--surface-2); color: var(--muted); border-radius: 10px; }
.side-logout svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.side-logout:hover { background: var(--danger); color: #fff; }

.main { min-width: 0; padding: 30px 34px 60px; }
.main.solo { padding: 0; }
.page { max-width: 1180px; margin: 0 auto; }

/* ============================ typography ============================ */
h1 { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 4px; }
h2 { font-size: 1.2rem; font-weight: 700; margin: 30px 0 10px; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.error, .err { color: var(--danger); }
.ok { color: var(--ok); }
.badge {
  background: var(--accent-grad); color: #051018; padding: 2px 9px;
  border-radius: 20px; font-size: 11px; font-weight: 800; letter-spacing: .02em;
}
.badge.alt { background: var(--surface-2); color: var(--fg); }

/* ============================ buttons ============================ */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface-2); color: var(--fg); border: 1px solid var(--border);
  cursor: pointer; padding: 9px 16px; border-radius: 10px; font-weight: 600;
  font-size: 14px; font-family: inherit; transition: all .16s;
}
button:hover, .btn:hover {
  background: rgba(255, 255, 255, 0.1); color: var(--fg);
  transform: translateY(-1px); border-color: rgba(255, 255, 255, 0.16);
}
.btn.small, button.small { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.primary, .btn.primary, button.primary {
  background: var(--accent-grad); color: #051018; border: none; font-weight: 700;
  box-shadow: 0 8px 22px rgba(56, 189, 248, 0.28);
}
.primary:hover, .btn.primary:hover, button.primary:hover {
  color: #051018; filter: brightness(1.08); box-shadow: 0 10px 28px rgba(56, 189, 248, 0.4);
}
.btn.danger, button.danger { background: rgba(244, 63, 94, 0.16); color: #fda4b4; border: 1px solid rgba(244, 63, 94, 0.35); }
.btn.danger:hover, button.danger:hover { background: var(--danger); color: #fff; }
.link-btn { background: none; border: none; padding: 2px 4px; color: var(--accent); }
.link-btn:hover { background: none; text-decoration: underline; transform: none; }
.link-btn.danger { background: none; border: none; color: #fb7185; text-decoration: underline; font-weight: 500; }
.link-btn.danger:hover { background: none; color: #fda4b4; }
button:disabled, .btn:disabled { opacity: 0.55; cursor: progress; transform: none; }
.admin-actions { display: flex; gap: 14px; align-items: center; }
.admin-actions form { margin: 0; }

/* ============================ forms ============================ */
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  background: rgba(0, 0, 0, 0.28); color: var(--fg);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  font-size: 14px; font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}
select option { background: var(--surface-solid); }

/* ============================ auth cards ============================ */
.auth-card {
  max-width: 380px; margin: 9vh auto; background: var(--surface);
  backdrop-filter: blur(16px); padding: 32px; border-radius: var(--radius);
  border: 1px solid var(--glass-border); box-shadow: var(--shadow);
}
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }

/* ============================ dashboard tiles ============================ */
.pool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin-top: 22px; }
.pool-tile {
  background: var(--surface); backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border); border-radius: var(--radius);
  padding: 20px; display: block; position: relative; overflow: hidden;
  transition: transform .18s, border-color .18s, box-shadow .18s;
}
.pool-tile::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: linear-gradient(135deg, rgba(56,189,248,.08), transparent 45%);
  opacity: 0; transition: opacity .18s;
}
.pool-tile:hover { transform: translateY(-3px); border-color: rgba(56, 189, 248, 0.5); box-shadow: var(--shadow); }
.pool-tile:hover::after { opacity: 1; }
.pool-owner { font-weight: 700; color: var(--fg); display: flex; gap: 8px; align-items: center; }
.pool-meta { color: var(--muted); margin-top: 8px; font-size: 13px; }

/* ============================ create / rename lists ============================ */
.new-list { position: relative; }
.new-list > summary { list-style: none; display: inline-flex; }
.new-list > summary::-webkit-details-marker { display: none; }
.new-list-form {
  display: flex; gap: 8px; margin-top: 10px; position: absolute; right: 0; z-index: 20;
  background: var(--surface-solid); border: 1px solid var(--glass-border);
  border-radius: 12px; padding: 12px; box-shadow: var(--shadow); width: min(340px, 80vw);
}
.new-list-form input { flex: 1; }
.pool-name { font-weight: 700; }

.pool-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.pool-title h1 { display: inline; }
.back-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2);
  color: var(--fg); font-size: 18px; flex: none;
}
.back-link:hover { background: var(--surface-2); color: var(--accent); }
.icon-btn { background: var(--surface-2); border: 1px solid var(--border); padding: 6px 9px; border-radius: 9px; cursor: pointer; }
.rename-list { position: relative; }
.rename-list > summary { list-style: none; }
.rename-list > summary::-webkit-details-marker { display: none; }
.rename-form {
  display: flex; gap: 8px; margin-top: 8px; position: absolute; left: 0; z-index: 20;
  background: var(--surface-solid); border: 1px solid var(--glass-border);
  border-radius: 12px; padding: 12px; box-shadow: var(--shadow); width: min(340px, 80vw);
}

/* ============================ pool page ============================ */
.pool-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 14px; }
.pool-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.pool-actions form { margin: 0; }
.panel {
  background: var(--surface); backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border); border-radius: var(--radius);
  padding: 14px 18px; margin: 14px 0;
}
.panel summary { cursor: pointer; font-weight: 700; }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-top: 12px; }
.filterbar {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin: 20px 0;
  background: var(--surface); border: 1px solid var(--glass-border);
  border-radius: var(--radius); padding: 14px 16px; backdrop-filter: blur(12px);
}

/* ============================ tables ============================ */
table.data {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface); border: 1px solid var(--glass-border);
  border-radius: var(--radius); overflow: hidden; backdrop-filter: blur(12px);
}
table.data th, table.data td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data thead th {
  background: rgba(255, 255, 255, 0.04); font-size: 12px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); font-weight: 700;
}
table.data tbody tr { transition: background .12s; }
table.data tbody tr:hover { background: rgba(255, 255, 255, 0.03); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data.compact td { padding: 6px 12px; }
.accounts td select, .accounts td input { height: 36px; }
.accounts .flag-cell select { padding: 5px 8px; }
.accounts .flag-select { max-width: 150px; }
.mark-badge { display: inline-block; padding: 2px 8px; border: 1px solid var(--muted);
  border-radius: 999px; font-size: .82em; font-weight: 600; }
.bal-form { margin: 0; }
.accounts .rownum { color: var(--muted); text-align: right; width: 1%; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-actions { white-space: nowrap; }
.row-actions form { display: inline-block; margin: 0 0 0 8px; }
.row-actions .btn { min-width: 104px; text-align: center; }

/* ============================ device / token ============================ */
.device-box { margin-top: 14px; padding: 16px; background: var(--surface-2); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.device-box.ok { border-color: var(--ok); }
.device-box.error { border-color: var(--danger); }
.device-code { font-size: 1.9rem; font-weight: 800; letter-spacing: 4px; color: var(--accent); }
.token {
  width: 100%; font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 13px;
  line-height: 1.5; word-break: break-all; resize: vertical; padding: 12px;
  background: rgba(0, 0, 0, 0.4); color: #bae6fd; border: 1px solid var(--border); border-radius: 10px;
}

/* HTMX indicator */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: block; }

/* ============================ avatars ============================ */
.avatar { border-radius: 50%; object-fit: cover; vertical-align: middle; flex: none; }
.avatar-fallback {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-grad); color: #051018; font-weight: 800; text-transform: uppercase;
}
.card {
  background: var(--surface); backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border); border-radius: var(--radius);
  padding: 20px 22px; margin-top: 16px;
}
.avatar-settings { display: flex; gap: 18px; align-items: center; }
.avatar-settings .inline-form { margin-top: 0; }

/* ============================ chat ============================ */
.chat-panel { margin-top: 12px; }
.chat-msgs {
  background: rgba(0, 0, 0, 0.25); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px;
}
.chat-msg { display: flex; gap: 10px; align-items: flex-start; }
.chat-body { min-width: 0; flex: 1; }
.chat-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.chat-author { font-weight: 700; color: var(--fg); }
.chat-via {
  color: var(--muted); font-weight: 600; font-size: 11px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 7px; letter-spacing: 0.01em;
}
.chat-time { color: var(--muted); }
.chat-del { background: none; border: none; color: var(--muted); padding: 0 4px; font-size: 15px; line-height: 1; margin-left: auto; }
.chat-del:hover { background: none; color: var(--danger); transform: none; }
.chat-text { word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; margin-top: 2px; }
.chat-empty { margin: auto; }
.chat-notice { color: var(--danger); font-size: 13px; margin: 0; }
.chat-form { display: flex; gap: 10px; margin-top: 12px; }
.chat-form input { flex: 1; }

/* ============================ 2FA nudge ============================ */
.nudge {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: linear-gradient(90deg, var(--accent-soft), rgba(99,102,241,.1));
  border: 1px solid rgba(56, 189, 248, 0.3); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 20px;
}
.nudge span { flex: 1; min-width: 200px; }
.nudge-x { background: none; border: none; color: var(--muted); padding: 0 6px; font-size: 20px; line-height: 1; }
.nudge-x:hover { background: none; color: var(--fg); transform: none; }
.backup-codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 16px 0; }
.backup-codes code { font-size: 1.05rem; letter-spacing: 1px; }

.api-key-once {
  margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid rgba(56, 189, 248, 0.35); background: var(--accent-soft);
}
.api-key-secret {
  display: block; margin: 8px 0; padding: 8px 10px; word-break: break-all;
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 13px;
  background: rgba(0,0,0,.35); border-radius: 6px; border: 1px solid var(--border);
}
.api-keys-table th { color: var(--muted); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); }
.api-keys-table td { border-bottom: 1px solid var(--border); vertical-align: middle; }

/* ============================ modal overlay ============================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4, 7, 14, 0.7); backdrop-filter: blur(6px);
  animation: fade-in .16s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  position: relative; width: min(720px, 94vw); max-height: 88vh; overflow-y: auto;
  background: linear-gradient(180deg, rgba(20, 28, 46, 0.96), rgba(11, 16, 30, 0.98));
  border: 1px solid var(--glass-border); border-radius: 20px;
  padding: 30px 32px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: pop-in .18s ease;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-close { position: absolute; top: 14px; right: 16px; background: none; border: none; color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; }
.modal-close:hover { color: #fff; background: none; transform: none; }
.session-title { margin: 0 0 3px; font-size: 1.5rem; font-weight: 800; background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.session-sub { margin: 0 0 20px; color: var(--muted); }
/* Summed balance of the rows currently shown, sitting above the table. */
.table-total {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  margin: 0 0 10px; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  font-size: .9em; font-weight: 700; color: #c4d2e4;
}
.table-total strong {
  font-size: 1.15em;
  background: var(--accent-grad); -webkit-background-clip: text;
  background-clip: text; color: transparent;
}
.table-total .muted { font-weight: 500; }
/* The exact figure and its toggle sit at the far right, away from the summary. */
.table-total .total-exact {
  margin-left: auto; font-variant-numeric: tabular-nums;
  font-weight: 600; color: #e6edf7;
}
.table-total .total-toggle {
  margin-left: auto; padding: 2px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: none;
  color: var(--muted); font-size: .85em; font-weight: 600; cursor: pointer;
}
/* Once the figure is showing it owns the auto margin, so the button hugs it. */
.table-total .total-exact:not([hidden]) + .total-toggle { margin-left: 0; }
.table-total .total-toggle:hover { color: #fff; border-color: #6b7c93; transform: none; }

/* Optional "auto-flag by balance" rule inside the donut-check form. */
.bal-rule {
  margin: 14px 0 4px; padding: 12px 14px 10px;
  border: 1px solid var(--border); border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
}
.bal-rule legend { padding: 0 6px; font-size: .85em; font-weight: 700; color: #c4d2e4; }
.bal-rule-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bal-rule-row select { flex: 0 1 auto; min-width: 0; }
.bal-rule-row input { flex: 0 1 90px; min-width: 60px; }
.bal-rule-hint { display: block; margin-top: 8px; font-size: .8em; }

.session-steps { list-style: none; margin: 0; padding: 0; }
.session-step {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--border); border-radius: 12px; color: #c4d2e4;
}
.session-step .step-icon { width: 20px; text-align: center; font-weight: 700; flex: none; }
.session-step.is-done .step-icon { color: var(--ok); }
.session-step.is-failed { border-color: rgba(244, 63, 94, 0.5); background: rgba(244, 63, 94, 0.1); }
.session-step.is-failed .step-icon { color: var(--danger); }
.session-step.is-running { border-color: var(--accent); }
.session-step .step-detail { margin-left: auto; color: var(--danger); font-size: 13px; }
.session-step .step-note { margin-left: auto; color: var(--muted); font-size: 13px; }
.spin, .session-step .spin, .locked-item .spin {
  display: inline-block; width: 13px; height: 13px; border: 2px solid var(--accent);
  border-top-color: transparent; border-radius: 50%; animation: session-spin 0.7s linear infinite;
}
@keyframes session-spin { to { transform: rotate(360deg); } }
.session-result { margin-top: 18px; }
.session-result.ok .token { width: 100%; }
.session-result .token-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.session-result .token-head p { margin: 0; }
.session-result.error { color: var(--danger); }

/* ============================ bulk get-sessions ============================ */
.bulk-actions { display: flex; gap: 8px; align-items: center; margin: 0 0 10px; }
.bulk-actions .inline-form { margin: 0; }
.batch-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.batch-bar p { margin: 0; }
.batch-total { margin-top: 3px; font-size: 15px; }
.batch-bar-actions { display: flex; align-items: center; gap: 8px; }
.sb-setall { margin: 0; }
.sb-setall select, .sb-flag select { background: rgba(0,0,0,.3); color: #cfe3ff; border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px; font-size: 13px; }
.sb-balance { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 13px; }
.sb-flag { margin: 0 0 0 8px; }
.session-batch-list { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto; }
.session-batch-item { padding: 12px 14px; margin-bottom: 8px; background: rgba(255,255,255,.03); border: 1px solid var(--border); border-radius: 12px; }
.sb-head { display: flex; align-items: center; gap: 8px; }
.sb-icon { width: 16px; display: inline-flex; justify-content: center; }
.sb-name { font-weight: 700; }
.sb-err { color: var(--danger); font-size: 12px; margin-left: auto; }
.sb-token-row { display: flex; gap: 8px; align-items: flex-start; margin-top: 8px; }
.sb-token { flex: 1; }

/* ============================ locked / donut checker ============================ */
.locked-progress { margin-bottom: 14px; }
.locked-bar { height: 8px; background: rgba(255,255,255,.06); border-radius: 6px; overflow: hidden; margin-bottom: 6px; }
.locked-bar span { display: block; height: 100%; background: var(--accent-grad); transition: width 0.3s ease; }
.locked-progress .ok { color: var(--ok); }
.locked-progress .locked { color: var(--warn); }
.locked-progress .err { color: var(--danger); }
.locked-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.locked-item { display: flex; align-items: center; gap: 12px; padding: 9px 12px; margin-bottom: 6px; background: rgba(255,255,255,.03); border: 1px solid var(--border); border-radius: 10px; color: #c4d2e4; }
.locked-item .item-icon { width: 20px; text-align: center; flex: none; font-weight: 700; }
.locked-item .item-detail { margin-left: auto; font-size: 13px; color: var(--muted); }
.locked-item.is-ok .item-icon { color: var(--ok); }
.locked-item.is-locked { border-color: rgba(251, 191, 36, 0.4); background: rgba(251, 191, 36, 0.08); }
.locked-item.is-locked .item-detail { color: var(--warn); }
.locked-item.is-locked .item-icon { color: var(--danger); }
.locked-item.is-error { border-color: rgba(244, 63, 94, 0.4); }
.locked-item.is-error .item-icon, .locked-item.is-error .item-detail { color: var(--danger); }
.locked-item.is-ip_locked { border-color: rgba(251, 191, 36, 0.4); background: rgba(251, 191, 36, 0.08); }
.locked-item.is-ip_locked .item-icon, .locked-item.is-ip_locked .item-detail { color: var(--warn); }
.tag.ip-locked { display: inline-block; margin-left: 6px; padding: 1px 8px; font-size: 11px; font-weight: 600; border-radius: 10px; background: rgba(251,191,36,.12); color: var(--warn); border: 1px solid rgba(251,191,36,.35); white-space: nowrap; }
.locked-summary { margin-top: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.locked-summary p { margin: 0; }

/* Wide tables scroll horizontally instead of overflowing the page. */
#accounts-live { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ============================ payment modal ============================ */
.pay-box { background: rgba(255,255,255,.03); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.pay-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); flex-wrap: wrap; }
.pay-row:last-child { border-bottom: none; }
.pay-amount { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 1.15rem; }
.pay-addr-row { align-items: flex-start; }
.pay-addr { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pay-addr code { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 13px; word-break: break-all; padding: 4px 8px; background: rgba(0,0,0,.3); border-radius: 6px; border: 1px solid var(--border); }
.pay-hint { margin-top: 12px; display: flex; align-items: center; gap: 8px; }
.pay-warn { margin-top: 6px; font-size: 12px; }
.pay-status { padding: 16px; border-radius: 12px; text-align: center; }
.pay-status.ok { background: rgba(52, 211, 153, 0.08); border: 1px solid rgba(52, 211, 153, 0.4); }
.pay-status.err { background: rgba(244, 63, 94, 0.08); border: 1px solid rgba(244, 63, 94, 0.4); }
.pay-admin-row { display: flex; gap: 24px; margin-top: 12px; flex-wrap: wrap; }

/* ============================ responsive ============================ */
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; height: auto; flex-direction: row; align-items: center;
    gap: 4px; padding: 10px 12px; overflow-x: auto; z-index: 50;
  }
  .side-brand { padding: 0 8px 0 4px; }
  .brand-text { display: none; }
  .side-nav { flex-direction: row; flex: 1; }
  .side-link span:not(.side-ic) { display: none; }
  .side-link { padding: 10px; }
  .side-link.active::before { display: none; }
  .side-foot { border-top: none; padding-top: 0; margin-top: 0; }
  .side-user-info { display: none; }
  .main { padding: 20px 16px 48px; }
}

/* vault */
.vault-add { display: flex; gap: 10px; flex-wrap: wrap; }
.vault-add input { flex: 1; min-width: 160px; }
.vault-add-bar { margin-bottom: 16px; }
.vault-add-bar .primary { display: inline-flex; align-items: center; gap: 8px; }
.modal-overlay[hidden] { display: none; }
.vault-add-card .stack-form { max-width: none; }
.suffix-field { display: flex; align-items: stretch; }
.suffix-field input { flex: 1; min-width: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.suffix-tag { display: flex; align-items: center; padding: 0 12px; color: var(--muted);
  background: rgba(255,255,255,.05); border: 1px solid var(--border); border-left: none;
  border-top-right-radius: 10px; border-bottom-right-radius: 10px; white-space: nowrap; }
.import-refresh { display: flex; align-items: flex-start; gap: 8px; margin: 14px 0;
  color: var(--muted); font-size: .9rem; max-width: 620px; cursor: pointer; }
.import-refresh input { margin-top: 2px; flex: none; }
.vault-export-bar { display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px; margin: 12px 0 4px; }
.vault-selall { display: inline-flex; align-items: center; gap: 8px; color: var(--muted);
  font-size: .9rem; cursor: pointer; }
.vault-export-btns { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.vault-row { display: flex; align-items: center; gap: 12px; }
.vault-row .vault-sel { flex: none; width: 18px; height: 18px; cursor: pointer; }
.vault-row .vault-card { flex: 1; min-width: 0; }
.vault-card { display: flex; align-items: center; gap: 12px; padding: 14px 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.02));
  border: 1px solid var(--glass-border); border-radius: var(--radius); color: var(--fg);
  transition: border-color .16s, box-shadow .16s; }
.vault-card:hover { border-color: rgba(56,189,248,.45); box-shadow: var(--shadow); color: var(--fg); }
.vault-detail { display: grid; grid-template-columns: 220px 1fr; gap: 22px; align-items: start; }
.vault-side { display: flex; flex-direction: column; gap: 10px; }
.vault-back { display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  padding: 7px 12px; border-radius: 10px; background: var(--surface-2); color: var(--muted);
  font-size: .9rem; line-height: 1; }
.vault-back:hover { color: var(--accent); }
.vault-side-title { font-size: 1.05rem; margin: 6px 0; overflow-wrap: anywhere; }
.vault-subnav { display: flex; flex-direction: column; gap: 4px; }
.vault-tab { text-align: left; padding: 9px 12px; border-radius: 10px; background: transparent;
  border: 1px solid transparent; color: var(--muted); cursor: pointer; }
.vault-tab:hover { color: var(--fg); background: var(--surface-2); }
.vault-tab.active { color: var(--accent); background: var(--accent-soft); border-color: rgba(56,189,248,.35); }
.vault-del { margin-top: 8px; }
.cred-grid { display: grid; gap: 16px; }
.cred-card { background: var(--surface); border: 1px solid var(--glass-border);
  border-radius: var(--radius); padding: 16px 18px; }
.cred-h { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-size: 1rem; }
.cred-row { margin-bottom: 12px; }
.cred-label { display: block; font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); margin-bottom: 5px; }
.cred-field { display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.22); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; }
.cred-val { flex: 1; font-family: "JetBrains Mono", ui-monospace, monospace;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cred-btn { flex: none; display: inline-flex; width: 30px; height: 30px; padding: 0;
  align-items: center; justify-content: center; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); cursor: pointer; }
.cred-btn:hover { color: var(--accent); border-color: rgba(56,189,248,.4); }
.cred-btn.copied { color: #7ee2a8; border-color: rgba(34,197,94,.4); }
.cred-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.vault-edit { margin-top: 16px; }
.vault-edit > summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.cred-notes { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--fg); }
/* live TOTP */
.totp-live { display: flex; align-items: center; gap: 16px; }
.totp-code { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 2rem;
  letter-spacing: .18em; color: var(--accent); }
.totp-ring { width: 42px; height: 42px; transform: rotate(-90deg); }
.totp-ring-bg { fill: none; stroke: var(--border); stroke-width: 3; }
.totp-ring-fg { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round;
  stroke-dasharray: 100.5; transition: stroke-dashoffset 1s linear; }
.totp-secs { color: var(--muted); font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  body { font-size: 14px; }
  h1 { font-size: 1.4rem; }
  .main { padding: 16px 12px 44px; }
  .vault-detail { grid-template-columns: 1fr; }

  /* Stack the pool header + make action buttons full-width & tappable. */
  .pool-head { flex-direction: column; align-items: stretch; }
  .pool-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .pool-actions .btn, .pool-actions button { width: 100%; }
  .pool-actions form { display: contents; }

  /* Keep the wide accounts table usable: let it scroll, shrink cells. */
  table.accounts { min-width: 680px; }
  table.data th, table.data td { padding: 9px 10px; }
  .row-actions .btn { min-width: 0; }

  /* Filters + inline forms stack full-width. */
  .filterbar { flex-direction: column; align-items: stretch; }
  .filterbar label, .filterbar input, .filterbar select, .filterbar button { width: 100%; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form input, .inline-form select, .inline-form button { width: 100%; }

  /* Dashboard tiles: single column. */
  .pool-grid { grid-template-columns: 1fr; }

  /* Modals fill the screen comfortably. */
  .modal-card { padding: 22px 18px; width: 96vw; max-height: 92vh; border-radius: 16px; }
  .batch-bar { flex-direction: column; align-items: stretch; }
  .batch-bar-actions { justify-content: space-between; }

  /* Bulk actions + new-list popovers span the width. */
  .bulk-actions { flex-wrap: wrap; }
  .new-list-form, .rename-form { position: static; width: 100%; }
  .chat-msgs { height: 300px; }
}

/* ============================ email / temp-mail ============================ */
.mail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.mail-head p { margin: 4px 0 0; max-width: 640px; }
.mail-head code, .mailbox-addr code { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .92em; }

/* claim bar */
.claim-card { padding: 16px 18px; }
.claim-row { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; margin: 0; }
.claim-field {
  flex: 1; min-width: 220px; display: flex; align-items: center; gap: 2px;
  flex-direction: row; background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border); border-radius: 10px; padding: 0 12px;
  transition: border-color .15s, box-shadow .15s;
}
.claim-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15); }
.claim-field input { flex: 1; min-width: 80px; border: none; background: none; padding: 12px 0; }
.claim-field input:focus { outline: none; box-shadow: none; }
.claim-suffix { color: var(--muted); font-weight: 600; white-space: nowrap; }

/* mailbox cards on /email */
.mailbox-heading { font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 0 0; }
.mailbox-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 12px; }
.mailbox {
  position: relative;
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.02));
  backdrop-filter: blur(12px); border: 1px solid var(--glass-border);
  border-radius: var(--radius); overflow: hidden;
  transition: border-color .16s, box-shadow .16s;
}
.mailbox::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent-grad); opacity: 0; transition: opacity .16s; z-index: 1;
}
.mailbox:hover { border-color: rgba(56, 189, 248, 0.45); box-shadow: var(--shadow); }
.mailbox[open], .mailbox:hover::before { }
.mailbox:hover::before { opacity: 1; }
.mailbox[open]::before { opacity: 1; }
.mailbox-summary {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 14px 58px 14px 18px; cursor: pointer; list-style: none; user-select: none;
}
.mailbox-summary::-webkit-details-marker { display: none; }
.mailbox-summary:hover .mailbox-chev { color: var(--accent); }
.mailbox-del-form { position: absolute; top: 12px; right: 14px; margin: 0; z-index: 2; }
.mailbox-body { padding: 6px 18px 16px; border-top: 1px solid var(--glass-border); }
.mailbox-loading { color: var(--muted); font-size: 13px; padding: 14px 2px; }
.mailbox[open] .mailbox-chev { transform: rotate(90deg); color: var(--accent); }
.mailbox-icon {
  width: 46px; height: 46px; border-radius: 13px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-grad); color: #051018;
  box-shadow: 0 8px 20px rgba(56, 189, 248, 0.28);
}
.mailbox-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.mailbox-main { min-width: 0; flex: 1; }
.mailbox-addr { font-weight: 700; font-size: 15px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mailbox-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; display: flex; align-items: center; gap: 6px; }
.count-pill {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px;
  height: 20px; padding: 0 7px; border-radius: 999px; font-size: 11px; font-weight: 800;
  background: var(--accent-grad); color: #051018;
}
.mailbox-copy {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; border-radius: 9px; line-height: 1;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  cursor: pointer; transition: background .14s, color .14s, border-color .14s;
}
.mailbox-copy:hover { background: var(--accent-soft); color: var(--accent); border-color: rgba(56, 189, 248, 0.4); }
.mailbox-copy svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.mailbox-copy .ic-check { display: none; }
.mailbox-copy.copied { background: rgba(34, 197, 94, 0.16); color: #7ee2a8; border-color: rgba(34, 197, 94, 0.4); }
.mailbox-copy.copied .ic-copy { display: none; }
.mailbox-copy.copied .ic-check { display: inline; }
.mailbox-chev { flex: none; color: var(--muted); display: inline-flex; transition: transform .18s ease, color .16s; }
.mailbox-chev svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mailbox-del {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; padding: 0; border-radius: 10px; line-height: 1;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.mailbox-del svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mailbox-del:hover { background: rgba(244, 63, 94, 0.16); color: #fda4b4; border-color: rgba(244, 63, 94, 0.4); transform: none; }
.mailbox-empty {
  list-style: none; padding: 52px 20px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius);
}
.mailbox-empty-ic, .mail-empty-ic { width: 42px; height: 42px; fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; opacity: .7; }
.mailbox-empty p, .mail-empty p { margin: 12px 0 0; }
.btn-ic { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* inbox header + message rows */
.inbox-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
.inbox-title { min-width: 0; }
.inbox-title h1 { font-size: 1.5rem; overflow-wrap: anywhere; }
.inbox-title h1 .muted { font-weight: 700; }
.inbox-count { color: var(--muted); font-size: 13px; }

.maillist { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.mailrow {
  background: var(--surface); backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border); border-radius: 12px;
  transition: border-color .12s, transform .12s, box-shadow .12s;
}
.mailrow:hover { border-color: rgba(56, 189, 248, 0.5); transform: translateX(2px); box-shadow: var(--shadow); }
.mailrow-link { display: flex; align-items: center; gap: 14px; padding: 12px 16px; color: var(--fg); min-width: 0; }
.mailrow-link:hover { color: var(--fg); }
.mail-ava {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-grad); color: #051018; font-weight: 800; text-transform: uppercase;
}
.mailrow-main { min-width: 0; flex: 1; }
.mailrow-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.mailrow-from { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mailrow-time { color: var(--muted); font-size: 12px; white-space: nowrap; flex: none; }
.mailrow-subject { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.mailrow-snippet { display: block; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.mail-empty {
  padding: 52px 20px; text-align: center; color: var(--muted); margin-top: 16px;
  border: 1px dashed var(--border); border-radius: var(--radius);
}

/* single-message reading view */
.msg-card { margin-top: 16px; }
.msg-head { display: flex; align-items: center; gap: 14px; padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.msg-headmain { min-width: 0; flex: 1; }
.msg-from { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.msg-del { margin: 0; flex: none; }
.msg-body {
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; margin: 0;
  background: rgba(0, 0, 0, 0.22); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; font-family: inherit; font-size: 14px; line-height: 1.6;
}
.msg-html { margin-top: 16px; }
.msg-html > summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.msg-attach { margin-top: 20px; }
.msg-attach h3 { margin: 0 0 10px; }
.attach-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.attach-item {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 13px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; color: var(--fg);
}
.attach-item:hover { border-color: var(--accent); color: var(--fg); }
.attach-size { color: var(--muted); font-size: 12px; }

/* inbox refresh footer */
.maillist-foot { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.refresh-btn { display: inline-flex; align-items: center; gap: 7px; }
.refresh-ic { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.refresh-btn.htmx-request .refresh-ic { animation: spin .7s linear infinite; }
.js-inbox.htmx-request { opacity: .6; transition: opacity .12s; }
.maillist-hint { font-size: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* pop-in message modal */
.msg-modal { max-width: 720px; width: 100%; }
.msg-modal-subject { margin: 0 34px 16px 0; font-size: 1.35rem; overflow-wrap: anywhere; }
.msg-modal .msg-body { max-height: 46vh; overflow: auto; }
.msg-modal-foot { margin-top: 20px; display: flex; justify-content: flex-end; }
.msg-modal-foot form { margin: 0; }

@media (max-width: 640px) {
  .claim-row { flex-direction: column; align-items: stretch; }
  .claim-row .primary, .claim-row .btn { width: 100%; }
  .mailbox-chev { display: none; }
}

/* --- wallet page --- */
.stack-form { display: flex; flex-direction: column; gap: .75rem; max-width: 480px; }
.stack-form label { display: flex; flex-direction: column; gap: .3rem; }
.stack-form button { align-self: flex-start; }
