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

:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-input: #252833;
    --border: #2d3141;
    --text: #e1e4ea;
    --text-dim: #8b8fa3;
    --accent: #5b8af5;
    --accent-hover: #4a7ae8;
    --green: #34d399;
    --red: #f87171;
    --gray: #6b7280;
    --radius: 8px;
}

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

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

.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
}
.nav-brand:hover { text-decoration: none; }

.nav-links {
    display: flex;
    align-items: center;
    gap: 16px;
}

.nav-links a { color: var(--text-dim); font-size: 0.9rem; }
.nav-links a:hover { color: var(--text); text-decoration: none; }

.btn-logout {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 4px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
}
.btn-logout:hover { border-color: var(--red); color: var(--red); }

.content { padding: 16px; max-width: 1200px; margin: 0 auto; }

/* Buttons */
.btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.15s;
}
.btn:hover { background: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-sm { padding: 4px 12px; font-size: 0.85rem; }
.btn-xs { padding: 2px 8px; font-size: 0.8rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-info { border-color: var(--accent); color: var(--accent); }
.btn-info:hover { background: var(--accent); color: #fff; }

/* Badges */
.badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-green { background: rgba(52,211,153,0.15); color: var(--green); }
.badge-red { background: rgba(248,113,113,0.15); color: var(--red); }
.badge-gray { background: rgba(107,114,128,0.15); color: var(--gray); }

/* Login */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 360px;
}

.login-card h1 {
    font-size: 1.5rem;
    margin-bottom: 24px;
    text-align: center;
}

.login-card input {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
    outline: none;
}
.login-card input:focus { border-color: var(--accent); }

.login-card button {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    font-weight: 600;
}
.login-card button:hover { background: var(--accent-hover); }
.login-card button:disabled { opacity: 0.6; cursor: not-allowed; }

.error {
    background: rgba(248,113,113,0.1);
    color: var(--red);
    padding: 8px 12px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.page-header h2 { font-size: 1.3rem; }

/* Host cards */
.host-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
}

.host-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(255,255,255,0.02);
    border-bottom: 1px solid var(--border);
}

.host-ip {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-left: 8px;
}

.host-count {
    color: var(--text-dim);
    font-size: 0.85rem;
}

.service-list { padding: 4px 0; }

.service-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    gap: 8px;
}
.service-row:last-child { border-bottom: none; }

.service-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    flex-wrap: wrap;
}

.service-name {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.restarts { color: var(--text-dim); font-size: 0.8rem; }
.duration { color: var(--accent); font-size: 0.8rem; font-weight: 600; }
.uptime { color: var(--text-dim); font-size: 0.8rem; display: none; }

.service-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* Log viewer */
.log-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.log-panel {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    width: 100%;
    max-width: 1000px;
    height: 70vh;
    display: flex;
    flex-direction: column;
}

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

.log-header span { font-weight: 600; font-size: 0.9rem; }
.log-header .badge { margin-left: 8px; }

.log-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.8rem;
    line-height: 1.6;
    background: #0a0c10;
}

.log-line {
    white-space: pre-wrap;
    word-break: break-all;
}

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

/* Playbooks */
.playbook-form {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.form-row {
    margin-bottom: 12px;
}

.form-row label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.form-row select,
.form-row input[type="text"] {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
}
.form-row select:focus,
.form-row input:focus { border-color: var(--accent); }

.required { color: var(--red); }

.params-section {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-top: 4px;
}
.params-section h3 { font-size: 0.95rem; margin-bottom: 8px; }

.run-output {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
}

.run-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    font-weight: 600;
}

.terminal {
    background: #0a0c10;
    color: #c9d1d9;
    padding: 12px 16px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    overflow: auto;
    max-height: 400px;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}

.recent-runs {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.recent-runs h3 { font-size: 0.95rem; margin-bottom: 12px; }

.run-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    font-size: 0.85rem;
}
.run-row:last-child { border-bottom: none; }

.loading, .empty {
    text-align: center;
    padding: 40px;
    color: var(--text-dim);
}

.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--text-dim);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
}

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

/* Config Editor */
.config-page { display: flex; flex-direction: column; height: calc(100vh - 60px - 48px); overflow: hidden; }

.config-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.config-select {
    flex: 1;
    min-width: 200px;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
}
.config-select:focus { border-color: var(--accent); }

.save-bar {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dirty-indicator {
    color: var(--red);
    font-weight: 700;
    margin-left: 6px;
}

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

.save-status { font-size: 0.85rem; }
.save-status-success { color: var(--green); }
.save-status-error { color: var(--red); }

.editor-wrapper {
    position: relative;
    flex: 1;
    min-height: 300px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: #0a0c10;
}

.editor-highlight,
.editor-textarea {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 12px 16px;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    white-space: pre;
    overflow: auto;
    border: none;
    tab-size: 4;
}

.editor-highlight {
    color: var(--text);
    pointer-events: none;
    z-index: 1;
}

.editor-textarea {
    color: transparent;
    caret-color: #fff;
    background: transparent;
    resize: none;
    outline: none;
    z-index: 2;
    -webkit-text-fill-color: transparent;
}

.hl-comment { color: #6b7280; font-style: italic; }
.hl-section { color: var(--accent); font-weight: 700; }
.hl-key { color: #e1e4ea; }
.hl-string { color: #34d399; }
.hl-number { color: #fb923c; }
.hl-bool { color: #c084fc; }

/* Desktop */
@media (min-width: 768px) {
    .content { padding: 24px; }
    .uptime { display: inline; }
    .duration { display: inline; }

    .log-panel {
        height: 80vh;
        border-radius: var(--radius);
        margin: auto;
    }

    .log-overlay {
        align-items: center;
        padding: 24px;
    }
}
