/* ══════════════════════════════════════════════════════════
   Admin Panel Styles — Aloe AI
   ══════════════════════════════════════════════════════════ */

:root {
    --bg: #0f0f14;
    --surface: #1a1a24;
    --surface2: #22222f;
    --border: #2a2a3a;
    --text: #e0e0e0;
    --text2: #9090a0;
    --accent: #7c5ce7;
    --accent2: #a78bfa;
    --green: #34d399;
    --red: #f87171;
    --yellow: #fbbf24;
    --radius: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ─── Header ─────────────────────────── */
.admin-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.admin-header h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--accent2);
}
.admin-header .nav-links {
    display: flex;
    gap: 16px;
    align-items: center;
}
.admin-header .nav-links a,
.admin-header .nav-links button {
    color: var(--text2);
    text-decoration: none;
    font-size: 14px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 6px;
    transition: all 0.2s;
}
.admin-header .nav-links a:hover,
.admin-header .nav-links button:hover,
.admin-header .nav-links a.active {
    color: var(--text);
    background: var(--surface2);
}

/* ─── Layout ─────────────────────────── */
.admin-layout {
    display: flex;
    flex: 1;
    min-height: 0;
}
.admin-sidebar {
    width: 220px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 16px 0;
    flex-shrink: 0;
}
.admin-sidebar .menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text2);
    cursor: pointer;
    font-size: 14px;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: all 0.15s;
}
.admin-sidebar .menu-item:hover { color: var(--text); background: var(--surface2); }
.admin-sidebar .menu-item.active { color: var(--accent2); background: rgba(124,92,231,0.1); border-right: 2px solid var(--accent); }
.admin-sidebar .menu-item .icon { font-size: 16px; width: 20px; text-align: center; }
.admin-sidebar .menu-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 16px;
}

.admin-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ─── Cards ──────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.stat-card .label {
    font-size: 12px;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.stat-card .value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}
.stat-card .sub {
    font-size: 12px;
    color: var(--text2);
    margin-top: 4px;
}
.stat-card.accent .value { color: var(--accent2); }
.stat-card.green .value { color: var(--green); }
.stat-card.red .value { color: var(--red); }
.stat-card.yellow .value { color: var(--yellow); }

/* ─── Analytics: dashboard ───────────── */
.dash-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.dash-head h2 { font-size: 20px; }
.period-switch { display: flex; gap: 6px; }
.period-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text2);
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: all .15s;
}
.period-btn:hover { color: var(--text); border-color: var(--accent); }
.period-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.alerts-block { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.alert-item {
    background: rgba(251, 191, 36, .08);
    border: 1px solid rgba(251, 191, 36, .35);
    color: var(--yellow);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
}

.charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}
.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.chart-card h3 { font-size: 14px; margin-bottom: 12px; color: var(--text2); }
.chart-box { position: relative; height: 240px; }
.chart-box-lg { height: 320px; }

.token-summary {
    display: flex; gap: 24px; justify-content: space-around; padding: 24px 0;
}
.token-summary .t-num { display: block; font-size: 26px; font-weight: 700; }
.token-summary .t-num.green { color: var(--green); }
.token-summary .t-num.red { color: var(--red); }
.token-summary .t-lbl { font-size: 12px; color: var(--text2); }

/* ─── Funnel ─────────────────────────── */
.funnel-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex; flex-direction: column; gap: 12px;
}
.funnel-row { display: flex; align-items: center; gap: 12px; }
.funnel-label { width: 220px; font-size: 13px; color: var(--text); flex-shrink: 0; }
.funnel-conv { color: var(--text2); font-size: 11px; margin-left: 6px; }
.funnel-bar-wrap { flex: 1; background: var(--surface2); border-radius: 6px; height: 22px; overflow: hidden; }
.funnel-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    border-radius: 6px;
    transition: width .4s ease;
}
.funnel-count { width: 70px; text-align: right; font-weight: 600; flex-shrink: 0; }

@media (max-width: 900px) {
    .charts-row { grid-template-columns: 1fr; }
    .funnel-label { width: 150px; }
}

/* ─── Table ──────────────────────────── */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.table-toolbar {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    align-items: center;
}
.table-toolbar input {
    flex: 1;
    max-width: 300px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
}
.table-toolbar input:focus { border-color: var(--accent); }
.table-toolbar .count { color: var(--text2); font-size: 13px; margin-left: auto; }

table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    padding: 10px 14px;
    text-align: left;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}
th {
    color: var(--text2);
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--surface2);
}
tr:hover td { background: rgba(124,92,231,0.04); }
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
}
.badge-admin { background: rgba(124,92,231,0.2); color: var(--accent2); }
.badge-blocked { background: rgba(248,113,113,0.2); color: var(--red); }
.badge-active { background: rgba(52,211,153,0.2); color: var(--green); }
.badge-guest { background: rgba(251,191,36,0.2); color: var(--yellow); }

/* ─── Buttons ────────────────────────── */
.btn {
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    border: none;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.15s;
}
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #6d4fd4; }
.btn-danger { background: rgba(248,113,113,0.15); color: var(--red); }
.btn-danger:hover { background: rgba(248,113,113,0.25); }
.btn-ghost { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-green { background: rgba(52,211,153,0.15); color: var(--green); }
.btn-green:hover { background: rgba(52,211,153,0.25); }

/* ─── Modal ──────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 440px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
}
.modal h3 { font-size: 16px; margin-bottom: 16px; color: var(--text); }
.modal label {
    display: block;
    font-size: 12px;
    color: var(--text2);
    margin-bottom: 4px;
    margin-top: 12px;
}
.modal input, .modal textarea, .modal select {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    font-family: inherit;
}
.modal input:focus, .modal textarea:focus { border-color: var(--accent); }
.modal textarea { resize: vertical; min-height: 80px; }
.modal .actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

/* ─── Chat (tickets) ──────────────────── */
.chat-container {
    display: flex;
    gap: 16px;
    height: calc(100vh - 140px);
    min-height: 400px;
}
.chat-list {
    width: 300px;
    flex-shrink: 0;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    padding-right: 8px;
}
.chat-list-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: border-color 0.2s;
}
.chat-list-item:hover { border-color: var(--accent); }
.chat-list-item.active { border-color: var(--accent); background: rgba(124,92,231,0.08); }
.chat-list-item .cli-user { font-weight: 600; font-size: 13px; }
.chat-list-item .cli-preview { font-size: 12px; color: var(--text2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list-item .cli-meta { font-size: 10px; color: var(--text2); margin-top: 2px; display: flex; justify-content: space-between; }
.chat-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.chat-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.chat-msg {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
    word-break: break-word;
}
.chat-msg.user {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg.admin {
    align-self: flex-start;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.chat-msg-time {
    font-size: 10px;
    color: var(--text2);
    margin: 1px 4px 4px;
}
.chat-input-row {
    display: flex;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-input-row textarea {
    flex: 1;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    min-height: 38px;
    max-height: 80px;
    outline: none;
}
.chat-input-row textarea:focus { border-color: var(--accent); }
.chat-placeholder {
    color: var(--text2);
    text-align: center;
    padding: 40px 20px;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 768px) {
    .chat-container { flex-direction: column; height: auto; }
    .chat-list { width: 100%; border-right: none; border-bottom: 1px solid var(--border); padding-right: 0; padding-bottom: 8px; max-height: 200px; }
    .chat-msgs { max-height: 350px; }
}

/* ─── Pagination ─────────────────────── */
.pagination {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.pagination button {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
}
.pagination button:disabled { opacity: 0.4; cursor: default; }
.pagination button:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
.pagination span { font-size: 13px; color: var(--text2); }

/* ─── Toast ──────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 300;
    animation: slideUp 0.3s ease;
}
.toast-success { background: #065f46; color: #d1fae5; }
.toast-error { background: #7f1d1d; color: #fecaca; }
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ─── Loading ────────────────────────── */
.loading { text-align: center; padding: 40px; color: var(--text2); }
.spinner {
    display: inline-block;
    width: 24px; height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* ─── Mobile ───────────────────────── */
@media (max-width: 768px) {
    .admin-layout { flex-direction: column; height: auto; }
    .admin-sidebar {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        padding: 8px;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow-x: auto;
    }
    .admin-sidebar .menu-item {
        width: auto;
        padding: 8px 12px;
        font-size: 12px;
        border-radius: 6px;
        white-space: nowrap;
    }
    .admin-sidebar .menu-item.active { border-right: none; background: rgba(124,92,231,0.2); }
    .admin-sidebar .menu-divider { display: none; }
    .admin-content { padding: 12px; }
    .admin-header { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
    .admin-header h1 { font-size: 16px; }
    .admin-header .nav-links { gap: 8px; }
    .admin-header .nav-links a,
    .admin-header .nav-links button { font-size: 12px; padding: 4px 8px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-card { padding: 12px; }
    .stat-card .value { font-size: 22px; }
    .table-wrap { overflow-x: auto; }
    table { min-width: 600px; }
    th, td { padding: 6px 8px; font-size: 11px; }
    .table-toolbar { flex-wrap: wrap; }
    .table-toolbar input { max-width: 100%; flex: auto; }
    .modal { width: 95vw; padding: 16px; }
    .pagination button { padding: 4px 8px; font-size: 12px; }
    .toast { left: 12px; right: 12px; bottom: 12px; text-align: center; }
}

@media (max-width: 400px) {
    .stats-grid { grid-template-columns: 1fr; }
    .admin-sidebar .menu-item { font-size: 11px; padding: 6px 10px; }
}

/* ─── Login Form ────────────────────── */
.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 380px;
    max-width: 90vw;
}
.login-card h2 {
    font-size: 20px;
    margin-bottom: 4px;
    color: var(--accent2);
}
.login-card .subtitle {
    font-size: 13px;
    color: var(--text2);
    margin-bottom: 20px;
}
.login-card label {
    display: block;
    font-size: 12px;
    color: var(--text2);
    margin-bottom: 4px;
    margin-top: 12px;
}
.login-card input {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card .login-error {
    color: var(--red);
    font-size: 13px;
    margin-top: 12px;
    display: none;
}
.login-card .btn-login {
    width: 100%;
    margin-top: 16px;
    padding: 10px;
    font-size: 14px;
}
