:root {
    --bg: #090a0e;
    --bg-2: #0c0e13;
    --surface: #12141b;
    --surface-2: #181b23;
    --surface-3: #1e222c;
    --border: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.11);
    --text: #eef0f5;
    --muted: #868c9b;
    --faint: #5a6070;
    --accent: #7c83ff;
    --accent-2: #a06bff;
    --grad: linear-gradient(135deg, #7c83ff 0%, #a06bff 100%);
    --green: #34d399;
    --red: #fb7185;
    --amber: #fbbf24;
    --radius: 16px;
    --shadow: 0 16px 50px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    letter-spacing: -0.005em;
}

a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
svg { width: 16px; height: 16px; flex-shrink: 0; }
.hidden { display: none !important; }

/* Brand */
.logo { display: inline-flex; align-items: center; gap: 10px; }
.logo .mark {
    width: 30px; height: 30px; border-radius: 9px; background: var(--grad);
    display: grid; place-items: center; box-shadow: 0 6px 18px rgba(124, 131, 255, 0.35);
    flex-shrink: 0;
}
.logo .mark svg { width: 17px; height: 17px; color: #fff; }
.logo .word { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
.logo .word b { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* Login */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background:
        radial-gradient(900px 500px at 50% -20%, rgba(124, 131, 255, 0.16), transparent 70%),
        radial-gradient(700px 500px at 90% 110%, rgba(160, 107, 255, 0.10), transparent 70%),
        var(--bg);
}
.login-card {
    width: 350px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 20px; padding: 36px 32px; box-shadow: var(--shadow);
}
.login-card .logo { margin-bottom: 22px; }
.login-card .sub { color: var(--muted); margin: -16px 0 22px; font-size: 13px; }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 244px; flex-shrink: 0; padding: 20px 14px;
    background: linear-gradient(180deg, var(--bg-2), var(--bg));
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .logo { padding: 6px 10px 22px; }
.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav button {
    display: flex; align-items: center; gap: 12px; background: transparent; border: none;
    color: var(--muted); padding: 10px 12px; border-radius: 11px; font-size: 14px;
    font-weight: 500; text-align: left; position: relative; transition: all 0.15s;
}
.nav button svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.active { background: rgba(124, 131, 255, 0.12); color: #fff; }
.nav button.active::before {
    content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px;
    border-radius: 0 3px 3px 0; background: var(--grad);
}
.nav button.active svg { opacity: 1; color: var(--accent); }
.side-foot { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 8px; }

.main { flex: 1; min-width: 0; }
.topbar {
    height: 62px; display: flex; align-items: center; justify-content: space-between;
    padding: 0 30px; border-bottom: 1px solid var(--border);
    position: sticky; top: 0; background: rgba(9, 10, 14, 0.72); backdrop-filter: blur(14px); z-index: 5;
}
.topbar h1 { font-size: 17px; font-weight: 650; letter-spacing: -0.02em; }
.content { padding: 28px 30px 70px; max-width: 1100px; }

/* Cards */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 22px; margin-bottom: 18px;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset;
}
.card h3 {
    font-size: 13px; font-weight: 650; margin-bottom: 18px; letter-spacing: 0.01em;
    color: var(--text); display: flex; align-items: center; gap: 8px;
}
.card h3 .muted, h3 .muted { font-weight: 400; color: var(--muted); }

.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

.stat {
    background: linear-gradient(180deg, var(--surface-2), var(--surface));
    border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px;
}
.stat .label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.stat .value { font-size: 28px; font-weight: 750; margin-top: 8px; letter-spacing: -0.03em; }

/* Forms */
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 7px; font-weight: 500; }
.input, textarea.input, select.input {
    width: 100%; background: var(--surface-2); border: 1px solid var(--border);
    color: var(--text); padding: 11px 13px; border-radius: 11px; font-size: 14px;
    transition: border 0.15s, box-shadow 0.15s; outline: none;
}
.input::placeholder, textarea.input::placeholder { color: var(--faint); }
.input:focus, textarea.input:focus, select.input:focus {
    border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 131, 255, 0.16);
}
textarea.input { resize: vertical; min-height: 84px; line-height: 1.5; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 120px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 7px; justify-content: center;
    border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
    padding: 10px 17px; border-radius: 11px; font-size: 13.5px; font-weight: 550;
    transition: filter 0.15s, background 0.15s, transform 0.05s, box-shadow 0.15s;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn.primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: 0 8px 22px rgba(124, 131, 255, 0.28); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.green { background: linear-gradient(135deg, #34d399, #20bd83); border-color: transparent; color: #06231a; }
.btn.danger { background: rgba(251, 113, 133, 0.12); border-color: rgba(251, 113, 133, 0.3); color: var(--red); }
.btn.danger:hover { background: rgba(251, 113, 133, 0.2); }
.btn.sm { padding: 7px 12px; font-size: 12.5px; border-radius: 9px; }
.btn.ghost { background: transparent; }
.btn.icon { padding: 7px; }

/* Toggle */
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); }
.toggle:last-child { border-bottom: none; }
.toggle .t-label { font-size: 14px; }
.switch { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { display: none; }
.switch span { position: absolute; inset: 0; background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: 30px; transition: background 0.18s; }
.switch span::after { content: ""; position: absolute; width: 20px; height: 20px; left: 2px; top: 2px; background: #cfd2da; border-radius: 50%; transition: transform 0.18s; }
.switch input:checked + span { background: var(--grad); border-color: transparent; }
.switch input:checked + span::after { transform: translateX(18px); background: #fff; }

/* Table */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 12px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: rgba(255, 255, 255, 0.018); }
td .actions { display: flex; gap: 6px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.pill.on { background: rgba(52, 211, 153, 0.14); color: var(--green); }
.pill.off { background: rgba(255, 255, 255, 0.06); color: var(--muted); }
.empty { color: var(--muted); padding: 28px 4px; text-align: center; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; color: var(--muted); }

/* Tabs (bot management) */
.tabbar { display: flex; gap: 4px; flex-wrap: wrap; }
.tabbar button {
    background: transparent; border: 1px solid transparent; color: var(--muted);
    padding: 8px 14px; border-radius: 10px; font-size: 13px; font-weight: 550; transition: all 0.15s;
}
.tabbar button:hover { color: var(--text); background: var(--surface-2); }
.tabbar button.active { background: rgba(124, 131, 255, 0.14); color: #fff; }
.bot-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.bot-head .name { font-weight: 650; font-size: 15px; }

/* Thread */
.thread { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; max-height: 360px; overflow-y: auto; }
.msg { padding: 9px 13px; border-radius: 13px; max-width: 80%; font-size: 13.5px; }
.msg.user { background: var(--surface-2); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.admin { background: var(--grad); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }

/* Toast */
.toast-wrap { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 50; }
.toast {
    background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text);
    padding: 13px 17px; border-radius: 12px; box-shadow: var(--shadow); font-size: 13.5px;
    animation: slidein 0.22s cubic-bezier(.2,.8,.2,1); min-width: 210px;
}
.toast.ok { border-left: 3px solid var(--green); }
.toast.err { border-left: 3px solid var(--red); }
@keyframes slidein { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.spacer { height: 8px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; line-height: 1.5; }
.section-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chk {
    display: inline-flex; align-items: center; gap: 7px; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 10px; padding: 8px 13px; font-size: 13px; cursor: pointer;
}
.chk input { accent-color: var(--accent); }
input[type="range"] { accent-color: var(--accent); height: 38px; }

@media (max-width: 760px) {
    .sidebar { display: none; }
    .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
    .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
    .content { padding: 20px 16px 60px; }
}
