:root {
    --primary: #9C1F1F;
    --primary-hi: #c62828;
    --primary-glow: rgba(156, 31, 31, 0.35);
    --bg: #0a0a0c;
    --surface: #141418;
    --surface-2: #1c1c22;
    --surface-3: #232329;
    --surface-4: #2a2a32;
    --text: #ececf1;
    --muted: #8a8a94;
    --border: #26262e;
    --border-2: #33333d;
    --green: #34c771;
    --red: #e74c3c;
    --yellow: #f0b429;
    --discord: #5865F2;
    --sidebar-w: 250px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 20px 60px rgba(0,0,0,0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
        'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    font-size: 15px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 0.78rem; }
.error { color: var(--red); font-size: 0.9rem; }

.icon {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

/* ---------- logo ---------- */
.logo-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px; height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hi));
    color: #fff;
    font-weight: 800;
    font-size: 1.55rem;
    letter-spacing: -1px;
    box-shadow: 0 10px 30px var(--primary-glow);
}
.logo-mark.lg { width: 72px; height: 72px; font-size: 2rem; margin-bottom: 1.5rem; }
.logo-mark.sm { width: 34px; height: 34px; font-size: 1rem; border-radius: 9px; }

/* ---------- loading ---------- */
#screen-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
}
.spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
#screen-login {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background:
        radial-gradient(1000px 500px at 50% -20%, rgba(156,31,31,0.18), transparent 60%),
        var(--bg);
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 3rem 2.5rem;
    max-width: 420px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow);
}
.login-card h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
}
.login-card p { margin-bottom: 2rem; }
.btn-discord {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    background: var(--discord);
    color: #fff;
    text-decoration: none;
    padding: 0.9rem 1.75rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    transition: transform 0.15s, filter 0.15s;
    width: 100%;
}
.btn-discord:hover { transform: translateY(-2px); filter: brightness(1.1); }
.login-card .tiny { margin-top: 1.25rem; margin-bottom: 0; }

/* ---------- dashboard layout ---------- */
#screen-dashboard {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.25rem 0.75rem;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem 1.5rem;
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.3px;
}
#nav {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    flex: 1;
    overflow-y: auto;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 0;
    color: var(--muted);
    font-size: 0.88rem;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
    background: var(--surface-3);
    color: var(--text);
    box-shadow: inset 2px 0 0 var(--primary);
}
.nav-icon { display: inline-flex; color: currentColor; }
.sidebar-footer {
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}
.lang-btn {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.55rem 0.75rem;
    background: transparent;
    border: 0;
    color: var(--muted);
    font-family: inherit;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.lang-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- topbar ---------- */
.main { min-width: 0; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.15rem 2rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
}
.topbar h2 { font-size: 1.1rem; font-weight: 600; }
.user-menu { display: flex; align-items: center; gap: 0.75rem; }
.user-menu img {
    width: 38px; height: 38px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    object-fit: cover;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta strong { font-size: 0.9rem; }
.user-meta span { color: var(--muted); font-size: 0.75rem; }
.logout-btn {
    margin-left: 0.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--muted);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}
.logout-btn:hover { background: var(--surface-3); color: var(--text); }

/* ---------- content ---------- */
#content { padding: 2rem; max-width: 1280px; margin: 0 auto; }
.panel { display: none; animation: fade 0.2s ease; }
.panel.active { display: block; }
@keyframes fade {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem;
    margin-bottom: 1.25rem;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.card h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
}
.card p { margin-bottom: 0.5rem; }
.empty {
    margin-top: 1rem;
    padding: 2rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
}

/* ---------- buttons ---------- */
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, border-color 0.15s;
    white-space: nowrap;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-hi); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
    background: var(--surface-3);
    color: var(--text);
    border-color: var(--border-2);
}
.btn-secondary:hover { background: var(--surface-4); }

.btn-danger {
    background: transparent;
    color: var(--red);
    border-color: rgba(231,76,60,0.4);
}
.btn-danger:hover { background: rgba(231,76,60,0.1); }

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border-color: transparent;
    padding: 0.4rem 0.6rem;
}
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px; height: 34px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.danger:hover { background: rgba(231,76,60,0.15); color: var(--red); }

/* ---------- form elements ---------- */
input[type=text],
input[type=url],
input[type=color],
textarea,
select {
    width: 100%;
    padding: 0.65rem 0.85rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    transition: border-color 0.15s, background 0.15s;
}
input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface-3);
}
textarea { resize: vertical; min-height: 90px; font-family: ui-monospace, monospace; }
label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.4rem;
}
.form-row { margin-bottom: 1rem; }
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ---------- toolbar / search ---------- */
.toolbar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.search {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}
.search .icon {
    position: absolute;
    left: 0.75rem;
    color: var(--muted);
    pointer-events: none;
}
.search input { padding-left: 2.4rem; }

/* ---------- list ---------- */
.list { display: flex; flex-direction: column; gap: 0.6rem; }
.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1.1rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s;
}
.list-item:hover { border-color: var(--border-2); }
.list-item-info { min-width: 0; flex: 1; }
.list-item-title {
    font-weight: 600;
    font-size: 0.92rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.list-item-sub {
    color: var(--muted);
    font-size: 0.82rem;
    margin-top: 0.15rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.list-item-actions { display: flex; gap: 0.25rem; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.55rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge.on  { background: rgba(52,199,113,0.15); color: var(--green); }
.badge.off { background: rgba(138,138,148,0.15); color: var(--muted); }

/* ---------- stat grid ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.stat-label {
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-value.ok { color: var(--green); }

/* ---------- modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    z-index: 1000;
    animation: fade 0.15s ease;
}
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    animation: pop 0.18s ease;
}
.modal.wide { max-width: 820px; }
@keyframes pop {
    from { transform: scale(0.96); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }
.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
}

/* ---------- embed preview ---------- */
.embed-preview {
    border-left: 4px solid var(--primary);
    background: var(--surface-2);
    padding: 1rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    line-height: 1.5;
}
.embed-preview .embed-title {
    font-weight: 700;
    margin-bottom: 0.35rem;
    color: var(--text);
}
.embed-preview .embed-desc {
    white-space: pre-wrap;
    color: #d0d0d6;
}
.embed-preview .embed-footer {
    margin-top: 0.6rem;
    color: var(--muted);
    font-size: 0.78rem;
}
.embed-preview img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin-top: 0.6rem;
}

/* ---------- toast ---------- */
#toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--surface-3);
    color: var(--text);
    padding: 0.7rem 1.2rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-2);
    box-shadow: var(--shadow);
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 2000;
    pointer-events: none;
}
#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ---------- responsive ---------- */
@media (max-width: 820px) {
    #screen-dashboard { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        bottom: 0; left: 0; right: 0; top: auto;
        height: auto;
        flex-direction: row;
        padding: 0.5rem;
        border-right: 0;
        border-top: 1px solid var(--border);
        z-index: 100;
    }
    .brand { display: none; }
    #nav {
        flex-direction: row;
        overflow-x: auto;
        gap: 0.2rem;
    }
    .nav-item {
        flex-direction: column;
        padding: 0.45rem 0.7rem;
        font-size: 0.68rem;
        white-space: nowrap;
        text-align: center;
        gap: 0.2rem;
    }
    .sidebar-footer { display: none; }
    .main { padding-bottom: 90px; }
    .topbar { padding: 1rem; }
    #content { padding: 1rem; }
    .user-meta { display: none; }
    .form-grid { grid-template-columns: 1fr; }
}