:root {
    --md-primary: #1565c0;
    --md-primary-container: #1976d2;
    --md-on-primary: #ffffff;
    --md-secondary: #42a5f5;
    --md-surface: #0d1117;
    --md-surface-dim: #161b22;
    --md-surface-bright: #1c2333;
    --md-surface-container: #21262d;
    --md-surface-container-high: #2d333b;
    --md-outline: rgba(66, 165, 245, 0.2);
    --md-on-surface: #e6edf3;
    --md-on-surface-variant: #8b949e;
    --md-success: #2ea043;
    --md-warning: #d29922;
    --md-error: #f85149;
    --md-elev-1: 0 1px 3px rgba(0,0,0,.35), 0 4px 12px rgba(21,101,192,.08);
    --md-elev-2: 0 4px 16px rgba(0,0,0,.4), 0 8px 32px rgba(21,101,192,.12);
    --md-elev-3: 0 8px 28px rgba(0,0,0,.45), 0 16px 48px rgba(33,150,243,.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 999px;
    --font: 'Source Sans 3', system-ui, sans-serif;
    --sidebar-w: 260px;
    --topbar-h: 64px;
}

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

body.admin-body {
    font-family: var(--font);
    background: var(--md-surface);
    color: var(--md-on-surface);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.admin-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.admin-sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #0a1628 0%, var(--md-surface-dim) 100%);
    border-right: 1px solid var(--md-outline);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.admin-brand {
    padding: 1.25rem 1.5rem;
    font-weight: 800;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #fff 30%, var(--md-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.admin-nav { flex: 1; padding: 0.5rem 0.75rem 1.5rem; }

.nav-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--md-on-surface-variant);
    padding: 1rem 0.75rem 0.35rem;
    text-transform: uppercase;
}

.admin-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    margin-bottom: 0.2rem;
    border-radius: var(--radius-full);
    color: var(--md-on-surface-variant);
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
    text-decoration: none;
}

.admin-nav-link:hover {
    background: rgba(33, 150, 243, 0.1);
    color: var(--md-on-surface);
}

.admin-nav-link.active {
    background: linear-gradient(135deg, var(--md-primary-container), #0d47a1);
    color: var(--md-on-primary);
    box-shadow: var(--md-elev-2);
}

.admin-nav-link .nav-icon {
    width: 22px;
    height: 22px;
    opacity: 0.85;
    flex-shrink: 0;
}

.nav-badge {
    margin-left: auto;
    background: var(--md-error);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: var(--radius-full);
    min-width: 1.25rem;
    text-align: center;
}

/* Main */
.admin-main {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.admin-topbar {
    background: rgba(13, 17, 23, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--md-outline);
    position: sticky;
    top: 0;
    z-index: 100;
}

.admin-topbar-inner {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
}

.admin-role-badge {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--md-secondary);
}

.admin-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--md-primary-container), var(--md-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
    box-shadow: var(--md-elev-1);
}

.admin-content {
    padding: 1.75rem 0 3rem;
    flex: 1;
}

.page-header { margin-bottom: 1.75rem; }

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-bottom: 0.25rem;
}

.page-header p { color: var(--md-on-surface-variant); font-size: 0.95rem; }

/* Cards */
.md-card {
    background: var(--md-surface-container);
    border: 1px solid var(--md-outline);
    border-radius: var(--radius-lg);
    box-shadow: var(--md-elev-1);
    overflow: hidden;
}

.md-card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--md-outline);
    font-weight: 700;
    font-size: 1rem;
}

.md-card-body { padding: 1.5rem; }

/* Stat grid */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-tile {
    background: var(--md-surface-container);
    border: 1px solid var(--md-outline);
    border-radius: var(--radius-lg);
    padding: 1.35rem;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-tile:hover {
    transform: translateY(-2px);
    box-shadow: var(--md-elev-2);
}

.stat-tile-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--md-on-surface-variant);
    margin-bottom: 0.35rem;
}

.stat-tile-value {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.stat-tile-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, rgba(21,101,192,.35), rgba(66,165,245,.2));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

/* Tables */
.table-wrap { overflow-x: auto; }

.md-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.md-table thead th {
    background: linear-gradient(135deg, var(--md-primary-container), #0d47a1);
    color: var(--md-on-primary);
    font-weight: 600;
    text-align: left;
    padding: 0.85rem 1rem;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.md-table tbody td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--md-outline);
    vertical-align: middle;
}

.md-table tbody tr:hover { background: rgba(33, 150, 243, 0.04); }

.md-table tbody tr:nth-child(even) { background: rgba(255,255,255,0.02); }

/* Light table variant for logs */
.md-table-light {
    background: #fff;
    color: #1a1a2e;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.md-table-light thead th {
    background: linear-gradient(135deg, #1976d2, #1565c0);
}

.md-table-light tbody td { border-color: #e8eef5; color: #334155; }
.md-table-light tbody tr:nth-child(even) { background: #f8fafc; }
.md-table-light tbody tr:hover { background: #e3f2fd; }

/* Badges */
.badge {
    display: inline-flex;
    padding: 0.25rem 0.65rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-success { background: rgba(46,160,67,.2); color: #3fb950; }
.badge-warning { background: rgba(210,153,34,.2); color: #e3b341; }
.badge-danger { background: rgba(248,81,73,.2); color: #f85149; }

.user-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem 2rem;
    margin: 0;
}

.user-detail-item dt {
    margin: 0 0 0.35rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--md-on-surface-variant);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.user-detail-item dd {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--md-on-surface);
}

@media (max-width: 560px) {
    .user-detail-grid {
        grid-template-columns: 1fr;
    }
}

.balance-adjust-card .md-card-header {
    font-weight: 800;
}

.balance-adjust-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.balance-adjust-form {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.balance-adjust-input {
    width: 100%;
}

.balance-adjust-btn {
    width: 100%;
    border-radius: 12px;
    padding: 0.75rem 1rem;
}

.balance-adjust-error {
    margin: -0.35rem 0 0;
    font-size: 0.8rem;
    color: #f85149;
}

.balance-adjust-hint {
    margin: 0;
    padding: 0 1.25rem 1.15rem;
    font-size: 0.85rem;
    color: var(--md-on-surface-variant);
}

@media (max-width: 640px) {
    .balance-adjust-body {
        grid-template-columns: 1fr;
    }
}

.promo-picker-hint {
    margin: 0 0 0.65rem;
    font-size: 0.85rem;
    color: var(--md-on-surface-variant);
}

.promo-picker-error {
    margin: 0.5rem 0 0;
    font-size: 0.8rem;
    color: #f85149;
}

/* Buttons */
.md-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.15rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
    text-decoration: none;
}

.md-btn-filled {
    background: linear-gradient(135deg, var(--md-primary-container), #0d47a1);
    color: #fff;
    box-shadow: var(--md-elev-1);
}

.md-btn-filled:hover {
    box-shadow: var(--md-elev-2);
    transform: translateY(-1px);
    color: #fff;
}

.md-btn-tonal {
    background: rgba(33, 150, 243, 0.15);
    color: var(--md-secondary);
}

.md-btn-outline {
    background: transparent;
    border: 1px solid var(--md-outline);
    color: var(--md-on-surface);
}

.md-btn-success { background: var(--md-success); color: #fff; }
.md-btn-danger { background: var(--md-error); color: #fff; }
.md-btn-warning { background: #b8860b; color: #fff; }
.md-btn-sm { padding: 0.35rem 0.85rem; font-size: 0.8rem; }

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

.form-field { margin-bottom: 1rem; }

.form-field label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--md-on-surface-variant);
    margin-bottom: 0.35rem;
}

.md-input, .md-select, .md-textarea {
    width: 100%;
    padding: 0.7rem 1rem;
    font-family: inherit;
    font-size: 0.9rem;
    background: var(--md-surface-bright);
    border: 1px solid var(--md-outline);
    border-radius: var(--radius-sm);
    color: var(--md-on-surface);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.md-input:focus, .md-select:focus, .md-textarea:focus {
    outline: none;
    border-color: var(--md-secondary);
    box-shadow: 0 0 0 3px rgba(66, 165, 245, 0.25);
}

.md-textarea { min-height: 120px; resize: vertical; }

/* Alerts */
.alert {
    padding: 0.85rem 1.15rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.alert-success { background: rgba(46,160,67,.15); border: 1px solid rgba(46,160,67,.35); color: #3fb950; }
.alert-error { background: rgba(248,81,73,.15); border: 1px solid rgba(248,81,73,.35); color: #f85149; }

.admin-alerts--bottom {
    margin-top: 1.5rem;
    margin-bottom: 0;
}

.admin-alerts--bottom .alert:last-child {
    margin-bottom: 0;
}

/* Support chat */
.support-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 260px;
    grid-template-rows: minmax(520px, calc(100vh - var(--topbar-h) - 11rem));
    gap: 0;
    min-height: calc(100vh - var(--topbar-h) - 11rem);
    border: 1px solid var(--md-outline);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--md-surface-container);
    align-items: stretch;
}

.support-list {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    border-right: 1px solid var(--md-outline);
    overflow: hidden;
}

.support-list > p:first-child {
    flex-shrink: 0;
}

.support-list-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.support-chat {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    background: #f0f4f8;
}

.support-chat-header {
    flex-shrink: 0;
    padding: 0.85rem 1rem;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    font-weight: 600;
    color: #1e293b;
}

.support-messages {
    flex: 1 1 auto;
    min-height: 0;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.support-messages--empty {
    align-items: center;
    justify-content: center;
    color: #64748b;
}

.chat-bubble {
    max-width: 75%;
    padding: 0.65rem 1rem;
    border-radius: var(--radius-lg);
    font-size: 0.9rem;
    line-height: 1.45;
}

.chat-bubble.admin {
    align-self: flex-end;
    background: linear-gradient(135deg, #1976d2, #1565c0);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-bubble.user {
    align-self: flex-start;
    background: #fff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

.support-compose {
    flex-shrink: 0;
    padding: 1rem;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 0.5rem;
}

.contact-item {
    display: block;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--md-outline);
    color: inherit;
    text-decoration: none;
    transition: background 0.15s;
}

.support-list--details {
    border-left: 1px solid var(--md-outline);
    border-right: none;
}

.contact-item:hover, .contact-item.active {
    background: rgba(33, 150, 243, 0.12);
}

.contact-item strong { display: block; font-size: 0.9rem; }
.contact-item small { color: var(--md-on-surface-variant); }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1.25rem;
}

.toolbar .md-input { max-width: 220px; }

.action-group { display: flex; gap: 0.35rem; flex-wrap: wrap; }

@media (max-width: 1024px) {
    .admin-sidebar { transform: translateX(-100%); }
    .admin-main { margin-left: 0; }
    .support-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(420px, 60vh) auto;
        min-height: auto;
    }
}
