:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1a2230;
  --muted: #6b7686;
  --line: #e3e8ef;
  --brand: #7c3aed;
  --brand-ink: #6d28d9;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --warn-bg: #fff7ed;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1; }
.num { text-align: right; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.userbox { display: flex; align-items: center; gap: 12px; }

/* Přepínač jazyka CZ | EN */
.langswitch { display: flex; align-items: center; gap: 4px; }
.lang {
  background: none; border: none; padding: 2px 4px; cursor: pointer;
  font-size: 13px; font-weight: 700; color: var(--muted); line-height: 1;
}
.lang:hover { color: var(--ink); }
.lang.active { color: var(--brand-ink); }
.lang-sep { color: var(--line); font-size: 13px; }

/* Cards / layout */
main { max-width: 1180px; margin: 0 auto; padding: 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.authwrap { display: flex; justify-content: center; padding-top: 8vh; }
.auth-card { width: 380px; max-width: 92vw; padding: 24px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 12px; }
.row .field { flex: 1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 12px; color: var(--muted); font-weight: 600; }
input, select {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus { outline: 2px solid #ddd6fe; border-color: var(--brand); }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.check input { width: auto; }
.toolbar select { width: auto; max-width: 170px; }

/* Buttons */
.btn {
  padding: 9px 14px; border-radius: 8px; border: 1px solid transparent;
  font-size: 13px; font-weight: 600; cursor: pointer; background: #eef1f6; color: var(--ink);
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-sm { padding: 5px 9px; font-size: 12px; }
.btn-call { background: #dcfce7; color: #166534; }
.btn-mail { background: #dbeafe; color: #1e40af; }
.btn-status { background: #ede9fe; color: #5b21b6; }
.btn-wa { display: inline-flex; align-items: center; gap: 4px; background: #25d366; color: #fff; text-decoration: none; }
.btn-wa:hover { filter: brightness(0.97); color: #fff; }
/* telefon jako WhatsApp proklik v tabulce/detailu */
.wa { color: #128c7e; text-decoration: none; font-weight: 600; }
.wa:hover { text-decoration: underline; }
.wa-ico { margin-left: 3px; font-size: 0.95em; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.auth-card .tabs { margin-bottom: 20px; }
.tab {
  padding: 9px 14px; background: none; border: none; border-bottom: 2px solid transparent;
  cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px;
}
.tab.active { color: var(--brand-ink); border-bottom-color: var(--brand); }

/* Stats (dashboard) */
.stats { display: grid; grid-template-columns: repeat(8, 1fr); gap: 10px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); cursor: pointer; }
.stat:hover { border-color: var(--brand); }
.stat-num { display: block; font-size: 22px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.stat-due { background: var(--warn-bg); }
.stat-due .stat-num { color: var(--warn); }

/* Toolbar */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.queue-hint { margin: 0 0 12px; }

/* Table */
.tablewrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.grid td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: none; }
.grid tbody tr.rowlink { cursor: pointer; }
.grid tbody tr.rowlink:hover { background: #f8f6ff; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }

/* Badges: status pipeline */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-novy { background: #e0e7ff; color: #3730a3; }
.st-kontaktovan { background: #dbeafe; color: #1e40af; }
.st-zajem { background: #fef3c7; color: #92400e; }
.st-demo { background: #fce7f3; color: #9d174d; }
.st-klient { background: #dcfce7; color: #166534; }
.st-odmitl { background: #fee2e2; color: #991b1b; }
.st-mrtvy { background: #e5e7eb; color: #4b5563; }

/* Priorita */
.pr-vysoka { background: #fee2e2; color: #991b1b; }
.pr-stredni { background: #fef3c7; color: #92400e; }
.pr-nizka { background: #e5e7eb; color: #4b5563; }

/* Typ kontaktu */
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.sys-odberatel { background: #dcfce7; color: #166534; }
.sys-dodavatel { background: #dbeafe; color: #1e40af; }
.sys-partner { background: #fef3c7; color: #92400e; }
.sys-personal { background: #ede9fe; color: #6d28d9; }
.sys-nezjisteno { background: #f3f4f6; color: #9ca3af; }

/* Overdue next action */
.due-today { color: var(--warn); font-weight: 700; }
.due-over { color: var(--danger); font-weight: 700; }

.empty { padding: 28px; text-align: center; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.error { color: var(--danger); font-size: 13px; margin: 0; }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: flex; align-items: flex-start; justify-content: center; z-index: 20; padding: 4vh 16px; overflow-y: auto; }
.modal { width: 520px; max-width: 96vw; padding: 22px; }
.modal-wide { width: 680px; }
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* Lead detail */
.lead-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.lead-head p { margin: 2px 0 0; }
.lead-badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.lead-info { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 16px; background: #fafbfc; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; }
.lead-info .kv { min-width: 0; }
.lead-info .kv b { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.lead-info .kv span { font-size: 13px; overflow-wrap: anywhere; }
.quick-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.quick-form { border: 1px solid var(--line); border-radius: 8px; padding: 14px; margin-bottom: 14px; background: #fafbfc; }

/* Timeline */
.timeline-title { margin: 6px 0 10px; font-size: 14px; }
.timeline { list-style: none; margin: 0 0 12px; padding: 0; max-height: 320px; overflow-y: auto; }
.timeline li { display: flex; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: none; }
.timeline .t-icon { flex: 0 0 22px; text-align: center; }
.timeline .t-body { flex: 1; min-width: 0; }
.timeline .t-meta { font-size: 12px; color: var(--muted); }
.timeline .t-note { font-size: 13px; overflow-wrap: anywhere; }

/* Toast */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px; z-index: 40; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); }

/* Role gating: admin-only prvky schované, dokud UI neví, že jsi admin
   (body.is-admin nastaví app.js po /crm/me). */
body:not(.is-admin) .admin-only { display: none !important; }

/* Přiřazovací lišta nad tabulkou leadů */
.assignbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; padding: 8px 12px; background: #f3f0ff; border: 1px solid #e3ddff; border-radius: 8px; flex-wrap: wrap; }
.assignbar .assign-arrow { font-weight: 600; color: var(--brand-ink); font-size: 13px; }
.assignbar select { width: auto; max-width: 220px; }
#selCount { font-size: 13px; }

/* Výběrový checkbox ve sloupci tabulky */
.col-check { width: 34px; text-align: center; }
.col-check input { width: auto; margin: 0; cursor: pointer; }

/* Připomínkový balík: stale zvýraznění, chip tlačítka, sekce „Hrozí zapomenutí" */
.stale { color: #c2410c; font-weight: 600; }
.btn-chip {
  padding: 4px 10px; font-size: 12px; border-radius: 999px;
  background: transparent; border: 1px solid var(--line); color: var(--muted);
}
.btn-chip:hover { border-color: var(--brand); color: var(--brand-ink); }
.reminder-actions { align-items: center; }
.reminder-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.btn-dnc { background: #fee2e2; color: #991b1b; }
.btn-reengage { background: #dcfce7; color: #166534; }
.stale-section { margin-top: 26px; }
.stale-title { margin: 0 0 10px; font-size: 14px; }

/* Period přepínač v Týmu (menší taby bez spodního rámečku) */
.period-tabs { border-bottom: none; margin-bottom: 0; }
.period-tabs .tab { padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; }
.period-tabs .tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  .lead-info { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid th:nth-child(2), .grid td:nth-child(2) { display: none; }
}

/* Návrh outreach zprávy (copy → WhatsApp) */
.outreach-box { background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.outreach-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.outreach-text { margin: 0; white-space: pre-wrap; font-size: 13px; line-height: 1.5; }
.btn-copy { background: #dcfce7; color: #166534; }
