:root {
  --bg: #f5f4f0; --surface: #fff; --ink: #1d1c1a; --ink-2: #45433f; --muted: #77746d; --line: #e3e0d8; --line-2: #eeece6;
  --accent: #c8102e; --accent-ink: #fff; --focus: #1f5fa8;
  --in: #1f5fa8; --in-bg: #e8f0fa; --out: #2c7a4b; --out-bg: #e6f3eb; --int: #7a5c1f; --int-bg: #f6efdf;
  --open: #9a5b00; --open-bg: #fdf1dc; --closed: #5f5d57; --closed-bg: #ecebe6;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); }
a { color: inherit; }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
.approx { color: var(--open); cursor: help; }

/* ---------- top bar ---------- */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.logo img { height: 28px; display: block; }
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1 1 auto; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.crumbs > * { overflow: hidden; text-overflow: ellipsis; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--ink); text-decoration: underline; }
.crumbs > * + *::before { content: "›"; margin-right: 6px; color: var(--line); }
.crumbs span:last-child { color: var(--ink); font-weight: 600; }
.top-search { position: relative; flex: 0 1 420px; display: flex; align-items: center; }
.top-search svg { position: absolute; left: 11px; width: 17px; height: 17px; fill: none; stroke: var(--muted); stroke-width: 2; }
.top-search input[type=search] { width: 100%; height: 38px; padding: 0 34px 0 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font: inherit; }
.top-search input:focus { background: #fff; border-color: var(--focus); outline: none; }
.top-search kbd { position: absolute; right: 9px; font: 12px var(--font); color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.user-menu { position: relative; }
.user-menu summary { list-style: none; cursor: pointer; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--ink); color: #fff; font-size: 13px; font-weight: 600; }
.user-menu summary::-webkit-details-marker { display: none; }
.menu { position: absolute; right: 0; top: 42px; width: 260px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px; }
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line-2); margin-bottom: 4px; display: grid; }
.menu-head span { font-size: 13px; color: var(--muted); }
.menu a { display: block; padding: 8px 10px; border-radius: 6px; text-decoration: none; }
.menu a:hover { background: var(--bg); }

/* ---------- layout ---------- */
.page { max-width: 1320px; margin: 0 auto; padding: 24px 24px 48px; }
.page-wide { max-width: 1600px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 0 0 24px; }
.h1 { font-size: 26px; line-height: 1.2; margin: 0 0 4px; letter-spacing: -.01em; }
.h2 { font-size: 21px; line-height: 1.25; margin: 2px 0 6px; }
.h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 28px 0 10px; font-weight: 600; }
.sub { margin: 0; color: var(--muted); }
.empty { padding: 32px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--out-bg); color: var(--out); }
.flash-blad { background: #fbe9ea; color: #a1121f; }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: 600 14px var(--font); text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--ink-2); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #000; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], select, textarea {
  font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 8px 10px; min-height: 38px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(31,95,168,.12); }
textarea { resize: vertical; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.form label small { font-weight: 400; color: var(--muted); }
.form label.inline { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.form-narrow { max-width: 640px; background: var(--surface); padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.drop input { padding: 18px; border: 2px dashed var(--line); border-radius: 8px; background: var(--bg); }

/* ---------- home ---------- */
.sites { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-top: 18px; }
.site { display: grid; gap: 6px; padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; box-shadow: var(--shadow); border-top: 3px solid var(--accent); }
.site:hover { border-color: var(--ink-2); border-top-color: var(--accent); }
.site-off { border-top-color: var(--line); opacity: .8; }
.site-name { font-size: 19px; font-weight: 700; }
.site-inv { color: var(--muted); font-size: 14px; }
.site-stats { display: flex; gap: 18px; margin-top: 6px; color: var(--ink-2); }
.site-last { font-size: 13px; color: var(--muted); }

/* ---------- site head & tabs ---------- */
.site-head, .case-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 16px 0 16px; }
.tabs a { padding: 9px 14px; text-decoration: none; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); }
.tabs a:hover { color: var(--ink); }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters .f-q { flex: 1 1 320px; height: 42px; font-size: 16px; }
.filters select { width: auto; max-width: 260px; min-width: 0; }
.f-date { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.f-date input { width: 150px; }
.list-bar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 14px 2px 8px; font-size: 14px; color: var(--ink-2); }
.list-bar-r { display: flex; gap: 16px; }

/* ---------- journal table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.journal { width: 100%; border-collapse: collapse; }
.journal th { text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 12px; background: #faf9f6; border-bottom: 1px solid var(--line); }
.journal td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.journal tbody tr { position: relative; }
.journal tbody tr:hover { background: #fbfaf7; }
.journal tbody tr:last-child td { border-bottom: 0; }
.journal tr.is-hidden { opacity: .55; }
.row-link { position: absolute; inset: 0; }
.journal td a:not(.row-link) { position: relative; z-index: 1; }
.c-date { white-space: nowrap; width: 96px; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.c-dir { width: 82px; }
.c-party { width: 180px; color: var(--ink-2); font-size: 14px; }
.c-site { width: 150px; font-size: 14px; }
.c-case { width: 230px; }
.c-ldz { width: 70px; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.c-files { width: 44px; text-align: right; color: var(--muted); }
.c-title .t { display: block; font-weight: 600; text-decoration: none; }
.c-title .t:hover { text-decoration: underline; }
.about { display: block; color: var(--muted); font-size: 14px; margin-top: 2px; }
.dir { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.dir-in { color: var(--in); background: var(--in-bg); }
.dir-out { color: var(--out); background: var(--out-bg); }
.dir-int { color: var(--int); background: var(--int-bg); }
.dir-none { color: var(--muted); }
.chip { display: inline-block; max-width: 100%; font-size: 13px; padding: 2px 8px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); text-decoration: none; line-height: 1.35; }
.chip:hover { border-color: var(--ink-2); }
.chip-closed { color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; color: var(--muted); }
.pager a { font-weight: 600; color: var(--ink); }

/* ---------- cases ---------- */
.cases-bar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.seg a { padding: 6px 12px; border-radius: 6px; text-decoration: none; font-size: 14px; color: var(--ink-2); }
.seg a b { color: var(--muted); font-weight: 600; margin-left: 4px; }
.seg a.on { background: var(--ink); color: #fff; }
.seg a.on b { color: #ddd; }
.cases-search input { width: 280px; }
.cases { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 12px; }
.case { display: grid; gap: 6px; align-content: start; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; box-shadow: var(--shadow); }
.case:hover { border-color: var(--ink-2); }
.case-closed { background: #fbfbf9; }
.case-closed .case-title { color: var(--ink-2); }
.case-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.case-title { font-weight: 700; font-size: 16px; }
.case-desc { color: var(--ink-2); font-size: 14px; }
.case-meta { color: var(--muted); font-size: 13px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.badge-open { color: var(--open); background: var(--open-bg); }
.badge-closed { color: var(--closed); background: var(--closed-bg); }
.new-case { display: flex; gap: 8px; margin-top: 18px; max-width: 720px; }

/* ---------- case page ---------- */
.case-head .badge { margin-bottom: 6px; }
.summary { margin-top: 18px; padding: 16px 20px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius); max-width: 980px; }
.summary .h3 { margin-top: 0; }
.summary p { margin: 0; font-size: 16px; }
.edit { margin-top: 12px; }
.edit summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.edit .form { margin-top: 12px; }
.timeline { list-style: none; margin: 0; padding: 0; max-width: 980px; }
.tl-year { font-weight: 700; color: var(--muted); margin: 18px 0 6px 0; padding-left: 0; }
.tl-item { display: grid; grid-template-columns: 70px 22px 1fr; align-items: start; }
.tl-date { padding-top: 14px; font-size: 13px; color: var(--muted); text-align: right; padding-right: 8px; font-variant-numeric: tabular-nums; }
.tl-dot { position: relative; height: 100%; }
.tl-dot::before { content: ""; position: absolute; left: 10px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.tl-dot::after { content: ""; position: absolute; left: 5px; top: 17px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--muted); }
.tl-przychodzace .tl-dot::after { border-color: var(--in); background: var(--in-bg); }
.tl-wychodzace .tl-dot::after { border-color: var(--out); background: var(--out-bg); }
.tl-card { display: grid; gap: 4px; margin: 6px 0; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; }
.tl-card:hover { border-color: var(--ink-2); }
.tl-wychodzace .tl-card { border-left: 3px solid var(--out); }
.tl-przychodzace .tl-card { border-left: 3px solid var(--in); }
.tl-meta { font-size: 13px; color: var(--muted); }
.tl-title { font-weight: 700; }
.tl-about { color: var(--ink-2); font-size: 14px; }
.tl-files { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--muted); }

/* ---------- document page ---------- */
.doc-head { display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: start; margin-bottom: 14px; }
.back { text-decoration: none; color: var(--muted); padding-top: 4px; white-space: nowrap; }
.back:hover { color: var(--ink); }
.doc-meta { font-size: 13px; color: var(--muted); }
.about-lg { margin: 0; color: var(--ink-2); font-size: 15px; max-width: 900px; }
.doc-nav { display: flex; gap: 14px; font-size: 14px; white-space: nowrap; padding-top: 4px; }
.doc { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.doc-view { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.doc-side { position: sticky; top: 70px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; max-height: calc(100vh - 90px); overflow: auto; }
.file-tabs { display: flex; gap: 2px; overflow-x: auto; background: #faf9f6; border-bottom: 1px solid var(--line); padding: 6px 6px 0; }
.file-tabs a { padding: 8px 12px; font-size: 13px; text-decoration: none; color: var(--muted); border-radius: 6px 6px 0 0; white-space: nowrap; }
.file-tabs a.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 -1px 0 var(--line) inset; border: 1px solid var(--line); border-bottom-color: var(--surface); margin-bottom: -1px; }
.pdf-view { display: block; width: 100%; height: calc(100vh - 230px); min-height: 520px; border: 0; background: #525659; }
.img-view { display: block; margin: 0 auto; max-height: calc(100vh - 230px); }
.no-preview { padding: 48px 24px; text-align: center; color: var(--muted); }
.file-foot { margin: 0; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 14px; }
.mail { padding: 18px 22px; }
.mail-head { display: grid; grid-template-columns: 64px 1fr; gap: 4px 10px; margin: 0 0 12px; font-size: 14px; }
.mail-head dt { color: var(--muted); }
.mail-head dd { margin: 0; word-break: break-word; }
.mail-att { list-style: none; padding: 10px 12px; margin: 0 0 14px; background: var(--bg); border-radius: 8px; display: grid; gap: 4px; font-size: 14px; }
.mail-body { white-space: pre-wrap; word-break: break-word; font: 15px/1.55 var(--font); margin: 0; max-height: calc(100vh - 320px); overflow: auto; }
.facts { display: grid; grid-template-columns: 80px 1fr; gap: 6px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.related ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.related a { text-decoration: none; }
.related a:hover { text-decoration: underline; }
.related time { color: var(--muted); margin-right: 4px; font-variant-numeric: tabular-nums; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 14px; padding: 28px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.login-card label { display: grid; gap: 4px; font-weight: 600; font-size: 14px; }
.login-logo { height: 34px; justify-self: start; }
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login ~ .foot { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .doc { grid-template-columns: 1fr; }
  .doc-side { position: static; max-height: none; }
  .c-party { width: 140px; }
  .c-case { width: 180px; }
}
@media (max-width: 760px) {
  .top { padding: 8px 16px; gap: 10px; flex-wrap: wrap; }
  .crumbs { order: 3; flex-basis: 100%; }
  .top-search { flex: 1 1 auto; }
  .top-search kbd { display: none; }
  .page { padding: 16px 16px 40px; }
  .h1 { font-size: 22px; }
  .filters select, .f-date { flex: 1 1 45%; max-width: 100%; width: auto; min-width: 0; }
  .f-date input { flex: 1; min-width: 0; width: auto; }
  .filters .f-q { flex-basis: 100%; }
  .journal thead { display: none; }
  .journal, .journal tbody, .journal tr, .journal td { display: block; width: auto; }
  .journal tr { display: grid; grid-template-columns: auto auto 1fr auto; gap: 4px 8px; padding: 12px 14px; border-bottom: 1px solid var(--line-2); }
  .journal td { padding: 0; border: 0; }
  .journal .c-title { grid-column: 1 / -1; order: 5; }
  .journal .c-case { grid-column: 1 / -1; order: 6; }
  .journal .c-party { grid-column: 3; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .journal .c-ldz:empty { display: none; }
  .journal .c-ldz { order: 4; }
  .dir span { display: none; }
  .doc-head { grid-template-columns: 1fr; }
  .cases { grid-template-columns: 1fr; }
  .cases-search, .cases-search input { width: 100%; }
  .new-case { flex-direction: column; }
  .row2 { grid-template-columns: 1fr; }
  .tl-item { grid-template-columns: 52px 18px 1fr; }
  .tl-dot::before { left: 8px; } .tl-dot::after { left: 3px; }
}
