/* Admin Panel Styles */

:root, [data-theme="dark"] {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --radius: 8px;
}

[data-theme="light"] {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-light: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #cbd5e1;
    --success: #16a34a;
    --warning: #d97706;
    --error: #dc2626;
    --radius: 8px;
}

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

body {
    font-family: 'Onest', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* Login */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-card {
    background: var(--surface);
    padding: 40px;
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
}

.login-card h1 {
    margin-bottom: 24px;
    text-align: center;
    font-size: 24px;
}

.login-card input {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
}

.login-card button {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

.login-card button:hover { background: var(--primary-dark); }

/* Admin Layout */
.admin-app {
    display: flex;
    min-height: 100vh;
}

.topbar {
    position: fixed;
    top: 12px;
    left: 12px;
    display: flex;
    align-items: center;
    gap: 24px;
    z-index: 100;
    pointer-events: none;
}

.topbar > * { pointer-events: auto; }

.topbar-brand {
    font-size: 28px;
    font-weight: 300;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 8px 24px;
    border-radius: 999px;
    letter-spacing: 0.3px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.sidebar-toggle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: background 0.2s, color 0.2s;
}

.sidebar-toggle:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

.sidebar {
    width: 220px;
    background: var(--surface);
    padding: 0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: width 0.25s ease;
}

.sidebar.collapsed {
    width: 72px;
}

.sidebar-header {
    height: 80px;
    flex-shrink: 0;
}

.nav-links {
    list-style: none;
    padding: 12px 0;
    flex: 1;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 16px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s;
    white-space: nowrap;
    overflow: hidden;
    line-height: 1;
}

.nav-links a svg {
    flex-shrink: 0;
    width: 15px;
    height: 15px;
    min-width: 15px;
    min-height: 15px;
    vertical-align: middle;
}

.nav-links a .nav-label {
    transition: opacity 0.2s;
}

.sidebar.collapsed .nav-links a .nav-label { opacity: 0; width: 0; overflow: hidden; }
.sidebar.collapsed .nav-links a { padding: 10px 0; justify-content: center; gap: 0; }
.sidebar.collapsed .sidebar-header { }

.nav-links a:hover { color: var(--text); background: var(--surface-light); }
.nav-links a.active { color: var(--primary); background: rgba(37, 99, 235, 0.1); border-right: 3px solid var(--primary); }

.sidebar-bottom-link {
    padding: 0;
}

.sidebar-bottom-link a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 16px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    transition: all 0.2s;
    white-space: nowrap;
    overflow: hidden;
    line-height: 1;
}

.sidebar-bottom-link a:hover { color: var(--text); background: var(--surface-light); }

.sidebar.collapsed .sidebar-bottom-link a { padding: 10px 0; justify-content: center; gap: 0; }
.sidebar.collapsed .sidebar-bottom-link .nav-label { opacity: 0; width: 0; overflow: hidden; }

.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    overflow: hidden;
    white-space: nowrap;
}

.sidebar.collapsed .sidebar-footer { padding: 12px 8px; text-align: center; }
.sidebar.collapsed .sidebar-footer span { display: none; }

.sidebar-footer a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
}

.content {
    flex: 1;
    padding: 97px 32px 32px;
    overflow-y: auto;
}

.content > h2 { margin-bottom: 28px; font-size: 22px; }
.page h3 { margin: 16px 0 12px; font-size: 16px; }

/* Tabs */
.tab-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border);
}

.tab {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
}

.tab:hover { color: var(--text); }
.tab-active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: color-mix(in srgb, var(--stat-accent, var(--primary)) 10%, var(--surface));
    padding: 20px;
    border-radius: var(--radius);
    border: 1px solid color-mix(in srgb, var(--stat-accent, var(--primary)) 25%, var(--border));
    transition: transform 0.2s, box-shadow 0.2s;
    display: block;
}

.stat-card .value { color: var(--stat-accent, var(--primary)); }

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}

.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Buttons */
.btn {
    padding: 8px 20px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.btn:hover { background: var(--surface-light); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-sm { padding: 4px 12px; font-size: 12px; }

/* Forms */
.form-card {
    background: var(--surface);
    padding: 24px;
    border-radius: var(--radius);
    margin-top: 16px;
    border: 1px solid var(--border);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
}

.form-group label small {
    font-weight: 400;
    color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}

.form-group input[type="color"] {
    height: 40px;
    padding: 4px;
    cursor: pointer;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
}

.data-table th,
.data-table td {
    padding: 10px 14px;
    text-align: left;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: var(--surface-light);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    user-select: none;
    color: var(--text-muted);
}

.data-table td { color: var(--text); }

.data-table tr:hover td { background: rgba(255,255,255,0.02); }

/* Status badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-error { background: rgba(239,68,68,0.15); color: var(--error); }
.badge-info { background: rgba(37,99,235,0.15); color: var(--primary); }

/* Status card */
.status-card {
    background: var(--surface);
    padding: 16px 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 14px;
}

/* Toolbar */
.toolbar {
    margin-bottom: 16px;
    display: flex;
    gap: 8px;
}

.search-input {
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    width: 300px;
}

.search-input:focus { outline: none; border-color: var(--primary); }

/* Pagination */
.pagination {
    display: flex;
    gap: 4px;
    margin-top: 12px;
    justify-content: center;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
}

.modal-meta {
    padding: 12px 20px;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.modal-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-msg {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.5;
    max-width: 85%;
    white-space: pre-wrap;
}

.modal-msg.user {
    background: var(--primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.modal-msg.assistant {
    background: var(--surface-light);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.modal-msg .msg-time {
    font-size: 10px;
    opacity: 0.7;
    margin-top: 4px;
}

/* Messages */
.error { color: var(--error); margin-top: 8px; font-size: 13px; }
.msg { margin-top: 8px; font-size: 13px; padding: 8px 12px; border-radius: var(--radius); }
.msg.success { background: rgba(34,197,94,0.1); color: var(--success); }
.msg.error { background: rgba(239,68,68,0.1); color: var(--error); }

/* Store cards in settings */
.store-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.store-card .store-info h4 { font-size: 15px; margin-bottom: 4px; }
.store-card .store-info span { font-size: 12px; color: var(--text-muted); }

/* Utility: 2-column grid */
.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* Chat test page: fill remaining viewport height without overflowing */
.chattest-grid {
    height: calc(100vh - 97px - 32px);
    overflow: hidden;
}
.chattest-grid > div {
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Filter form on data pages */
.filter-form {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}

/* Responsive */
@media (max-width: 768px) {
    .admin-app { flex-direction: column; }

    /* Mobile topbar: static bar with hamburger + brand */
    .topbar { position: fixed; top: 0; left: 0; right: 0; padding: 10px 14px; gap: 12px; pointer-events: auto; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 200; }
    .topbar .sidebar-toggle { width: 40px; height: 40px; background: var(--primary); color: #fff; border: none; box-shadow: 0 2px 6px rgba(0,0,0,0.2); }
    .topbar-brand { font-size: 20px; padding: 6px 16px; border: none; background: none; box-shadow: none; }

    /* Mobile sidebar: full-width dropdown under topbar, hidden by default */
    .sidebar { width: 100% !important; height: auto; position: fixed; top: 62px; left: 0; right: 0; flex-direction: column; align-items: stretch; border-right: none; border-bottom: 1px solid var(--border); z-index: 190; overflow-y: auto; max-height: calc(100vh - 62px); display: none; box-shadow: 0 8px 24px rgba(0,0,0,0.3); }
    .sidebar.mobile-open { display: flex; }
    .sidebar-header { display: none; }

    /* Nav links stack vertically */
    .nav-links { display: flex; flex-direction: column; padding: 8px 0; }
    .nav-links li { flex-shrink: 0; }
    .nav-links a { padding: 12px 20px; font-size: 14px; }
    .nav-links a .nav-label { opacity: 1 !important; width: auto !important; }
    .nav-links a.active { border-right: 3px solid var(--primary); border-bottom: none; }
    .sidebar.collapsed .nav-links a .nav-label { opacity: 1; width: auto; overflow: visible; }
    .sidebar.collapsed .nav-links a { padding: 12px 20px; justify-content: flex-start; gap: 12px; }

    /* Theme toggle + logout in mobile menu */
    .sidebar-bottom-link { padding: 0; }
    .sidebar-bottom-link a { padding: 12px 20px; font-size: 14px; }
    .sidebar-footer { padding: 12px 20px; border-top: 1px solid var(--border); }
    .sidebar-footer a { font-size: 14px; }
    .sidebar.collapsed .sidebar-footer { padding: 12px 20px; text-align: left; }
    .sidebar.collapsed .sidebar-footer span { display: inline; }
    .sidebar.collapsed .sidebar-bottom-link a { padding: 12px 20px; justify-content: flex-start; gap: 12px; }
    .sidebar.collapsed .sidebar-bottom-link .nav-label { opacity: 1; width: auto; overflow: visible; }

    /* Content below fixed topbar */
    .content { padding: 16px; padding-top: 74px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 14px; }
    .stat-card .value { font-size: 22px; }
    .search-input { width: 100%; }
    .toolbar { flex-wrap: wrap; }
    .data-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
    .store-card { flex-direction: column; align-items: flex-start; gap: 10px; }
    .form-card { padding: 16px; }
    .form-actions { flex-wrap: wrap; }
    .modal { padding: 10px; }
    .modal-content { max-height: 90vh; }
    .modal-msg { max-width: 95%; }
    .tab-bar { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
    .tab { white-space: nowrap; flex-shrink: 0; }
    .grid-2col { grid-template-columns: 1fr; }
    input, select, textarea { font-size: 16px !important; }
    .filter-form select { width: 100%; }
    .hour-chart { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .hour-chart > div { min-width: 500px; }
    .chattest-grid { height: auto; }
    .chattest-grid > div { min-height: 0; overflow: visible; }
    .chattest-grid > div:first-child { min-height: 50vh; max-height: 60vh; overflow: hidden; }
}

/* Mobile menu backdrop */
.mobile-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: 62px;
    background: rgba(0,0,0,0.4);
    z-index: 180;
}

@keyframes dotBounce {
    0% { transform: translateY(2px); }
    100% { transform: translateY(-4px); }
}

@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}
