/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-success: #16a34a;
    --color-danger: #dc2626;
    --color-warning: #d97706;
    --color-info: #0891b2;
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --color-border-hover: #cbd5e1;
    --radius: 6px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] {
    --color-primary: #3b82f6;
    --color-primary-hover: #60a5fa;
    --color-success: #22c55e;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;
    --color-info: #06b6d4;
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-text: #e2e8f0;
    --color-text-muted: #94a3b8;
    --color-border: #334155;
    --color-border-hover: #475569;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    font-size: 14px;
}

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 16px;
}

/* Navbar */
.navbar {
    display: flex;
    align-items: center;
    padding: 0 24px;
    height: 56px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.navbar-brand a {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-primary);
    text-decoration: none;
}

.navbar-menu {
    display: flex;
    gap: 4px;
    margin-left: 32px;
}

.nav-link {
    padding: 8px 16px;
    color: var(--color-text-muted);
    text-decoration: none;
    border-radius: var(--radius);
    font-weight: 500;
    transition: color 0.15s, background 0.15s;
}

.nav-link:hover,
.nav-link.active {
    color: var(--color-primary);
    background: #eff6ff;
}

[data-theme="dark"] .nav-link:hover,
[data-theme="dark"] .nav-link.active {
    background: #1e3a5f;
}

.navbar-end {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-user {
    color: var(--color-text-muted);
    font-size: 13px;
}

.nav-logout-form {
    display: inline;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.btn-success {
    background: var(--color-success);
    color: #fff;
}

.btn-success:hover:not(:disabled) {
    background: #15803d;
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: #b91c1c;
}

.btn-outline {
    background: transparent;
    color: var(--color-text-muted);
    border-color: var(--color-border);
}

.btn-outline:hover:not(:disabled) {
    background: var(--color-bg);
    border-color: var(--color-border-hover);
    color: var(--color-text);
}

.btn-sm {
    padding: 4px 12px;
    font-size: 13px;
}

.btn-block {
    display: flex;
    width: 100%;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
    font-size: 13px;
    color: var(--color-text);
}

.form-control {
    display: block;
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    transition: border-color 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

[data-theme="dark"] .form-control:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

select.form-control {
    appearance: auto;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-info {
    background: #ecfeff;
    color: #155e75;
    border: 1px solid #a5f3fc;
}

/* Cards */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* Tables */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

th {
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    background: var(--color-bg);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: var(--color-bg);
}

/* Status badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 9999px;
    text-transform: capitalize;
}

.badge-queued {
    background: #f1f5f9;
    color: #475569;
}

.badge-running {
    background: #dbeafe;
    color: #1d4ed8;
}

.badge-success {
    background: #dcfce7;
    color: #15803d;
}

.badge-failed {
    background: #fef2f2;
    color: #dc2626;
}

.badge-cancelled {
    background: #fef9c3;
    color: #a16207;
}

.badge-admin {
    background: #ede9fe;
    color: #6d28d9;
}

.badge-user {
    background: #e0f2fe;
    color: #0369a1;
}

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
}

/* Deploy log */
.deploy-log {
    background: #1e293b;
    color: #e2e8f0;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    line-height: 1.6;
    padding: 16px;
    border-radius: var(--radius);
    max-height: 500px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.deploy-log .log-line {
    padding: 1px 0;
}

.deploy-log .log-error {
    color: #fca5a5;
}

.deploy-log .log-warning {
    color: #fcd34d;
}

.deploy-log .log-success {
    color: #86efac;
}

.deploy-log .log-info {
    color: #93c5fd;
}

/* Action bar */
.action-bar {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Modal overlay */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 480px;
    width: 100%;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.modal h3 {
    margin-bottom: 12px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--color-text-muted);
}

.empty-state p {
    font-size: 15px;
}

/* Permission checkboxes */
.permission-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
}

.permission-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.permission-item label {
    font-weight: 400;
    cursor: pointer;
}

/* Config card for deploy page */
.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 16px;
}

.config-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.config-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.config-card-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.config-card-status {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-bottom: 16px;
}

/* Theme toggle */
.theme-toggle {
    padding: 4px 8px;
    font-size: 16px;
    line-height: 1;
}

.theme-toggle-icon {
    display: inline-block;
}

/* Dark theme overrides */
[data-theme="dark"] .alert-error {
    background: #451a1a;
    color: #fca5a5;
    border-color: #7f1d1d;
}

[data-theme="dark"] .alert-success {
    background: #14332a;
    color: #86efac;
    border-color: #166534;
}

[data-theme="dark"] .alert-info {
    background: #0c2d3e;
    color: #67e8f9;
    border-color: #155e75;
}

[data-theme="dark"] .badge-queued {
    background: #334155;
    color: #94a3b8;
}

[data-theme="dark"] .badge-running {
    background: #1e3a5f;
    color: #60a5fa;
}

[data-theme="dark"] .badge-success {
    background: #14332a;
    color: #4ade80;
}

[data-theme="dark"] .badge-failed {
    background: #451a1a;
    color: #f87171;
}

[data-theme="dark"] .badge-cancelled {
    background: #422006;
    color: #fbbf24;
}

[data-theme="dark"] .badge-admin {
    background: #2e1065;
    color: #a78bfa;
}

[data-theme="dark"] .badge-user {
    background: #0c2d3e;
    color: #38bdf8;
}

[data-theme="dark"] .btn-success:hover:not(:disabled) {
    background: #16a34a;
}

[data-theme="dark"] .btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

/* Responsive */
@media (max-width: 768px) {
    .navbar {
        flex-wrap: wrap;
        height: auto;
        padding: 12px 16px;
        gap: 8px;
    }

    .navbar-menu {
        margin-left: 0;
        order: 3;
        width: 100%;
    }

    .config-grid {
        grid-template-columns: 1fr;
    }
}
