:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --primary: #0d9488;
    --primary-hover: #0f766e;
    --primary-soft: #ccfbf1;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --warning-bg: #fffbeb;
    --warning-border: #fde68a;
    --warning-text: #92400e;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --radius: 10px;
}

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

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

.hidden {
    display: none !important;
}

/* Cold Start Banner */
.cold-start-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2000;
    background: #0f172a;
    color: #f8fafc;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
}

.cold-start-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #2dd4bf;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1500;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 360px;
}

.toast {
    background: var(--surface);
    color: var(--text);
    border-left: 4px solid var(--primary);
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    font-size: 0.9rem;
    animation: slideIn 0.2s ease-out;
}

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

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

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

/* Auth Screen */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #f0fdfa 0%, #f1f5f9 100%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 32px;
    box-shadow: var(--shadow-md);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
}

.brand-icon {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    background: var(--primary-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.brand-icon.small {
    width: 34px;
    height: 34px;
    font-size: 1.1rem;
}

.auth-brand h1 {
    font-size: 1.35rem;
    font-weight: 700;
}

.auth-brand p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.auth-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--surface-muted);
    padding: 4px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.auth-tab {
    border: none;
    background: transparent;
    padding: 8px 12px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.auth-tab.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.alert {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert.error {
    background: #fef2f2;
    color: #991b1b;
    border-color: #fecaca;
}

.alert.success {
    background: #f0fdfa;
    color: #115e59;
    border-color: #99f6e4;
}

/* Forms & Buttons */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

input, select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    color: var(--text);
    background: var(--surface);
    transition: border-color 0.15s ease;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
}

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

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface-muted);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    background: var(--surface-muted);
    color: var(--text);
}

.btn-link {
    background: transparent;
    color: var(--primary);
    padding: 4px 8px;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 0.82rem;
}

.btn-block {
    width: 100%;
    margin-top: 6px;
}

/* App Shell */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-title {
    font-weight: 700;
    font-size: 1.1rem;
}

.topbar-nav {
    display: flex;
    gap: 6px;
}

.nav-btn {
    border: none;
    background: transparent;
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
    cursor: pointer;
}

.nav-btn.active {
    background: var(--primary-soft);
    color: var(--primary-hover);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 0.85rem;
}

.user-name {
    font-weight: 600;
}

.role-badge {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    letter-spacing: 0.03em;
}

.role-admin {
    background: #fef3c7;
    color: #92400e;
}

.role-user {
    background: #e0f2fe;
    color: #075985;
}

/* Main Content */
.main-content {
    max-width: 1180px;
    margin: 0 auto;
    padding: 28px 20px;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 22px;
}

.page-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.92rem;
}

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

.search-input {
    width: 260px;
    padding: 8px 12px;
    font-size: 0.9rem;
}

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

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-label {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 600;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

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

.panel-header h3 {
    font-size: 1rem;
    font-weight: 700;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

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

.data-table th {
    background: var(--surface-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    font-weight: 700;
}

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

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.actions-col {
    text-align: right !important;
    white-space: nowrap;
}

.row-actions {
    display: inline-flex;
    gap: 6px;
    justify-content: flex-end;
}

.empty-cell {
    text-align: center !important;
    color: var(--text-muted);
    padding: 28px 16px !important;
}

/* Modals */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 1200;
}

.modal-card {
    background: var(--surface);
    border-radius: 12px;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

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

.modal-close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
}

.modal-form {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

@media (max-width: 860px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        height: auto;
        flex-wrap: wrap;
        padding: 12px 16px;
    }

    .topbar-nav {
        order: 3;
        width: 100%;
        justify-content: center;
        border-top: 1px solid var(--border);
        padding-top: 8px;
    }

    .search-input {
        width: 100%;
    }
}
