:root {
  --bg: #0b0f17;
  --bg-2: #121826;
  --bg-3: #1a2336;
  --border: #232f47;
  --border-soft: #1c2741;
  --text: #e6ecf5;
  --muted: #8595b0;
  --accent: #4f8cff;
  --accent-2: #6ea8ff;
  --sev1: #4a90d9;
  --sev2: #e6a13a;
  --sev3: #e0524b;
  --green: #34c77b;

  /* System designu */
  --radius: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --shadow-1: 0 1px 2px rgba(0,0,0,.25);
  --shadow-2: 0 14px 40px -16px rgba(0,0,0,.65);
  --shadow-glow: 0 0 24px -4px rgba(79,140,255,.35);
  --ease: cubic-bezier(.22,.61,.36,1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01";
  letter-spacing: -0.005em;
}
::selection { background: rgba(79,140,255,.32); color: #fff; }

/* ---------- Płynne przejścia między stronami ---------- */
/* Cross-document View Transitions: przeglądarki wspierające (Chromium)
   przenikają płynnie między np. stroną główną a logowaniem/rejestracją. */
@view-transition { navigation: auto; }

::view-transition-old(root) { animation: page-out .26s var(--ease) both; }
::view-transition-new(root) { animation: page-in .36s var(--ease) both; }
@keyframes page-out { to { opacity: 0; transform: translateY(-8px) scale(.995); } }
@keyframes page-in  { from { opacity: 0; transform: translateY(10px) scale(.995); } }

/* Fallback dla przeglądarek bez View Transitions: delikatne wejście strony. */
@supports not (view-transition-name: none) {
  @media (prefers-reduced-motion: no-preference) {
    body { animation: page-in .42s var(--ease) both; }
  }
}

/* Poszanowanie preferencji ograniczenia ruchu. */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none !important; }
  body { animation: none !important; }
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); font-size: 12px; }

/* ---------- AUTH ---------- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh;
  position: relative; overflow: hidden; }
.auth-page::before { content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(700px 460px at 50% -8%, rgba(79,140,255,.28), transparent 60%),
    linear-gradient(rgba(79,140,255,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79,140,255,.045) 1px, transparent 1px);
  background-size: auto, 46px 46px, 46px 46px;
  mask-image: radial-gradient(ellipse 90% 70% at 50% 30%, #000 40%, transparent 85%); }
.auth-card {
  position: relative; z-index: 1; width: 380px;
  background: linear-gradient(180deg, rgba(22,30,46,.9), rgba(15,20,32,.92));
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 38px 32px; box-shadow: var(--shadow-2);
  backdrop-filter: blur(10px);
}
.auth-card::before { content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1px;
  background: linear-gradient(140deg, rgba(79,140,255,.35), transparent 45%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude; pointer-events: none; }
.auth-brand { text-align: center; margin-bottom: 26px; }
.auth-brand .logo-dot { width: 48px; height: 48px; }
.auth-brand h1 { font-size: 22px; margin: 12px 0 4px; font-weight: 800; letter-spacing: -.5px; }
.logo-dot {
  display: inline-block; width: 26px; height: 26px; flex: none; vertical-align: middle;
  background: currentColor;
  -webkit-mask: url(/static/logo.svg) center / contain no-repeat;
  mask: url(/static/logo.svg) center / contain no-repeat; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form label { display: flex; flex-direction: column; gap: 7px; font-size: 12.5px; color: var(--muted);
  letter-spacing: .2px; }
.auth-form .btn-primary { margin-top: 4px; height: 46px; }
input, select {
  background: rgba(10,14,22,.7); border: 1px solid var(--border); color: var(--text);
  padding: 12px 14px; border-radius: 10px; font-size: 14px; outline: none;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease); }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,140,255,.18); }
.btn {
  cursor: pointer; border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 15px; font-size: 13px; background: var(--bg-3); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  line-height: 1; text-decoration: none; font-weight: 500;
  transition: background .2s var(--ease), border-color .2s var(--ease),
    transform .2s var(--ease), box-shadow .2s var(--ease), filter .2s var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: rgba(18,24,38,.85); backdrop-filter: blur(8px);
  border-color: var(--sev2); color: var(--sev2); font-weight: 600;
}
.btn-primary:hover { background: var(--sev2); color: #1a1206; transform: translateY(-1px);
  box-shadow: 0 0 22px rgba(230,161,58,.45); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-3); border-color: #34456b; transform: translateY(-1px); }
.auth-switch { text-align: center; margin-top: 18px; font-size: 13px; color: var(--muted); }
.auth-home { width: 100%; margin-top: 14px; height: 42px; color: var(--muted); }
.auth-home:hover { color: var(--text); }
.alert { background: rgba(224,82,75,.15); border: 1px solid var(--sev3); color: #ffb3ae;
  padding: 10px 12px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }

/* ---------- TOPBAR ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 13px 24px; background: rgba(18,24,38,.75); backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.live-badge { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700;
  color: var(--green); letter-spacing: .5px; }
.live-pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--green);
  animation: pulse 1.6s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(52,199,123,.6)} 70%{box-shadow:0 0 0 8px rgba(52,199,123,0)} 100%{box-shadow:0 0 0 0 rgba(52,199,123,0)} }

/* ---------- STATS ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; padding: 18px 22px 4px; }
.stat-card { position: relative; background: linear-gradient(180deg, var(--bg-2), rgba(18,24,38,.6));
  border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; overflow: hidden;
  transition: transform .2s var(--ease), border-color .2s var(--ease); }
.stat-card::before { content: ""; position: absolute; top: 0; left: 0; width: 3px; height: 100%;
  background: linear-gradient(180deg, var(--accent), transparent); opacity: .8; }
.stat-card:hover { transform: translateY(-2px); border-color: #2e3c5a; }
.stat-card .num { font-size: 27px; font-weight: 800; letter-spacing: -.5px; }
.stat-card .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-card.high .num { color: var(--sev3); }

/* ---------- LAYOUT ---------- */
.layout { display: grid; grid-template-columns: 240px 1fr; gap: 18px; padding: 18px 22px; }
.sidebar h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted);
  margin: 18px 0 8px; }
.sidebar h3:first-child { margin-top: 0; }
.cat-filter { list-style: none; margin: 0; padding: 0; }
.cat-filter li { display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.cat-filter li:hover { background: var(--bg-2); color: var(--text); }
.cat-filter li.active { background: var(--bg-3); color: var(--text); font-weight: 600; }
.count { background: var(--bg-3); border-radius: 10px; padding: 1px 8px; font-size: 11px; color: var(--muted); }
.cat-filter li.active .count { background: var(--accent); color: #fff; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; background: var(--bg-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; padding: 7px; cursor: pointer; font-size: 12px; }
.seg button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
#search { width: 100%; }

/* ---------- FEED ---------- */
.feed { min-width: 0; }   /* pozwala kolumnie kurczyc sie -> brak poziomego paska */
.feed-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.feed-head h2 { font-size: 18px; margin: 0; }
.incident-list { display: flex; flex-direction: column; gap: 10px; }
.incident {
  background: var(--bg-2); border: 1px solid var(--border); border-left-width: 4px;
  border-radius: 10px; padding: 14px 16px; transition: transform .08s;
  min-width: 0; overflow: hidden;
}
.incident:hover { transform: translateX(2px); border-color: #2e3c5a; }
.incident.sev-1 { border-left-color: var(--sev1); }
.incident.sev-2 { border-left-color: var(--sev2); }
.incident.sev-3 { border-left-color: var(--sev3); }
.incident .title { font-size: 15px; font-weight: 600; margin: 0 0 6px; line-height: 1.35;
  overflow-wrap: anywhere; }
.incident .title a { color: var(--text); }
.incident .meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 11px; color: var(--muted); }
.tag { background: var(--bg-3); padding: 2px 8px; border-radius: 6px; font-size: 11px; }
.tag.cat { background: rgba(79,140,255,.18); color: #9cc0ff; }
.tag.sev-3 { background: rgba(224,82,75,.18); color: #ff9a94; }
.tag.sev-2 { background: rgba(230,161,58,.18); color: #ffce86; }
.tag.country { background: rgba(52,199,123,.15); color: #8be6b6; }
.incident .summary { color: var(--muted); font-size: 13px; margin: 8px 0 0; line-height: 1.5;
  overflow-wrap: anywhere; overflow: hidden;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.incident .summary.expanded { display: block; -webkit-line-clamp: unset; }
.more-btn { background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: 12px; font-weight: 600; padding: 6px 0 0; }
.more-btn:hover { text-decoration: underline; }
.loading { padding: 30px; text-align: center; }
.empty-hint { margin: 0 22px 22px; padding: 16px; background: var(--bg-2);
  border: 1px dashed var(--border); border-radius: 10px; color: var(--muted); font-size: 13px; }

/* ---------- ADMIN ---------- */
.admin-table { width: 100%; border-collapse: collapse; background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.admin-table th, .admin-table td { padding: 11px 14px; text-align: left; font-size: 13px;
  border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table th { background: var(--bg-3); color: var(--muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: .5px; }
.admin-table tr:last-child td { border-bottom: none; }
.badge { padding: 2px 9px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge.ok { background: rgba(52,199,123,.18); color: #8be6b6; }
.badge.wait { background: rgba(230,161,58,.18); color: #ffce86; }
.badge.no { background: rgba(224,82,75,.18); color: #ff9a94; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions form { margin: 0; }
.btn-sm { cursor: pointer; border: 1px solid var(--border); background: var(--bg-3);
  color: var(--text); border-radius: 6px; padding: 5px 10px; font-size: 12px; }
.btn-sm:hover { filter: brightness(1.15); }
.btn-sm.ok { background: var(--green); border-color: var(--green); color: #04210f; font-weight: 600; }
.btn-sm.no { background: transparent; border-color: var(--sev3); color: #ff9a94; }

/* ---------- Strzalka "do gory" (globalna: landing + panel) ---------- */
.to-top {
  position: fixed; right: 28px; bottom: 28px; z-index: 60;
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(18,24,38,.85); backdrop-filter: blur(8px);
  color: var(--sev2); border: 1px solid var(--sev2); cursor: pointer;
  font-size: 20px; line-height: 1; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-2);
  opacity: 0; visibility: hidden; transform: translateY(12px) scale(.9);
  transition: opacity .28s var(--ease), transform .28s var(--ease), visibility .28s, background .15s, color .15s;
}
.to-top.show { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.to-top:hover { background: var(--sev2); color: #1a1206; box-shadow: 0 0 22px rgba(230,161,58,.5); }
@media (max-width: 560px) { .to-top { right: 16px; bottom: 16px; width: 44px; height: 44px; } }

/* ====================== RESPONSYWNOSC / MOBILE ====================== */

/* Kontener z poziomym scrollem dla szerokich tabel (panel admina) */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 820px) {
  /* Panel: sidebar laduje nad feedem */
  .layout { grid-template-columns: 1fr; padding: 14px; gap: 16px; }

  /* Topbar: zawijanie i mniejsze odstepy */
  .topbar { padding: 10px 14px; gap: 8px 10px; flex-wrap: wrap; }
  .topbar-left { gap: 8px; }
  .topbar-left strong { font-size: 14px; }
  .topbar-right { gap: 8px; flex-wrap: wrap; }
  #last-update { display: none; }            /* oszczedza miejsce w waskim pasku */

  /* Kategorie jako kompaktowe "chipy" zamiast dlugiej pionowej listy */
  .sidebar h3 { margin: 14px 0 6px; }
  .cat-filter { display: flex; flex-wrap: wrap; gap: 6px; }
  .cat-filter li { width: auto; padding: 6px 11px; }

  /* Statystyki: 2 kolumny */
  .stats { grid-template-columns: 1fr 1fr; padding: 14px 14px 0; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card .num { font-size: 22px; }

  /* Tabela admina: poziomy scroll, nie rozpycha ekranu */
  .admin-table { min-width: 660px; }

  /* Logowanie/rejestracja: karta na cala szerokosc */
  .auth-page { padding: 16px; }
  .auth-card { width: 100%; max-width: 420px; padding: 30px 22px; }
}

@media (max-width: 480px) {
  .topbar-right .muted { max-width: 130px; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; }
  .feed-head h2 { font-size: 16px; }
  .incident { padding: 12px 13px; }
  .incident .title { font-size: 14px; }
  .seg button { font-size: 11px; padding: 7px 5px; }
  .stat-card .num { font-size: 20px; }
}
