:root {
    --base: #1e1e2e;
    --mantle: #181825;
    --crust: #11111b;
    --surface0: #313244;
    --surface1: #45475a;
    --surface2: #585b70;
    --overlay0: #6c7086;
    --overlay1: #7f849c;
    --text: #cdd6f4;
    --subtext0: #a6adc8;
    --subtext1: #bac2de;
    --blue: #89b4fa;
    --green: #a6e3a1;
    --red: #f38ba8;
    --peach: #fab387;
    --yellow: #f9e2af;
    --mauve: #cba6f7;
    --teal: #94e2d5;
    --lavender: #b4befe;
    --sapphire: #74c7ec;
    --rosewater: #f5e0dc;
    --sidebar-width: 240px;
    --radius: 8px;
    --radius-sm: 4px;
    --transition: 0.2s ease;
}

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

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

/* ── Login ── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--crust);
}

.login-card {
    background: var(--base);
    border: 1px solid var(--surface0);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo h1 {
    font-size: 22px;
    color: var(--text);
    margin-top: 12px;
}

.login-subtitle {
    color: var(--overlay1);
    font-size: 13px;
    margin-top: 4px;
}

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

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

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--surface0);
    border: 1px solid var(--surface1);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border var(--transition);
}

input:focus, select:focus, textarea:focus {
    border-color: var(--blue);
}

input::placeholder { color: var(--overlay0); }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--blue); color: var(--crust); }
.btn-primary:hover:not(:disabled) { background: #7ba8f0; }

.btn-success { background: var(--green); color: var(--crust); }
.btn-success:hover:not(:disabled) { background: #96d696; }

.btn-danger { background: var(--red); color: var(--crust); }
.btn-danger:hover:not(:disabled) { background: #e67d9a; }

.btn-warning { background: var(--peach); color: var(--crust); }
.btn-warning:hover:not(:disabled) { background: #eba37a; }

.btn-ghost {
    background: transparent;
    color: var(--subtext1);
    border: 1px solid var(--surface1);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface0); color: var(--text); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }

.btn-icon {
    background: none;
    border: none;
    color: var(--overlay1);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    transition: all var(--transition);
}
.btn-icon:hover { color: var(--text); background: var(--surface0); }

/* ── Alerts ── */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-top: 12px;
}

.alert-error { background: rgba(243,139,168,0.15); color: var(--red); border: 1px solid rgba(243,139,168,0.3); }
.alert-success { background: rgba(166,227,161,0.15); color: var(--green); border: 1px solid rgba(166,227,161,0.3); }

/* ── App Shell ── */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--mantle);
    border-right: 1px solid var(--surface0);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px;
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
    border-bottom: 1px solid var(--surface0);
}

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

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: var(--overlay1);
    text-decoration: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
    margin-bottom: 2px;
}

.nav-link:hover { background: var(--surface0); color: var(--text); }
.nav-link.active { background: var(--surface0); color: var(--blue); }

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid var(--surface0);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--blue);
    color: var(--crust);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}

.user-details {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 11px;
    color: var(--overlay0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Main Content ── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 28px 32px;
    min-height: 100vh;
    overflow-x: hidden;
}

.page { animation: fadeIn 0.15s ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Page Header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h2 {
    font-size: 22px;
    font-weight: 700;
}

.page-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ── Stat Cards ── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--mantle);
    border: 1px solid var(--surface0);
    border-radius: var(--radius);
    padding: 20px;
    transition: border var(--transition);
}

.stat-card:hover { border-color: var(--surface1); }

.stat-card .stat-label {
    font-size: 12px;
    color: var(--overlay1);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
}

.stat-card .stat-sub {
    font-size: 12px;
    color: var(--overlay0);
    margin-top: 4px;
}

.stat-blue .stat-value { color: var(--blue); }
.stat-green .stat-value { color: var(--green); }
.stat-peach .stat-value { color: var(--peach); }
.stat-mauve .stat-value { color: var(--mauve); }
.stat-teal .stat-value { color: var(--teal); }
.stat-red .stat-value { color: var(--red); }
.stat-lavender .stat-value { color: var(--lavender); }

/* ── Tables ── */
.table-wrapper {
    background: var(--mantle);
    border: 1px solid var(--surface0);
    border-radius: var(--radius);
    overflow: hidden;
}

.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--surface0);
    gap: 12px;
    flex-wrap: wrap;
}

.table-toolbar h3 {
    font-size: 15px;
    font-weight: 600;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface0);
    border: 1px solid var(--surface1);
    border-radius: var(--radius-sm);
    padding: 0 10px;
}

.search-box input {
    border: none;
    background: none;
    padding: 7px 4px;
    width: 200px;
}

.search-box input:focus { border: none; }

.search-box svg { color: var(--overlay0); flex-shrink: 0; }

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 10px 18px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--overlay1);
    background: var(--crust);
    border-bottom: 1px solid var(--surface0);
}

td {
    padding: 12px 18px;
    font-size: 13px;
    border-bottom: 1px solid rgba(49,50,68,0.5);
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(49,50,68,0.25); }

.table-empty {
    padding: 40px;
    text-align: center;
    color: var(--overlay0);
    font-size: 14px;
}

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-green { background: rgba(166,227,161,0.15); color: var(--green); }
.badge-red { background: rgba(243,139,168,0.15); color: var(--red); }
.badge-blue { background: rgba(137,180,250,0.15); color: var(--blue); }
.badge-peach { background: rgba(250,179,135,0.15); color: var(--peach); }
.badge-mauve { background: rgba(203,166,247,0.15); color: var(--mauve); }
.badge-yellow { background: rgba(249,226,175,0.15); color: var(--yellow); }
.badge-teal { background: rgba(148,226,213,0.15); color: var(--teal); }

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.1s ease;
}

.modal {
    background: var(--base);
    border: 1px solid var(--surface0);
    border-radius: 12px;
    width: 90%;
    max-width: 520px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 48px rgba(0,0,0,0.5);
}

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

.modal-header h3 { font-size: 16px; }

.modal-body {
    padding: 22px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--surface0);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 18px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    animation: slideIn 0.2s ease;
    max-width: 360px;
}

.toast-success { background: var(--green); color: var(--crust); }
.toast-error { background: var(--red); color: var(--crust); }
.toast-info { background: var(--blue); color: var(--crust); }

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

/* ── Utilities ── */
.text-muted { color: var(--overlay0); }
.text-sm { font-size: 12px; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-blue { color: var(--blue); }
.text-peach { color: var(--peach); }
.mono { font-family: 'Cascadia Code', 'Fira Code', monospace; font-size: 12px; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; display: inline-block; vertical-align: middle; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-gap { display: flex; gap: 8px; align-items: center; }

/* ── Loading Spinner ── */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--surface1);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.page-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
    gap: 10px;
    color: var(--overlay0);
}

/* ── Upload Area ── */
.upload-area {
    border: 2px dashed var(--surface1);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    margin-bottom: 16px;
}

.upload-area:hover { border-color: var(--blue); background: rgba(137,180,250,0.05); }
.upload-area.dragover { border-color: var(--blue); background: rgba(137,180,250,0.1); }

.upload-area svg { margin-bottom: 12px; color: var(--overlay0); }
.upload-area p { color: var(--overlay1); font-size: 14px; }
.upload-area .text-sm { margin-top: 4px; }

.upload-progress {
    background: var(--surface0);
    border-radius: 4px;
    height: 6px;
    overflow: hidden;
    margin-top: 12px;
}

.upload-progress-bar {
    height: 100%;
    background: var(--blue);
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* ── Detail Panel ── */
.detail-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 8px 16px;
    font-size: 13px;
}

.detail-grid dt {
    color: var(--overlay1);
    font-weight: 500;
}

.detail-grid dd {
    color: var(--text);
}

/* ── Tabs ── */
.tab-bar {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--surface0);
    margin-bottom: 16px;
}

.tab-btn {
    padding: 8px 16px;
    background: none;
    border: none;
    color: var(--overlay1);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }

/* ── Quick Actions Grid ── */
.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.quick-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 8px;
    background: var(--surface0);
    border: 1px solid var(--surface1);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
    font-size: 12px;
    font-weight: 500;
}

.quick-action-btn:hover {
    background: var(--surface1);
    border-color: var(--blue);
    transform: translateY(-1px);
}

/* ── Health Indicators ── */
.health-items {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.health-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--surface0);
    border-radius: var(--radius-sm);
}

.health-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.health-ok { background: var(--green); box-shadow: 0 0 6px rgba(166,227,161,0.4); }
.health-warn { background: var(--yellow); box-shadow: 0 0 6px rgba(249,226,175,0.4); }
.health-idle { background: var(--overlay0); }

/* ── Activity Feed ── */
.activity-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--surface0);
    font-size: 13px;
}

.activity-item:last-child { border-bottom: none; }

.activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    animation: pulse 2s infinite;
}

.activity-content {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

/* ── Top Content Bars ── */
.top-content-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
}

/* ── Stats Grid (for analytics) ── */
.stats-grid {
    display: grid;
    gap: 16px;
}

/* ── Group Member Management ── */
.member-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.member-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--surface0);
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}

.member-item:hover { background: var(--surface1); }

.member-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--mauve);
    color: var(--crust);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
}

/* ── Watch Progress (User Detail) ── */
.mini-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.watch-progress-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(49,50,68,0.5);
}

.watch-progress-item:last-child { border-bottom: none; }

.watch-bar-container {
    height: 4px;
    background: var(--surface0);
    border-radius: 2px;
    margin-top: 4px;
    overflow: hidden;
}

.watch-bar {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-header span,
    .nav-link span,
    .user-details,
    .sidebar .nav-link { font-size: 0; gap: 0; justify-content: center; }
    .sidebar .nav-link svg { margin: 0; }
    .main-content { margin-left: 60px; padding: 16px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
