/* Kartoteka kontaktów – ten sam system wizualny co drzewo genealogiczne, z granatowym akcentem */
:root {
  --accent: #2C4A6E;
  --ground: #F6F4EF;
  --surface: #FFFFFF;
  --surface-2: #FBFAF7;
  --ink: #1F2A24;
  --ink-2: #2E3832;
  --muted: #4A544E;
  --muted-2: #5C665F;
  --line: #DDD8CC;
  --line-2: #ECE8DE;
  --line-strong: #CFC9BB;
  --ochre: #8A5A14;
  --chip: #F1EEE6;
  --sel: #EEF2F7;
  --star: #B7791F;
  --danger: #A3321C;
  --ok-bg: #E3EEE8; --ok-ink: #1E3F31;
  --err-bg: #F8E3DD; --err-ink: #7A2412;
  --serif: 'Lora', Georgia, serif;
  --sans: 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font: 16px/1.5 var(--sans); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 6px; z-index: 50; }
.skip:focus { left: 8px; }
.ic { flex: none; }
.wrap { max-width: 1440px; margin: 0 auto; padding-left: 24px; padding-right: 24px; }
@media (max-width: 640px) { .wrap { padding-left: 16px; padding-right: 16px; } }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; }
h1 { font-size: clamp(26px, 4vw, 34px); letter-spacing: -.01em; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
.eyebrow { font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ochre); }
.hint { font-size: 14px; color: var(--muted); font-weight: 400; }
code { background: var(--chip); padding: 1px 6px; border-radius: 4px; font-size: .92em; }

/* ---------- górny pasek ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-row { display: flex; align-items: center; gap: 8px 28px; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); text-decoration: none; }
.brand span { font-family: var(--serif); font-weight: 700; font-size: 20px; color: var(--ink); white-space: nowrap; }
.tabs { display: flex; gap: 4px 22px; flex: 1 1 auto; flex-wrap: wrap; }
.tabs a { color: var(--muted); text-decoration: none; padding: 10px 0; min-height: 44px; display: inline-flex; align-items: center; gap: 8px; border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.tabs .count { font-size: 12px; font-weight: 600; background: var(--chip); color: var(--muted); border-radius: 99px; padding: 1px 8px; }
.menu { position: relative; }
.menu summary { list-style: none; display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; color: var(--ink-2); }
.menu summary::-webkit-details-marker { display: none; }
.menu .role-tag { font-size: 12px; color: var(--muted); }
/* od 2.4 w menu jest też „Listy” – na węższych ekranach chowamy podpis roli, żeby menu konta zostało w jednym wierszu */
@media (max-width: 1500px) { .menu .role-tag { display: none; } }
@media (max-width: 1360px) { .topbar-row { column-gap: 20px; } .tabs { column-gap: 16px; } }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(31,42,36,.14); min-width: 220px; padding: 6px; z-index: 30; display: flex; flex-direction: column; }
.menu-pop a, .menu-pop button { display: block; text-align: left; padding: 10px 12px; border-radius: 6px; color: var(--ink); text-decoration: none; background: none; border: 0; width: 100%; }
.menu-pop a:hover, .menu-pop button:hover, .menu-pop a.on { background: var(--chip); }
.menu-pop hr { border: 0; border-top: 1px solid var(--line-2); margin: 6px 0; }
@media (max-width: 760px) {
  .tabs { order: 3; flex-basis: 100%; }
  .menu { margin-left: auto; }
  .menu .who, .menu .role-tag { display: none; }
}

/* ---------- strona ---------- */
.page { padding-top: 24px; padding-bottom: 48px; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-head .titles { display: flex; flex-direction: column; gap: 4px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.foot { color: var(--muted-2); font-size: 13px; padding-bottom: 24px; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.box > h2 + * { margin-top: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.flash { padding: 12px 16px; border-radius: 8px; }
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash.err { background: var(--err-bg); color: var(--err-ink); }

/* ---------- przyciski ---------- */
.btn { min-height: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: #E3B9AE; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--chip); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.dropdown { position: relative; }
.dropdown summary { list-style: none; }
.dropdown summary::-webkit-details-marker { display: none; }
.dropdown .menu-pop { right: auto; left: 0; }
@media (max-width: 640px) { .dropdown .menu-pop { left: auto; right: 0; } }

/* ---------- pasek narzędzi listy ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 12px; background: var(--surface); flex: 1 1 280px; max-width: 460px; color: var(--muted-2); }
.search input[type=search] { border: 0 !important; outline: none; background: transparent !important; box-shadow: none !important; padding: 0 !important; height: 44px; min-height: 0 !important; flex: 1; min-width: 0; color: var(--ink); }
.search:focus-within { outline: 3px solid var(--accent); outline-offset: 1px; }
.toolbar select { height: 44px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); padding: 0 10px; max-width: 240px; }
.toolbar .info { margin-left: auto; color: var(--muted); font-size: 14px; }
.selbar { display: none; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--sel); border: 1px solid #CBD6E4; border-radius: 10px; padding: 8px 12px; }
.selbar.show { display: flex; }
.tolist-pop { min-width: 300px; padding: 14px; }
.tolist-pop .btn.primary, .tolist-pop .btn.primary:hover { display: inline-flex; width: auto; padding: 0 12px; background: var(--accent); color: #fff; border: 1px solid var(--accent); border-radius: 8px; }
.tolist-pop .hint:empty { display: none; }
.tolist-pop .hint a { color: var(--accent); font-weight: 600; }
.selbar strong { margin-right: 6px; }

/* ---------- tabela ---------- */
.table-box { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: auto; max-height: calc(100vh - 230px); }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 15px; }
table.data th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); text-align: left; font-size: 13px; font-weight: 600; color: var(--muted-2); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th button.sort { background: none; border: 0; padding: 0; font-weight: 600; color: inherit; display: inline-flex; gap: 4px; align-items: center; }
table.data th button.sort[aria-sort]::after { content: '↓'; }
table.data th button.sort[aria-sort="descending"]::after { content: '↑'; }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover td { background: #FAF9F5; }
table.data tbody tr.is-open td { background: var(--sel); }
table.data tbody tr.is-checked td { background: #F3F6FA; }
table.data td.chk, table.data th.chk { width: 44px; padding-right: 0; }
table.data input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
table.data .person { font-weight: 600; color: var(--ink); }
table.data .sub { display: block; font-size: 13.5px; color: var(--muted); font-weight: 400; }
table.data .nowrap { white-space: nowrap; }
table.data .clip { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.data .col-extra { display: none; }
table.data.all-cols .col-extra { display: table-cell; }
table.data.all-cols .col-compact { display: none; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.lp { color: var(--muted-2); font-size: 13px; font-variant-numeric: tabular-nums; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; padding: 2px 10px 2px 8px; border-radius: 99px; background: var(--chip); color: var(--ink-2); white-space: nowrap; }
.pill .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.star { width: 36px; height: 36px; border: 0; background: none; color: #B9B3A5; font-size: 20px; line-height: 1; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; }
.star.on { color: var(--star); }
.star:hover { background: var(--chip); }
.star[disabled] { cursor: default; background: none; }

/* tabela na telefonie: wiersze jako karty */
@media (max-width: 700px) {
  .table-box { max-height: none; overflow: visible; background: transparent; border: 0; }
  table.data, table.data tbody { display: block; }
  table.data thead { display: none; }
  table.data tbody tr { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 2px 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 8px 10px 10px; margin-bottom: 8px; }
  table.data td { display: none; border: 0; padding: 0; }
  table.data td.chk, table.data td.m-show { display: block; }
  table.data td.m-main { grid-column: 2; }
  table.data td.m-side { grid-column: 3; grid-row: 1; }
  table.data td.m-wide { grid-column: 2 / 4; }
  table.data.all-cols .col-extra { display: none; }
}

/* ---------- panel szczegółów ---------- */
.drawer-bg { position: fixed; inset: 0; background: rgba(20,24,22,.35); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .15s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); background: var(--surface); z-index: 41; transform: translateX(100%); visibility: hidden; transition: transform .2s ease, visibility 0s linear .2s; display: flex; flex-direction: column; }
.drawer.open { transform: none; visibility: visible; box-shadow: -10px 0 40px rgba(31,42,36,.18); transition: transform .2s ease; }
.drawer.open + .drawer-bg, .drawer-bg.open { opacity: 1; pointer-events: auto; }
.drawer-head { display: flex; align-items: flex-start; gap: 12px; padding: 20px 20px 12px; border-bottom: 1px solid var(--line-2); }
.drawer-head .titles { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.drawer-head h2 { font-size: 22px; overflow-wrap: anywhere; }
.drawer-body { padding: 8px 20px 20px; overflow: auto; flex: 1; }
.drawer-foot { padding: 12px 20px; border-top: 1px solid var(--line-2); display: flex; gap: 10px; flex-wrap: wrap; }
.facts { margin: 0; }
.facts div { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.facts dt { color: var(--muted-2); font-size: 14px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts dd.none { color: #A39E92; }
.facts .sect { display: block; padding: 16px 0 4px; border: 0; font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ochre); }
@media (max-width: 480px) { .facts div { grid-template-columns: 1fr; gap: 2px; } }

/* ---------- formularze ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px 18px; }
.form-grid .wide { grid-column: 1 / -1; }
label.f, .f { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.f .hint { font-size: 13px; }
input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]), select, textarea {
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-2); padding: 9px 12px; min-height: 44px; width: 100%; font-weight: 400; color: var(--ink);
}
textarea { min-height: 100px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(44,74,110,.18); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 500; color: var(--ink); font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.combo { display: flex; gap: 8px; }
.combo > select, .combo > input { flex: 1; min-width: 0; }
.addrow { display: none; gap: 8px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.addrow.show { display: flex; }
.addrow input { flex: 1 1 180px; }
.section-title { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ochre); margin: 8px 0 -4px; grid-column: 1 / -1; padding-top: 12px; border-top: 1px solid var(--line-2); }
.section-title:first-child { border-top: 0; padding-top: 0; }
.social-row { display: flex; gap: 8px; margin-bottom: 8px; }
.social-row select { flex: 0 0 150px; }
.social-row input { flex: 1; min-width: 0; }
@media (max-width: 480px) { .social-row { flex-wrap: wrap; } .social-row select { flex-basis: calc(100% - 52px); } }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatches label { position: relative; }
.swatches input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.swatches span { display: block; width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line-strong); cursor: pointer; }
.swatches input:checked + span { box-shadow: 0 0 0 2px var(--ink); }
.swatches input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.swatches input[type=color] { position: static; opacity: 1; width: 36px; height: 32px; padding: 0; border: 1px solid var(--line-strong); border-radius: 6px; background: none; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--ground) 30%); padding: 16px 0 8px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- listy w panelu admina ---------- */
.rows { display: flex; flex-direction: column; }
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 12px 0; border-top: 1px solid var(--line-2); }
.row:first-child { border-top: 0; }
.row .main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.tag.admin { background: #E3EAF3; color: #1E3550; }
.tag.ok { background: var(--ok-bg); color: var(--ok-ink); }
.tag.warn { background: #F6EBD7; color: #6B4510; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form input:not([type=checkbox]):not([type=color]), .inline-form select { width: auto; min-width: 160px; flex: 1 1 160px; }
details.more > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 14px; min-height: 36px; display: inline-flex; align-items: center; }
.perm-tab { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; background: var(--surface-2); }
.perm-tab legend { font-weight: 600; padding: 0 6px; }
.perm-sub.off { opacity: .45; }
.perm-sub { padding-left: 30px; display: flex; flex-direction: column; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.chips .check { min-height: 36px; font-size: 14.5px; }
table.list { width: 100%; border-collapse: collapse; font-size: 15px; }
table.list th { text-align: left; font-size: 13px; color: var(--muted-2); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.list td.when { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- instytucje ---------- */
.tag.bad { background: var(--err-bg); color: var(--err-ink); }
.meter { display: inline-block; width: 64px; height: 8px; border-radius: 99px; background: var(--line-2); overflow: hidden; vertical-align: middle; }
.meter > span { display: block; height: 100%; border-radius: 99px; }
.meter.hi > span { background: #3F7A5A; }
.meter.mid > span { background: #B7791F; }
.meter.lo > span { background: #A3321C; }
.meter-n { font-size: 13px; color: var(--muted); margin-left: 6px; font-variant-numeric: tabular-nums; }
.flagdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--star); margin-left: 6px; vertical-align: middle; }
.toolbar.wrap2 { row-gap: 8px; }
.toolbar label.check { min-height: 44px; font-size: 14.5px; }
.mail-row { display: grid; grid-template-columns: minmax(200px, 1.4fr) repeat(2, minmax(140px, 1fr)) auto auto; gap: 8px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line-2); }
.mail-row:first-child { border-top: 0; }
.mail-row .addr { font-weight: 600; overflow-wrap: anywhere; }
.mail-row .meta { font-size: 13px; color: var(--muted); font-weight: 400; display: block; }
@media (max-width: 760px) { .mail-row { grid-template-columns: 1fr 1fr; } .mail-row .addr { grid-column: 1 / -1; } }
.missing { display: flex; flex-wrap: wrap; gap: 6px; }
textarea.copy { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; min-height: 140px; }

/* ---------- logowanie ---------- */
body.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-box { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.auth-box p { margin: 0; }
.auth-brand { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.auth-brand span { font-family: var(--serif); font-weight: 700; font-size: 20px; color: var(--ink); }
.code-input { text-align: center; letter-spacing: .4em; font-size: 22px !important; font-variant-numeric: tabular-nums; }
.qr { display: flex; justify-content: center; padding: 12px; background: #fff; border: 1px solid var(--line-2); border-radius: 10px; min-height: 224px; align-items: center; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; letter-spacing: 1px; text-align: center; background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: 6px; padding: 10px; user-select: all; overflow-wrap: anywhere; }
ol.steps { margin: 0; padding-left: 20px; color: var(--ink-2); font-size: 15px; display: flex; flex-direction: column; gap: 4px; }

@media print {
  .topbar, .toolbar, .selbar, .foot, .page-head .btn-row, td.chk, th.chk, .drawer, .drawer-bg { display: none !important; }
  .table-box { max-height: none; overflow: visible; border: 0; }
  body { background: #fff; }
}
