/* static/admin.css */
:root {
    --primary: #4a6cf7;
    --primary-dark: #3b5de7;
    --primary-light: #e8edff;
    --sidebar-bg: #0f0f1a;
    --sidebar-text: #a8b5d9;
    --sidebar-hover: #1a1a2e;
    --bg-main: #f0f2f8;
    --bg-white: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #4a5568;
    --text-muted: #6b7a8f;
    --border-color: #e8ecf1;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-lg: 20px;
    --transition: all 0.3s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    min-height: 100vh;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: var(--transition);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px 30px;
    font-size: 20px;
    font-weight: 700;
    color: white;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand .icon { font-size: 26px; }

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 18px;
    border-radius: 10px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    transition: var(--transition);
    cursor: pointer;
    margin-bottom: 2px;
}

.sidebar-nav a:hover { background: var(--sidebar-hover); color: white; }
.sidebar-nav a.active { background: var(--primary); color: white; box-shadow: 0 4px 16px rgba(74,108,247,0.3); }
.sidebar-nav a .icon { font-size: 20px; }

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(255,255,255,0.06);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-footer a {
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    transition: var(--transition);
    padding: 6px 0;
}
.sidebar-footer a:hover { color: white; }

.logout-btn {
    background: rgba(239,68,68,0.15);
    color: #ef4444;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
}
.logout-btn:hover { background: rgba(239,68,68,0.25); }

/* ===== Main Content ===== */
.main-content {
    margin-left: 240px;
    flex: 1;
    min-height: 100vh;
}

.main-header {
    background: var(--bg-white);
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(12px);
    background: rgba(255,255,255,0.92);
}

.main-header h1 { font-size: 20px; font-weight: 600; }

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
}
.header-user .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

/* ===== Pages ===== */
.page-content { padding: 24px 32px; }
.page { display: none; }
.page.active { display: block; }

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-white);
    padding: 20px 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 14px; color: var(--text-muted); margin-top: 4px; }

/* ===== Tool Stats ===== */
.tool-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 12px;
}
.tool-stats .tool-item {
    background: var(--bg-white);
    padding: 12px 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
}
.tool-stats .tool-item .count {
    font-weight: 700;
    color: var(--primary);
}

/* ===== Table ===== */
.table-container {
    background: var(--bg-white);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: var(--shadow);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

table th {
    background: var(--bg-main);
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
}

table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

table tr:hover td { background: var(--primary-light); }
table tr:last-child td { border-bottom: none; }

/* ===== Page Toolbar ===== */
.page-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.search-box input {
    padding: 10px 16px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    width: 260px;
    transition: var(--transition);
}
.search-box input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(74,108,247,0.1); }

.filter-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.filter-group select {
    padding: 10px 16px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.btn-refresh, .btn-primary {
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}
.btn-refresh { background: var(--bg-main); color: var(--text-secondary); }
.btn-refresh:hover { background: var(--border-color); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 16px rgba(74,108,247,0.3); }

/* ===== Action Buttons in Table ===== */
.btn-action {
    padding: 4px 12px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
    margin: 2px;
}
.btn-action.view { background: var(--primary-light); color: var(--primary); }
.btn-action.view:hover { background: var(--primary); color: white; }
.btn-action.edit { background: #fef3c7; color: #d97706; }
.btn-action.edit:hover { background: #d97706; color: white; }
.btn-action.balance { background: #d1fae5; color: #059669; }
.btn-action.balance:hover { background: #059669; color: white; }
.btn-action.toggle { background: #dbeafe; color: #2563eb; }
.btn-action.toggle:hover { background: #2563eb; color: white; }
.btn-action.delete { background: #fbe9e7; color: #dc2626; }
.btn-action.delete:hover { background: #dc2626; color: white; }
.btn-action.keys { background: #f3e8ff; color: #7c3aed; }
.btn-action.keys:hover { background: #7c3aed; color: white; }

.status-badge {
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}
.status-badge.active { background: #d1fae5; color: #059669; }
.status-badge.inactive { background: #fbe9e7; color: #dc2626; }
.status-badge.admin { background: #fef3c7; color: #d97706; }
.status-badge.normal { background: var(--primary-light); color: var(--primary); }

/* ===== Pagination ===== */
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 16px;
}
.pagination button {
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: var(--transition);
}
.pagination button:hover { background: var(--primary-light); border-color: var(--primary); }
.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}
.modal-overlay.show { display: flex; }

.modal {
    background: white;
    border-radius: var(--radius-lg);
    padding: 32px 36px;
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}
.modal-lg { max-width: 720px; }

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal .close-btn {
    float: right;
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition);
}
.modal .close-btn:hover { color: var(--text-primary); transform: rotate(90deg); }

.modal h2 { font-size: 22px; margin-bottom: 20px; }

.modal .form-group { margin-bottom: 16px; }
.modal .form-group label { display: block; font-weight: 500; font-size: 14px; color: var(--text-secondary); margin-bottom: 4px; }
.modal .form-group input, .modal .form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    transition: var(--transition);
}
.modal .form-group input:focus, .modal .form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(74,108,247,0.1);
}

.modal .btn-submit {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}
.modal .btn-submit:hover { background: var(--primary-dark); box-shadow: 0 4px 16px rgba(74,108,247,0.3); }

.modal .result-msg {
    margin-top: 12px;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    display: none;
}
.modal .result-msg.success { display: block; background: #d1fae5; color: #059669; border: 1px solid #6ee7b7; }
.modal .result-msg.error { display: block; background: #fbe9e7; color: #dc2626; border: 1px solid #fca5a5; }
.modal .result-msg.info { display: block; background: #dbeafe; color: #2563eb; border: 1px solid #93c5fd; }

/* ===== User Detail ===== */
.user-detail-content .detail-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}
.user-detail-content .detail-row:last-child { border-bottom: none; }
.user-detail-content .detail-label { color: var(--text-muted); }
.user-detail-content .detail-value { font-weight: 500; }

.user-detail-content .key-list {
    margin-top: 12px;
}
.user-detail-content .key-item {
    background: var(--bg-main);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 13px;
}
.user-detail-content .key-item .key-name { font-weight: 600; }
.user-detail-content .key-item .key-value { font-family: monospace; color: var(--text-muted); word-break: break-all; }
.user-detail-content .key-item .key-meta { font-size: 12px; color: var(--text-muted); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: 280px; }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
    .page-content { padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .search-box input { width: 100%; }
    .page-toolbar { flex-direction: column; align-items: stretch; }
    .filter-group { flex-wrap: wrap; }
    .modal { padding: 24px 20px; margin: 10px; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    table { font-size: 12px; }
    table th, table td { padding: 8px 10px; }
    .btn-action { font-size: 11px; padding: 3px 8px; }
    .modal-lg { max-width: 100%; }
}

/* ===== Toast ===== */
#toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    padding: 14px 24px;
    border-radius: 12px;
    color: white;
    z-index: 3000;
    background: #1a1a2e;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.4s ease;
    max-width: 400px;
    font-size: 14px;
    pointer-events: none;
}

/* ===== Chart section ===== */
.chart-section {
    background: var(--bg-white);
    padding: 20px 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}
.chart-section h3 { margin-bottom: 12px; font-size: 16px; }