:root {
    --bg: #0e100f;
    --bg-soft: #121513;
    --panel: #171a18;
    --panel-2: #1d211e;
    --panel-3: #232823;
    --line: #2b312c;
    --line-soft: #232823;
    --ink: #ece9e1;
    --ink-dim: #b6b9b1;
    --muted: #858c84;
    --accent: #c9f26b;
    --accent-ink: #14180d;
    --green: #75d18a;
    --amber: #e0b25b;
    --red: #e3756a;
    --blue: #82aee8;
    --violet: #b79ae8;
    --mono: "Cascadia Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
    --sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    --radius: 10px;
    --radius-sm: 7px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.5;
}

body {
    background-image:
        radial-gradient(1100px 600px at 80% -10%, rgba(201, 242, 107, 0.055), transparent 60%),
        linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
    background-size: auto, 44px 44px, 44px 44px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

.mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.gap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Login ---------- */

.login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px;
}

.login-card {
    width: 380px;
    max-width: 100%;
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
}

.login-brand,
.brand {
    display: flex;
    align-items: center;
    gap: 11px;
}

.login-brand { margin-bottom: 24px; }

.login-brand strong,
.brand strong {
    display: block;
    font-size: 15px;
    letter-spacing: 0.04em;
    text-transform: lowercase;
}

.login-brand small,
.brand small {
    display: block;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.mark {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: var(--accent);
    position: relative;
    flex: none;
}

.mark::after {
    content: "";
    position: absolute;
    inset: 7px;
    border: 2px solid var(--accent-ink);
    border-radius: 2px;
}

.login label,
.field {
    display: block;
    margin-bottom: 14px;
}

.login label span,
.field span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

input,
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--bg-soft);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 14px;
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(201, 242, 107, 0.09);
}

.login .btn { width: 100%; justify-content: center; margin-top: 4px; }

.login-error {
    min-height: 20px;
    margin: 12px 0 0;
    color: var(--red);
    font-size: 13px;
}

.login-note {
    margin: 20px 0 0;
    color: var(--muted);
    font-size: 11.5px;
    line-height: 1.55;
}

/* ---------- Shell ---------- */

.app {
    display: grid;
    grid-template-columns: 224px minmax(0, 1fr);
    min-height: 100vh;
}

.rail {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    border-right: 1px solid var(--line);
    background: rgba(14, 16, 15, 0.88);
    backdrop-filter: blur(6px);
}

.brand { padding: 0 6px 20px; }

.nav {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 8px;
}

.nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: var(--ink-dim);
    text-decoration: none;
    font-size: 13.5px;
    transition: background 0.12s, color 0.12s;
}

.nav a:hover {
    background: var(--panel-2);
    color: var(--ink);
    text-decoration: none;
}

.nav a.active {
    background: var(--panel-2);
    color: var(--ink);
}

.nav a.active .nav-dot {
    background: var(--accent);
    box-shadow: 0 0 0 3px rgba(201, 242, 107, 0.12);
}

.nav-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--line);
    flex: none;
}

.rail-foot {
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 6px 0;
    border-top: 1px solid var(--line-soft);
    color: var(--muted);
    font-size: 11px;
}

.live {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.live i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 8px rgba(117, 209, 138, 0.6);
}

.rail-version { font-family: var(--mono); }

.main {
    min-width: 0;
    padding: 0 30px 60px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    padding: 22px 0 16px;
    background: linear-gradient(var(--bg) 72%, rgba(14, 16, 15, 0));
}

.crumb {
    margin: 0 0 3px;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 10.5px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.topbar h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.clock {
    margin-right: 6px;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 11.5px;
}

.view { padding-top: 6px; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 13px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s, color 0.12s;
    white-space: nowrap;
}

.btn:hover { border-color: #3a423a; background: var(--panel-3); }

.btn-primary {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
}

.btn-primary:hover {
    background: #d7ff82;
    border-color: #d7ff82;
}

.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); background: rgba(227, 117, 106, 0.08); }

.btn-sm { padding: 5px 9px; font-size: 11.5px; }
.btn-ghost { background: transparent; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Cards / grid ---------- */

.grid { display: grid; gap: 14px; }
.stats {
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
}

.stat {
    padding: 14px 15px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

.stat-label {
    color: var(--muted);
    font-size: 10.5px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.stat-value {
    margin-top: 5px;
    font-family: var(--mono);
    font-size: 26px;
    line-height: 1.1;
    letter-spacing: -0.03em;
}

.stat-note {
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
}

.stat.accent { border-color: rgba(201, 242, 107, 0.35); }
.stat.accent .stat-value { color: var(--accent); }
.stat.bad .stat-value { color: var(--red); }
.stat.warn .stat-value { color: var(--amber); }
.stat.good .stat-value { color: var(--green); }

.two-col {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    gap: 14px;
    margin-top: 14px;
}

.card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    min-width: 0;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--line-soft);
}

.card-title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.card-body { padding: 14px 16px; }
.card-body.flush { padding: 0; }

/* ---------- Toolbar ---------- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 14px;
}

.toolbar .field { margin: 0; }
.toolbar .field.grow { flex: 1 1 260px; }
.toolbar .field span { margin-bottom: 4px; }
.toolbar .field input,
.toolbar .field select { min-width: 150px; }

/* ---------- Table ---------- */

.table-wrap { overflow: auto; border-radius: var(--radius); }

table.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}

.table th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}

.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: rgba(255, 255, 255, 0.018); }
.table .row-click { cursor: pointer; }
.table .login-cell { font-family: var(--mono); font-weight: 600; color: var(--ink); }
.table .email-cell { font-family: var(--mono); font-size: 11.5px; color: var(--ink-dim); }

.empty {
    padding: 34px 18px;
    color: var(--muted);
    text-align: center;
    font-size: 13px;
}

/* ---------- Chips ---------- */

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel-2);
    color: var(--ink-dim);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.chip::before {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--muted);
}

.chip.done { color: var(--green); border-color: rgba(117, 209, 138, 0.25); }
.chip.done::before { background: var(--green); }
.chip.error { color: var(--red); border-color: rgba(227, 117, 106, 0.28); }
.chip.error::before { background: var(--red); }
.chip.changing { color: var(--blue); border-color: rgba(130, 174, 232, 0.28); }
.chip.changing::before { background: var(--blue); animation: pulse 1.4s infinite; }
.chip.waiting { color: var(--amber); border-color: rgba(224, 178, 91, 0.28); }
.chip.waiting::before { background: var(--amber); }
.chip.new { color: var(--ink-dim); }
.chip.new::before { background: var(--ink-dim); }
.chip.accent { color: var(--accent); border-color: rgba(201, 242, 107, 0.25); }
.chip.accent::before { background: var(--accent); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* ---------- Events / timeline ---------- */

.events { display: flex; flex-direction: column; }

.event {
    display: grid;
    grid-template-columns: 8px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: start;
    padding: 9px 0;
    border-bottom: 1px solid var(--line-soft);
}

.event:last-child { border-bottom: 0; }

.event-dot {
    width: 7px;
    height: 7px;
    margin-top: 5px;
    border-radius: 50%;
    background: var(--muted);
}

.event.success .event-dot { background: var(--green); }
.event.error .event-dot { background: var(--red); }
.event.email .event-dot { background: var(--blue); }
.event.phone .event-dot { background: var(--violet); }
.event.mail .event-dot { background: var(--accent); }
.event.action .event-dot { background: var(--amber); }
.event.auth .event-dot { background: var(--ink-dim); }

.event-text {
    min-width: 0;
    font-size: 12.5px;
    overflow-wrap: anywhere;
}

.event-meta {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 10.5px;
    white-space: nowrap;
}

.event-sub {
    margin-top: 2px;
    color: var(--muted);
    font-size: 11px;
}

.event-kind,
.event-actor {
    font-size: 9.5px;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
}

.event-actor {
    margin-left: 6px;
    color: var(--ink-dim);
}

/* ---------- Account page ---------- */

.account-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
}

.account-identity {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--line);
    background: var(--panel-2);
    flex: none;
}

.modal-body h3 {
    margin: 4px 0 10px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.modal-body h3.mt { margin-top: 20px; }

.account-title {
    margin: 0;
    font-family: var(--mono);
    font-size: 22px;
    letter-spacing: -0.02em;
}

.account-sub {
    margin-top: 5px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 7px;
}

.account-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1px;
    background: var(--line-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.meta {
    padding: 11px 14px;
    background: var(--panel);
}

.meta dt {
    margin: 0;
    color: var(--muted);
    font-size: 10px;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.meta dd {
    margin: 4px 0 0;
    font-family: var(--mono);
    font-size: 12.5px;
    overflow-wrap: anywhere;
}

.mailcard {
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

.mailcard + .mailcard { margin-top: 10px; }

.mailcard-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.mailcard-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.mailcard-email {
    font-family: var(--mono);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.secret-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 5px;
}

.secret {
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--ink-dim);
    overflow-wrap: anywhere;
}

.link-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--line);
}

.link-row .mono {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--blue);
}

.stage-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.stage {
    flex: 1 1 150px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
}

.stage-label {
    color: var(--muted);
    font-size: 10px;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.stage-value {
    margin-top: 3px;
    font-family: var(--mono);
    font-size: 12.5px;
}

/* ---------- Modal ---------- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: center;
    padding: 22px;
    background: rgba(6, 8, 7, 0.72);
    backdrop-filter: blur(4px);
}

.modal-card {
    width: min(860px, 100%);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: var(--panel);
    overflow: hidden;
}

.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line-soft);
}

.modal-head h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.modal-body {
    padding: 16px 18px;
    overflow: auto;
}

.pre {
    margin: 0;
    padding: 13px 14px;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-sm);
    background: var(--bg-soft);
    color: var(--ink-dim);
    font-family: var(--mono);
    font-size: 11.5px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.code {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 9px;
    border: 1px solid rgba(201, 242, 107, 0.3);
    border-radius: var(--radius-sm);
    background: rgba(201, 242, 107, 0.07);
    color: var(--accent);
    font-family: var(--mono);
    font-size: 12px;
    cursor: pointer;
}

/* ---------- Toast ---------- */

.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 100;
    max-width: 420px;
    padding: 11px 14px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
    color: var(--ink);
    font-size: 12.5px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }

/* ---------- Misc ---------- */

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 14px;
    border-top: 1px solid var(--line-soft);
    color: var(--muted);
    font-size: 12px;
}

.notice {
    padding: 11px 13px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--amber);
    border-radius: var(--radius-sm);
    background: rgba(224, 178, 91, 0.05);
    color: var(--ink-dim);
    font-size: 12.5px;
}

.notice.danger { border-left-color: var(--red); background: rgba(227, 117, 106, 0.05); }
.notice.info { border-left-color: var(--blue); background: rgba(130, 174, 232, 0.05); }

.checkline {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line-soft);
}

.checkline:last-child { border-bottom: 0; }

.checkline input[type="checkbox"] {
    width: 15px;
    height: 15px;
    margin-top: 2px;
    accent-color: var(--accent);
    flex: none;
}

.checkline strong { display: block; font-size: 12.5px; font-weight: 600; }
.checkline span { color: var(--muted); font-size: 11.5px; }

.kv {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    gap: 8px 14px;
    font-size: 12.5px;
}

.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); overflow-wrap: anywhere; }

.from-line {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 12px;
}

.msg-list { border-top: 1px solid var(--line-soft); }

.msg {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--line-soft);
    cursor: pointer;
}

.msg:hover { background: rgba(255, 255, 255, 0.02); }
.msg-subject { font-weight: 600; font-size: 12.5px; overflow-wrap: anywhere; }
.msg-preview { color: var(--muted); font-size: 11.5px; overflow-wrap: anywhere; }

@media (max-width: 980px) {
    .app { grid-template-columns: 1fr; }
    .rail {
        position: static;
        height: auto;
        flex-direction: row;
        align-items: center;
        padding: 12px 14px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }
    .brand { padding: 0; }
    .brand small { display: none; }
    .nav { flex-direction: row; flex-wrap: wrap; margin: 0 0 0 14px; }
    .nav a { padding: 7px 9px; }
    .rail-foot { display: none; }
    .main { padding: 0 16px 40px; }
    .topbar { position: static; padding-top: 16px; }
    .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
    .topbar { flex-direction: column; align-items: flex-start; }
    .top-actions { width: 100%; justify-content: space-between; }
    .clock { display: none; }
    .kv { grid-template-columns: 1fr; gap: 2px; }
    .kv dt { margin-top: 8px; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
