/* Barwy SPIE (jak aplikacja iOS, vutlan-ios/docs/identyfikacja-wizualna.md): GRANAT to marka
   (pasek, karta podsumowania w normie, przyciski), kolory stanow tylko dla stanow. Czerwieni
   SPIE nie uzywamy - czerwony znaczy alarm. Kolory tekstu stanow maja kontrast >= 4,5:1 na
   tle kart w obu trybach; stan zawsze ma tez KSZTALT (ikona), nie tylko kolor.
   Wytyczne grupy (14.10, vutlan-ios/docs/identyfikacja-wizualna.md): kroj Jost (zamiennik tylko
   Arial), logo tylko proporcjonalnie i bez zmian kolorow, czerwien marki #CC0000 tylko w logo. */
/* Jost lokalnie (czcionka zmienna 400-700, lacina + polskie znaki) - bez Google Fonts CDN:
   zero zapytan do zewnetrznych serwerow, dziala offline w PWA. Licencja SIL OFL. */
@font-face {
  font-family: "Jost"; src: url("jost.woff2") format("woff2");
  font-weight: 100 900; font-style: normal; font-display: swap;
}
:root {
  color-scheme: light dark;
  --navy: #0F1E5A;
  --brand-grad: linear-gradient(135deg, #0F1E5A, #20388B);
  --warn-grad: linear-gradient(135deg, #b45309, #92400e);
  --alarm-grad: linear-gradient(135deg, #b91c1c, #8f1414);
  --on-brand: #fff;

  --bg: #f2f3f7; --surface: #fff; --surface-2: #eef0f6; --text: #0b1020; --dim: #5b6070;
  --sep: rgb(15 30 90 / .12); --accent: #0F1E5A; --on-accent: #fff;
  --ok: #1a7f37; --warn: #b45309; --alarm: #c8102e; --off: #5f6473;
  --shadow: 0 1px 2px rgb(15 30 90 / .06), 0 4px 16px rgb(15 30 90 / .06);
  --radius: 18px;

  @media (prefers-color-scheme: dark) {
    --bg: #0b0d14; --surface: #171a26; --surface-2: #222636; --text: #f1f2f6; --dim: #a3a8b8;
    --sep: rgb(255 255 255 / .09); --accent: #738BE7; --on-accent: #0b1020;
    --ok: #3ddc6a; --warn: #ffa53d; --alarm: #ff6b5e; --off: #9aa0b0;
    --shadow: none;
  }
  accent-color: var(--accent);
}
html { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
*, *::before, *::after { box-sizing: inherit; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 16px/1.4 "Jost", Arial, sans-serif;
  font-feature-settings: "tnum" 0;
  overscroll-behavior-y: contain;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
button, input { font-family: inherit; }
.val, .chip, .when, .chg, .legend, .badge, .cnt { font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.ic { width: 1.25em; height: 1.25em; flex: none; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.st-normal { color: var(--ok); } .st-warning { color: var(--warn); } .st-alarm { color: var(--alarm); }
.st-off, .st-unknown, .st-offline { color: var(--off); }
.dim { color: var(--dim); } .small { font-size: 13px; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- pasek marki */
header {
  position: sticky; top: 0; z-index: 20; color: var(--on-brand); background: var(--brand-grad);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 12px;
  display: flex; align-items: center; gap: 12px;
  & .brand { flex: 1; min-width: 0; }
  /* logo tylko proporcjonalnie (wysokosc, szerokosc auto) - wytyczne: bez znieksztalcen */
  & .logo { height: 40px; width: auto; flex: none; margin-right: 4px; }
  & .org { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; opacity: .78; }
  & h1 { font-size: 21px; font-weight: 750; margin: 0; letter-spacing: -.02em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  & #status { font-size: 12px; opacity: .85; }
  & .iconbtn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
    background: rgb(255 255 255 / .14); }
  & .iconbtn:hover { background: rgb(255 255 255 / .22); }
}
main { padding: 16px 16px 28px; max-width: 900px; margin: 0 auto; container-type: inline-size; }

/* ------------------------------------------------------------------ karty */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; margin-bottom: 14px; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; }
.row:not(:last-child) { border-bottom: 1px solid var(--sep); }
a.row:hover { background: var(--surface-2); }
/* Karta urzadzenia: obwodka zamiast tla - tlo w kolorze pigulek zlewalo je z karta */
a.dev:hover { box-shadow: var(--shadow), 0 0 0 2px var(--sep); }
.grow { flex: 1; min-width: 0; }
.t { display: block; font-weight: 600; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; }
.s { display: block; font-size: 13px; color: var(--dim); }
.val { font-variant-numeric: tabular-nums; font-weight: 650; font-size: 17px; white-space: nowrap; }
.chev { color: var(--dim); width: 18px; height: 18px; }
h2.sec { font-size: 13px; font-weight: 650; letter-spacing: .02em; color: var(--dim);
  margin: 22px 6px 8px; }
.empty { text-align: center; color: var(--dim); padding: 48px 20px;
  & .ic { width: 44px; height: 44px; color: var(--ok); margin-bottom: 8px; } }

/* Podsumowanie stanu - jak PodsumowanieStanu w aplikacji iOS */
.summary { color: var(--on-brand); background: var(--brand-grad); border-radius: 22px;
  padding: 18px 20px; margin-bottom: 18px; display: grid; grid-template-columns: auto 1fr;
  gap: 4px 14px; align-items: center;
  &.warning { background: var(--warn-grad); } &.alarm { background: var(--alarm-grad); }
  & .ic { width: 38px; height: 38px; grid-row: span 2; }
  & .title { font-size: 20px; font-weight: 750; letter-spacing: -.01em; }
  & .sub { font-size: 13px; opacity: .88; }
}

/* Karty urzadzen: jedna kolumna, dwie gdy jest miejsce (container query, fallback = 1 kolumna) */
.devgrid { display: grid; gap: 12px; }
@container (min-width: 620px) { .devgrid { grid-template-columns: 1fr 1fr; } }
.dev { display: flex; gap: 12px; padding: 15px 16px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); border-inline-start: 5px solid transparent;
  &:has(.head .st-warning) { border-inline-start-color: var(--warn); }
  &:has(.head .st-alarm, .head .st-offline) { border-inline-start-color: var(--alarm); }
  & .head { display: flex; align-items: center; gap: 8px; }
  & .name { font-weight: 650; font-size: 17px; letter-spacing: -.01em; }
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip { font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2);
  font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 5px;
  & b { font-weight: 650; } }
.badge { font-size: 12px; font-weight: 750; min-width: 24px; text-align: center; padding: 3px 8px;
  border-radius: 999px; color: #fff; align-self: center;
  &.alarm { background: var(--alarm); } &.warning { background: var(--warn); } }
@media (prefers-color-scheme: dark) { .badge { color: #0b1020; } }

/* ------------------------------------------------------------- nawigacja */
nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30; display: flex;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--sep); padding-bottom: env(safe-area-inset-bottom);
  & a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 8px 0 7px; color: var(--dim); font-size: 11px; font-weight: 550; position: relative; }
  & a .ic { width: 24px; height: 24px; }
  & a[aria-current="page"] { color: var(--accent); font-weight: 700; }
  & .cnt { position: absolute; top: 3px; left: 50%; margin-left: 6px; background: var(--alarm);
    color: #fff; font-size: 11px; font-weight: 750; padding: 1px 6px; border-radius: 9px; }
}

/* --------------------------------------------------- opis raportu (20.10) */
.opis { padding: 12px 16px; line-height: 1.5;
  & p { margin: 0 0 10px; } & ul { margin: 0 0 10px; padding-left: 20px; } & li { margin: 2px 0; }
  & > :last-child { margin-bottom: 0; } }

/* ------------------------------------------------------------ przyciski */
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  background: var(--accent); color: var(--on-accent); font-weight: 650; border-radius: 14px;
  padding: 14px; margin-top: 12px;
  &.sec { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
  &.danger { background: var(--surface); color: var(--alarm); box-shadow: var(--shadow); }
}
.seg { display: flex; padding: 4px; gap: 4px;
  & button { flex: 1; padding: 8px 0; border-radius: 10px; color: var(--dim); font-weight: 550; }
  & button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
}
input[type=password] { font: inherit; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--sep); border-radius: 12px; padding: 12px; width: 100%; }
.toggle { width: 51px; height: 31px; border-radius: 16px; background: var(--off); flex: none;
  position: relative; transition: background .2s;
  & i { position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .3); transition: translate .2s; }
  &[aria-pressed="true"] { background: var(--ok); & i { translate: 20px 0; } }
  &.busy { opacity: .5; }
}
.spin { width: 15px; height: 15px; border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: sp .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes sp { to { rotate: 360deg; } }
@media (prefers-reduced-motion: reduce) {
  .spin { animation-duration: 3s; }
  .toggle, .toggle i { transition: none; }
}

/* ---------------------------------------------------------------- logowanie */
#login { min-height: 100dvh; padding: calc(env(safe-area-inset-top) + 9vh) 20px 40px;
  max-width: 440px; margin: 0 auto; }
.brandcard { color: var(--on-brand); background: var(--brand-grad); border-radius: 24px; padding: 24px;
  & .logo { height: 60px; width: auto; display: block; }
  & .name { font-size: 22px; font-weight: 600; margin-top: 16px; }
  & .org { font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; opacity: .8; }
  & p { font-size: 14px; opacity: .88; margin: 12px 0 0; }
}
details.alt { margin-top: 22px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px;
  & summary { cursor: pointer; font-weight: 600; }
  & p { margin: 10px 0; }
}
.err { color: var(--alarm); text-align: center; font-size: 14px; }
/* Formularz administracji */
.form { padding: 14px 16px 16px;
  & h3 { font-size: 13px; font-weight: 650; color: var(--dim); margin: 18px 0 6px; }
  & .pole { display: block; margin: 10px 0; }
  & .pole span { display: block; font-size: 13px; color: var(--dim); margin-bottom: 4px; }
  & .pole input { font: inherit; width: 100%; padding: 11px 12px; border-radius: 12px; color: var(--text);
    background: var(--surface-2); border: 1px solid var(--sep); }
  & .pole input[readonly] { color: var(--dim); }
  & .pole input:user-invalid { border-color: var(--alarm); }
  & code { font-size: 12px; word-break: break-all; }
  & .kontakt { border-top: 1px solid var(--sep); padding-top: 6px; margin-top: 10px; }
  & .test { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
  & .test p { margin: 4px 0; display: flex; gap: 6px; align-items: flex-start; flex-wrap: wrap; }
  & .potw { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; margin-top: 8px; }
  & .potw input { margin-top: 3px; flex: none; }
  &[inert] { opacity: .75; }
}
button.link { color: var(--accent); font-weight: 600; padding: 8px 0; font-size: 14px;
  &.danger { color: var(--alarm); } }
.langs { display: flex; justify-content: center; gap: 4px; margin-top: 18px;
  & button { padding: 8px 12px; border-radius: 10px; color: var(--dim); font-size: 14px; }
  & button[aria-pressed="true"] { color: var(--accent); font-weight: 650; } }

/* ------------------------------------------------------------- szczegoly */
.sheet-head { display: flex; align-items: center; gap: 10px; margin: 2px 6px 4px;
  & .big { font-size: 26px; font-weight: 750; letter-spacing: -.02em; flex: 1; }
  & .ic { width: 28px; height: 28px; } }
svg.chart { width: 100%; height: 160px; display: block; }
.legend { display: flex; justify-content: space-between; padding: 0 16px 12px; font-size: 12px; color: var(--dim); }
pre.raw { padding: 14px; margin: 0; overflow-x: auto; font-size: 11px; white-space: pre-wrap; word-break: break-all; }

/* Zdarzenia */
.filters { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 0 6px 14px; font-size: 14px;
  & label { display: inline-flex; align-items: center; gap: 6px; color: var(--dim); } }
.ev { align-items: flex-start;
  & > .ic { width: 24px; height: 24px; margin-top: 1px; }
  & .top { display: flex; gap: 8px; align-items: baseline; }
  & .top .t { flex: 1; white-space: normal; }
  & .when { font-size: 13px; color: var(--dim); font-variant-numeric: tabular-nums; }
  & .chg { font-size: 14px; color: var(--dim); font-variant-numeric: tabular-nums; }
  & .chg b { color: var(--text); }
}

@media (forced-colors: active) {
  header, .summary, .brandcard, .card, .dev, .btn { border: 1px solid CanvasText; }
}
