/* ============================================================
   VIZAPP — Panel pre manažérov
   Farby podľa css/index.css, používať len cez premenné nižšie.
   Fonty: Inter ak je nainštalovaný, inak systémový —
   TODO: self-hosted Inter ako na webe.
   ============================================================ */
:root {
  /* Plochy */
  --bg:            #05081a;
  --bg-2:          #070f2b;
  --surface:       #0a1230;
  --surface-2:     #0e1840;
  --border:        rgba(140, 160, 255, 0.12);
  --border-strong: rgba(150, 170, 255, 0.24);
  --backdrop:      rgba(2, 4, 14, 0.65);
  --shadow:        rgba(0, 0, 0, 0.4);

  /* Akcent */
  --accent:        #3b5bfd;
  --accent-hover:  #4d6bff;
  --accent-light:  #8fa4ff;
  --accent-border: rgba(59, 91, 253, 0.6);
  --on-accent:     #ffffff;
  --hover-bg:      rgba(90, 120, 255, 0.08);
  --row-hover:     rgba(90, 120, 255, 0.06);
  --selected-bg:   rgba(59, 91, 253, 0.18);
  --focus-ring:    rgba(59, 91, 253, 0.25);
  --chip-bg:       rgba(255, 255, 255, 0.06);
  --toolbar-bg:    rgba(10, 18, 48, 0.72);
  --toolbar-blur:  blur(14px);
  --avatar-bg:     var(--accent);
  --chart:         #5a78ff;
  --chart-gutter:  36px;

  /* Text */
  --text:          #ffffff;
  --text-2:        rgba(255, 255, 255, 0.68);
  --muted:         rgba(255, 255, 255, 0.45);

  /* Stavy */
  --warn:          #fbbf24;
  --danger:        #f87171;
  --danger-bg:     rgba(248, 113, 113, 0.15);
  --danger-border: rgba(248, 113, 113, 0.4);
  --ok:            #4ade80;

  /* Štítky firmy: pevná paleta (org_tags.color), žiadny voľný hex z dát */
  --tag-red:       #fca5a5; --tag-red-bg:    rgba(248, 113, 113, 0.16);
  --tag-amber:     #fcd34d; --tag-amber-bg:  rgba(251, 191, 36, 0.15);
  --tag-teal:      #5eead4; --tag-teal-bg:   rgba(45, 212, 191, 0.14);
  --tag-violet:    #c4b5fd; --tag-violet-bg: rgba(167, 139, 250, 0.16);
  --tag-blue:      #93c5fd; --tag-blue-bg:   rgba(96, 165, 250, 0.15);
  --tag-gray:      rgba(255, 255, 255, 0.7); --tag-gray-bg: rgba(255, 255, 255, 0.08);

  --radius:        14px;
  --font-body:     'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-heading:  'Inter Tight', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:     ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-light); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Brána (prihlásenie / bez prístupu) ---------- */
.gate { display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; }
.gate[hidden], #app[hidden] { display: none; }
.gate__box {
  width: min(380px, 100%); padding: 28px 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
}
.gate__logo { display: block; width: auto; height: 22px; margin-bottom: 24px; }
.gate__form { display: flex; flex-direction: column; gap: 14px; }
.gate__form[hidden] { display: none; }
.gate__form h1 { font-family: var(--font-heading); font-size: 22px; font-weight: 700; }
.gate__form .link-btn { align-self: center; }
.form-error { min-height: 1.4em; color: var(--text-2); font-size: 13px; }
.form-error:empty { min-height: 0; }
.org__select { max-width: 100%; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 24px;
  padding: 24px 16px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
}
.sidebar__brand {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  padding: 4px 8px 0;
  color: var(--text); text-decoration: none;
}
.sidebar__brand img { display: block; width: auto; height: 22px; }
.sidebar__sub { color: var(--muted); font-size: 13px; }
.sidebar__nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 10px 12px;
  background: none; border: 0; border-radius: 10px;
  color: var(--text-2); text-align: left; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--hover-bg); color: var(--text); }
.nav-item.is-active { background: var(--selected-bg); color: var(--text); }
/* Počet neprečítaných kontaktov — len číslo, tučné */
.nav-badge { color: var(--text); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.nav-badge:empty { display: none; }
.sidebar__foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 8px; }
.foot-links { display: flex; gap: 16px; }
.foot-link {
  padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--text-2); font-size: 13px; text-decoration: none;
}
.foot-link:hover { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
.foot-link:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; border-radius: 4px; }
.org { display: flex; flex-direction: column; }
.org__name { font-weight: 600; font-size: 14px; }
.org__meta { color: var(--muted); font-size: 12px; }

.main { padding: 16px clamp(16px, 4vw, 40px) 64px; min-width: 0; }
.section[hidden] { display: none; }
.section__head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.section__head h1 { font-family: var(--font-heading); font-size: clamp(24px, 3vw, 30px); font-weight: 700; }

/* ---------- Tabuľky ---------- */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-x: auto;
}
.table-wrap--flat { background: none; border: 0; border-radius: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  padding: 12px 16px; text-align: left; white-space: nowrap;
  color: var(--muted); font-weight: 500; font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.table th.num { text-align: right; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table--clickable tbody tr { cursor: pointer; }
.table--clickable tbody tr:hover td, .table--clickable tbody tr:focus-visible td { background: var(--row-hover); }
.table--clickable tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.table .cell-main { font-weight: 500; }
.table .cell-sub { display: block; color: var(--muted); font-size: 12px; }
.actions-col { width: 1%; }
.th-sort { padding: 0; border: 0; background: none; cursor: pointer; color: inherit; font: inherit; }
th[aria-sort="ascending"] .th-sort::after { content: ' ↑'; }
th[aria-sort="descending"] .th-sort::after { content: ' ↓'; }
th[aria-sort="ascending"] .th-sort, th[aria-sort="descending"] .th-sort { color: var(--text); }
.th-sort:hover { color: var(--text); }
.th-sort:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; border-radius: 4px; }
.field--search input { min-width: 260px; }

/* ---------- Toolbar (vyhľadávanie + filtre) ---------- */
.toolbar {
  position: sticky; top: 0; z-index: 4;
  display: flex; align-items: center; gap: 10px 12px;
  margin-bottom: 12px; padding: 8px;
  background: var(--toolbar-bg);
  -webkit-backdrop-filter: var(--toolbar-blur); backdrop-filter: var(--toolbar-blur);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.toolbar__search {
  flex: 0 1 240px; min-width: 160px; position: relative; display: flex; align-items: center;
}
.toolbar__icon { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.toolbar__search input {
  width: 100%; padding: 8px 12px 8px 36px;
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: 10px;
  color: var(--text); font-size: 14px;
}
.toolbar__search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
/* Chipy sa pri nedostatku miesta posúvajú do strany, nikdy neprekryjú koniec toolbaru */
.toolbar__chips {
  display: flex; align-items: center; gap: 6px; min-width: 0; flex: 0 1 auto;
  overflow-x: auto; scrollbar-width: none; padding: 2px; margin: -2px;
}
.toolbar__chips::-webkit-scrollbar { display: none; }
.toolbar__end { display: flex; align-items: center; gap: 12px; margin-left: auto; flex: none; }
.toolbar__count { color: var(--text-2); font-size: 13px; white-space: nowrap; }

/* Chip: viditeľný text, natívny select neviditeľne cez celý chip */
.chip {
  position: relative; flex: none;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 10px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: none;
  color: var(--text-2); font-size: 13px; white-space: nowrap; cursor: pointer;
}
.chip:hover { background: var(--hover-bg); color: var(--text); }
.chip.is-active { color: var(--text); font-weight: 700; }
.chip__caret { color: var(--muted); }
.chip__select {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; font-size: 16px;
}
.chip:focus-within { outline: 2px solid var(--accent-light); outline-offset: 2px; }
.link-btn {
  flex: none; padding: 4px 6px; border: 0; background: none;
  color: var(--accent-light); font-size: 13px; text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.link-btn[hidden] { display: none; }
.link-btn:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; border-radius: 4px; }

/* Lepiaca hlavička tabuľky pod toolbarom — wrap nesmie mať overflow */
.table-wrap--sticky { overflow: visible; }
.table-wrap--sticky thead th {
  position: sticky; top: var(--sticky-top, 0); z-index: 2;
  background: var(--surface);
}
.table-wrap--sticky thead th:first-child { border-top-left-radius: var(--radius); }
.table-wrap--sticky thead th:last-child { border-top-right-radius: var(--radius); }

.empty { padding: 32px; text-align: center; color: var(--muted); }

/* Obchodník: avatar + text */
.who { display: flex; align-items: center; gap: 12px; }
.who__text { display: flex; flex-direction: column; min-width: 0; }
.avatar {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%; object-fit: cover;
  background: var(--avatar-bg); color: var(--on-accent);
  font-size: 13px; font-weight: 600;
}
.avatar--sm { width: 34px; height: 34px; font-size: 12px; }
.avatar--md { width: 48px; height: 48px; font-size: 16px; }
.avatar--lg { width: 72px; height: 72px; font-size: 22px; }
.avatar--free { background: var(--chip-bg); color: var(--muted); font-size: 12px; }
.avatar--org { border-radius: 16px; }

/* Tím: riadok bez aktivity za obdobie je len tlmený, nie „chyba“ */
.table tr.is-idle td { color: var(--muted); }
.table tr.is-idle .cell-main { font-weight: 400; }
.table tr.is-idle .avatar { opacity: .5; }
.table[aria-busy="true"] tbody { opacity: .5; transition: opacity .15s; }
.section__head .segmented { flex: none; }
abbr[title] { text-decoration: none; }

/* Cieľ mesiaca: editovateľné číslo + plnenie */
/* Hlavičky v Tíme sa môžu zalomiť, inak by tabuľka pri 1280 px pretiekla */
#tim .table th { white-space: normal; vertical-align: bottom; }
.col-goal { width: 150px; }
.goal { display: flex; flex-direction: column; gap: 6px; }
.goal__line { display: flex; align-items: center; gap: 10px; }
.goal__input {
  width: 64px; padding: 5px 8px;
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: 8px;
  color: var(--text); font-size: 14px; font-variant-numeric: tabular-nums;
}
.goal__input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.goal__input:disabled { opacity: .5; }
.goal__done { color: var(--text-2); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.goal__bar { height: 4px; border-radius: 2px; background: var(--chip-bg); overflow: hidden; }
.goal__bar span { display: block; height: 100%; background: var(--accent); }

/* Stav kontaktu — len text */
.status { font-size: 13px; white-space: nowrap; }
.status--new { color: var(--text); font-weight: 600; }
.status--contacted { color: var(--text-2); }
.status--archived { color: var(--muted); }

/* ---------- Tlačidlá a polia ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 500; font-size: 14px; text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn--sm { padding: 6px 12px; font-size: 13px; }
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--ghost { background: none; border-color: var(--border-strong); color: var(--text); }
.btn--ghost:hover { background: var(--hover-bg); }
.btn--danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.btn:focus-visible, .nav-item:focus-visible, .tab:focus-visible, .segmented button:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; margin-bottom: 16px; }
.filters--stack { margin: 16px 0 20px; }
.filters__count { margin-left: auto; font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 12px;
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: 10px;
  color: var(--text); font-size: 14px;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.field--inline select { min-width: 160px; }

.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--bg); }
.segmented button { padding: 6px 14px; border: 0; border-radius: 7px; background: none; color: var(--text-2); cursor: pointer; font-size: 14px; }
.segmented button.is-active { background: var(--accent); color: var(--on-accent); }
.segmented--full { display: flex; }
.segmented--full button { flex: 1; }

/* ---------- Štatistiky ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpis--3 { grid-template-columns: repeat(3, 1fr); }
.kpi { padding: 18px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.kpi__label { color: var(--text-2); font-size: 13px; }
.kpi__value { margin-top: 4px; font-family: var(--font-heading); font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi__delta { font-size: 12px; color: var(--muted); }

.panel-card {
  position: relative;
  margin-bottom: 16px; padding: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.panel-card__title { margin-bottom: 14px; font-family: var(--font-heading); font-size: 16px; font-weight: 600; }
.panel-card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-card__head .panel-card__title { margin-bottom: 0; }
.card-note { margin-top: 14px; }
.insights[aria-busy="true"] { opacity: .5; transition: opacity .15s; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-2 > .panel-card { margin-bottom: 16px; }

/* Detail obchodníka */
.back-btn {
  margin: 0 0 12px -6px; padding: 4px 6px; border: 0; border-radius: 6px; background: none;
  color: var(--text-2); font-size: 14px; cursor: pointer;
}
.back-btn:hover { color: var(--text); background: var(--hover-bg); }
.back-btn:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; }
#obchodnik .section__head .who h1 { font-family: var(--font-heading); font-size: clamp(22px, 3vw, 28px); font-weight: 700; line-height: 1.2; }
.segmented--sm button { padding: 4px 10px; font-size: 13px; }

/* Malé grafy pod sebou: jedna séria, jedna os */
.charts { display: flex; flex-direction: column; gap: 20px; }
.mini-chart { position: relative; }
.mini-chart__title { margin-bottom: 6px; color: var(--text-2); font-size: 13px; font-weight: 500; }
.mini-chart__title .muted { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.chart--sm { height: 120px; }
.chart-tip[hidden] { display: none; }

/* Vodorovné pruhy: zdroje a záujmy */
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) auto 3.2em; align-items: center; gap: 10px; font-size: 14px; }
.hbar__label { min-width: 0; overflow-wrap: anywhere; }
.hbar__track { height: 8px; border-radius: 4px; background: var(--chip-bg); overflow: hidden; }
.hbar__track span { display: block; height: 100%; background: var(--chart); border-radius: 4px; }
.hbar__val { font-variant-numeric: tabular-nums; text-align: right; }
.hbar__extra { color: var(--muted); font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; margin-left: 8px; padding: 1px 6px; border-radius: 6px; background: var(--chip-bg); color: var(--muted); font-size: 11px; vertical-align: 1px; }
.empty--sm { padding: 16px 0; text-align: left; }
.drawer__actions[hidden] { display: none; }

.chart {
  position: relative;
  display: flex; align-items: flex-end; gap: 2px;
  height: 180px; padding: 8px 0 0 var(--chart-gutter);
  border-bottom: 1px solid var(--border);
}
/* Čiara maxima: presne na vrchu najvyššieho stĺpca */
.chart__max {
  position: absolute; top: 8px; left: 0; right: 0; height: 0;
  display: flex; align-items: center; gap: 6px;
  pointer-events: none;
}
.chart__max::after { content: ''; flex: 1; border-top: 1px solid var(--border-strong); }
.chart__max-label {
  width: calc(var(--chart-gutter) - 6px); text-align: right; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; line-height: 1;
}
.chart__bar {
  position: relative; z-index: 1;
  flex: 1 1 0; min-width: 2px; height: 100%;
  display: flex; align-items: flex-end;
  cursor: default;
}
.chart__bar span { display: block; width: 100%; background: var(--chart); border-radius: 4px 4px 0 0; min-height: 1px; }
.chart__bar:hover span, .chart__bar.is-hover span { background: var(--accent-light); }
.chart__axis { display: flex; justify-content: space-between; margin-top: 6px; padding-left: var(--chart-gutter); color: var(--muted); font-size: 12px; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 2;
  padding: 6px 10px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  font-size: 12px; white-space: nowrap; transform: translate(-50%, -100%);
}
.chart-tip strong { font-variant-numeric: tabular-nums; }

/* ---------- Export ---------- */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 6;
  min-width: 180px; padding: 4px;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: 0 10px 30px var(--shadow);
}
.menu[hidden] { display: none; }
.menu__item {
  display: block; width: 100%; padding: 8px 12px;
  border: 0; border-radius: 7px; background: none;
  color: var(--text); font-size: 14px; text-align: left; white-space: nowrap; cursor: pointer;
}
.menu__item:hover, .menu__item:focus-visible { background: var(--hover-bg); outline: none; }
.export-note { margin: -4px 4px 12px; text-align: right; color: var(--text-2); font-size: 13px; }

.nowrap { white-space: nowrap; }

/* ---------- Nastavenia (drawer) ---------- */
.set-block { display: flex; flex-direction: column; gap: 12px; padding: 18px 0; border-top: 1px solid var(--border); }
.set-block:first-child { padding-top: 0; border-top: 0; }
.set-block__title { font-family: var(--font-heading); font-size: 15px; font-weight: 600; }
.set-block__actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.set-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; font-size: 14px; }
.select-sm {
  padding: 6px 10px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--border-strong); color: var(--text); font-size: 13px;
}
.select-sm:disabled { opacity: .5; }
.select-sm:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }

/* ---------- Bočný panel (drawer) ---------- */
.drawer {
  margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(440px, 100vw); max-width: 100vw;
  padding: 0; border: 0; border-left: 1px solid var(--border-strong);
  background: var(--bg-2); color: var(--text);
}
.drawer[open] { animation: drawer-in .2s ease-out; }
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .drawer[open] { animation: none; } }
.drawer::backdrop { background: var(--backdrop); }
.drawer__inner { display: flex; flex-direction: column; height: 100%; }
.drawer__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 20px 16px; border-bottom: 1px solid var(--border); }
.drawer__who { display: flex; align-items: center; gap: 14px; min-width: 0; }
.drawer__head > h2, .drawer__who h2 { font-family: var(--font-heading); font-size: 20px; line-height: 1.2; }
.drawer__sub { margin-top: 2px; color: var(--text-2); font-size: 13px; }
.drawer__sub--muted { color: var(--muted); font-size: 12px; }
.drawer__close {
  flex: none; width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: none; color: var(--text-2);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.drawer__close:hover { color: var(--text); background: var(--hover-bg); }
.drawer__close:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; }
.drawer__body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer__h { margin: 22px 0 10px; color: var(--muted); font-size: 13px; font-weight: 500; }
.drawer__actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 20px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.drawer__actions .btn { flex: 1 1 auto; }
.lead-message { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.dd--small { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }

.mini-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.mini-stat { display: flex; flex-direction: column; padding: 10px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); }
.mini-stat__value { font-family: var(--font-heading); font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mini-stat__label { color: var(--muted); font-size: 12px; }

/* ---------- Modály ---------- */
.modal {
  margin: auto; width: min(480px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 0; border: 1px solid var(--border-strong); border-radius: 18px;
  background: var(--bg-2); color: var(--text);
}
.modal--sm { width: min(380px, calc(100vw - 32px)); }
.modal--sm .modal__body { gap: 20px; }
.modal--sm h2 { font-size: 18px; }
.modal::backdrop { background: var(--backdrop); }
.modal__body { display: flex; flex-direction: column; gap: 14px; padding: 24px; }
.modal h2 { font-family: var(--font-heading); font-size: 20px; }
.modal fieldset { display: flex; flex-direction: column; gap: 10px; border: 0; }
.modal legend { margin-bottom: 8px; color: var(--muted); font-size: 13px; font-weight: 500; }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.dl dt { color: var(--muted); }
.dl dd { word-break: break-word; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10;
  padding: 10px 18px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  font-size: 14px; box-shadow: 0 10px 30px var(--shadow);
}

/* ---------- Mobil ---------- */
.tabbar { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar__brand { flex: none; }
  .sidebar__brand img { height: 18px; }
  .sidebar__foot { min-width: 0; gap: 12px; }
  .org { min-width: 0; }
  .org__name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .org__select { max-width: 38vw; }
  .sidebar__nav { display: none; }
  .sidebar__foot { margin: 0; flex-direction: row; align-items: center; padding: 0; }
  .sidebar__sub { display: none; }
  #user-email { display: none; }
  .main { padding: 12px 16px 96px; }
  .section__head { flex-wrap: wrap; align-items: flex-start; }
  .section__head .segmented { width: 100%; }
  .section__head .segmented button { flex: 1; padding: 6px 4px; font-size: 13px; }
  .col-goal { width: auto; }
  .kpis, .kpis--3 { grid-template-columns: repeat(2, 1fr); }
  .kpis--3 .kpi:last-child { grid-column: 1 / -1; }
  .export-note { text-align: left; }
  .mini-stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; gap: 0; }
  /* 90 denných stĺpcov sa musí zmestiť aj na 320 px */
  .chart { gap: 1px; }
  .chart__bar { min-width: 1px; }
  .panel-card__head { flex-wrap: wrap; }
  .field--search { flex-basis: 100%; }

  /* Toolbar: vyhľadávanie na celú šírku, filtre pod ním s horizontálnym scrollom */
  .toolbar { flex-wrap: wrap; }
  .toolbar__search { flex: 1 1 100%; min-width: 0; }
  .toolbar__chips { order: 3; flex: 1 1 100%; margin: 0 -8px; padding: 2px 8px; }
  .toolbar__end { order: 4; flex: 1 1 100%; justify-content: space-between; margin: 0; padding: 0 4px; }
  .field--search input { min-width: 0; }
  .tabbar {
    display: grid; grid-template-columns: repeat(3, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: var(--bg-2); border-top: 1px solid var(--border);
  }
  .tab { padding: 10px 2px; border: 0; border-radius: 8px; background: none; color: var(--text-2); font-size: 12px; cursor: pointer; }
  .tab.is-active { background: var(--selected-bg); color: var(--text); }
  .filters__count { margin-left: 0; width: 100%; }
  .field--inline { flex: 1 1 140px; }
  .field--inline select { min-width: 0; }

  /* Tabuľka tímu ako karty */
  #tim .table thead { display: none; }
  #tim .table, #tim .table tbody, #tim .table td { display: block; }
  #tim .table tr { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
  #tim .table tr:last-child { border-bottom: 0; }
  #tim .table td { padding: 0; border: 0; text-align: left; font-size: 13px; }
  #tim .table td:first-child { grid-column: 1 / -1; font-size: 14px; }
  #tim .table td[data-label]::before { content: attr(data-label) ': '; color: var(--muted); }
  #tim .table td.actions-col { grid-column: 1 / -1; width: auto; }
  #tim .table td.actions-col:empty { display: none; }
}

/* ============================================================
   Kontakty v2: zoznam vľavo, detail vpravo (js/contacts.js)
   Červená iba pri leade po termíne, ostatné stavy len bodkou.
   ============================================================ */
.section--contacts { margin: -16px calc(-1 * clamp(16px, 4vw, 40px)) -64px; }
.ct { display: grid; grid-template-columns: minmax(320px, 420px) minmax(0, 1fr); height: 100vh; }

.ct-list { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--border); }
.ct-list__head { position: relative; display: flex; flex-direction: column; gap: 12px; padding: 20px 16px 0; }
.ct-list__title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ct-list__title h1 { font-family: var(--font-heading); font-size: clamp(22px, 3vw, 26px); font-weight: 700; }
.ct-tools { position: relative; display: flex; gap: 8px; }
.ct-tools .toolbar__search { flex: 1 1 auto; }
.ct-filter-btn { flex: none; }
.ct-badge { min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: 11px; line-height: 18px; }

.ct-filters {
  position: absolute; z-index: 6; top: calc(100% + 6px); left: 0; right: 0;
  display: grid; gap: 12px; padding: 16px;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: 0 16px 40px var(--shadow);
}
.ct-filters[hidden] { display: none; }
.ct-check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.ct-check input, .ct-pick input, .ct-tag-check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.ct-filters__end { display: flex; align-items: center; justify-content: space-between; }

.ct-tabs { display: flex; margin: 0 -16px; padding: 0 8px; border-bottom: 1px solid var(--border); }
.ct-tab {
  flex: 1; padding: 8px 4px 10px; margin-bottom: -1px;
  border: 0; border-bottom: 2px solid transparent; background: none;
  color: var(--muted); font-size: 13.5px; white-space: nowrap; cursor: pointer;
}
.ct-tab b { margin-left: 4px; color: var(--text-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.ct-tab:hover { color: var(--text-2); }
.ct-tab[aria-pressed="true"] { color: var(--text); border-bottom-color: var(--accent); }
.ct-tab[aria-pressed="true"] b { color: var(--text); }
.ct-tab:focus-visible { outline: 2px solid var(--accent-light); outline-offset: -2px; }

.ct-items { flex: 1; overflow-y: auto; padding: 4px 8px 96px; }
.ct-items[aria-busy="true"] { opacity: .5; transition: opacity .15s; }
.ct-group { padding: 14px 10px 4px; color: var(--muted); font-size: 12px; }
.ct-item {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 10px; border-radius: 10px; cursor: pointer;
}
.ct-item:hover { background: var(--row-hover); }
.ct-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ct-item.is-open { background: var(--selected-bg); }
.ct-item.is-arch { opacity: .6; }
/* Checkbox iba pri prejdení myšou alebo pri hromadnom výbere — nahradí avatar */
.ct-pick { position: relative; display: grid; place-items: center; width: 34px; height: 34px; }
.ct-pick input { position: absolute; opacity: 0; pointer-events: none; }
.ct-item:hover .ct-pick input, .has-sel .ct-pick input, .ct-pick input:focus-visible { opacity: 1; pointer-events: auto; }
.ct-item:hover .ct-pick .avatar, .has-sel .ct-pick .avatar, .ct-pick:focus-within .avatar { visibility: hidden; }
.ct-item__main { min-width: 0; }
.ct-item__name { display: flex; align-items: center; gap: 7px; min-width: 0; white-space: nowrap; }
.ct-item__name b { overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.ct-item__co { overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 13px; }
.ct-item__sub { padding-left: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.ct-item__side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; color: var(--text-2); font-size: 12.5px; white-space: nowrap; }
.ct-item__owner { color: var(--muted); font-size: 12px; }
.ct-empty { padding: 24px 10px; }
.ct-note { padding: 0 16px 12px; color: var(--muted); font-size: 12px; }
.ct-note[hidden] { display: none; }

/* Bodka podľa stavu: nový, čaká, oslovený */
.ct-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.ct-dot--new { background: var(--accent-light); }
.ct-dot--followup { background: var(--danger); }
.ct-dot--contacted { background: var(--ok); }
.ct-late { color: var(--danger); }
.ct-ok { color: var(--ok); }

.ct-bulk {
  position: absolute; left: 12px; right: 12px; bottom: 14px; z-index: 3;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--accent); box-shadow: 0 10px 30px var(--shadow);
}
.ct-bulk[hidden] { display: none; }
.ct-bulk__actions { display: flex; align-items: center; gap: 6px; }
.menu--up { top: auto; bottom: calc(100% + 6px); }

/* Detail kontaktu */
.ct-detail { min-width: 0; overflow-y: auto; padding: 32px clamp(16px, 3vw, 40px) 64px; }
.ct-detail__in { max-width: 720px; }
.ct-placeholder { padding-top: 40px; }
.ct-back { display: none; }
.ct-d-head { display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 16px; }
.ct-d-head h2 { font-family: var(--font-heading); font-size: 24px; line-height: 1.25; overflow-wrap: anywhere; }
.ct-d-co { color: var(--text-2); font-weight: 400; }
.ct-d-contacts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; margin-top: 6px; font-size: 15px; font-variant-numeric: tabular-nums; }
.ct-d-contacts a { color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.ct-d-contacts a:hover { color: var(--accent-light); }
.ct-unverified { padding: 1px 8px; border-radius: 6px; background: rgba(251, 191, 36, 0.12); color: var(--warn); font-size: 12px; cursor: help; }
.ct-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.ct-tag { display: inline-block; max-width: 16em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; vertical-align: middle; }
.ct-tag--red { color: var(--tag-red); background: var(--tag-red-bg); }
.ct-tag--amber { color: var(--tag-amber); background: var(--tag-amber-bg); }
.ct-tag--teal { color: var(--tag-teal); background: var(--tag-teal-bg); }
.ct-tag--violet { color: var(--tag-violet); background: var(--tag-violet-bg); }
.ct-tag--blue { color: var(--tag-blue); background: var(--tag-blue-bg); }
.ct-tag--gray { color: var(--tag-gray); background: var(--tag-gray-bg); }

.ct-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 22px; }
/* Hlavná akcia výrazná, nesmie vyzerať ako vypnutá */
.ct-main { padding: 10px 20px; font-size: 15px; font-weight: 600; box-shadow: 0 6px 20px rgba(59, 91, 253, 0.4); }
.ct-actions .btn:disabled, .ct-actions .btn[disabled] { opacity: .35; box-shadow: none; cursor: not-allowed; }
.ct-actions__tools { display: inline-flex; gap: 2px; margin-left: 4px; }
.ct-icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border: 0; border-radius: 10px; background: none; color: var(--text-2); cursor: pointer;
}
.ct-icon-btn:hover { background: var(--hover-bg); color: var(--text); }
.ct-icon-btn:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; }

.ct-sec { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border); }
.ct-sec h3 { margin-bottom: 10px; color: var(--muted); font-size: 13px; font-weight: 500; }
.ct-owner { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; font-size: 15px; }
.ct-owner strong { font-weight: 600; }
.ct-meta { color: var(--muted); font-size: 13px; }
.ct-meta--block { display: block; margin-top: 6px; }

.ct-note-box { display: grid; gap: 8px; }
.ct-note-box textarea {
  width: 100%; min-height: 76px; resize: vertical; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: 10px;
  color: var(--text); font: inherit; font-size: 14px;
}
.ct-note-box textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.ct-note-box__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ct-notes { list-style: none; display: grid; gap: 12px; margin-top: 14px; }
.ct-notes li { padding: 2px 0 2px 12px; border-left: 2px solid var(--border-strong); }
.ct-note__meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.ct-note__meta .link-btn { padding: 0; font-size: 12px; }
.ct-note__body { font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }

.ct-tl { list-style: none; position: relative; display: flex; flex-direction: column; gap: 18px; }
.ct-tl::before { content: ''; position: absolute; left: 15px; top: 8px; bottom: 8px; width: 1px; background: var(--border-strong); }
.ct-tl[aria-busy="true"] { opacity: .6; }
.ct-tl li { position: relative; display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 12px; }
.ct-tl__dot { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text-2); }
.ct-tl li[data-kind="ok"] .ct-tl__dot { color: var(--ok); border-color: var(--ok); }
.ct-tl li[data-kind="remind"] .ct-tl__dot, .ct-tl li[data-kind="edit"] .ct-tl__dot { color: var(--accent-light); }
.ct-tl__title { font-size: 14px; font-weight: 600; }
.ct-tl__title time { margin-left: 4px; color: var(--muted); font-size: 12.5px; font-weight: 400; }
.ct-tl__text { color: var(--text-2); font-size: 13.5px; overflow-wrap: anywhere; }

/* Modál štítkov */
.ct-tag-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.ct-tag-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 4px 0; }
.ct-tag-row .link-btn { padding: 0 2px; font-size: 12px; }
.ct-tag-check { display: flex; flex: 1; align-items: center; gap: 10px; min-width: 0; cursor: pointer; }
.ct-tag-new { display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.ct-tag-new[hidden] { display: none; }
.ct-tag-input {
  flex: 1; min-width: 0; padding: 6px 10px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--border-strong); color: var(--text); font-size: 14px;
}
.ct-tag-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }

@media (max-width: 900px) {
  .section--contacts { margin: -12px -16px -96px; }
  .ct { display: block; height: auto; }
  .ct-list { border-right: 0; }
  .ct-items { overflow: visible; padding-bottom: 120px; }
  .ct.show-detail .ct-list { display: none; }
  .ct:not(.show-detail) .ct-detail { display: none; }
  .ct-detail { padding: 16px 16px 120px; overflow: visible; }
  .ct-back { display: inline-block; }
  .ct-bulk { position: fixed; bottom: calc(72px + env(safe-area-inset-bottom)); left: 12px; right: 12px; }
  /* Na dotyku nie je hover: checkbox vždy namiesto avatara */
  .ct-pick input { opacity: 1; pointer-events: auto; }
  .ct-pick .avatar { visibility: hidden; }
  .ct-main { flex: 1 0 100%; }
}
