:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #0d9488;
  --accent-dark: #0f766e;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08);
  --topbar-h: 56px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- top bar / nav ---------- */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-h);
  padding: 0 14px;
  background: #0f172a; color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.save-status { margin-left: auto; font-size: 12px; opacity: .85; white-space: nowrap; }
.save-status.err { color: #fca5a5; }
.save-status.ok { color: #6ee7b7; }

.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: transparent; color: #cbd5e1;
  padding: 8px 12px; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-family: inherit;
}
.tab:hover { background: rgba(255,255,255,.1); }
.tab.active { background: var(--accent); color: #fff; }

/* mobile: nav at bottom */
@media (max-width: 767px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
    background: #0f172a;
    justify-content: space-around;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 8px rgba(0,0,0,.25);
  }
  .tab { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; padding: 6px 10px; flex: 1; }
  body { padding-bottom: 78px; }
}

.local-banner {
  background: #fef3c7; color: #92400e;
  padding: 8px 14px; font-size: 13px; text-align: center;
  border-bottom: 1px solid #fde68a;
}
.hidden { display: none !important; }

main { max-width: 1400px; margin: 0 auto; padding: 14px; }
.narrow { max-width: 720px; margin: 0 auto; }

h2 { font-size: 17px; margin: 0; }

/* ---------- generic ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; margin-bottom: 12px;
}
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 8px 12px; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-family: inherit; white-space: nowrap;
}
.btn:hover { background: #f8fafc; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.accent:hover { background: var(--accent-dark); }
.btn.small { padding: 4px 8px; font-size: 13px; }
.btn.icon { padding: 4px 7px; font-size: 13px; line-height: 1; }
.btn.danger { color: var(--danger); }

input[type="text"], input[type="number"], input[type="date"], input[type="time"], textarea, select {
  font-family: inherit; font-size: 15px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text);
  min-width: 0;
}
textarea { width: 100%; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.add-form { display: flex; flex-direction: column; gap: 8px; }
.form-row { display: flex; gap: 8px; }
.form-row > input[type="text"], .form-row > input[type="number"] { flex: 1; }
.form-row > select { flex: 1; }

.empty {
  color: var(--muted); text-align: center; padding: 24px 12px; font-size: 14px;
  border: 1px dashed var(--border); border-radius: var(--radius);
}

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; color: #fff;
}

/* ---------- plan layout ---------- */
.plan-layout { display: flex; flex-direction: column; gap: 14px; }
@media (min-width: 900px) {
  .plan-layout { flex-direction: row; align-items: flex-start; }
  .map-pane { flex: 1.15; position: sticky; top: calc(var(--topbar-h) + 14px); }
  .days-pane { flex: 1; }
  #map { height: calc(100vh - var(--topbar-h) - 140px); min-height: 420px; }
}
#map { height: 46vh; min-height: 300px; border-radius: var(--radius); border: 1px solid var(--border); z-index: 1; }
.map-wrap { position: relative; }
.map-toolbar { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.map-toolbar select { flex: 1; }
.map-hint {
  background: #ccfbf1; color: #115e59; border: 1px solid #99f6e4;
  padding: 6px 10px; border-radius: 8px; font-size: 13px; margin-bottom: 8px;
}
.route-info { font-size: 13px; color: var(--muted); margin-top: 6px; min-height: 18px; }

.point-form {
  position: absolute; z-index: 1200;
  left: 10px; right: 10px; bottom: 10px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(15,23,42,.2);
  padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.pf-title { font-weight: 700; font-size: 14px; }
.pf-row { display: flex; gap: 8px; }
.pf-row > select, .pf-row > .btn { flex: 1; }
#pfName { width: 100%; }

.pane-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }

/* ---------- day card ---------- */
.day-card { margin-bottom: 12px; padding: 0; overflow: hidden; }
.day-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: #f8fafc; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.day-num {
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13px;
  border-radius: 8px; padding: 4px 8px; white-space: nowrap;
}
.day-head input[type="date"] { font-size: 13px; padding: 4px 6px; }
.day-head .day-title { flex: 1; min-width: 120px; border: none; background: transparent; font-weight: 600; padding: 4px 6px; }
.day-head .day-title:focus { background: #fff; }
.day-weekday { font-size: 12px; color: var(--muted); width: 100%; padding-left: 2px; }

.day-items { padding: 6px 10px; }
.plan-item {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 7px 4px; border-bottom: 1px solid #f1f5f9;
}
.pi-body { flex-basis: 120px; }
.pi-actions { margin-left: auto; }
@media (max-width: 520px) {
  .pi-actions { width: 100%; justify-content: flex-end; }
}
.plan-item:last-child { border-bottom: none; }
.pi-icon {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
  color: #fff;
}
.pi-body { flex: 1; min-width: 0; }
.pi-name { font-weight: 600; overflow-wrap: anywhere; }
.pi-meta { font-size: 12px; color: var(--muted); }
.pi-actions { display: flex; gap: 3px; flex-shrink: 0; }

.item-edit { display: flex; flex-direction: column; gap: 6px; padding: 8px 4px; }
.item-edit .form-row > input[type="time"] { width: 110px; flex: 0 0 auto; }

.day-foot { padding: 8px 10px 10px; }
.add-item-form { display: flex; gap: 6px; flex-wrap: wrap; }
.add-item-form input[type="text"] { flex: 1 1 140px; }
.add-item-form input[type="time"] { flex: 0 0 auto; width: 102px; }
.add-item-form select { flex: 0 1 auto; }

/* ---------- chips (note filters) ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--border); background: #fff; border-radius: 999px;
  padding: 5px 12px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.chip.active { background: var(--text); color: #fff; border-color: var(--text); }

/* ---------- notes ---------- */
.note-card { display: flex; flex-direction: column; gap: 6px; }
.note-head { display: flex; align-items: center; gap: 8px; }
.note-date { font-size: 12px; color: var(--muted); }
.note-actions { margin-left: auto; display: flex; gap: 4px; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- expenses ---------- */
.rates-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.rates-row { display: flex; gap: 14px; flex-wrap: wrap; }
.rates-row label { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.rates-row input { width: 110px; }
.rates-info { font-size: 12px; color: var(--muted); margin-top: 6px; }
.rates-info.err { color: var(--danger); }
.filters .form-row > select { flex: 1.4; }
.filters .form-row > input[type="date"] { flex: 1; }
.new-cat-box { border: 1px dashed var(--border); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.exp-orig { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sum-warn { margin-top: 8px; font-size: 13px; color: #92400e; background: #fef3c7; border-radius: 8px; padding: 6px 10px; }
.sum-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.summary .sum-total { font-size: 26px; font-weight: 800; }
.summary .sum-label { font-size: 13px; color: var(--muted); }
.sum-cats { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.sum-cat-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.sum-cat-row .bar-wrap { flex: 1; background: #f1f5f9; border-radius: 4px; height: 8px; overflow: hidden; }
.sum-cat-row .bar { display: block; height: 100%; border-radius: 4px; }
.sum-cat-row .cat-name { width: 110px; flex-shrink: 0; }
.sum-cat-row .cat-val { width: 110px; text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }

.exp-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 12px; margin-bottom: 6px;
}
.exp-amount { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.exp-desc { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.exp-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------- packing ---------- */
.pack-section { margin-bottom: 16px; }
.pack-section h3 { font-size: 15px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.pack-progress { font-size: 12px; color: var(--muted); font-weight: 400; }
.pack-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 12px; margin-bottom: 6px;
}
.pack-item label { flex: 1; display: flex; align-items: center; gap: 10px; cursor: pointer; min-width: 0; }
.pack-item input[type="checkbox"] { width: 19px; height: 19px; accent-color: var(--accent); flex-shrink: 0; }
.pack-item.done .pack-text { text-decoration: line-through; color: var(--muted); }
.pack-text { overflow-wrap: anywhere; }

/* ================= MOBILE: przełącznik Mapa / Plan dni ================= */
.plan-switch { display: none; gap: 6px; margin-bottom: 10px; }
.ps-btn {
  flex: 1; border: 1px solid var(--border); background: #fff; color: var(--muted);
  font-family: inherit; font-size: 15px; font-weight: 600;
  padding: 10px; border-radius: 10px; cursor: pointer;
}
.ps-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

@media (max-width: 899px) {
  .plan-switch { display: flex; }
  .plan-layout[data-pane="map"] .days-pane,
  .plan-layout[data-pane="days"] .map-pane { display: none; }
  /* Wysokość wyliczana w JS (fitMapHeight) z realnie wolnego miejsca; poniżej wartość
     startowa, zanim skrypt się wykona — dvh, żeby nie skakało przy pasku przeglądarki. */
  #map { height: calc(100vh - var(--topbar-h) - 260px); }
  @supports (height: 100dvh) {
    #map { height: calc(100dvh - var(--topbar-h) - 260px); }
  }
}

/* ================= DOTYK: większe pola i przyciski ================= */
@media (pointer: coarse), (max-width: 620px) {
  * { -webkit-tap-highlight-color: rgba(13, 148, 136, .15); }
  input[type="text"], input[type="number"], input[type="date"], input[type="time"], textarea, select {
    font-size: 16px;            /* mniej = Android/iOS przybliża widok przy wpisywaniu */
    padding: 10px 12px;
  }
  .btn { padding: 10px 14px; min-height: 44px; }
  .btn.small { padding: 8px 12px; min-height: 40px; }
  .btn.icon { min-width: 42px; min-height: 40px; font-size: 16px; padding: 4px; }
  .chip { padding: 9px 15px; }
  .pack-item { padding: 12px; }
  .pack-item input[type="checkbox"] { width: 24px; height: 24px; }
  .day-head .day-title, .day-head input[type="date"] { font-size: 16px; padding: 8px; }
}

/* ================= WĄSKIE EKRANY: zawijanie formularzy ================= */
@media (max-width: 620px) {
  main { padding: 10px; }
  .form-row { flex-wrap: wrap; }
  .form-row > input[type="text"], .form-row > input[type="number"],
  .form-row > input[type="date"], .form-row > select { flex: 1 1 140px; }
  #expAmount { flex: 2 1 110px; }
  #expCurrency { flex: 0 0 84px; }
  #expDate { flex: 1 1 150px; }
  .map-toolbar > select { flex: 1 1 140px; }
  .map-toolbar > .btn { flex: 1 1 auto; }
  .add-item-form { gap: 8px; }
  .add-item-form input[type="text"] { flex: 1 1 100%; }
  .add-item-form input[type="time"] { flex: 1 1 auto; }
  .add-item-form select { flex: 2 1 auto; }
  .add-item-form button { flex: 0 0 56px; }
  .rates-row { gap: 10px; }
  .rates-row label { flex: 1 1 100%; justify-content: space-between; }
  .rates-row input { width: 120px; }
  .exp-row { flex-wrap: wrap; row-gap: 4px; }
  .exp-desc { flex: 1 1 100%; order: 3; }
  .sum-cat-row .cat-name { width: auto; flex: 1 1 auto; }
  .sum-cat-row .bar-wrap { flex: 0 0 60px; }
  .sum-cat-row .cat-val { width: auto; min-width: 92px; }
  .point-form { left: 6px; right: 6px; bottom: 6px; }
}

/* zwijanie dni (przydatne przy długim wyjeździe na małym ekranie) */
.day-toggle {
  border: none; background: transparent; cursor: pointer;
  font-size: 15px; color: var(--muted); padding: 4px 6px; line-height: 1;
}
.day-card.collapsed .day-items, .day-card.collapsed .day-foot { display: none; }
.day-summary { font-size: 12px; color: var(--muted); padding: 8px 12px; }

/* leaflet marker */
.num-marker {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50% 50% 50% 4px;
  color: #fff; font-weight: 700; font-size: 13px;
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
