/* ================================================================
   IC Office CRM — Main Stylesheet
   Paleta: Červená #E31E24 | Černá #0D0D0D | Bílá #FFFFFF
   Fonty: Barlow Condensed (nadpisy), Inter (UI), JetBrains Mono (kódy)
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;600&display=swap');

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --color-primary:        #E31E24;
  --color-primary-dark:   #B01519;
  --color-primary-light:  #FF4D52;

  --color-black:          #0D0D0D;
  --color-gray-900:       #1A1A1A;
  --color-gray-800:       #2C2C2C;
  --color-gray-700:       #3D3D3D;
  --color-gray-600:       #555555;
  --color-gray-400:       #888888;
  --color-gray-200:       #E8E8E8;
  --color-gray-100:       #F2F2F2;
  --color-gray-50:        #F7F7F7;
  --color-white:          #FFFFFF;

  --color-success:        #1E8A3E;
  --color-warning:        #D4750A;
  --color-danger:         #C0191E;
  --color-info:           #1A5FA8;

  /* Status badge colors */
  --badge-trial:          #FF8C00;
  --badge-full:           #1E8A3E;
  --badge-expired:        #C0191E;
  --badge-prospect:       #555555;
  --badge-new:            #1A5FA8;

  --font-display:  'Barlow Condensed', sans-serif;
  --font-ui:       'Inter', sans-serif;
  --font-mono:     'JetBrains Mono', monospace;

  --sidebar-width: 240px;
  --topbar-height: 56px;
  --radius:        6px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.1);
  --shadow-md:     0 4px 12px rgba(0,0,0,.12);
  --shadow-lg:     0 8px 24px rgba(0,0,0,.15);

  --transition:    150ms ease;

  /* ── Theme-aware surface tokens (Phase 14) ─────────────────────
     Light defaults; dark overrides in body.dark-mode below. Use these
     instead of hardcoded #fff / #f9fafb / #fff8e1 etc. in inline styles
     so dark mode doesn't leave invisible "white-on-white" patches. */
  --surface-default:        #ffffff;
  --surface-muted:          #f9fafb;
  --surface-chip:           #f3f4f6;
  --surface-info-soft:      #eff6ff;
  --surface-success-soft:   #e8f5e9;
  --surface-warning-soft:   #fff8e1;
  --surface-danger-soft:    #fef2f2;
  --surface-purple-soft:    #eef2ff;

  --text-default:           #1a1a1a;
  --text-muted:             #6b7280;
  --text-chip:              #374151;
  --text-on-soft-info:      #1565c0;
  --text-on-soft-success:   #2e7d32;
  --text-on-soft-warning:   #e65100;
  --text-on-soft-danger:    #c62828;
  --text-on-soft-purple:    #5b21b6;

  --border-soft:            #e5e7eb;
}

/* ── Dark mode (Phase 11) ──────────────────────────────────────
   body.dark-mode is added by JS from localStorage('theme') OR auto-set
   from prefers-color-scheme on first visit. Keeps the brand red the
   same — only neutrals invert.

   Coverage: body bg, all .card surfaces, modals, form controls, table
   rows, badges, alerts, search-filters bar, toast container. The brand
   red (--color-primary) stays for buttons, active nav, CTAs.

   Anything not covered yet (legacy hardcoded white/black inline styles
   in some pages) will surface as light spots — pošli, doplníme. */
body.dark-mode {
  background: #0d0d0d;
  color: #e5e5e5;

  /* Dark overrides for surface tokens — same names, different values.
     Inline styles using var(--surface-*) auto-flip without JS. */
  --surface-default:        #1a1a1a;
  --surface-muted:          #1f1f1f;
  --surface-chip:           #2a2a2a;
  --surface-info-soft:      rgba(26,95,168,.18);
  --surface-success-soft:   rgba(30,138,62,.18);
  --surface-warning-soft:   rgba(212,117,10,.18);
  --surface-danger-soft:    rgba(192,25,30,.20);
  --surface-purple-soft:    rgba(124,58,237,.18);

  --text-default:           #e5e5e5;
  --text-muted:             #9a9a9a;
  --text-chip:              #d0d0d0;
  --text-on-soft-info:      #7cb1ff;
  --text-on-soft-success:   #6ee0a3;
  --text-on-soft-warning:   #ffc375;
  --text-on-soft-danger:    #ff8a8a;
  --text-on-soft-purple:    #c4b5fd;

  --border-soft:            #2a2a2a;
}
body.dark-mode .card,
body.dark-mode .modal,
body.dark-mode .modal__dialog,
body.dark-mode .modal__header,
body.dark-mode .modal__body,
body.dark-mode .modal__footer {
  background: #1a1a1a !important;
  color: #e5e5e5;
  border-color: #2a2a2a;
}
body.dark-mode .card,
body.dark-mode .card__header {
  border-color: #2a2a2a;
}
body.dark-mode .card__header,
body.dark-mode .modal__header,
body.dark-mode .modal__footer {
  border-bottom-color: #2a2a2a;
  border-top-color: #2a2a2a;
}
body.dark-mode .topbar {
  background: #161616;
  border-bottom-color: #2a2a2a;
  color: #e5e5e5;
}
body.dark-mode .topbar__title { color: #f0f0f0; }
body.dark-mode .page-header__title { color: #f0f0f0; }

/* Form controls — keep them visible against the dark card background. */
body.dark-mode .form-control,
body.dark-mode .form-input,
body.dark-mode input[type=text],
body.dark-mode input[type=email],
body.dark-mode input[type=password],
body.dark-mode input[type=tel],
body.dark-mode input[type=number],
body.dark-mode input[type=date],
body.dark-mode input[type=time],
body.dark-mode input[type=month],
body.dark-mode input[type=search],
body.dark-mode select,
body.dark-mode textarea {
  background: #232323;
  color: #e5e5e5;
  border-color: #3a3a3a;
}
body.dark-mode .form-control::placeholder,
body.dark-mode input::placeholder,
body.dark-mode textarea::placeholder { color: #777; }
body.dark-mode .form-label { color: #cfcfcf; }

/* Tables — invert row striping. */
body.dark-mode table { background: #1a1a1a; color: #e5e5e5; }
body.dark-mode table th,
body.dark-mode table td { border-color: #2a2a2a; }
body.dark-mode tr:hover { background: #232323 !important; }

/* Muted helpers — readable on dark. */
body.dark-mode .text-muted,
body.dark-mode .text-small.text-muted { color: #9a9a9a !important; }

/* Alerts — soften the existing tinted backgrounds. */
body.dark-mode .alert--success { background: rgba(30,138,62,.18); color: #6ee0a3; }
body.dark-mode .alert--info    { background: rgba(26,95,168,.18); color: #7cb1ff; }
body.dark-mode .alert--warning { background: rgba(212,117,10,.18); color: #ffc375; }
body.dark-mode .alert--danger  { background: rgba(192,25,30,.20); color: #ff8a8a; }

/* Search / filter bar — same dark surface as cards. */
body.dark-mode .search-filters,
body.dark-mode .search-input-wrapper { background: #1a1a1a; }

/* Sidebar already dark — leave it but bump the active item contrast. */
body.dark-mode .nav-item:hover { background: rgba(255,255,255,.07); }

/* Buttons — secondary variants get dark backgrounds, primary stays red. */
body.dark-mode .btn-secondary,
body.dark-mode .btn--outline,
body.dark-mode .btn-ghost {
  background: #232323;
  color: #e5e5e5;
  border-color: #3a3a3a;
}
body.dark-mode .btn-secondary:hover,
body.dark-mode .btn--outline:hover,
body.dark-mode .btn-ghost:hover { background: #2c2c2c; }

/* Bottom-nav (mobile) — also dark. */
body.dark-mode .bottom-nav {
  background: #161616;
  border-top-color: #2a2a2a;
}
body.dark-mode .bottom-nav__item { color: #888; }
body.dark-mode .bottom-nav__item.active { color: var(--color-primary-light); }

/* Toast container is positioned but transparent; toasts themselves keep
   their colored backgrounds. No override needed. */

/* Login card in dark mode — gradient backdrop is already dark, only the
   card itself needs flipping. */
body.dark-mode .login-card {
  background: #1a1a1a !important;
  color: #e5e5e5;
}
body.dark-mode .login-card__title { color: #f0f0f0; }
body.dark-mode .login-card__subtitle { color: #a0a0a0; }

/* ── Phase 14b: dark-mode overrides for surfaces & borders ─────
   Classes co rule pozadí přes `var(--color-white)` nebo `white` se
   teď v dark vrátí tmavé. Bordery mapují na --border-soft (#2a2a2a). */
body.dark-mode .stat-card,
body.dark-mode .client-row,
body.dark-mode .fab-menu-item,
body.dark-mode .page-btn,
body.dark-mode .btn-secondary {
  background: var(--surface-default);
  color: var(--text-default);
  border-color: var(--border-soft);
}
body.dark-mode .client-row { border-bottom-color: var(--border-soft); }
body.dark-mode .client-row:hover { background: var(--surface-muted); }
body.dark-mode .page-btn:hover { background: var(--surface-muted); }
body.dark-mode .btn-secondary:hover { background: var(--surface-muted); color: var(--text-default); }
body.dark-mode .stat-card__value { color: var(--text-default); }
body.dark-mode .stat-card__label { color: var(--text-muted); }
body.dark-mode .table .client-name { color: var(--text-default); }
body.dark-mode .tab:hover { color: var(--text-default); }
body.dark-mode .btn-ghost:hover { background: var(--surface-muted); color: var(--text-default); }

/* Modal headers/footers were already overridden but borders weren't.
   Also catch any remaining --color-gray-200 borders that bleed light. */
body.dark-mode .modal__header,
body.dark-mode .modal__footer,
body.dark-mode .modal__dialog,
body.dark-mode .stat-card,
body.dark-mode .card { border-color: var(--border-soft); }
body.dark-mode .divider { background: var(--border-soft); }

/* Floating theme toggle — visible on the login page (and welcome screens)
   so users can switch theme before they sign in. Top-right corner, always
   on top. Light icon shown when dark is active and vice versa. */
.theme-toggle-floating {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top, 0px));
  right: 16px;
  z-index: 200;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.6);
  color: white;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform .15s, background .15s;
}
.theme-toggle-floating:hover {
  transform: scale(1.05);
  background: rgba(0,0,0,.8);
}
body.dark-mode .theme-toggle-floating {
  background: rgba(255,255,255,.1);
  border-color: rgba(255,255,255,.2);
}
/* Hide floating toggle in main app — sidebar has its own .sidebar__theme.
   `.app-active` body class is set by showMainApp() in app.js. */
body.app-active .theme-toggle-floating { display: none; }

/* The page topbar (desktop) and mobile-topbar (mobile) already render the
   page title from PAGES config in app.js. Per-page templates also wrote a
   <div class="page-header__title"> with the same string — visible duplicate.
   Hide the in-content title by default; pages that need a personalized
   header (dashboard "Dobrý den, X 👋") opt back in via the --keep modifier. */
.page-header__title:not(.page-header__title--keep) { display: none; }

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--surface-muted);
  color: var(--color-black);
  min-height: 100vh;
  line-height: 1.5;
  /* Phase 10 mobile: kill the iOS Safari grey tap blob — we use our own
     :active styling per component. Safe-area insets are applied per-component
     (mobile-topbar pads under the notch, bottom-nav above the home indicator)
     rather than globally, so the colored bars extend edge-to-edge. */
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
/* Inputs on iOS: prevent the auto-zoom-to-input behavior by forcing 16px+
   font-size on all form fields. Smaller fields (filter selects in toolbars)
   keep their visual size via line-height. */
input, select, textarea, button {
  font-family: inherit;
  font-size: 16px;
}
/* Tap targets: every clickable thing should hit Apple's 44×44 minimum.
   Buttons and links opt in via min-height; large click areas (table rows,
   cards) already pass on size. */
button, a.btn {
  min-height: 36px;          /* desktop default — overridden ↓ on mobile */
}

/* ── Layout ─────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar (PC) ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-gray-900);
  color: var(--color-white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition), width var(--transition);
}

/* Phase 11: collapsed mode (desktop). Slides the sidebar fully off-screen
   and shrinks the main-content margin so the page reclaims the width.
   #sidebarExpandBtn becomes visible so the user can re-open it. */
.sidebar.collapsed {
  transform: translateX(-100%);
}
body.sidebar-collapsed .main-content { margin-left: 0; }
body.sidebar-collapsed #sidebarExpandBtn {
  display: flex !important;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 101;
  width: 38px; height: 38px;
  align-items: center; justify-content: center;
  background: var(--color-gray-900);
  color: white;
  border: none; border-radius: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
}
body.sidebar-collapsed #sidebarExpandBtn:hover { background: var(--color-gray-800); }

/* Collapse button inside the sidebar — small chevron, only on desktop. */
.sidebar__collapse,
.sidebar__theme {
  background: transparent;
  border: none;
  color: var(--color-gray-400);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}
.sidebar__collapse { margin-left: auto; }
.sidebar__theme    { margin-left: auto; }
/* When both are present (theme + collapse), only theme keeps margin-left:auto */
.sidebar__theme + .sidebar__collapse { margin-left: 0; }
.sidebar__collapse:hover,
.sidebar__theme:hover { background: rgba(255,255,255,.08); color: white; }
@media (max-width: 768px) {
  /* Mobile already has its own drawer mechanism + ☰ in mobile-topbar.
     The desktop collapse button would be redundant + confusing. Theme
     toggle stays available because it's useful on mobile too. */
  .sidebar__collapse { display: none; }
}

.sidebar__logo {
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-gray-800);
  display: flex;
  align-items: center;
  gap: 12px;
}
.sidebar__logo-icon {
  width: 32px; height: 32px;
  background: var(--color-primary);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-family: var(--font-display); font-size: 14px; font-weight: 700;
}
.sidebar__logo-text {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: white;
  letter-spacing: 0.5px;
}

.sidebar__nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--color-gray-400);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border-left: 3px solid transparent;
  text-decoration: none;
}
.nav-item:hover { color: var(--color-white); background: var(--color-gray-800); text-decoration: none; }
.nav-item.active {
  color: var(--color-white);
  background: rgba(227,30,36,0.15);
  border-left-color: var(--color-primary);
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.nav-section-label {
  padding: 16px 20px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--color-gray-700);
}

.sidebar__footer {
  padding: 16px 20px;
  border-top: 1px solid var(--color-gray-800);
}
.sidebar__user {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.sidebar__avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: white; flex-shrink: 0;
}
.sidebar__user-info { flex: 1; min-width: 0; }
.sidebar__user-name { font-size: 13px; font-weight: 600; color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__user-role { font-size: 11px; color: var(--color-gray-400); }

/* ── Main content ───────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Top bar ────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: var(--surface-default);
  border-bottom: 1px solid var(--color-gray-200);
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 12px;
}
.topbar__title { font-family: var(--font-display); font-size: 20px; font-weight: 700; flex: 1; }
.topbar__actions { display: flex; align-items: center; gap: 8px; }

/* Mobile top bar — červený pruh. Extends *under* the notch via padding-top
   so the red status-bar background is continuous. */
.mobile-topbar {
  display: none;
  height: calc(52px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--color-primary);
  color: white;
  align-items: center;
  padding-left: 16px;
  padding-right: 16px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.mobile-topbar__title { font-family: var(--font-display); font-size: 18px; font-weight: 700; flex: 1; }

/* ── Page content ───────────────────────────────────────────── */
.page-content { padding: 24px; flex: 1; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface-default);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-gray-200);
  overflow: hidden;
}
.card--action-needed { border-left: 3px solid var(--color-primary); }
.card__header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-gray-200);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card__title { font-family: var(--font-display); font-size: 17px; font-weight: 700; flex: 1; }
.card__body { padding: 16px 20px; }

/* ── Stat cards (dashboard) ─────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface-default);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--color-gray-200);
  box-shadow: var(--shadow-sm);
}
.stat-card__value { font-family: var(--font-display); font-size: 32px; font-weight: 700; color: var(--text-default); }
.stat-card__label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.stat-card--warning .stat-card__value { color: var(--color-warning); }
.stat-card--success .stat-card__value { color: var(--color-success); }
.stat-card--danger  .stat-card__value { color: var(--color-danger); }
.stat-card--primary .stat-card__value { color: var(--color-primary); }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge--trial    { background: rgba(255,140,0,.12); color: #B35F00; border: 1px solid rgba(255,140,0,.3); }
.badge--full     { background: rgba(30,138,62,.12); color: #136129; border: 1px solid rgba(30,138,62,.3); }
.badge--expired  { background: rgba(192,25,30,.12); color: #8B0F12; border: 1px solid rgba(192,25,30,.3); }
.badge--prospect { background: rgba(85,85,85,.1);   color: #3D3D3D; border: 1px solid rgba(85,85,85,.25); }
.badge--type-a   { background: rgba(26,95,168,.1);  color: #0F3B6E; border: 1px solid rgba(26,95,168,.25); font-family: var(--font-mono); }
.badge--type-b   { background: rgba(85,85,85,.1);   color: #555;    border: 1px solid rgba(85,85,85,.2); }
.badge--segment-a{ background: rgba(30,138,62,.15); color: #136129; border: 1px solid rgba(30,138,62,.3); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
  font-family: var(--font-ui);
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary   { background: var(--color-primary); color: white; }
.btn-primary:hover { background: var(--color-primary-dark); color: white; }
.btn-secondary { background: var(--surface-default); color: var(--color-black); border: 1px solid var(--color-gray-200); }
.btn-secondary:hover { background: var(--surface-muted); }
.btn-danger    { background: var(--color-danger); color: white; }
.btn-ghost     { background: transparent; color: var(--color-gray-600); }
.btn-ghost:hover { background: var(--color-gray-100); color: var(--color-black); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 8px; border-radius: 50%; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--color-gray-800); }
.form-label .required { color: var(--color-primary); }
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font-ui);
  transition: border-color var(--transition), box-shadow var(--transition);
  background: var(--surface-default);
  color: var(--color-black);
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(227,30,36,.1);
}
.form-control.error { border-color: var(--color-danger); }
.form-error { font-size: 12px; color: var(--color-danger); margin-top: 4px; }
.form-hint  { font-size: 12px; color: var(--color-gray-600); margin-top: 4px; }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--color-gray-600);
  border-bottom: 2px solid var(--color-gray-200);
  white-space: nowrap;
}
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-gray-100);
  vertical-align: middle;
}
.table tr:hover td { background: var(--surface-muted); }
.table tr:last-child td { border-bottom: none; }
.table .client-name { font-weight: 600; color: var(--color-black); }
.table .customer-num { font-family: var(--font-mono); font-size: 12px; }

/* ── Client card (list view) ────────────────────────────────── */
.client-list { display: flex; flex-direction: column; gap: 1px; }
.client-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface-default);
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--color-gray-100);
}
.client-row:hover { background: var(--surface-muted); }
.client-row__avatar {
  width: 38px; height: 38px; border-radius: 8px;
  background: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  color: white; font-family: var(--font-display); font-size: 16px; font-weight: 700;
  flex-shrink: 0;
}
.client-row__name { font-weight: 600; font-size: 14px; }
.client-row__meta { font-size: 12px; color: var(--color-gray-600); }

/* ── Tabs ───────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--color-gray-200);
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-gray-600);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all var(--transition);
}
.tab:hover { color: var(--color-black); }
.tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }

/* Tab panels */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Page header ────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header__title { font-family: var(--font-display); font-size: 24px; font-weight: 700; }

/* ── Search & filters ───────────────────────────────────────── */
.search-filters {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.search-input-wrapper {
  position: relative;
  flex: 1;
  min-width: 200px;
}
.search-input-wrapper svg {
  position: absolute;
  left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--color-gray-400);
  width: 16px; height: 16px;
}
.search-input-wrapper .form-control { padding-left: 34px; }
.filter-select { width: auto; min-width: 140px; }

/* ── Timeline ───────────────────────────────────────────────── */
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-gray-100);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-item__dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--color-gray-300);
  margin-top: 6px; flex-shrink: 0;
}
.timeline-item__dot--red    { background: var(--color-primary); }
.timeline-item__dot--green  { background: var(--color-success); }
.timeline-item__dot--orange { background: var(--color-warning); }
.timeline-item__content { flex: 1; }
.timeline-item__text { font-size: 14px; }
.timeline-item__meta { font-size: 12px; color: var(--color-gray-400); margin-top: 2px; }

/* ── Meeting item ───────────────────────────────────────────── */
.meeting-item {
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--surface-muted);
  border-left: 3px solid var(--color-gray-300);
  margin-bottom: 8px;
}
.meeting-item--upcoming { border-left-color: var(--color-info); }
.meeting-item--past     { border-left-color: var(--color-success); opacity: 0.85; }
.meeting-item--cancelled{ opacity: 0.55; }
.meeting-item__time   { font-size: 12px; color: var(--color-gray-600); font-family: var(--font-mono); }
.meeting-item__title  { font-weight: 600; font-size: 14px; margin: 2px 0; }
.meeting-item__meta   { font-size: 12px; color: var(--color-gray-600); }

/* ── Modals ─────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--surface-default);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal__header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--color-gray-200);
  display: flex;
  align-items: center;
  gap: 12px;
}
.modal__title { font-family: var(--font-display); font-size: 20px; font-weight: 700; flex: 1; }
.modal__body { padding: 20px 24px; }
.modal__footer { padding: 16px 24px; border-top: 1px solid var(--color-gray-200); display: flex; gap: 8px; justify-content: flex-end; }

/* BEM-style modal used by JS-generated dialogs (admin_wizard, calendar Nová schůzka, …).
   Kept separate from .modal-overlay so the existing dash-style markup keeps working.

   The :has() selector targets only BEM modals (those that contain a .modal__dialog
   child) so dash-style .modal nodes inside .modal-overlay (which need to render
   as the visible card) aren't affected. Without this rule the BEM modal markup
   sat inline in the page flow as a white box even when not "active". */
.modal:has(> .modal__dialog) { display: none; }
.modal.active { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; max-width: none; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; background: transparent; box-shadow: none; }
.modal__overlay { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.modal__dialog { position: relative; z-index: 1; background: var(--surface-default); border-radius: 10px; box-shadow: var(--shadow-lg); width: 100%; max-width: 540px; max-height: 90vh; overflow-y: auto; }

/* ── FAB (Floating Action Button) ───────────────────────────── */
.fab {
  display: none;
  position: fixed;
  bottom: 80px;
  right: 16px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  font-size: 22px;
  align-items: center;
  justify-content: center;
  z-index: 90;
  transition: all var(--transition);
}
.fab:hover { background: var(--color-primary-dark); transform: scale(1.05); }
.fab-menu {
  display: none;
  position: fixed;
  bottom: 140px;
  right: 12px;
  z-index: 91;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}
.fab-menu.active { display: flex; }
.fab-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-default);
  box-shadow: var(--shadow-md);
  border-radius: 24px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
}
.fab-menu-item:hover { background: var(--surface-muted); }
.fab-menu-item__icon {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}

/* ── Bottom nav (mobile) ────────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface-default);
  border-top: 1px solid var(--color-gray-200);
  z-index: 100;
  /* Lift the bar above the iPhone home indicator. The base 64px stays the
     visual height; safe-area pads underneath. */
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottom-nav__items {
  display: flex;
  height: 100%;
}
.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--color-gray-400);
  cursor: pointer;
  font-size: 10px;
  font-weight: 500;
  border: none;
  background: none;
  transition: color var(--transition);
}
.bottom-nav__item.active { color: var(--color-primary); }
.bottom-nav__item svg { width: 22px; height: 22px; }

/* ── Alerts & Toasts ────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert--warning { background: rgba(212,117,10,.1); border: 1px solid rgba(212,117,10,.3); color: #7A4200; }
.alert--danger  { background: rgba(192,25,30,.1);  border: 1px solid rgba(192,25,30,.3);  color: #7A0A0C; }
.alert--success { background: rgba(30,138,62,.1);  border: 1px solid rgba(30,138,62,.3);  color: #0E4A1E; }
.alert--info    { background: rgba(26,95,168,.1);  border: 1px solid rgba(26,95,168,.3);  color: #0C3166; }

.toast-container {
  position: fixed;
  top: 70px; right: 16px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 500;
  min-width: 250px;
  max-width: 350px;
  pointer-events: all;
  animation: slideIn 0.2s ease;
}
.toast--success { background: var(--color-success); color: white; }
.toast--error   { background: var(--color-danger);  color: white; }
.toast--info    { background: var(--color-info);    color: white; }

@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ── Offline indicator ──────────────────────────────────────── */
.offline-banner {
  display: none;
  background: var(--color-warning);
  color: white;
  text-align: center;
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
}
.offline-banner.active { display: block; }

/* ── Loader / Spinner ───────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--color-gray-200);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/* ── Utilities ──────────────────────────────────────────────── */
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8   { margin-top: 8px; }
.mt-16  { margin-top: 16px; }
.mt-24  { margin-top: 24px; }
.mb-8   { margin-bottom: 8px; }
.mb-16  { margin-bottom: 16px; }
.mb-24  { margin-bottom: 24px; }
.text-muted { color: var(--color-gray-600); }
.text-small { font-size: 12px; }
.text-mono  { font-family: var(--font-mono); }
.font-bold  { font-weight: 700; }
.text-center{ text-align: center; }
.w-full { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.divider { height: 1px; background: var(--color-gray-200); margin: 16px 0; }

/* ── Empty state ────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 40px 20px; color: var(--color-gray-600); }
.empty-state__icon { font-size: 40px; margin-bottom: 12px; }
.empty-state__title { font-family: var(--font-display); font-size: 18px; font-weight: 700; color: var(--color-gray-700); }
.empty-state__text  { font-size: 14px; margin-top: 6px; }

/* ── Login page ─────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-gray-900) 0%, var(--color-black) 100%);
  padding: 16px;
}
.login-card {
  background: var(--surface-default);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-card__logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-card__logo-icon {
  width: 56px; height: 56px;
  background: var(--color-primary);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px;
  font-family: var(--font-display); font-size: 22px; font-weight: 700; color: white;
}
.login-card__title { font-family: var(--font-display); font-size: 24px; font-weight: 700; }
.login-card__subtitle { font-size: 14px; color: var(--color-gray-600); margin-top: 4px; }

/* ── Pagination ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  margin-top: 20px;
}
.page-btn {
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--color-gray-200);
  background: var(--surface-default);
  transition: all var(--transition);
}
.page-btn:hover { background: var(--surface-muted); }
.page-btn.active { background: var(--color-primary); color: white; border-color: var(--color-primary); }
.page-btn:disabled { opacity: 0.4; cursor: default; }

/* ── Responsive (mobile-first) ──────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 99; }
  .main-content { margin-left: 0; }
  .topbar { display: none; }
  .mobile-topbar { display: flex; }
  .fab { display: flex; }
  .bottom-nav { display: flex; }
  /* page-content reserves space for the bottom nav (64px) plus the home
     indicator safe area, so list rows aren't trapped under the bar. */
  .page-content {
    padding: 16px;
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .search-filters { flex-direction: column; }
  .filter-select { width: 100%; }
  /* Bottom-sheet modals on phones — slides up from the bottom, height
     follows content (no awkward grey expanse for short modals like
     "Přidat klienta" type-picker), capped at 90vh with internal scroll
     for long forms. Both dash-style (.modal-overlay > .modal) and BEM
     (.modal.active > .modal__dialog) markup get the same treatment. */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    /* height stays auto — sheet is the size of its contents, not the screen */
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,.15);
    display: flex;
    flex-direction: column;
  }
  .modal.active { padding: 0; align-items: flex-end; justify-content: stretch; }
  .modal__dialog {
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,.15);
    display: flex;
    flex-direction: column;
  }

  /* Header — drag-indicator pseudo-bar above the title hints "this is a
     bottom sheet, swipe down to dismiss" (familiar from iOS/Android). */
  .modal__header {
    padding: 16px;
    padding-top: 20px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    background: var(--surface-default);
    z-index: 1;
    border-radius: 16px 16px 0 0;
  }
  .modal__header::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--color-gray-200);
  }
  .modal__body {
    padding: 16px;
    /* No flex:1 — body sizes to content, the dialog height shrinks to fit.
       overflow-y:auto kicks in only if the body taller than the cap. */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Footer stays above the home indicator and never gets squashed by the
     virtual keyboard rising. */
  .modal__footer {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    background: var(--surface-default);
    z-index: 1;
    /* Primary action stretches and is the lowest tap target — closest
       to thumb, matches native bottom-sheet conventions. */
    flex-direction: column-reverse;
    gap: 8px;
  }
  .modal__footer > .btn,
  .modal__footer > button { width: 100%; }

  /* Close (✕) buttons in modal headers — bump to 44×44 hit target. */
  .modal__close, .btn-icon {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Toasts on mobile drop down to a bottom-anchored stack — easier to see
     near the thumb, and sits *above* the bottom-nav (+ home indicator)
     instead of getting hidden behind it. Width also stretches edge-to-edge
     with 12px side margin so messages aren't cropped on narrow screens. */
  .toast-container {
    top: auto;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    right: 12px;
    align-items: stretch;
  }
  .toast {
    min-width: 0;
    max-width: 100%;
    width: 100%;
  }

  .login-card { padding: 28px 20px; }

  /* Touch target compliance — Apple HIG 44px minimum.
     btn-sm icon buttons used in list rows (🗑, →, ✏️) are tappable. */
  .btn { min-height: 44px; padding: 10px 16px; }
  .btn-sm, .btn--sm { min-height: 40px; padding: 8px 12px; font-size: 14px; }
  .btn-ghost.btn-sm, .btn--ghost.btn--sm { min-width: 40px; }

  /* Tables on phones: bigger row hit targets, no horizontal squeeze on
     truncated columns — the action buttons drift to a new line if needed. */
  table td, table th { padding: 14px 10px; }

  /* Page header: title + add button stack instead of cramming horizontally. */
  .page-header { flex-wrap: wrap; gap: 12px; }
  .page-header > * { min-width: 0; }

  /* Dashboard stat-cards readable on a phone — bump the value font but
     pack labels tighter. */
  .stat-card__value { font-size: 28px; }
  .stat-card__label { font-size: 11px; }

  /* Phase 10 — admin wizard branch grid was 3-up on desktop; collapse to
     a single column so the per-branch contact rows don't truncate. */
  #wizard-org-tree > div > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Phase 10 — Moje úkoly add-form had 4 inputs in a row; let them wrap. */
  #tasks-add-form > div { min-width: 0 !important; }
  #tasks-add-form > div[style*="width:140px"],
  #tasks-add-form > div[style*="width:120px"] { width: 100% !important; flex: 1 1 100% !important; }

  /* Phase 10 — feedback filter bar wraps too tightly; let dropdowns grow. */
  #feedback-filter-category, #feedback-filter-days { flex: 1; }
}

/* ── Tighter mobile (≤480px — iPhone SE / 12 mini portrait) ────── */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card__value { font-size: 24px; }
  .page-content { padding: 12px; }
  /* Dashboard week strip: 5 days side-by-side gets cramped under 380px;
     allow horizontal scroll instead of squeezing. */
  .dashboard-grid { grid-template-columns: 1fr !important; }
  /* Mobile keyboard pushes content up: make sure inline forms don't lose
     the action button below the fold. */
  #tasks-add-form, #feedback-add-form { padding-bottom: 8px; }
}
