/* ===== Dlužníček — mobilní-first stylování + tmavý režim ===== */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1f3864;
  --primary-light: #2e75b6;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --surface-3: #f9fafb;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #ea580c;
  --info-bg: #e0f2fe;
  --info-fg: #075985;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.04);
  /* Z-index hierarchie — od nejnižší po nejvyšší vrstvu */
  --z-fab: 5;
  --z-tabs: 9;
  --z-topbar: 10;
  --z-modal-action: 11;
  --z-modal: 100;
  --z-toast: 200;
  --z-viewer: 300;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #2e75b6;
    --primary-light: #4a90d9;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #0f172a;
    --surface-3: #1a2336;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #334155;
    --danger: #f87171;
    --success: #4ade80;
    --warning: #fb923c;
    --info-bg: #1e3a5f;
    --info-fg: #93c5fd;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.2);
  }
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }

/* ===== Login ===== */
#screen-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.login-box h1 {
  color: var(--primary);
  font-size: 32px;
  margin-bottom: 8px;
}
.subtitle {
  color: var(--muted);
  margin-bottom: 32px;
}
.invite-banner {
  background: var(--info-bg);
  color: var(--info-fg);
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}

/* ===== Tlačítka ===== */
.btn {
  border: none;
  cursor: pointer;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 500;
  transition: opacity .15s, transform .05s;
  font-family: inherit;
}
.btn:active { transform: scale(.98); }
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-light); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover { color: var(--text); }
.btn-danger {
  background: transparent;
  color: var(--danger);
  margin-right: auto;
}
.btn-danger:hover { background: rgba(220,38,38,.06); }
.btn-small {
  padding: 6px 12px;
  font-size: 14px;
}
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 24px;
  width: 100%;
  justify-content: center;
}
.btn-google:hover { background: var(--surface-3); }
.btn-share {
  width: 100%;
  background: var(--surface);
  color: var(--primary);
  border: 1px dashed var(--primary-light);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  font-size: 15px;
  cursor: pointer;
  font-family: inherit;
}
.btn-share:hover { background: var(--surface-3); }

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.topbar h1 {
  flex: 1;
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  margin: 0 12px;
  cursor: pointer;
}
.topbar-btn {
  background: transparent;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.topbar-btn:hover { background: rgba(255,255,255,.1); }
.topbar-btn svg {
  width: 22px;
  height: 22px;
  display: block;
}

/* Instalační tlačítko se zvýraznilo — ikona + text */
.topbar-btn-install {
  gap: 6px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  background: rgba(255,255,255,.18);
  font-family: inherit;
}
.topbar-btn-install svg {
  width: 18px;
  height: 18px;
}
.topbar-btn-install:hover { background: rgba(255,255,255,.28); }

/* ===== View ===== */
.view {
  position: relative;
  padding: 16px;
  padding-bottom: 96px;
  min-height: calc(100vh - 56px);
}

/* ===== Seznamy a karty ===== */
.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .05s;
}
.card:active { transform: scale(.99); }
.card-title {
  font-weight: 600;
  margin-bottom: 4px;
}
.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-meta {
  font-size: 13px;
  color: var(--muted);
}
.card-meta-converted {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.amount-pos { color: var(--success); }
.amount-neg { color: var(--danger); }

/* Kategorie ikona v meta řádku */
.category-icon {
  display: inline-block;
  margin-right: 4px;
}

/* ===== Floating Action Button ===== */
.fab {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 28px;
  font-weight: 300;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(31, 56, 100, 0.32), 0 2px 6px rgba(31, 56, 100, 0.18);
  z-index: var(--z-fab);
}
.fab:hover { background: var(--primary-light); }
.fab:active { transform: scale(.95); }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 56px;
  z-index: var(--z-tabs);
}
.tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 16px 4px;     /* zvětšeno z 14 na 16 → větší dotyková plocha */
  min-height: 48px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  font-family: inherit;
}
.tab-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-pane {
  padding: 16px;
  padding-bottom: 96px;
  min-height: calc(100vh - 110px);
}

.section-title {
  margin: 24px 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ===== Empty state ===== */
.empty {
  text-align: center;
  padding: 32px 24px;
  color: var(--muted);
}
.empty p { margin-bottom: 8px; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: var(--z-modal);
  animation: fadeIn .15s ease;
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp .25s ease;
  color: var(--text);
}
.modal-card h2 {
  font-size: 20px;
  margin-bottom: 16px;
}
.modal-card label {
  display: block;
  margin: 12px 0 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}
.modal-card input, .modal-card select {
  width: 100%;
  padding: 12px;
  border: 2px solid transparent;
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color .15s, background .15s;
  min-height: 44px;       /* dotyková plocha */
}
.modal-card input:focus, .modal-card select:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}

/* Sticky tlačítka modalu — vždy viditelná i u dlouhých formulářů */
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  align-items: center;
  position: sticky;
  bottom: -24px;          /* kompenzace paddingu modal-card */
  margin: 16px -24px -24px;
  padding: 16px 24px 24px;
  background: var(--surface);
  z-index: var(--z-modal-action);
}
.modal-actions::before {
  /* Měkký fade gradient nad tlačítky — naznačí, že obsah pokračuje */
  content: "";
  position: absolute;
  top: -16px;
  left: 0;
  right: 0;
  height: 16px;
  background: linear-gradient(to bottom, transparent, var(--surface));
  pointer-events: none;
}

.row-2col {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
}

.rate-info {
  margin-top: 6px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-radius: 6px;
  font-size: 13px;
}

/* ===== Split mode tabs ===== */
.split-mode-tabs {
  display: flex;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 3px;
  margin-top: 4px;
  margin-bottom: 8px;
}
.split-mode-tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 4px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
}
.split-mode-tab.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow);
}
.split-mode-hint {
  font-size: 13px;
  margin-bottom: 8px;
}

/* ===== Split rows (participants) ===== */
.split-list {
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface);
}
.split-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px;       /* o trochu větší pro dotykovou plochu */
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}
.split-row:last-child { border-bottom: none; }
.split-row-label {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-weight: 400;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  min-height: 44px;
}
.split-row-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
}
.split-row-name {
  flex: 1;
}
.split-row-input {
  width: 90px !important;
  padding: 6px 8px !important;
  font-size: 15px !important;
  text-align: right;
}
.split-row-suffix {
  width: 40px;
  font-size: 13px;
  color: var(--muted);
  text-align: left;
}
.split-sum {
  padding: 10px 12px;
  text-align: right;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface-3);
  border-radius: 0 0 8px 8px;
}
.split-sum.error { color: var(--danger); font-weight: 500; }
.split-sum.success { color: var(--success); }

/* ===== Invite link box ===== */
.invite-link-box {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.invite-link-box input {
  flex: 1;
  font-size: 13px !important;
  padding: 8px !important;
}
.invite-link-box button {
  padding: 8px 14px;
  font-size: 14px;
  white-space: nowrap;
}

/* ===== Účtenky (receipts) ===== */
.btn-receipt-add {
  width: 100%;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  color: var(--muted);
  padding: 14px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  font-family: inherit;
}
.btn-receipt-add:hover {
  background: var(--surface-3);
  color: var(--text);
}
.receipt-preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}
.receipt-preview img {
  max-width: 100%;
  max-height: 240px;
  border-radius: 8px;
  cursor: pointer;
  object-fit: contain;
  background: var(--surface-2);
}
.receipt-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.receipt-progress {
  padding: 10px;
  background: var(--info-bg);
  color: var(--info-fg);
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
}

.receipt-icon {
  display: inline-block;
  margin-right: 4px;
  vertical-align: middle;
  color: var(--muted);
}
.receipt-icon svg {
  width: 14px;
  height: 14px;
  vertical-align: middle;
}

.receipt-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-viewer);
  animation: fadeIn 0.2s;
}
.receipt-viewer img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
}
.receipt-viewer-close {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: none;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
}
.receipt-viewer-close:hover { background: rgba(255, 255, 255, 0.25); }

/* ===== Expense metadata (kdo a kdy vytvořil/upravil) ===== */
.expense-meta {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

/* ===== Statistiky ===== */
.stats-summary {
  cursor: default !important;
}
.stats-summary-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  text-align: center;
}
.stats-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 4px;
}
.stats-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.chart-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  max-width: 360px;
  margin: 0 auto 12px;
}
.chart-wrap-bar {
  max-width: 100%;
}
.chart-wrap canvas {
  max-height: 280px;
}
.stats-legend {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px 4px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  font-size: 14px;
}
.legend-color {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}
.legend-label {
  flex: 1;
  color: var(--text);
}
.legend-value {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ===== PWA install instructions ===== */
.install-steps {
  margin: 12px 0;
  padding-left: 24px;
  line-height: 1.7;
}
.install-steps li {
  margin-bottom: 8px;
}

/* ===== Color picker (barva skupiny) ===== */
.color-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
  padding: 4px 0;
}
.color-swatch {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform .1s, border-color .1s;
  padding: 0;
  flex-shrink: 0;
}
.color-swatch:hover { transform: scale(1.06); }
.color-swatch.active {
  border-color: var(--text);
  transform: scale(1.08);
}

/* ===== Group card s barevným pruhem + hvězdou ===== */
.group-card {
  position: relative;
  border-left: 4px solid var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-star {
  background: transparent;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--muted);
  flex-shrink: 0;
  font-family: inherit;
  line-height: 1;
  transition: color .15s, transform .1s;
}
.card-star.active { color: #f59e0b; }
.card-star:active { transform: scale(1.2); }
.card-star:hover { color: var(--text); }
.group-card .card-star.active:hover { color: #d97706; }

.group-card-content {
  flex: 1;
  min-width: 0;
}
.group-card-arrow {
  font-size: 20px;
  color: var(--muted);
  flex-shrink: 0;
}

/* Banner pro neaktivní skupiny */
.inactivity-banner {
  background: var(--info-bg);
  color: var(--info-fg);
  border-left: 3px solid var(--warning);
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 14px;
  line-height: 1.5;
}
.inactivity-banner.danger {
  background: rgba(220,38,38,.08);
  color: var(--danger);
  border-left-color: var(--danger);
}

/* ===== Help modal ===== */
.help-modal-card {
  max-width: 600px;
}
.help-content h3 {
  margin-top: 24px;
  margin-bottom: 8px;
  font-size: 16px;
  color: var(--primary);
  font-weight: 600;
}
.help-content h3:first-child { margin-top: 0; }
.help-content p {
  margin: 8px 0;
  line-height: 1.6;
  font-size: 15px;
  color: var(--text);
}
.help-content ul, .help-content ol {
  margin: 8px 0 12px 22px;
  line-height: 1.7;
  font-size: 15px;
  color: var(--text);
}
.help-content li {
  margin-bottom: 6px;
}
.help-content code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: Consolas, monospace;
}
.help-tip {
  background: var(--info-bg);
  color: var(--info-fg);
  border-left: 3px solid var(--primary);
  padding: 10px 14px;
  margin: 12px 0;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.5;
}

/* ===== Safe area pro iOS standalone (notch) ===== */
@supports (padding: env(safe-area-inset-top)) {
  .topbar {
    padding-top: calc(14px + env(safe-area-inset-top));
  }
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ===== Větší obrazovky ===== */
@media (min-width: 600px) {
  .view, .tab-pane { max-width: 720px; margin: 0 auto; }
  .modal { align-items: center; }
  .modal-card { border-radius: var(--radius); }
  .topbar h1 { text-align: left; }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: var(--z-toast);
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  animation: fadeIn .2s;
  max-width: 90%;
  text-align: center;
}
.toast.error { background: var(--danger); color: white; }
.toast.success { background: var(--success); color: white; }
