/* Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #d1d5db;
    --text: #1f2937;
    --text-muted: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0891b2;
    --secondary: #4b5563;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header / nav */
header {
    background: #1e293b;
    color: #f8fafc;
    padding: 0 1.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

nav {
    display: flex;
    align-items: center;
    height: 52px;
    gap: 2rem;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: #f8fafc;
    text-decoration: none;
    letter-spacing: 0.02em;
}

nav ul {
    list-style: none;
    display: flex;
    gap: 0.25rem;
}

nav ul a {
    color: #94a3b8;
    text-decoration: none;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius);
    transition: background 0.15s, color 0.15s;
}

nav ul a:hover {
    background: rgba(255,255,255,0.1);
    color: #f8fafc;
}

/* Nav user dropdown */
.nav-user-menu {
    position: relative;
}

.nav-user-trigger {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 0.82rem;
    cursor: pointer;
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius);
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.nav-user-trigger:hover,
.nav-user-menu.open .nav-user-trigger {
    background: rgba(255,255,255,0.1);
    color: #f8fafc;
}

.nav-user-role {
    opacity: 0.5;
    margin-left: 0.1rem;
}

.nav-user-caret {
    width: 8px;
    height: 5px;
    opacity: 0.6;
    transition: transform 0.15s;
    flex-shrink: 0;
}

.nav-user-menu.open .nav-user-caret {
    transform: rotate(180deg);
}

.nav-user-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 160px;
    background: #1e293b;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.35);
    list-style: none;
    padding: 0.25rem 0;
    z-index: 200;
}

.nav-user-menu.open .nav-user-dropdown {
    display: block;
}

.nav-user-dropdown li a,
.nav-user-dropdown li button {
    display: block;
    width: 100%;
    padding: 0.45rem 1rem;
    font-size: 0.82rem;
    color: #94a3b8;
    text-decoration: none;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    box-sizing: border-box;
    transition: background 0.12s, color 0.12s;
}

.nav-user-dropdown li a:hover,
.nav-user-dropdown li button:hover {
    background: rgba(255,255,255,0.08);
    color: #f8fafc;
}

.nav-user-dropdown-divider {
    border-top: 1px solid rgba(255,255,255,0.08);
    margin: 0.25rem 0;
}

/* Main content */
main {
    flex: 1;
    padding: 1.5rem;
    max-width: 1300px;
    width: 100%;
    margin: 0 auto;
}

h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 1.25rem; }
h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.75rem; }

/* Flash messages */
.flash-container { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }

.flash {
    padding: 0.65rem 1rem;
    border-radius: var(--radius);
    border-left: 4px solid transparent;
    font-size: 0.9rem;
}

.flash-success { background: #dcfce7; border-color: var(--success); color: #14532d; }
.flash-error   { background: #fee2e2; border-color: var(--danger);  color: #7f1d1d; }
.flash-warning { background: #fef9c3; border-color: var(--warning); color: #78350f; }
.flash-info    { background: #e0f2fe; border-color: var(--info);    color: #0c4a6e; }

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.info-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}

/* Tables */
.container-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.container-table th,
.container-table td {
    padding: 0.65rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.container-table th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.container-table tbody tr:hover { background: #f8fafc; }
.container-table tbody tr:last-child td { border-bottom: none; }

.info-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}
.info-table th, .info-table td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid #f0f0f0;
    text-align: left;
}
.info-table th { color: var(--text-muted); font-weight: 500; width: 45%; }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}
.badge-running { background: #dcfce7; color: #15803d; }
.badge-stopped { background: #fee2e2; color: #b91c1c; }
.badge-frozen  { background: #e0f2fe; color: #0369a1; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.4rem 0.9rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: opacity 0.15s, filter 0.15s;
    line-height: 1.4;
}

.btn:hover { filter: brightness(0.92); }

.btn-primary   { background: var(--primary);   color: #fff; }
.btn-success   { background: var(--success);   color: #fff; }
.btn-warning   { background: var(--warning);   color: #fff; }
.btn-danger    { background: var(--danger);    color: #fff; }
.btn-info      { background: var(--info);      color: #fff; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-sm        { padding: 0.25rem 0.6rem; font-size: 0.8rem; }

.inline-form { display: inline; }
.action-row  { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.actions     { display: flex; flex-wrap: wrap; gap: 0.4rem; }

/* Forms */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 640px;
    box-shadow: var(--shadow);
}

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

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
}

.form-group .hint {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="url"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

select {
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.15s;
}

select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.form-group textarea { resize: vertical; }

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.field-note {
    margin-top: 0.3rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.warning-note {
    margin-top: 1rem;
    padding: 0.65rem 0.9rem;
    background: #fef9c3;
    border-left: 3px solid var(--warning);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 0.85rem;
    color: #78350f;
}

/* Inline limits form in profiles table */
.edit-row td { background: #f8fafc; }
.edit-row.hidden { display: none; }

.inline-limits-form { padding: 0.75rem 0; }

.limits-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}

.limits-fields label {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
    font-weight: 500;
    gap: 0.3rem;
}

.limits-fields input[type="text"] {
    padding: 0.4rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    width: 140px;
}

/* Profile YAML editor */
.code-editor {
    width: 100%;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.85rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #1e1e1e;
    color: #d4d4d4;
    resize: vertical;
    tab-size: 2;
}

.code-editor:focus {
    outline: none;
    border-color: var(--primary);
}

/* Log output */
.log-output {
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.82rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* xterm.js terminal */
#terminal {
    width: 100%;
    height: 500px;
    background: #1e1e1e;
    border-radius: var(--radius);
    overflow: hidden;
    padding: 4px;
}

/* Container header */
.container-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.container-header h1 { margin-bottom: 0; }

/* Key-value spans */
.kv {
    display: inline-block;
    background: #f1f5f9;
    border-radius: 4px;
    padding: 0.1rem 0.35rem;
    font-size: 0.8rem;
    font-family: monospace;
    margin: 1px;
}

/* Misc */
.empty {
    color: var(--text-muted);
    font-style: italic;
    padding: 1rem 0;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
    background: #f1f5f9;
    border-radius: 3px;
    padding: 0.1em 0.35em;
    font-family: monospace;
    font-size: 0.9em;
}

/* Footer */
footer {
    background: #1e293b;
    color: #64748b;
    text-align: center;
    padding: 0.75rem;
    font-size: 0.8rem;
}

/* Jobs page */
.jobs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 800px) { .jobs-grid { grid-template-columns: 1fr; } }
.job-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.badge { padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-idle    { background: #e2e8f0; color: #475569; }
.badge-running { background: #dcfce7; color: #166534; }
.job-log { background: #1e1e1e; color: #d4d4d4; padding: 0.75rem; border-radius: 6px; font-size: 0.78rem; max-height: 300px; overflow-y: auto; margin-top: 0.75rem; white-space: pre-wrap; word-break: break-all; }

/* Snapshot / inline form */
.inline-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.inline-form input[type="text"] { flex: 1; min-width: 200px; padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: 4px; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn-warning { background: #f59e0b; color: #fff; border: none; border-radius: 4px; cursor: pointer; }
.btn-warning:hover { background: #d97706; }
.btn-danger  { background: #ef4444; color: #fff; border: none; border-radius: 4px; cursor: pointer; }
.btn-danger:hover  { background: #dc2626; }

/* Loading overlay */
#loading-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}
#loading-overlay.active { display: flex; }
.loading-box {
    background: var(--surface);
    padding: 2rem 3rem;
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    text-align: center;
    min-width: 220px;
}
.spinner {
    width: 38px; height: 38px;
    margin: 0 auto 1rem;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Container sub-navigation */
.sub-nav {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

/* Checkbox groups (provision page) */
.checkbox-group { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 0.4rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; font-weight: normal; }
.checkbox-label input[type="checkbox"] { width: 1rem; height: 1rem; cursor: pointer; }
