/* RP-Panel — direction visuelle inspirée d'Apple (macOS / iOS) :
   surfaces blanches arrondies, verre dépoli sur les éléments flottants,
   ombres très douces, couleur système réservée au sens (état), typo SF. */

:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f8f8fb;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #9a9a9f;
  --sep: rgba(60, 60, 67, .1);
  --sep-strong: rgba(60, 60, 67, .16);

  --blue: #007aff;
  --green: #34c759;
  --green-soft: #e6f9ec;
  --orange: #ff9500;
  --orange-soft: #fff3e0;
  --red: #ff3b30;
  --red-soft: #ffece9;
  --gray: #98989d;
  --gray-soft: #eeeef1;

  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 12px;
  --r-xs: 9px;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, .08), 0 20px 48px rgba(0, 0, 0, .12);

  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Inter, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-2: #242426;
  --text: #f5f5f7;
  --text-2: #98989d;
  --text-3: #6e6e73;
  --sep: rgba(255, 255, 255, .08);
  --sep-strong: rgba(255, 255, 255, .14);

  --green-soft: rgba(52, 199, 89, .16);
  --orange-soft: rgba(255, 149, 0, .16);
  --red-soft: rgba(255, 59, 48, .16);
  --gray-soft: rgba(152, 152, 157, .16);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .4);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, .4), 0 20px 48px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
::selection { background: var(--blue); color: #fff; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--sans);
  font-feature-settings: "tnum" 1;
  -webkit-font-smoothing: antialiased;
}
body { min-height: 100vh; display: flex; flex-direction: column; transition: background .25s; }

h1, h2, h3 { margin: 0; }
button, input { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- Entete */

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(20px) saturate(1.6);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  border-bottom: 1px solid var(--sep);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 14px 24px;
  display: flex; align-items: center; gap: 18px;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.appicon {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(160deg, #2b9fff, #007aff);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 122, 255, .35);
}
.appicon svg { width: 17px; height: 17px; }
.appicon.ok { background: linear-gradient(160deg, #57d97e, var(--green)); box-shadow: 0 2px 6px rgba(52, 199, 89, .35); }
.appicon.degraded { background: linear-gradient(160deg, #ffb143, var(--orange)); box-shadow: 0 2px 6px rgba(255, 149, 0, .35); }
.appicon.down { background: linear-gradient(160deg, #ff6b60, var(--red)); box-shadow: 0 2px 6px rgba(255, 59, 48, .4); }

.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.brand-name { font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.brand-status { font-size: 12.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar-tools { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.search {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: 980px; background: var(--gray-soft);
  color: var(--text-3); width: 190px; transition: width .2s;
}
.search:focus-within { width: 230px; color: var(--text); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 22%, transparent); }
.search svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.4; flex: none; }
.search input { border: 0; outline: none; background: transparent; width: 100%; font-size: 13.5px; }
.search input::placeholder { color: var(--text-3); }

.iconbtn {
  width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--gray-soft);
  color: var(--text-2); display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: background .12s, transform .08s;
}
.iconbtn svg { width: 17px; height: 17px; }
.iconbtn:hover { background: var(--sep-strong); color: var(--text); }
.iconbtn:active { transform: scale(.92); }

.pillbtn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: var(--blue); color: #fff; font-weight: 590;
  padding: 8px 16px 8px 13px; border-radius: 980px; cursor: pointer; font-size: 13.5px;
  transition: transform .08s, background .12s;
}
.pillbtn svg { width: 13px; height: 13px; }
.pillbtn:hover { background: color-mix(in srgb, var(--blue) 88%, black); }
.pillbtn:active { transform: scale(.96); }

.linkbtn {
  border: 0; background: none; color: var(--blue); cursor: pointer; font-size: 13.5px; font-weight: 560;
  padding: 8px 2px;
}
.linkbtn:hover { text-decoration: underline; }

/* -------------------------------------------------------- Bandeau alerte */

.attention {
  max-width: 1180px; margin: 14px auto 0; padding: 0 24px;
  display: flex; flex-direction: column; gap: 8px;
}
.attention-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: var(--r-sm);
  background: var(--red-soft);
}
.attention-row.degraded { background: var(--orange-soft); }
.attention-row .sev {
  width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex: none;
}
.attention-row.degraded .sev { background: var(--orange); }
.attention-row .who { font-weight: 600; flex: none; }
.attention-row .why { color: var(--text-2); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.attention-row .since { color: var(--text-3); font-size: 12.5px; flex: none; font-variant-numeric: tabular-nums; }
.attention-row button {
  border: 0; background: var(--surface); border-radius: 980px; box-shadow: var(--shadow-1);
  padding: 5px 12px; font-size: 12.5px; cursor: pointer; color: var(--text); flex: none; font-weight: 560;
}
.attention-row button:hover { background: var(--surface-2); }
.attention-row .acked { color: var(--text-3); font-size: 12.5px; flex: none; }

/* ----------------------------------------------------------------- Main */

main { flex: 1; padding: 26px 24px 50px; max-width: 1180px; width: 100%; margin: 0 auto; }
.block { margin-top: 34px; }
.block:first-child { margin-top: 0; }
.block-head { display: flex; align-items: baseline; gap: 9px; margin-bottom: 12px; padding: 0 4px; }
.block-head h2 { font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
.block-meta { color: var(--text-3); font-size: 13px; }
.block[hidden] { display: none; }

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

.empty {
  padding: 30px; text-align: center; color: var(--text-3); font-size: 13.5px;
  background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-1); grid-column: 1 / -1;
}

/* ------------------------------------------------------------------ Card */

.card {
  background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-1);
  padding: 16px 17px; cursor: pointer; transition: transform .14s cubic-bezier(.2,.8,.2,1), box-shadow .14s;
  display: flex; flex-direction: column; gap: 12px;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.card:active { transform: translateY(0) scale(.99); }
.card.muted { opacity: .5; }

.card-top { display: flex; align-items: flex-start; gap: 10px; }
.card-top .id { min-width: 0; flex: 1; }
.card-top .name { font-weight: 620; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-top .sub { color: var(--text-3); font-size: 12px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.status-pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px 3px 8px; border-radius: 980px;
  font-size: 11px; font-weight: 650; letter-spacing: .01em; flex: none;
}
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pill.ok { background: var(--green-soft); color: var(--green); }
.status-pill.degraded { background: var(--orange-soft); color: var(--orange); }
.status-pill.down { background: var(--red-soft); color: var(--red); }
.status-pill.paused, .status-pill.unknown { background: var(--gray-soft); color: var(--gray); }

.card-msg { font-size: 12.5px; color: var(--text-2); line-height: 1.4; }
.card-msg.bad { color: var(--red); }
.card-msg.warn { color: var(--orange); }

.card-stats { display: flex; gap: 18px; }
.card-stats .stat .v { font-family: var(--mono); font-size: 14px; font-weight: 500; }
.card-stats .stat .v.bad { color: var(--red); }
.card-stats .stat .v.warn { color: var(--orange); }
.card-stats .stat .k { display: block; color: var(--text-3); font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; margin-top: 1px; }

.card-spark { width: 100%; height: 30px; display: block; margin-top: -2px; }
.card-spark path { fill: none; stroke: var(--text-3); stroke-width: 1.5; }
.card-spark rect { fill: var(--red); opacity: .55; }
.card.ok .card-spark path { stroke: var(--green); }
.card.degraded .card-spark path { stroke: var(--orange); }
.card.down .card-spark path { stroke: var(--red); }

.card-foot { font-size: 11.5px; color: var(--text-3); }

/* ----------------------------------------------------- Anneaux (Raspberry) */

.rings { display: flex; align-items: center; gap: 14px; }
.rings svg { width: 72px; height: 72px; flex: none; }
.ring-track { fill: none; stroke: var(--gray-soft); stroke-width: 3.6; }
.ring-val { fill: none; stroke-linecap: round; stroke-width: 3.6; transition: stroke-dashoffset .4s ease; transform: rotate(-90deg); transform-origin: 50% 50%; }
.ring-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; flex: 1; min-width: 0; }
.ring-legend .li { display: flex; align-items: baseline; gap: 6px; font-size: 12px; }
.ring-legend .li .dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.ring-legend .li .v { font-family: var(--mono); font-weight: 600; }
.ring-legend .li .v.warn { color: var(--orange); }
.ring-legend .li .v.bad { color: var(--red); }
.ring-legend .li .k { color: var(--text-3); font-size: 10.5px; }

/* --------------------------------------------------------------- Journal */

.logcard { background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-1); overflow: hidden; }
.log-row {
  display: flex; align-items: center; gap: 13px; padding: 12px 16px;
  border-bottom: 1px solid var(--sep); font-size: 13.5px;
}
.log-row:last-child { border-bottom: 0; }
.log-row .when { color: var(--text-3); font-family: var(--mono); font-size: 11.5px; width: 78px; flex: none; }
.log-row .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--red); flex: none; }
.log-row .dot.degraded { background: var(--orange); }
.log-row .dot.closed { background: var(--green); }
.log-row .who { font-weight: 600; flex: none; }
.log-row .why { color: var(--text-2); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-row .dur { color: var(--text-3); font-family: var(--mono); font-size: 11.5px; flex: none; }

/* ---------------------------------------------------------------- Footer */

.footer {
  padding: 18px 24px 30px; color: var(--text-3); font-size: 12px;
  display: flex; align-items: center; justify-content: center; gap: 12px;
}
.livepill { display: inline-flex; align-items: center; gap: 6px; }
.livepill i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: pulse 2.2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* ---------------------------------------------------------------- Tiroir */

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .22); z-index: 40; backdrop-filter: blur(2px); }
[data-theme="dark"] .scrim { background: rgba(0, 0, 0, .55); }

.sheet-panel {
  position: fixed; top: 10px; right: 10px; bottom: 10px; width: min(420px, calc(100% - 20px));
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-2);
  z-index: 41; overflow-y: auto; animation: sheet-in .22s cubic-bezier(.2,.8,.2,1);
}
@keyframes sheet-in { from { transform: translateX(14px) scale(.98); opacity: 0; } }
#panelBody { padding: 22px 22px 34px; display: flex; flex-direction: column; gap: 22px; }

.p-head { display: flex; align-items: flex-start; gap: 10px; }
.p-head .t { flex: 1; min-width: 0; }
.p-head h3 { font-size: 19px; font-weight: 650; letter-spacing: -.01em; }
.p-head .sub { color: var(--text-3); font-size: 12.5px; margin-top: 3px; }
.p-close {
  width: 28px; height: 28px; border-radius: 50%; border: 0; background: var(--gray-soft);
  color: var(--text-2); cursor: pointer; font-size: 13px; flex: none; display: flex; align-items: center; justify-content: center;
}
.p-close:hover { background: var(--sep-strong); }

.p-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin-bottom: 9px; font-weight: 600; }
.p-alert { padding: 13px 15px; border-radius: var(--r-sm); background: var(--red-soft); }
.p-alert.degraded { background: var(--orange-soft); }
.p-alert .cause { font-size: 13.5px; color: var(--text); margin-bottom: 4px; }
.p-alert .meta { font-size: 12px; color: var(--text-2); }

.kvcard { background: var(--surface-2); border-radius: var(--r-sm); overflow: hidden; }
.kv { display: flex; justify-content: space-between; gap: 14px; padding: 10px 14px; font-size: 13.5px; border-bottom: 1px solid var(--sep); }
.kv:last-child { border-bottom: 0; }
.kv dt { color: var(--text-3); margin: 0; }
.kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }

.chart { width: 100%; height: 90px; display: block; }
.chart-legend { display: flex; gap: 16px; font-size: 11.5px; color: var(--text-3); margin-top: 8px; }
.chart-legend i { display: inline-block; width: 9px; height: 2px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.abtn {
  border: 0; padding: 9px 15px; border-radius: 980px; cursor: pointer; font-size: 13px; font-weight: 560;
  background: var(--gray-soft); color: var(--text);
}
.abtn:hover { background: var(--sep-strong); }
.abtn.primary { background: var(--blue); color: #fff; }
.abtn.primary:hover { background: color-mix(in srgb, var(--blue) 88%, black); }
.abtn.danger { background: var(--red-soft); color: var(--red); }
.abtn.danger:hover { background: color-mix(in srgb, var(--red) 20%, var(--red-soft)); }

.token {
  font-family: var(--mono); font-size: 12px; padding: 12px 14px; border-radius: var(--r-sm);
  background: var(--surface-2); overflow-wrap: anywhere; user-select: all; white-space: pre-wrap; line-height: 1.6;
}

.svc { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--sep); font-size: 13.5px; }
.svc:last-child { border-bottom: 0; }
.svc .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.svc .dot.off { background: var(--red); }
.svc .st { margin-left: auto; color: var(--text-3); font-size: 12px; font-family: var(--mono); }

.gauges { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.gauge-item { background: var(--surface-2); border-radius: var(--r-sm); padding: 12px 14px; }
.gauge-item .v { font-family: var(--mono); font-size: 18px; font-weight: 600; }
.gauge-item .v.warn { color: var(--orange); }
.gauge-item .v.bad { color: var(--red); }
.gauge-item .k { font-size: 11px; color: var(--text-3); margin-top: 1px; }
.gauge-bar { height: 4px; background: var(--sep-strong); border-radius: 4px; margin-top: 9px; overflow: hidden; }
.gauge-bar > i { display: block; height: 100%; border-radius: 4px; background: var(--green); }
.gauge-bar > i.warn { background: var(--orange); }
.gauge-bar > i.bad { background: var(--red); }

/* --------------------------------------------------------------- Modale */

.sheet-modal {
  border: 0; border-radius: var(--r-lg); padding: 0;
  background: var(--surface); color: var(--text); width: min(430px, 92vw);
  box-shadow: var(--shadow-2);
}
.sheet-modal::backdrop { background: rgba(0, 0, 0, .28); backdrop-filter: blur(2px); }
[data-theme="dark"] .sheet-modal::backdrop { background: rgba(0, 0, 0, .6); }
.sheet-modal form { padding: 24px; display: flex; flex-direction: column; gap: 15px; }
.sheet-modal h3 { font-size: 18px; font-weight: 650; letter-spacing: -.01em; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--text-2); font-weight: 520; }
.field input, .field select {
  padding: 10px 12px; background: var(--surface-2); border: 1px solid transparent;
  border-radius: var(--r-xs); outline: none; font-size: 14px;
}
.field input:focus, .field select:focus { border-color: var(--blue); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 18%, transparent); }
.field .hint { font-size: 11.5px; color: var(--text-3); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.checkline input { width: 16px; height: 16px; accent-color: var(--blue); }

.seg { display: flex; gap: 2px; padding: 2px; background: var(--gray-soft); border-radius: var(--r-sm); }
.seg button { flex: 1; padding: 8px; border: 0; border-radius: 10px; background: transparent; color: var(--text-2); cursor: pointer; font-size: 13.5px; font-weight: 560; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* --------------------------------------------------------------- Toasts */

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  padding: 12px 16px; border-radius: var(--r-sm); background: var(--surface);
  box-shadow: var(--shadow-2); font-size: 13.5px; animation: sheet-in .16s ease-out; max-width: 320px;
}
.toast.bad { box-shadow: var(--shadow-2), inset 3px 0 0 var(--red); }
.toast.good { box-shadow: var(--shadow-2), inset 3px 0 0 var(--green); }

@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; }
  .search { width: 100%; order: 3; }
  main, .attention { padding-left: 16px; padding-right: 16px; }
  .sheet-panel { top: 0; right: 0; bottom: 0; left: 0; width: 100%; border-radius: 0; }
}
