:root {
    --bg: #0d1117;
    --panel: #161b22;
    --panel-2: #1c232c;
    --border: #2a323d;
    --text: #e6edf3;
    --muted: #8b949e;
    --accent: #58a6ff;
    --green: #3fb950;
    --red: #f85149;
    --yellow: #d29922;
    --gray: #6e7681;
    --radius: 10px;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "DejaVu Sans Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "DejaVu Sans", sans-serif;
    -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--red); min-height: 1.2em; margin: 0; font-size: 13px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; }
.logo {
    width: 22px; height: 22px; border-radius: 6px;
    background: linear-gradient(135deg, var(--accent), #a371f7);
}

/* Boutons */
.btn {
    border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
    padding: 7px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500;
    transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0d1117; }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(248, 81, 73, .15); border-color: rgba(248, 81, 73, .5); color: #ffb3ae; }
.btn.success { background: rgba(63, 185, 80, .15); border-color: rgba(63, 185, 80, .5); color: #a5f0b0; }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

input, select {
    background: var(--bg); color: var(--text); border: 1px solid var(--border);
    border-radius: 8px; padding: 7px 10px; font: inherit;
}

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
    width: 100%; max-width: 340px; display: grid; gap: 14px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px;
}
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }

/* En-tête */
.topbar {
    position: sticky; top: 0; z-index: 5;
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px; background: rgba(13, 17, 23, .85); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.container { max-width: 1200px; margin: 0 auto; padding: 16px; display: grid; gap: 24px; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; }

/* Cartes services */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card {
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; display: grid; gap: 14px; transition: border-color .15s;
}
.card.selected { border-color: var(--accent); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-title { font-weight: 600; font-size: 15px; cursor: pointer; }
.card-unit { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gray); }
.status.active .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(63, 185, 80, .2); }
.status.active { color: var(--green); }
.status.failed .dot { background: var(--red); box-shadow: 0 0 0 3px rgba(248, 81, 73, .2); }
.status.failed { color: var(--red); }
.status.transition .dot { background: var(--yellow); animation: pulse 1s infinite; }
.status.transition { color: var(--yellow); }
.status.inactive { color: var(--muted); }
@keyframes pulse { 50% { opacity: .3; } }

.metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 16px; }
.metric { display: grid; gap: 4px; }
.metric-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.metric-value { font-family: var(--mono); font-size: 13px; }
.bar { height: 4px; border-radius: 2px; background: var(--panel-2); overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.bar.warn > span { background: var(--yellow); }
.bar.crit > span { background: var(--red); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1; }

/* Logs */
.logs { display: grid; gap: 10px; }
.logs-head { display: flex; justify-content: space-between; align-items: baseline; }
.logs-head .section-title { margin: 0; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.pill.live { color: var(--green); border-color: rgba(63, 185, 80, .5); }
.pill.paused { color: var(--yellow); border-color: rgba(210, 153, 34, .5); }
.pill.off { color: var(--red); border-color: rgba(248, 81, 73, .5); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar input[type="search"] { flex: 1; min-width: 180px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; user-select: none; }
.log-output {
    margin: 0; height: 60vh; min-height: 280px; overflow: auto;
    background: #090c10; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 10px 12px; font: 12px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word;
}
.log-line { display: block; }
.log-line .ts { color: var(--gray); margin-right: 8px; }
.log-line.p3, .log-line.p2, .log-line.p1, .log-line.p0 { color: #ff9b94; }
.log-line.p4 { color: #e3b341; }
.log-line.p7 { color: var(--muted); }
.log-line mark { background: rgba(88, 166, 255, .35); color: inherit; border-radius: 2px; }
.log-sys { color: var(--accent); font-style: italic; }

/* Dialogue & toast */
dialog {
    background: var(--panel); color: var(--text); border: 1px solid var(--border);
    border-radius: 12px; padding: 20px; max-width: 380px; width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog p { margin: 0 0 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast {
    position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
    background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
    padding: 10px 16px; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, .4); z-index: 10;
}
.toast.err { border-color: rgba(248, 81, 73, .6); color: #ffb3ae; }

@media (max-width: 600px) {
    .container { padding: 12px; gap: 18px; }
    .log-output { height: 55vh; font-size: 11px; }
    .toolbar select { flex: 1; }
    .topbar #refresh-state { display: none; }
}
