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

:root {
    --bg-0: #09090b;
    --bg-1: #18181b;
    --bg-2: #27272a;
    --bg-3: #3f3f46;
    --border: #2e2e33;
    --border-hover: #52525b;
    --text-1: #fafafa;
    --text-2: #a1a1aa;
    --text-3: #71717a;

    --green: #22c55e;
    --green-dim: rgba(34,197,94,.12);
    --red: #ef4444;
    --red-dim: rgba(239,68,68,.12);
    --amber: #f59e0b;
    --amber-dim: rgba(245,158,11,.12);
    --blue: #3b82f6;
    --blue-dim: rgba(59,130,246,.12);
    --purple: #a78bfa;
    --purple-dim: rgba(167,139,250,.12);

    --radius: 10px;
    --radius-sm: 6px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
    --mono: 'JetBrains Mono', 'SF Mono', 'Menlo', monospace;
}

[x-cloak] { display: none !important; }

html, body {
    font-family: var(--font);
    background: var(--bg-0);
    color: var(--text-1);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* === Header === */
.header {
    position: sticky; top: 0; z-index: 50;
    background: var(--bg-1);
    border-bottom: 1px solid var(--border);
}
.header-content {
    max-width: 1400px; margin: 0 auto;
    padding: 0 24px;
    height: 56px;
    display: flex; align-items: center; justify-content: space-between;
}
.logo {
    display: flex; align-items: center; gap: 10px;
}
.logo-icon {
    width: 22px; height: 22px; color: var(--blue);
}
.logo h1 {
    font-size: 16px; font-weight: 600; letter-spacing: -0.3px;
}

.connection-badge {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px; font-weight: 500;
}
.badge-live {
    background: var(--green-dim); color: var(--green);
}
.badge-offline {
    background: var(--amber-dim); color: var(--amber);
}
.badge-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: currentColor;
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .4; }
}

/* === Metrics Strip === */
.metrics-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1px;
    background: var(--border);
    border-bottom: 1px solid var(--border);
}
.metric-card {
    background: var(--bg-1);
    padding: 14px 20px;
    display: flex; flex-direction: column; gap: 8px;
}
.metric-header {
    display: flex; justify-content: space-between; align-items: baseline;
}
.metric-label {
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .5px; color: var(--text-3);
}
.metric-value {
    font-size: 15px; font-weight: 600; font-family: var(--mono);
}
.metric-track {
    height: 3px; background: var(--bg-3); border-radius: 2px; overflow: hidden;
}
.metric-fill {
    height: 100%; border-radius: 2px;
    transition: width .6s ease;
}
.level-ok    { color: var(--green); }
.level-warn  { color: var(--amber); }
.level-crit  { color: var(--red);   }
.metric-fill.level-ok   { background: var(--green); }
.metric-fill.level-warn { background: var(--amber); }
.metric-fill.level-crit { background: var(--red);   }

/* === Main Content === */
.main {
    max-width: 1400px; margin: 0 auto;
    padding: 28px 24px 60px;
    display: flex; flex-direction: column; gap: 32px;
}

/* === Groups === */
.group { display: flex; flex-direction: column; gap: 14px; }
.group-header {
    display: flex; align-items: center; gap: 8px;
}
.group-icon { font-size: 18px; }
.group-header h2 {
    font-size: 15px; font-weight: 600;
}
.group-count {
    font-size: 12px; color: var(--text-3);
    margin-left: 4px;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 10px;
}

/* === Service Cards === */
.card {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
    transition: border-color .15s, box-shadow .15s;
}
.card:hover {
    border-color: var(--border-hover);
    box-shadow: 0 2px 12px rgba(0,0,0,.25);
}
.card--running { border-left: 3px solid var(--green); }
.card--stopped { border-left: 3px solid var(--text-3); opacity: .7; }
.card--unknown { border-left: 3px solid var(--text-3); }
.card--starting { border-left: 3px solid var(--blue); }
.card--unhealthy { border-left: 3px solid var(--red); }
.card--scheduled { border-left: 3px solid var(--purple); }

.card-top {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.card-identity {
    display: flex; align-items: flex-start; gap: 10px; min-width: 0;
}

/* Status indicator dot */
.status-indicator {
    width: 8px; height: 8px; border-radius: 50%;
    margin-top: 6px; flex-shrink: 0;
    background: var(--text-3);
}
.si--running  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.si--stopped  { background: var(--text-3); }
.si--unknown  { background: var(--text-3); }
.si--starting { background: var(--blue); animation: pulse 1.5s infinite; }
.si--unhealthy { background: var(--red); box-shadow: 0 0 6px var(--red); }
.si--scheduled { background: var(--purple); }

.card-label {
    font-size: 14px; font-weight: 500; color: var(--text-1);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-subtitle {
    display: flex; align-items: center; gap: 8px;
    margin-top: 2px; flex-wrap: wrap;
}
.type-tag {
    font-size: 10px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .5px;
    padding: 1px 6px; border-radius: 3px;
    background: var(--bg-3); color: var(--text-2);
}
.card-uptime {
    font-size: 12px; color: var(--text-3); font-family: var(--mono);
}
.card-status-text {
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .3px;
    padding: 2px 8px; border-radius: 4px;
    flex-shrink: 0;
}
.cst--running  { background: var(--green-dim); color: var(--green); }
.cst--stopped  { background: var(--bg-2); color: var(--text-3); }
.cst--unknown  { background: var(--bg-2); color: var(--text-3); }
.cst--starting { background: var(--blue-dim); color: var(--blue); }
.cst--unhealthy { background: var(--red-dim); color: var(--red); }
.cst--scheduled { background: var(--purple-dim); color: var(--purple); }

.health-pill {
    font-size: 10px; font-weight: 600; text-transform: uppercase;
    padding: 1px 6px; border-radius: 3px;
}
.hp--healthy   { background: var(--green-dim); color: var(--green); }
.hp--unhealthy { background: var(--red-dim); color: var(--red); }
.hp--starting  { background: var(--blue-dim); color: var(--blue); }

/* === Action Buttons === */
.card-actions {
    display: flex; gap: 6px; flex-wrap: wrap;
    padding-top: 4px;
    border-top: 1px solid var(--border);
}
.action-btn {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 5px 10px;
    font-size: 12px; font-weight: 500; font-family: var(--font);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg-2); color: var(--text-2);
    cursor: pointer; transition: all .15s;
}
.action-btn svg { width: 12px; height: 12px; }
.action-btn:hover:not(:disabled) {
    color: var(--text-1);
    border-color: var(--border-hover);
    background: var(--bg-3);
}
.action-btn:disabled { opacity: .4; cursor: not-allowed; }

.ab--restart:hover:not(:disabled) { color: var(--purple); border-color: var(--purple); background: var(--purple-dim); }
.ab--stop:hover:not(:disabled)    { color: var(--red); border-color: var(--red); background: var(--red-dim); }
.ab--start:hover:not(:disabled)   { color: var(--green); border-color: var(--green); background: var(--green-dim); }
.ab--logs:hover:not(:disabled)    { color: var(--blue); border-color: var(--blue); background: var(--blue-dim); }

/* === Modal === */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex; align-items: flex-end; justify-content: center;
    opacity: 0; visibility: hidden;
    transition: opacity .2s, visibility .2s;
}
.modal-overlay.is-open {
    opacity: 1; visibility: visible;
}
.modal-panel {
    width: 100%; max-width: 960px; max-height: 80vh;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    display: flex; flex-direction: column;
    transform: translateY(20px);
    transition: transform .25s ease;
}
.modal-overlay.is-open .modal-panel {
    transform: translateY(0);
}
.modal-top {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-subtitle { font-size: 12px; color: var(--text-3); }
.modal-close {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none;
    color: var(--text-3); cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all .15s;
}
.modal-close svg { width: 16px; height: 16px; }
.modal-close:hover { background: var(--bg-2); color: var(--text-1); }

.modal-logs {
    flex: 1; overflow-y: auto;
    padding: 12px 20px;
    font-family: var(--mono);
    font-size: 12px; line-height: 1.6;
}
.log-row {
    padding: 1px 0; color: var(--text-2);
    white-space: pre-wrap; word-break: break-all;
}
.log-row:hover { background: var(--bg-2); }
.log-empty {
    text-align: center; padding: 40px;
    color: var(--text-3); font-family: var(--font);
}

/* === Toast === */
.toast {
    position: fixed; bottom: -60px; left: 50%; transform: translateX(-50%);
    padding: 10px 20px;
    background: var(--bg-2); color: var(--text-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px; font-weight: 500;
    z-index: 300;
    transition: bottom .3s ease;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast-visible { bottom: 24px; }

/* === Responsive === */
@media (max-width: 768px) {
    .header-content { padding: 0 16px; }
    .metrics-strip { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
    .metric-card { padding: 10px 14px; }
    .metric-value { font-size: 13px; }
    .main { padding: 20px 16px 40px; gap: 24px; }
    .cards-grid { grid-template-columns: 1fr; }
    .modal-panel { max-height: 90vh; }
}

@media (max-width: 480px) {
    .logo h1 { font-size: 14px; }
    .connection-badge { font-size: 11px; padding: 3px 8px; }
    .metrics-strip { grid-template-columns: repeat(2, 1fr); }
}
