:root {
    --bg:        #0a0e17;
    --bg-2:      #0e131f;
    --surface:   #131a28;
    --surface-2: #182133;
    --border:    #243043;
    --border-2:  #2e3c54;
    --text:      #e8edf6;
    --muted:     #8b9ab2;
    --accent:    #6366f1;
    --accent-2:  #8b5cf6;
    --ok:        #34d399;
    --err:       #fb7185;
    --warn:      #fbbf24;
    --radius:    16px;
    --shadow:    0 10px 30px -12px rgba(0,0,0,.6);

    --c-dynadot:    #3b82f6;
    --c-cloudflare: #f6821f;
    --c-stormwall:  #ef4444;
    --c-isp:        #22c55e;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text);
    background:
        radial-gradient(1200px 600px at 80% -10%, rgba(99,102,241,.18), transparent 60%),
        radial-gradient(900px 500px at -10% 110%, rgba(139,92,246,.14), transparent 55%),
        var(--bg);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.accent { color: #a5b4fc; }

/* ============ App shell ============ */
.shell {
    display: grid;
    grid-template-columns: 256px 1fr;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 22px 16px;
    background: linear-gradient(180deg, var(--bg-2), rgba(14,19,31,.6));
    border-right: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 10px 22px;
}

.logo-mark {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 6px 18px -6px rgba(99,102,241,.8);
}
.logo-mark.lg { width: 52px; height: 52px; border-radius: 15px; font-size: 24px; }
.logo-text { font-size: 19px; font-weight: 600; }
.logo-text strong { font-weight: 800; }

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 13px;
    border-radius: 11px;
    color: var(--muted);
    font-weight: 500;
    font-size: 14.5px;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.is-active {
    background: linear-gradient(135deg, rgba(99,102,241,.22), rgba(139,92,246,.16));
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(129,140,248,.35);
}
.nav-item.is-soon { cursor: default; opacity: .55; }
.nav-item.is-soon:hover { background: transparent; color: var(--muted); }

.nav-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: currentColor; opacity: .6; flex: none;
}
.nav-item.is-active .nav-dot { background: #818cf8; opacity: 1; box-shadow: 0 0 10px #818cf8; }
.nav-label { flex: 1; }
.nav-soon {
    font-size: 10.5px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .04em; color: var(--muted);
    background: var(--surface-2); padding: 2px 7px; border-radius: 999px;
}

.logout {
    margin-top: auto;
    display: flex; align-items: center; gap: 12px;
    padding: 11px 13px; border-radius: 11px;
    color: var(--muted); font-weight: 500; font-size: 14.5px;
    transition: background .15s, color .15s;
}
.logout:hover { background: rgba(251,113,133,.12); color: var(--err); }
.logout-dot { background: var(--err); opacity: .8; }

/* ============ Main ============ */
.main { padding: 30px 34px 48px; max-width: 1280px; width: 100%; }

.topbar {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 18px; flex-wrap: wrap; margin-bottom: 26px;
}
.topbar-title h1 { font-size: 26px; }
.topbar-title p { margin: 4px 0 0; font-size: 14px; }
.topbar-aside { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.pill {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 7px 13px; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--border);
    font-size: 13px; font-family: 'JetBrains Mono', monospace;
}
.pill-key { color: var(--muted); font-family: 'Inter', sans-serif; }
.pill-accent {
    font-family: 'Inter', sans-serif; font-weight: 600;
    background: linear-gradient(135deg, rgba(52,211,153,.16), rgba(52,211,153,.06));
    border-color: rgba(52,211,153,.3); color: #6ee7b7;
}

/* ============ Stat cards ============ */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px; margin-bottom: 28px;
}

.stat-card {
    position: relative; overflow: hidden;
    background: linear-gradient(180deg, var(--surface), var(--bg-2));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    transition: transform .18s, border-color .18s;
}
.stat-card:hover { transform: translateY(-3px); border-color: var(--border-2); }
.stat-card::before {
    content: ''; position: absolute; inset: 0 0 auto 0; height: 3px;
    background: var(--accent);
}
.stat-card[data-source="dynadot"]::before    { background: var(--c-dynadot); }
.stat-card[data-source="cloudflare"]::before  { background: var(--c-cloudflare); }
.stat-card[data-source="stormwall"]::before    { background: var(--c-stormwall); }
.stat-card[data-source="isp"]::before          { background: var(--c-isp); }

.stat-top { display: flex; align-items: center; gap: 12px; }

.avatar {
    display: grid; place-items: center; flex: none;
    width: 42px; height: 42px; border-radius: 12px;
    font-weight: 700; color: #fff; font-size: 17px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.avatar.sm { width: 28px; height: 28px; border-radius: 9px; font-size: 13px; }
.avatar[data-source="dynadot"]    { background: linear-gradient(135deg, #3b82f6, #60a5fa); }
.avatar[data-source="cloudflare"]  { background: linear-gradient(135deg, #f6821f, #fbbf24); }
.avatar[data-source="stormwall"]   { background: linear-gradient(135deg, #ef4444, #f97316); }
.avatar[data-source="isp"]         { background: linear-gradient(135deg, #22c55e, #4ade80); }

.stat-id { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.stat-name { font-weight: 600; font-size: 15px; }
.stat-sub { font-size: 12.5px; }

.status {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12px; font-weight: 600; color: var(--muted);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.is-ok .status { color: var(--ok); }
.is-ok .status-dot { background: var(--ok); box-shadow: 0 0 0 4px rgba(52,211,153,.16); animation: pulse 2.4s infinite; }
.is-error .status { color: var(--err); }
.is-error .status-dot { background: var(--err); box-shadow: 0 0 0 4px rgba(251,113,133,.16); }

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(52,211,153,.16); }
    50%       { box-shadow: 0 0 0 7px rgba(52,211,153,.05); }
}

.stat-body { margin-top: 16px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.stat-num { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; }
.stat-unit { font-size: 13px; color: var(--muted); }
.stat-err { font-size: 13px; color: var(--err); word-break: break-word; }

/* ============ Card blocks ============ */
.card-block {
    background: linear-gradient(180deg, var(--surface), var(--bg-2));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px; margin-bottom: 22px;
    box-shadow: var(--shadow);
}
.block-head { margin-bottom: 18px; }
.block-head h2 { font-size: 18px; }
.block-head p { margin: 5px 0 0; font-size: 13.5px; }

.mini-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 14px;
}

.mini-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 13px;
    padding: 14px;
    transition: border-color .15s;
}
.mini-card:hover { border-color: var(--border-2); }

.mini-head {
    display: flex; align-items: center; gap: 9px;
    font-weight: 600; font-size: 14px; margin-bottom: 10px;
}
.count-chip {
    margin-left: auto;
    background: var(--surface-2); color: var(--muted);
    font-size: 12px; font-weight: 600;
    padding: 2px 9px; border-radius: 999px;
    font-family: 'JetBrains Mono', monospace;
}

.empty { font-size: 13px; margin: 4px 0 0; }

.domain-list {
    list-style: none; margin: 0; padding: 0;
    display: flex; flex-direction: column; gap: 5px;
}
.domain-list li {
    flex: 0 0 auto;
    min-height: 32px;
    line-height: 18px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12.5px;
    color: #e2e8f0;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 7px 11px; border-radius: 8px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.domain-list.scroll { max-height: 320px; overflow-y: auto; padding-right: 4px; }
.domain-list.scroll::-webkit-scrollbar { width: 8px; }
.domain-list.scroll::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 8px; }
.domain-list.scroll::-webkit-scrollbar-track { background: transparent; }

/* ============ ISP sites (collapsible) ============ */
.site-list { display: flex; flex-direction: column; gap: 10px; }

.site {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 13px;
    overflow: hidden;
    transition: border-color .15s;
}
.site[open] { border-color: var(--border-2); }
.site:hover { border-color: var(--border-2); }

.site-summary {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 16px; cursor: pointer; user-select: none;
    list-style: none; font-weight: 600; font-size: 14.5px;
}
.site-summary::-webkit-details-marker { display: none; }
.site-summary::marker { content: ''; }
.site-summary:hover { background: var(--surface); }

.caret {
    width: 8px; height: 8px; flex: none; margin-right: 2px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(-45deg);
    transition: transform .18s ease;
}
.site[open] .caret { transform: rotate(45deg); }
.site[data-empty="1"] .caret { opacity: .3; }

.site-name {
    font-family: 'JetBrains Mono', monospace; font-size: 13.5px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}
.site-summary .count-chip { margin-left: auto; flex: none; }

.site-detail { padding: 2px 16px 16px; }
.site-root {
    font-family: 'JetBrains Mono', monospace; font-size: 11.5px;
    color: var(--muted); margin: 0 0 12px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    font-family: 'JetBrains Mono', monospace; font-size: 11.5px;
    color: #cbd5e1; background: var(--surface);
    border: 1px solid var(--border); border-radius: 7px;
    padding: 4px 8px;
}
.chip:hover { border-color: var(--accent); }

/* ============ Auth ============ */
body.auth { display: grid; place-items: center; }
.auth-wrap { width: 100%; display: grid; place-items: center; padding: 24px; }

.auth-card {
    width: 100%; max-width: 420px;
    background: linear-gradient(180deg, var(--surface), var(--bg-2));
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 34px;
    box-shadow: 0 30px 80px -30px rgba(0,0,0,.8);
}
.auth-brand { display: flex; align-items: center; gap: 16px; margin-bottom: 26px; }
.auth-brand h1 { font-size: 24px; font-weight: 600; }
.auth-brand h1 strong { font-weight: 800; }
.auth-brand p { margin: 2px 0 0; font-size: 13.5px; }

.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field-label { font-size: 13px; font-weight: 500; color: var(--muted); }
.field input {
    padding: 12px 14px;
    border-radius: 11px;
    border: 1px solid var(--border-2);
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
}
.field input::placeholder { color: #4b5a72; }
.field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,.22);
}

.btn {
    padding: 12px 16px; border: none; border-radius: 11px;
    font-weight: 600; font-size: 14.5px; font-family: inherit; cursor: pointer;
    transition: filter .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
    color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 10px 24px -10px rgba(99,102,241,.9);
    margin-top: 4px;
}
.btn-primary:hover { filter: brightness(1.08); }

.auth-foot { text-align: center; font-size: 12.5px; margin: 22px 0 0; }

.alert {
    display: flex; align-items: center; gap: 9px;
    padding: 11px 14px; border-radius: 11px; font-size: 13.5px;
    margin-bottom: 18px;
}
.alert-error { background: rgba(251,113,133,.12); color: #fda4af; border: 1px solid rgba(251,113,133,.3); }
.alert-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--err); flex: none; }

/* ============ Responsive ============ */
@media (max-width: 860px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar {
        position: static; height: auto; flex-direction: row;
        align-items: center; flex-wrap: wrap; gap: 8px;
    }
    .logo { padding: 4px 8px; }
    .nav { flex-direction: row; flex-wrap: wrap; flex: 1; }
    .nav-soon { display: none; }
    .logout { margin: 0; }
    .main { padding: 22px 18px 40px; }
}
