:root {
    --primary: #6366F1;
    --primary-light: #818CF8;
    --primary-dark: #4F46E5;
    --secondary: #8B5CF6;
    --accent: #EC4899;
    --success: #10B981;
    --warning: #F59E0B;
    --error: #EF4444;
    --info: #3B82F6;

    --bg-page: #EDE9FE;
    --bg-card: #FFFFFF;
    --bg-sidebar: #16163a;
    --bg-sidebar-hover: rgba(255, 255, 255, 0.05);
    --bg-sidebar-active: rgba(99, 102, 241, 0.25);

    --text-main: #1F2937;
    --text-muted: #6B7280;
    --text-light: #9CA3AF;
    --text-inverse: #FFFFFF;

    --border: #E5E7EB;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 2px 12px rgba(99, 102, 241, 0.08);
    --shadow-lg: 0 8px 30px rgba(99, 102, 241, 0.15);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --sidebar-width: 220px;
    --topbar-height: 64px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-page);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
}

/* Layout */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #16163a 0%, #24244e 100%);
    color: var(--text-inverse);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-brand {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: #fff;
}

.brand-title {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
}

.brand-sub {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    line-height: 1.2;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 14px;
    margin-bottom: 4px;
    transition: all 0.15s ease;
}

.nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: #fff;
}

.nav-item.active {
    background: var(--bg-sidebar-active);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--primary-light);
}

.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 90;
}

.breadcrumb {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
}

.breadcrumb a {
    color: var(--primary);
    text-decoration: none;
}

.user-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #F3F4F6;
    padding: 6px 12px;
    border-radius: 24px;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

.user-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
}

.user-role {
    font-size: 11px;
    color: var(--text-muted);
}

.main-content {
    flex: 1;
    padding: 24px;
}

/* Auth layout */
.auth-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #16163a 0%, #312e81 100%);
    padding: 24px;
}

.login-box {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 36px;
    box-shadow: var(--shadow-lg);
}

.login-box h2 {
    margin: 0 0 24px;
    font-size: 22px;
    text-align: center;
}

/* Page header */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.page-title h1 {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 700;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0;
}

.header-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card + .card {
    margin-top: 20px;
}

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

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
}

.stat-card.success::before { background: linear-gradient(90deg, #34D399, #10B981); }
.stat-card.error::before { background: linear-gradient(90deg, #F87171, #EF4444); }
.stat-card.warning::before { background: linear-gradient(90deg, #FBBF24, #F59E0B); }
.stat-card.info::before { background: linear-gradient(90deg, #60A5FA, #3B82F6); }
.stat-card.accent::before { background: linear-gradient(90deg, #F472B6, #EC4899); }

.stat-label {
    color: var(--text-muted);
    font-size: 13px;
    margin: 0 0 8px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}

.stat-desc {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 6px;
}

/* Resource grid */
.resource-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.resource-item {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.resource-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.resource-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
}

.resource-icon.blue { background: linear-gradient(135deg, #60A5FA, #3B82F6); }
.resource-icon.purple { background: linear-gradient(135deg, #A78BFA, #8B5CF6); }
.resource-icon.green { background: linear-gradient(135deg, #34D399, #10B981); }
.resource-icon.orange { background: linear-gradient(135deg, #FBBF24, #F59E0B); }
.resource-icon.pink { background: linear-gradient(135deg, #F472B6, #EC4899); }

.resource-title {
    font-weight: 600;
    font-size: 15px;
}

.resource-desc {
    font-size: 12px;
    color: var(--text-muted);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-main);
    transition: all 0.15s ease;
}

.btn:hover {
    background: #F9FAFB;
    border-color: #D1D5DB;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-color: transparent;
    color: #fff;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff;
}

.btn-danger {
    background: #FEF2F2;
    border-color: #FECACA;
    color: var(--error);
}

.btn-danger:hover {
    background: #FEE2E2;
}

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

/* Forms */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-main);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    font-size: 14px;
}

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

.data-table th {
    background: #F9FAFB;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.data-table tbody tr:hover {
    background: #F8FAFF;
}

.data-table td.actions {
    white-space: nowrap;
}

.data-table .empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
}

.mono {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 12px;
    color: var(--text-muted);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
}

.badge-pending { background: #EFF6FF; color: var(--info); }
.badge-processing { background: #FFFBEB; color: #B45309; }
.badge-completed { background: #ECFDF5; color: #047857; }
.badge-failed { background: #FEF2F2; color: #B91C1C; }
.badge-suspended { background: #F3F4F6; color: var(--text-muted); }
.badge-active { background: #ECFDF5; color: #047857; }
.badge-info { background: #EFF6FF; color: var(--info); }

/* Search/filter bar */
.search-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 20px;
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.search-card .form-group {
    margin-bottom: 0;
    flex: 1;
    min-width: 160px;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 20px;
    font-size: 14px;
    color: var(--text-muted);
}

.pagination-info {
    color: var(--text-muted);
}

.pagination-actions {
    display: flex;
    gap: 8px;
}

/* Modal / Drawer */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 90%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

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

.modal-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

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

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 16px;
}

.alert-error {
    background: #FEF2F2;
    color: #B91C1C;
    border: 1px solid #FECACA;
}

.alert-success {
    background: #ECFDF5;
    color: #047857;
    border: 1px solid #A7F3D0;
}

.alert-info {
    background: #EFF6FF;
    color: #1E40AF;
    border: 1px solid #BFDBFE;
}

/* Key display */
.key-value {
    font-family: 'SFMono-Regular', Consolas, monospace;
    background: #F3F4F6;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    word-break: break-all;
    font-size: 13px;
    border: 1px dashed var(--border);
}

/* Toast */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--primary);
    min-width: 240px;
    animation: slideIn 0.2s ease;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--error); }

@keyframes slideIn {
    from { transform: translateX(20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Progress bar */
.progress-bar {
    height: 8px;
    background: #E5E7EB;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Utilities */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-error { color: var(--error); }
.text-success { color: var(--success); }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.flex { display: flex; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.wrap { flex-wrap: wrap; }

@media (max-width: 768px) {
    .sidebar { width: 64px; }
    .sidebar .brand-text,
    .sidebar .nav-label,
    .sidebar .user-meta { display: none; }
    .main-wrapper { margin-left: 64px; }
    .stats-grid { grid-template-columns: 1fr; }
}
