:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    /* Theme colors */
    --bg-primary: #f3f4f6;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f9fafb;
    --text-primary: #1f2937;
    --text-secondary: #374151;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --shadow-color: rgba(0, 0, 0, 0.1);
    /* Status colors */
    --status-running-bg: #dcfce7;
    --status-running-text: #166534;
    --status-error-bg: #fef2f2;
    --status-error-text: #991b1b;
}

/* Dark Mode - Pure Black */
[data-theme="dark"] {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --gray-50: #18181b;
    --gray-100: #09090b;
    --gray-200: #27272a;
    --gray-300: #3f3f46;
    --gray-400: #71717a;
    --gray-500: #a1a1aa;
    --gray-600: #d4d4d8;
    --gray-700: #e4e4e7;
    --gray-800: #f4f4f5;
    --gray-900: #fafafa;
    --bg-primary: #000000;
    --bg-secondary: #0a0a0a;
    --bg-tertiary: #171717;
    --text-primary: #fafafa;
    --text-secondary: #e4e4e7;
    --text-muted: #a1a1aa;
    --border-color: #27272a;
    --shadow-color: rgba(0, 0, 0, 0.5);
    /* Status colors - dark mode */
    --status-running-bg: #166534;
    --status-running-text: #86efac;
    --status-error-bg: #991b1b;
    --status-error-text: #fca5a5;
}

/* Sidebar should always be dark */
[data-theme="dark"] .sidebar {
    background: #0a0a0a;
}

[data-theme="dark"] .sidebar-logo {
    border-bottom-color: #27272a;
}

[data-theme="dark"] .sidebar-nav a {
    color: #a1a1aa;
}

[data-theme="dark"] .sidebar-nav a:hover,
[data-theme="dark"] .sidebar-nav a.active {
    background: #171717;
    color: white;
}

/* Fix text colors that use gray-800 in dark mode */
[data-theme="dark"] .header h1,
[data-theme="dark"] .stat-card-value,
[data-theme="dark"] .table-header h2,
[data-theme="dark"] .modal-header h2 {
    color: var(--text-primary);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
}

/* Login Page */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-box {
    background: var(--bg-secondary);
    padding: 2.5rem;
    border-radius: 1rem;
    box-shadow: 0 25px 50px -12px var(--shadow-color);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    text-align: center;
    margin-bottom: 2rem;
    color: var(--text-primary);
    font-size: 1.5rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    gap: 0.5rem;
}

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

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

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #16a34a;
}

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

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

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
}

.btn-block {
    width: 100%;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.alert-error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: var(--success);
    border: 1px solid #bbf7d0;
}

/* Dashboard Layout */
.dashboard {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    background: var(--gray-800);
    color: white;
    padding: 1.5rem;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-logo {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--gray-700);
}

.sidebar-nav {
    list-style: none;
}

.sidebar-nav li {
    margin-bottom: 0.5rem;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--gray-300);
    text-decoration: none;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: var(--gray-700);
    color: white;
}

.sidebar-nav a svg {
    width: 20px;
    height: 20px;
}

.main-content {
    flex: 1;
    margin-left: 250px;
    padding: 2rem;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.header h1 {
    font-size: 1.5rem;
    color: var(--gray-800);
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px var(--shadow-color);
}

.stat-card-title {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-bottom: 0.5rem;
}

.stat-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-800);
}

.stat-card-subtitle {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: 0.25rem;
}

/* Table */
.table-container {
    background: var(--bg-secondary);
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px var(--shadow-color);
    overflow: hidden;
}

.table-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.table-header h2 {
    font-size: 1rem;
    color: var(--gray-800);
}

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

.table th,
.table td {
    padding: 0.875rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

.table th {
    background: var(--gray-50);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--gray-500);
}

.table tbody tr:hover {
    background: var(--gray-50);
}

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

/* Status Badge */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-running {
    background: var(--status-running-bg, #dcfce7);
    color: var(--status-running-text, #166534);
}

.status-stopped {
    background: var(--gray-100);
    color: var(--gray-600);
}

.status-error {
    background: var(--status-error-bg, #fef2f2);
    color: var(--status-error-text, #991b1b);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-running .status-dot {
    background: var(--success);
}

.status-stopped .status-dot {
    background: var(--gray-400);
}

.status-error .status-dot {
    background: var(--danger);
}

/* Actions */
.actions-menu {
    position: relative;
    display: inline-block;
}

.actions-btn {
    background: none;
    border: 1px solid var(--gray-300);
    padding: 0.375rem 0.625rem;
    border-radius: 0.375rem;
    cursor: pointer;
    color: var(--gray-500);
}

.actions-btn:hover {
    background: var(--gray-50);
}

.actions-dropdown {
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    box-shadow: 0 10px 15px -3px var(--shadow-color);
    z-index: 1000;
    min-width: 150px;
    display: none;
}

.actions-dropdown.show {
    display: block;
}

.actions-dropdown button {
    display: block;
    width: 100%;
    padding: 0.625rem 1rem;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--gray-700);
}

.actions-dropdown button:hover {
    background: var(--gray-50);
}

.actions-dropdown button.danger {
    color: var(--danger);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-secondary);
    border-radius: 0.75rem;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.95);
    transition: transform 0.2s;
}

.modal-overlay.show .modal {
    transform: scale(1);
}

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

.modal-header h2 {
    font-size: 1.125rem;
    color: var(--gray-800);
}

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

.modal-close:hover {
    color: var(--gray-600);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Form elements in modal */
.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.form-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-group textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 1rem;
    resize: vertical;
    min-height: 100px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Radio group */
.radio-group {
    display: flex;
    gap: 1rem;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.radio-option input {
    width: auto;
}

/* URI display */
.uri-display {
    background: var(--gray-100);
    padding: 1rem;
    border-radius: 0.5rem;
    font-family: monospace;
    font-size: 0.875rem;
    word-break: break-all;
    margin-bottom: 1rem;
}

.qr-code {
    text-align: center;
    padding: 1rem;
}

.qr-code img {
    max-width: 200px;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    background: white;
}

/* Checkbox */
.checkbox-cell {
    width: 40px;
}

.checkbox-cell input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--gray-400);
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--gray-500);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    color: var(--gray-300);
}

/* Responsive */
@media (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }
    .main-content {
        margin-left: 200px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        padding: 0.75rem 1rem;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.75rem;
    }
    .sidebar-logo {
        font-size: 1rem;
        margin-bottom: 0;
        padding-bottom: 0;
        border-bottom: none;
        flex-shrink: 0;
    }
    .sidebar-nav {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        flex: 1;
    }
    .sidebar-nav li {
        margin-bottom: 0;
    }
    .sidebar-nav a {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }
    /* Fix absolute positioned logout button */
    .sidebar > div[style*="absolute"] {
        position: static !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
        flex-shrink: 0;
    }
    .sidebar > div[style*="absolute"] .btn {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
    }
    .main-content {
        margin-left: 0;
        padding: 1rem;
    }
    .dashboard {
        flex-direction: column;
    }
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    .header h1 {
        font-size: 1.25rem;
    }
    .header-actions {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    .stat-card {
        padding: 1rem;
    }
    .stat-card-value {
        font-size: 1.25rem;
    }
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
    }
    .table {
        min-width: 650px;
    }
    .table th,
    .table td {
        padding: 0.5rem 0.625rem;
        font-size: 0.75rem;
        white-space: nowrap;
    }
    .modal {
        margin: 0.5rem;
        max-height: 95vh;
    }
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .login-box {
        margin: 0.75rem;
        padding: 1.25rem;
        border-radius: 0.75rem;
    }
    .login-box h1 {
        font-size: 1.2rem;
        margin-bottom: 1.25rem;
    }
    .form-group input {
        padding: 0.6rem 0.75rem;
        font-size: 0.9rem;
    }
    .sidebar {
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
    }
    .sidebar-logo {
        font-size: 0.9rem;
    }
    .sidebar-nav a {
        padding: 0.35rem 0.5rem;
        font-size: 0.75rem;
        gap: 0.35rem;
    }
    .sidebar-nav a svg {
        width: 14px;
        height: 14px;
    }
    .sidebar > div[style*="absolute"] .btn {
        padding: 0.35rem 0.6rem;
        font-size: 0.75rem;
    }
    .main-content {
        padding: 0.75rem;
    }
    .header {
        margin-bottom: 0.75rem;
        gap: 0.5rem;
    }
    .header h1 {
        font-size: 1rem;
    }
    .header-actions {
        gap: 0.4rem;
    }
    .btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.75rem;
    }
    .btn-sm {
        padding: 0.3rem 0.4rem;
        font-size: 0.65rem;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }
    .stat-card {
        padding: 0.625rem;
        flex-direction: column;
        align-items: flex-start;
    }
    .stat-card-title {
        font-size: 0.7rem;
        margin-bottom: 0.25rem;
    }
    .stat-card-value {
        font-size: 1rem;
    }
    .stat-card-subtitle {
        font-size: 0.6rem;
    }
    .table-container {
        border-radius: 0.5rem;
        margin: 0 -0.75rem;
        padding: 0 0.75rem;
    }
    .table-header {
        padding: 0.625rem 0.75rem;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
    .table-header h2 {
        font-size: 0.85rem;
    }
    .table {
        min-width: 580px;
    }
    .table th,
    .table td {
        padding: 0.4rem 0.5rem;
        font-size: 0.7rem;
    }
    .checkbox-cell {
        width: 28px;
        padding: 0.4rem 0.25rem !important;
    }
    .checkbox-cell input {
        width: 14px;
        height: 14px;
    }
    .status-badge {
        padding: 0.15rem 0.4rem;
        font-size: 0.6rem;
    }
    .actions-btn {
        padding: 0.2rem 0.4rem;
        font-size: 0.7rem;
    }
    .modal {
        margin: 0.25rem;
        border-radius: 0.5rem;
    }
    .modal-header {
        padding: 0.75rem;
    }
    .modal-header h2 {
        font-size: 0.95rem;
    }
    .modal-body {
        padding: 0.75rem;
    }
    .modal-footer {
        padding: 0.625rem 0.75rem;
        flex-wrap: wrap;
        gap: 0.4rem;
    }
    .uri-display {
        padding: 0.625rem;
        font-size: 0.7rem;
    }
    .qr-code img {
        max-width: 140px;
    }
    .alert {
        padding: 0.5rem 0.625rem;
        font-size: 0.75rem;
    }
}

/* Theme Toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.theme-toggle-btn {
    flex: 1;
    padding: 0.4rem 0.6rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    transition: all 0.2s;
}

.theme-toggle-btn:hover {
    color: var(--text-primary);
}

.theme-toggle-btn.active {
    background: var(--primary);
    color: white;
}

.theme-toggle-btn svg {
    width: 14px;
    height: 14px;
}

/* Language Selector */
.lang-selector {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.375rem;
    background: var(--bg-tertiary);
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
}

.lang-btn {
    flex: 1;
    padding: 0.3rem 0.4rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 0.375rem;
    font-size: 0.65rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    white-space: nowrap;
}

.lang-btn:hover {
    color: var(--text-primary);
}

.lang-btn.active {
    background: var(--primary);
    color: white;
}

/* Utility */
.hidden {
    display: none !important;
}

.text-muted {
    color: var(--gray-500);
}

.text-success {
    color: var(--success);
}

.text-danger {
    color: var(--danger);
}

.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
