:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #ca8a04;
  --warn-bg: #fef9c3;
  --crit: #dc2626;
  --crit-bg: #fee2e2;
  --radius: 12px;
  --nav-h: 60px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}

body.logged-out .bottomnav,
body.logged-out .topbar { display: none; }
body.logged-out { padding-bottom: 0; }

.hidden { display: none !important; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--primary);
  color: #fff;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 17px; }
.timer-chip {
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.4);
  color: #fff;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55%;
}

/* ---------- Layout ---------- */
.view {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
h1 { font-size: 22px; line-height: 1.2; }
.section-title { font-size: 16px; color: var(--muted); margin: 18px 0 10px; }
.back-link { display: inline-block; color: var(--muted); text-decoration: none; margin-bottom: 8px; font-size: 14px; }
.loading, .empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
}
.error-box { color: var(--crit); }

/* ---------- Karty ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.card-title { font-size: 15px; margin-bottom: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }

/* ---------- Przyciski ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  min-height: 44px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-danger { background: var(--crit); color: #fff; }
.btn-block { width: 100%; margin-bottom: 10px; }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: 13px; }
.btn:disabled { opacity: .6; }
.icon-btn {
  background: #e2e8f0;
  border: none;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 17px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.row-actions { display: flex; gap: 8px; align-items: center; }
.add-row { margin-bottom: 10px; }
.add-row .btn { flex: 1; }

/* ---------- Chipy filtrów ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; }
.chip {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}
.chip-active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Pigułki / badge ---------- */
.pill {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}
.pill-wycena { background: #e0e7ff; color: #3730a3; }
.pill-zaakceptowany { background: #cffafe; color: #155e75; }
.pill-w_realizacji { background: #dbeafe; color: #1e40af; }
.pill-zakonczony { background: #e2e8f0; color: #475569; }

.badge {
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-crit { background: var(--crit-bg); color: var(--crit); }
.badge-muted { background: #e2e8f0; color: var(--muted); font-weight: 500; }

/* ---------- Karty projektów ---------- */
.project-card { display: block; text-decoration: none; color: inherit; }
.project-card:active { background: #f8fafc; }
.project-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.project-name { font-weight: 700; font-size: 16px; }
.project-client { color: var(--muted); font-size: 14px; }
.project-card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.meta-item { color: var(--muted); font-size: 13px; }
.quote-total { font-weight: 700; }

/* ---------- Alerty ---------- */
.alerts { margin-bottom: 12px; }
.alert-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  text-decoration: none;
  font-size: 14px;
  border: 1px solid;
}
.alert-warning { background: var(--warn-bg); color: #854d0e; border-color: #fde047; }
.alert-critical { background: var(--crit-bg); color: #991b1b; border-color: #fca5a5; }

/* ---------- Statystyki ---------- */
.stat-row { display: flex; gap: 10px; margin-bottom: 10px; }
.stat-card { flex: 1; text-align: center; margin-bottom: 0; }
.stat-value { font-size: 22px; font-weight: 800; }
.stat-label { color: var(--muted); font-size: 13px; }

/* ---------- Paski postępu ---------- */
.bar-wrap {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
}
.bar { height: 100%; border-radius: 999px; transition: width .3s; }
.bar-ok { background: var(--ok); }
.bar-warn { background: var(--warn); }
.bar-crit { background: var(--crit); }
.bar-time { background: var(--primary); }
.bar-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- Widok projektu ---------- */
.contact-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 10px;
}
.contact-line a { color: var(--primary); text-decoration: none; }
.status-select { display: block; margin-bottom: 10px; font-size: 14px; color: var(--muted); }
.status-select select { margin-top: 4px; }
.quote-link { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.locked-note { background: var(--ok-bg); color: #166534; padding: 10px 12px; border-radius: 10px; }

.profit-card { border-left: 5px solid var(--ok); }
.profit-warn { border-left-color: var(--warn); }
.profit-crit { border-left-color: var(--crit); }
.profit-grid div { display: flex; justify-content: space-between; align-items: baseline; padding: 3px 0; gap: 10px; }
.profit-grid .k { color: var(--muted); font-size: 14px; }
.profit-grid .v { font-weight: 600; white-space: nowrap; }
.profit-main { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px !important; }
.profit-main .v { font-size: 18px; font-weight: 800; display: flex; gap: 8px; align-items: center; }
.breakdown { font-size: 13px; color: var(--muted); margin-top: 8px; }
.calibration {
  margin-top: 12px;
  padding: 10px 12px;
  background: #eff6ff;
  border-radius: 10px;
  font-size: 14px;
}
.calibration-bad { background: var(--warn-bg); }

/* ---------- Zakładki ---------- */
.tabs {
  display: flex;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 12px;
  gap: 4px;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 6px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.tab-active { background: var(--primary); color: #fff; }

/* ---------- Listy wpisów ---------- */
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
}
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.list-sub { color: var(--muted); font-size: 13px; }
.list-amount { font-weight: 700; white-space: nowrap; }
.inactive-row { opacity: .55; }

/* ---------- Zadania ---------- */
.task-check {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: #fff;
  font-size: 17px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}
.task-zrobione .task-check { background: var(--ok); border-color: var(--ok); color: #fff; }
.task-zrobione .list-title { text-decoration: line-through; color: var(--muted); }
.task-w_trakcie .task-check { border-color: var(--primary); }

.quick-add { display: flex; gap: 8px; margin-bottom: 12px; }
.quick-add input { flex: 1; }
.quick-add .hours-input { flex: 0 0 64px; }
.quick-add .btn { flex: 0 0 auto; min-width: 48px; }

/* ---------- Stoper ---------- */
.timer-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.timer-running { border-color: var(--primary); background: #eff6ff; font-weight: 600; }
.timer-banner { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Formularze ---------- */
form label {
  display: block;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}
input, select, textarea {
  width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
}
.radio-row { display: flex; gap: 16px; margin-bottom: 12px; }
.radio { display: flex !important; align-items: center; gap: 8px; margin-bottom: 0 !important; }
.radio input, .toggle-inactive input { width: auto; min-height: 0; margin: 0; }
.toggle-inactive { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.hint { font-size: 13px; color: var(--muted); margin: -6px 0 12px; display: block; }
label .hint { margin: 4px 0 0; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.form-actions .btn-danger { margin-right: auto; }
.confirm-msg { margin-bottom: 4px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .5);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal {
  background: var(--card);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  animation: slideUp .18s ease-out;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { font-size: 18px; }

/* ---------- Toasty ---------- */
.toasts {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  opacity: 0;
  transform: translateY(8px);
  transition: all .25s;
  text-align: center;
}
.toast.show { opacity: 1; transform: none; }
.toast-error { background: var(--crit); }

/* ---------- Dolna nawigacja ---------- */
.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 50;
}
.bottomnav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
.bottomnav a.active { color: var(--primary); }
.bottomnav svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Logowanie ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-logo { font-size: 40px; margin-bottom: 8px; }
.login-card h1 { margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.login-card input { margin-bottom: 12px; text-align: center; }
.login-err { color: var(--crit); font-size: 14px; margin-top: 10px; }

/* ---------- Wycena ---------- */
.totals-card .totals-grid { margin-bottom: 4px; }
.totals-grid div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals-grid .k { color: var(--muted); font-size: 14px; }
.totals-grid .v.strong { font-size: 20px; font-weight: 800; }
.totals-card .btn { margin-top: 10px; margin-bottom: 0; }
.notes-card { color: var(--muted); font-size: 14px; white-space: pre-wrap; }

/* ---------- Import ---------- */
.file-btn { cursor: pointer; margin-top: 4px; }
.file-link { display: block; text-align: center; font-size: 13px; color: var(--primary); cursor: pointer; text-decoration: underline; margin: -2px 0 6px; }
.import-list { margin-top: 12px; }
.import-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.import-row label { margin-bottom: 8px; }
.import-row-off { opacity: .6; }
.import-row-head { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; color: var(--muted); }
.import-amount { font-weight: 700; color: var(--text); text-align: right; white-space: nowrap; }
.import-amount small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.import-desc { font-weight: 600; margin: 4px 0 6px; overflow-wrap: anywhere; }
.import-desc a, .import-badges a { color: var(--primary); font-weight: 500; font-size: 13px; }
.import-badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.import-badges .badge { font-size: 12px; padding: 3px 8px; }
.import-check { display: flex !important; gap: 10px; align-items: center; color: var(--text) !important; font-size: 15px !important; }
.import-check input { width: 20px; height: 20px; min-height: 0; margin: 0; flex: 0 0 auto; }
.import-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.import-summary { font-size: 13px; color: var(--muted); margin: 6px 0 10px; text-align: center; }
.offer-link { color: var(--primary); text-decoration: none; }
.photo-link { text-decoration: none; margin-left: 4px; }

/* ---------- Oferty online ---------- */
.sync-card { border-left: 4px solid var(--primary); }
.sync-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sync-head .hint { margin: 2px 0 0; }
.sync-error { margin-top: 8px; font-size: 13px; color: #991b1b; background: var(--crit-bg); padding: 8px 10px; border-radius: 8px; }
.offer-note { background: #eff6ff; color: #1e3a8a; padding: 10px 12px; border-radius: 10px; margin: 0 0 12px; }

/* ---------- Ceny zakupu i koszty przy akceptacji ---------- */
.group-head { display: flex; align-items: center; gap: 8px; margin: 16px 0 8px; }
.group-head .hint { margin: 0; }
.group-head .btn { margin-left: auto; }
.koszt-preview { background: #eff6ff; color: #1e3a8a; padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 4px; }
.pending-note { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: var(--warn-bg); color: #854d0e; font-size: 14px; }
.warn-text { color: #a16207; font-weight: 600; }
.plan-auto { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 12px 0; }
.plan-auto summary { cursor: pointer; font-size: 14px; }
.plan-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); padding: 3px 0; }
.plan-row span:last-child { white-space: nowrap; }
.plan-head { font-size: 15px; margin: 14px 0 8px; }
.manual-row { border-bottom: 1px solid var(--border); padding-bottom: 6px; margin-bottom: 10px; }
.manual-row .radio { font-size: 13px; }

/* ---------- Desktop ---------- */
@media (min-width: 700px) {
  .view { padding: 24px; }
  .modal-overlay { align-items: center; }
  .modal { border-radius: 16px; }
  .stat-value { font-size: 26px; }
}
