:root {
    --bg: #0a0e14;
    --surface: #121820;
    --surface2: #1a2332;
    --surface3: #222d3f;
    --border: #2a3548;
    --text: #e8edf5;
    --muted: #8b9cb3;
    --accent: #3b82f6;
    --accent-dim: rgba(59,130,246,.15);
    --accent2: #22c55e;
    --warn: #f59e0b;
    --danger: #ef4444;
    --danger-dim: rgba(239,68,68,.15);
    --purple: #a855f7;
    --radius: 10px;
    --font: 'DM Sans', system-ui, sans-serif;
    --mono: 'JetBrains Mono', monospace;
    --sidebar-w: 260px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
a { color: #93c5fd; }
.hidden { display: none !important; }

/* Login */
.login-screen {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: radial-gradient(ellipse at 30% 20%, #1e3a5f 0%, transparent 50%),
                radial-gradient(ellipse at 70% 80%, #3b1f4a 0%, transparent 50%), var(--bg);
    padding: 24px;
}
.login-card {
    width: 100%; max-width: 440px; background: var(--surface);
    border: 1px solid var(--border); border-radius: 16px; padding: 36px;
    box-shadow: 0 24px 64px rgba(0,0,0,.45);
}
.login-brand { display: flex; gap: 16px; align-items: center; margin-bottom: 28px; }
.login-brand h1 { margin: 0; font-size: 1.15rem; letter-spacing: .02em; }
.login-brand p { margin: 4px 0 0; color: var(--muted); font-size: .85rem; }
.login-foot { margin: 20px 0 0; font-size: .75rem; color: var(--muted); text-align: center; }
.heimdall-link { font-weight: 600; text-decoration: none; }
.heimdall-link:hover { text-decoration: underline; }

.invite-box { background: var(--surface2); border: 1px solid var(--accent-dim); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.invite-box h3 { margin: 0 0 14px; font-size: .95rem; color: #93c5fd; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.captcha-field .captcha-row { display: flex; gap: 8px; }
.captcha-field .captcha-row input { flex: 1; }

.brand-shield {
    width: 48px; height: 48px; border-radius: 12px;
    background: linear-gradient(135deg, #dc2626, #991b1b);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .85rem; letter-spacing: .05em; flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(220,38,38,.3);
}
.brand-shield.sm { width: 36px; height: 36px; font-size: .7rem; border-radius: 8px; }

/* App shell */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; position: relative; }

.hamburger {
    display: none; position: fixed; top: 14px; left: 14px; z-index: 200;
    width: 42px; height: 42px; background: var(--surface2); border: 1px solid var(--border);
    border-radius: 8px; cursor: pointer; flex-direction: column; align-items: center;
    justify-content: center; gap: 5px; padding: 0;
}
.hamburger span { display: block; width: 20px; height: 2px; background: var(--text); border-radius: 2px; transition: .2s; }
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 150;
}
.sidebar-overlay.visible { display: block; }

.sidebar {
    background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 20px 16px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 160;
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 28px; padding: 0 4px; }
.brand h1 { margin: 0; font-size: .95rem; }
.brand p { margin: 2px 0 0; font-size: .7rem; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-btn {
    background: none; border: none; color: var(--muted); text-align: left;
    padding: 10px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-size: .88rem;
    display: flex; align-items: center; justify-content: space-between;
    transition: background .15s, color .15s;
}
.nav-btn:hover { background: rgba(255,255,255,.05); color: var(--text); }
.nav-btn.active { background: var(--accent-dim); color: #93c5fd; border-left: 3px solid var(--accent); padding-left: 11px; }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 16px; margin-top: 16px; }
.live-indicator { font-size: .75rem; color: var(--accent2); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.user-label { font-size: .85rem; margin-bottom: 10px; color: var(--muted); }
.heimdall-sidebar { font-size: .68rem; color: var(--muted); margin: 12px 0 0; text-align: center; }

.main { padding: 24px 28px; overflow-y: auto; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }
.topbar h2 { margin: 0; font-size: 1.4rem; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: .85rem; }
.topbar-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
    background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; position: relative; overflow: hidden;
}
.stat-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--accent); }
.stat-card.accent-green::before { background: var(--accent2); }
.stat-card.accent-amber::before { background: var(--warn); }
.stat-card.accent-purple::before { background: var(--purple); }
.stat-card.accent-red::before { background: var(--danger); }
.stat-label { display: block; font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-value { display: block; font-size: 2rem; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat-value.stat-sm { font-size: 1.4rem; }

/* Panels */
.panel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.panel { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.panel-wide { grid-column: 1 / -1; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); gap: 12px; flex-wrap: wrap; }
.panel-head h3 { margin: 0; font-size: .95rem; }
.panel-body { padding: 16px 18px; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: .82rem; min-width: 500px; }
.data-table.enhanced { min-width: 700px; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table th { color: var(--muted); font-weight: 600; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.data-table tbody tr:hover { background: rgba(255,255,255,.02); }
.data-table code { font-family: var(--mono); font-size: .78rem; color: #93c5fd; }

.search-input {
    background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
    color: var(--text); padding: 6px 12px; font: inherit; font-size: .82rem; min-width: 180px;
}

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: 8px; border: none; font: inherit; font-size: .85rem;
    font-weight: 600; cursor: pointer; transition: opacity .15s, transform .1s; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #2563eb; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-sm { padding: 6px 12px; font-size: .78rem; }
.btn-block { width: 100%; }
.btn-icon { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1.1rem; padding: 4px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .78rem; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); padding: 10px 12px; font: inherit; font-size: .88rem;
}
.field textarea { min-height: 80px; resize: vertical; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 10px; flex-wrap: wrap; }
.form-actions.row { margin-top: 8px; }
.config-section { grid-column: 1 / -1; margin: 8px 0 0; font-size: .85rem; color: #93c5fd; border-bottom: 1px solid var(--border); padding-bottom: 8px; }

.chk { display: flex; align-items: center; gap: 8px; font-size: .88rem; cursor: pointer; }
.weekday-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.weekday-chips label { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; font-size: .8rem; cursor: pointer; }

/* Alerts & badges */
.alert { padding: 12px 16px; border-radius: 8px; font-size: .85rem; margin-bottom: 14px; }
.alert.error { background: var(--danger-dim); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }
.alert.success { background: rgba(34,197,94,.15); border: 1px solid rgba(34,197,94,.3); color: #86efac; }

.badge { background: var(--danger); color: #fff; font-size: .68rem; padding: 2px 7px; border-radius: 99px; font-weight: 700; min-width: 18px; text-align: center; }

.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent2); animation: pulse 2s infinite; display: inline-block; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

.status-pill { font-size: .75rem; padding: 5px 12px; border-radius: 99px; background: rgba(34,197,94,.15); color: #86efac; border: 1px solid rgba(34,197,94,.3); font-weight: 600; }
.status-pill.danger { background: var(--danger-dim); color: #fca5a5; border-color: rgba(239,68,68,.4); }
.status-pill.lockdown-active { background: rgba(239,68,68,.25); color: #fff; animation: pulse 1.5s infinite; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.active { background: var(--accent2); box-shadow: 0 0 6px var(--accent2); }
.status-dot.idle { background: var(--warn); }

/* Tags */
.tag { display: inline-block; font-size: .68rem; padding: 2px 8px; border-radius: 4px; font-weight: 600; margin: 0 2px; }
.tag.minor { background: rgba(168,85,247,.2); color: #d8b4fe; }
.tag.locked { background: var(--danger-dim); color: #fca5a5; }
.tag.ok { background: rgba(34,197,94,.2); color: #86efac; }
.tag.warn { background: rgba(245,158,11,.2); color: #fcd34d; }
.tag.inactive { background: rgba(100,116,139,.2); color: #94a3b8; }

/* Tabs */
.tab-bar { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; border-bottom: 1px solid var(--border); padding-bottom: 0; }
.tab-btn {
    background: none; border: none; color: var(--muted); padding: 10px 18px;
    cursor: pointer; font: inherit; font-size: .88rem; border-bottom: 2px solid transparent;
    margin-bottom: -1px; transition: color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: #93c5fd; border-bottom-color: var(--accent); }

/* Messages feed */
.feed-list { display: flex; flex-direction: column; gap: 0; }
.feed-item {
    display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border);
    align-items: flex-start;
}
.feed-item:last-child { border-bottom: none; }
.feed-icon {
    width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center;
    justify-content: center; font-size: .75rem; font-weight: 700; flex-shrink: 0;
}
.feed-icon.incoming { background: var(--accent-dim); color: #93c5fd; }
.feed-icon.outgoing { background: rgba(34,197,94,.15); color: #86efac; }
.feed-content { flex: 1; min-width: 0; }
.feed-content h4 { margin: 0 0 4px; font-size: .88rem; }
.feed-content p { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.45; word-break: break-word; }
.feed-content time { font-size: .72rem; color: var(--muted); font-family: var(--mono); }

/* MOASS Shop */
.moass-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.moass-card {
    background: var(--surface3); border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden; cursor: pointer; transition: border-color .15s, transform .15s;
}
.moass-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.moass-card.inactive { opacity: .55; }
.moass-img {
    height: 140px; background: var(--bg); display: flex; align-items: center;
    justify-content: center; overflow: hidden;
}
.moass-img img { width: 100%; height: 100%; object-fit: cover; }
.moass-img .placeholder { font-size: 2.5rem; opacity: .3; }
.moass-info { padding: 14px; }
.moass-info h4 { margin: 0 0 6px; font-size: .92rem; }
.moass-price { font-size: 1.1rem; font-weight: 700; color: #86efac; }
.moass-meta { font-size: .72rem; color: var(--muted); margin-top: 6px; }

/* Mail client */
.mail-layout { display: grid; grid-template-columns: 200px 1fr; gap: 16px; min-height: 500px; }
.mail-sidebar { display: flex; flex-direction: column; gap: 8px; }
.mail-main { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.mail-view .panel-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.mail-compose { padding: 18px; }
.mail-list { max-height: 520px; overflow-y: auto; }
.mail-item {
    padding: 14px 18px; border-bottom: 1px solid var(--border); cursor: pointer;
    transition: background .15s;
}
.mail-item:hover { background: rgba(255,255,255,.03); }
.mail-item.unread { border-left: 3px solid var(--accent); }
.mail-item .mail-from { font-weight: 600; font-size: .88rem; }
.mail-item .mail-subject { color: var(--text); font-size: .85rem; margin: 4px 0; }
.mail-item .mail-preview { color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-item .mail-date { font-size: .72rem; color: var(--muted); font-family: var(--mono); }

/* User detail panel */
.user-detail { display: grid; gap: 16px; }
.user-detail-header { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.user-avatar {
    width: 56px; height: 56px; border-radius: 12px; background: linear-gradient(135deg, var(--accent), #1d4ed8);
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.2rem;
}
.user-detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.detail-field label { display: block; font-size: .72rem; color: var(--muted); text-transform: uppercase; margin-bottom: 4px; }
.detail-field span { font-size: .9rem; }
.detail-section { margin-top: 16px; }
.detail-section h4 { margin: 0 0 10px; font-size: .85rem; color: #93c5fd; }
.chat-log { max-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.chat-bubble { padding: 10px 14px; border-radius: 10px; font-size: .82rem; max-width: 85%; }
.chat-bubble.in { background: var(--surface3); align-self: flex-start; }
.chat-bubble.out { background: var(--accent-dim); align-self: flex-end; }
.chat-bubble time { display: block; font-size: .68rem; color: var(--muted); margin-top: 4px; }

/* Settings */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }

/* Lockdown */
.lockdown-desc { color: var(--muted); font-size: .88rem; line-height: 1.55; margin: 0 0 20px; }
.lockdown-status { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 20px; font-size: .88rem; }

/* Notifications */
.notif-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.notif-item:last-child { border-bottom: none; }
.notif-item .severity { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.notif-item .severity.critical { color: var(--danger); }
.notif-item .severity.warning { color: var(--warn); }
.notif-item .severity.info { color: var(--accent); }
.notif-item h4 { margin: 4px 0; font-size: .9rem; }
.notif-item p { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.45; }
.notif-item time { font-size: .72rem; color: var(--muted); font-family: var(--mono); }

.notif-drawer {
    position: fixed; right: 0; top: 0; bottom: 0; width: 340px; max-width: 90vw;
    background: var(--surface); border-left: 1px solid var(--border);
    transform: translateX(100%); transition: transform .25s;
    z-index: 100; display: flex; flex-direction: column;
}
.notif-drawer.open { transform: translateX(0); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { margin: 0; font-size: .95rem; }
.drawer-body { flex: 1; overflow-y: auto; padding: 12px 18px; }

/* Modals */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 300;
    display: flex; align-items: center; justify-content: center; padding: 20px;
    backdrop-filter: blur(4px);
}
.modal {
    background: var(--surface2); border: 1px solid var(--border); border-radius: 14px;
    width: 100%; max-width: 560px; max-height: 85vh; display: flex; flex-direction: column;
    box-shadow: 0 24px 64px rgba(0,0,0,.5);
}
.modal.modal-lg { max-width: 720px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 1rem; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.empty { color: var(--muted); font-size: .88rem; text-align: center; padding: 24px; }

/* Responsive */
@media (max-width: 1024px) {
    .mail-layout { grid-template-columns: 1fr; }
    .mail-sidebar { flex-direction: row; flex-wrap: wrap; }
    .mail-sidebar .btn-block { width: auto; flex: 1; min-width: 120px; }
    .panel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .hamburger { display: flex; }
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w);
        transform: translateX(-100%); transition: transform .25s;
        box-shadow: 4px 0 24px rgba(0,0,0,.4);
    }
    .sidebar.open { transform: translateX(0); }
    .main { padding: 60px 16px 16px; }
    .topbar h2 { font-size: 1.15rem; }
    .stat-value { font-size: 1.6rem; }
    .moass-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .login-card { padding: 24px 20px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid { grid-template-columns: 1fr; }
    .modal { max-height: 90vh; border-radius: 12px 12px 0 0; align-self: flex-end; }
    .modal-overlay { align-items: flex-end; padding: 0; }
}