:root {
  /* iOS light theme */
  --bg: #f2f2f7;          /* iOS grouped background */
  --surface: #ffffff;      /* cards */
  --surface-2: #ececef;    /* input fills / secondary */
  --border: #d9d9de;       /* hairline separators */
  --text: #1c1c1e;         /* label */
  --muted: #8a8a8e;        /* secondary label */
  --accent: #007aff;       /* iOS blue */
  --danger: #ff3b30;       /* iOS red */
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 1px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* top bar with search — sticky, translucent iOS blur */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: max(env(safe-area-inset-top), 12px) 12px 8px;
  background: rgba(249, 249, 251, 0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--border);
}
#search {
  width: 100%;
  padding: 11px 14px;
  font-size: 17px;
  color: var(--text);
  background: var(--surface-2);
  border: none;
  border-radius: 11px;
  outline: none;
}
#search::placeholder { color: var(--muted); }
#search:focus { background: #e4e4e9; }

/* menu row — iOS segmented control feel */
.menu {
  display: flex;
  gap: 6px;
  padding: 6px 12px 10px;
  position: sticky;
  top: 62px;
  z-index: 9;
  background: rgba(249, 249, 251, 0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--border);
}
.tab {
  flex: 1;
  padding: 8px 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.tab.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.tab.add-btn {
  flex: 0 0 auto;
  min-width: 44px;
  font-size: 20px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

/* ＋ action sheet — slides up from bottom */
.sheet-backdrop, .modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
/* `display: flex` above overrides the UA `[hidden] { display: none }`, so
   the attribute alone won't hide these overlays — the empty modal then
   sits on top and eats every click. Restore hiding with higher specificity. */
.sheet-backdrop[hidden], .modal-backdrop[hidden] { display: none; }
.modal-backdrop { align-items: center; padding: 16px; }
.sheet {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 12px 12px calc(env(safe-area-inset-bottom) + 12px);
}
.modal-backdrop .sheet { border-radius: 16px; }
.sheet-item, .sheet-cancel {
  width: 100%;
  padding: 16px;
  margin-bottom: 8px;
  font-size: 17px;
  text-align: left;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
.sheet-cancel { text-align: center; color: var(--muted); margin-bottom: 0; }

/* form */
.form h2, .sheet h2 { margin: 4px 4px 12px; font-size: 18px; }
.fld {
  display: block;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--muted);
  position: relative;
}
.fld input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  font-size: 16px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
}
/* iOS renders native date/time inputs with their own intrinsic width +
   centering, which overflows the card. Strip the native chrome so width:100%
   + box-sizing hold, and left-align the value like a normal iOS form field. */
.fld input[type="date"],
.fld input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
  text-align: left;
  min-width: 0;
}
.fld input:focus { border-color: var(--accent); }
.fld select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  font-size: 16px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
}
.fld select:focus { border-color: var(--accent); }
/* select used inline on the card */
select.inl { -webkit-appearance: none; appearance: none; }

/* ---- talismani block ---- */
.talis-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.talis-head h2 { margin: 0; }
.btn-add-talis {
  padding: 6px 12px;
  font-size: 14px;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  cursor: pointer;
}
.talis-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.talis-empty { color: var(--muted); font-size: 14px; padding: 6px 2px; }
.talis-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.talis-badge {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 3px 8px;
  border-radius: 6px;
}
.talis-badge.osobni { color: #fff; background: var(--accent); }
.talis-badge.ostali { color: var(--text); background: var(--surface-2); border: 1px solid var(--border); }
.talis-oblik { flex: 1; min-width: 0; font-weight: 600; }
.talis-datum { flex: 0 0 auto; color: var(--muted); font-size: 13px; }
.talis-del {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.talis-del:active { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ---- TISA issue-quantity block ---- */
.tisa-summary {
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
}
.tisa-summary b { color: var(--accent); }
.tisa-legacy { color: #efa85f; font-size: 13px; margin: -4px 2px 10px; }
/* inline summary in the collapsible TISA header */
.tisa-sum-inline { flex: 1; text-align: right; color: var(--accent); font-weight: 600; font-size: 14px; margin-right: 8px; }
.tisa-block .acc-body { padding-top: 6px; }
.tisa-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  margin-bottom: 6px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.tisa-label { font-size: 15px; }
.tisa-qty { display: flex; align-items: center; gap: 12px; }
.qty-n.zero { color: var(--muted); opacity: 0.5; }
.qty-btn {
  width: 34px; height: 34px;
  font-size: 20px;
  line-height: 1;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.qty-n { min-width: 20px; text-align: center; font-weight: 700; font-size: 16px; }

/* ---- bioterapija accordion log ---- */
.acc-list { display: flex; flex-direction: column; gap: 6px; }
.acc-item { background: var(--surface); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
.acc-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.acc-title { flex: 1; min-width: 0; }
.acc-caret { flex: 0 0 auto; color: var(--muted); font-size: 13px; }
.acc-body { padding: 0 14px 12px; }
.acc-note { white-space: pre-wrap; color: var(--text); font-size: 15px; padding: 4px 0 10px; }
.acc-actions { display: flex; gap: 8px; }
.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.btn-sm.bio-del { color: var(--danger); }
.form textarea, .sheet textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  font-size: 16px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  font-family: inherit;
  resize: vertical;
}
.form textarea:focus, .sheet textarea:focus { border-color: var(--accent); }

/* segmented control (osobni / ostali) */
.seg { display: flex; gap: 6px; margin-bottom: 12px; }
.seg-opt { flex: 1; }
.seg-opt input { display: none; }
.seg-opt span {
  display: block;
  text-align: center;
  padding: 10px;
  font-size: 15px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.seg-opt input:checked + span { color: #fff; background: var(--accent); border-color: var(--accent); }
.row { display: flex; gap: 10px; }
.row .fld { flex: 1; min-width: 0; } /* min-width:0 lets flex children shrink instead of overflowing */

/* quick-duration buttons under Od/Do */
.dur-row { display: flex; gap: 8px; margin-bottom: 10px; }
.dur-btn {
  flex: 1;
  padding: 9px 4px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.dur-btn.active { color: #fff; background: var(--accent); border-color: var(--accent); }

/* quick-note keyword chips */
.note-quick { display: flex; flex-wrap: wrap; gap: 8px; margin: -2px 0 10px; }
.note-btn {
  padding: 7px 14px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.note-btn.active { color: #fff; background: var(--accent); border-color: var(--accent); }

/* client autocomplete inside the title field */
.ac { position: absolute; left: 0; right: 0; z-index: 5; }
.ac-item {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-top: none;
  cursor: pointer;
}
.ac-item:first-child { border-top: 1px solid var(--border); border-radius: 8px 8px 0 0; }
.muted { color: var(--muted); font-size: 13px; }

/* assignee chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.chip input { display: none; }
.chip-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--c);
  opacity: 0.35;
  transition: opacity .1s;
}
.chip:has(input:checked) { border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, var(--surface-2)); }
.chip:has(input:checked) .chip-dot { opacity: 1; }

.form-actions { display: flex; gap: 10px; margin-top: 14px; }
.btn {
  flex: 1;
  padding: 13px;
  font-size: 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
}
.btn.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.btn.ghost { color: var(--text); background: var(--surface-2); }
.btn.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
#openCard { width: 100%; margin-bottom: 4px; }

main { padding: 8px 12px 40px; }

/* client list — iOS inset list feel */
.client {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  margin-bottom: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.client::after {
  content: "›";
  color: var(--muted);
  font-size: 20px;
  margin-left: 4px;
}
.client:active { background: #f2f2f7; }
.client .name { font-weight: 600; flex: 1; }
.client .meta { color: var(--muted); font-size: 13px; white-space: nowrap; }

.hint { color: var(--muted); text-align: center; padding: 30px 10px; }

/* detail card */
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0 14px;
}
.back {
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
}
.card-head h1 { font-size: 20px; margin: 0; }
.card-head .sp { color: var(--muted); font-size: 13px; }
.card-title { flex: 1; min-width: 0; }
.btn-edit, .btn-save {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
}
.btn-edit { color: var(--text); background: var(--surface); }
.btn-save { color: #fff; background: var(--accent); border-color: var(--accent); }
/* edit/add forms reuse .fld inputs; make them full-width inside groups */
.group .fld { margin-bottom: 8px; }

/* read-only identity block on the card */
.group.identity { margin-top: 4px; }

/* inline-editable field on the card: label above, input/textarea below */
.inline-fld { display: block; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
.inl {
  display: block;
  width: 100%;
  margin-top: 3px;
  padding: 10px 12px;
  font-size: 15px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 9px;
  outline: none;
  transition: border-color .15s, background .4s;
  font-family: inherit;
  resize: vertical;
}
.inl:focus { border-color: var(--accent); background: #fff; }
.inl.saved { border-color: #34c759; background: color-mix(in srgb, #34c759 14%, #fff); }
.inl.err { border-color: var(--danger); }

.group { margin-bottom: 22px; }
.group h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .02em;
  color: var(--muted);
  margin: 0 0 8px 4px;
  font-weight: 600;
}
.field {
  padding: 11px 14px;
  background: var(--surface);
  border-radius: 10px;
  margin-bottom: 6px;
  box-shadow: var(--shadow);
}
.field .k { font-size: 12px; color: var(--muted); }
.field .v { margin-top: 2px; white-space: pre-wrap; }

.stub { color: var(--muted); text-align: center; padding: 50px 16px; }
.stub .big { font-size: 40px; }

/* calendar — agenda view */
/* infinite agenda scroller — fills the viewport under the sticky header */
.cal-scroll {
  height: calc(100vh - 120px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px 40px;
}
/* "load past" button pinned at the top of the agenda */
.load-past {
  display: block;
  margin: 0 auto 12px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 999px;
  cursor: pointer;
}
.load-past:active { background: var(--surface-2); color: var(--accent); }

/* one block per day (Cozi): full-width date header on top, events below */
/* Each day is its own rounded card (Cozi day-grouping, softened + rounded).
   No padding on the card itself so today's accent bar can span edge-to-edge;
   the inner header/events carry the padding. */
.day-row {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
  position: relative;
}
.day-row.past { opacity: 0.6; }
/* today: soft accent tint + a slim accent bar across the top, like Cozi's
   teal line above the "(Today)" block. */
.day-row.today {
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
}
.day-row.today::before {
  content: "";
  display: block;
  height: 3px;
  background: var(--accent);
}
/* full-width date header on top of the day, like Cozi's "WED 8 July (Today)" */
.day-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 12px 16px 6px;
}
.day-header .dh-date { font-size: 16px; font-weight: 700; letter-spacing: .01em; }
.day-header .dh-rel {
  font-size: 11px; font-weight: 800; letter-spacing: .05em;
  text-transform: uppercase; color: var(--accent);
  align-self: center;
}
.day-row.today .day-header .dh-date { color: var(--accent); }
.day-events { display: flex; flex-direction: column; padding: 0 16px 8px; }
.day-empty { color: var(--muted); font-size: 14px; padding: 4px 2px 10px; }
/* ＋ sits at the right edge of the day header — soft circular ghost button */
.day-add {
  margin-left: auto;
  align-self: center;
  width: 28px;
  height: 28px;
  font-size: 16px;
  line-height: 1;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: background .12s ease;
}
.day-add:active { background: color-mix(in srgb, var(--accent) 22%, transparent); }
/* events are clean rows inside the day card, divided by hairlines (Cozi) —
   not individual floating cards anymore. */
.event {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  padding-right: 34px;   /* room for the absolute ✎ so it doesn't squeeze the body */
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  position: relative;
}
.event + .event { border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent); }
.ev-time {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: right;
}
.ev-start { font-weight: 700; font-size: 15px; }
.ev-end { color: var(--muted); font-size: 12px; }
.ev-body { flex: 1; min-width: 0; }
.ev-title { font-weight: 600; font-size: 15px; line-height: 1.3; }
.ev-title.linked { color: var(--accent); cursor: pointer; }
.ev-note { color: var(--muted); font-weight: 400; font-size: 13px; }
.ev-assignees {
  display: flex;
  flex-direction: row;   /* assignees side by side (Cozi-style), not stacked */
  flex-wrap: wrap;       /* wraps only when even tightened chips can't fit */
  gap: 3px 8px;
  margin-top: 4px;
}
.asg {
  color: var(--muted);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;   /* keep each name on one line */
}
.asg .dot { width: 9px; height: 9px; }
.ev-edit {
  position: absolute;
  top: 8px;
  right: 0;
  padding: 4px 6px;
  font-size: 14px;
  color: var(--muted);
  opacity: 0.5;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.ev-edit:active { opacity: 1; background: var(--surface-2); }
.dot {
  display: inline-block;
  width: 11px; height: 11px;
  border-radius: 50%;
  flex: 0 0 auto;
}

/* ---- login gate ---- */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.auth-gate[hidden] { display: none; }
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.10);
  padding: 32px 24px 26px;
  text-align: center;
}
.auth-logo {
  width: 72px; height: 72px;
  margin: 0 auto 16px;
  border-radius: 18px;
  background: linear-gradient(180deg, #4aa3ff, #007aff);
  color: #fff;
  font-size: 30px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: -1px;
}
.auth-card h1 { font-size: 22px; margin: 0 0 4px; }
.auth-sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.auth-field { display: block; text-align: left; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.auth-hint { text-align: left; font-size: 12px; color: var(--muted); margin: -8px 0 16px; }
.auth-field select, .auth-field input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 12px 14px;
  font-size: 17px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 11px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.auth-field input:focus, .auth-field select:focus { border-color: var(--accent); background: #fff; }
.auth-btn {
  width: 100%;
  padding: 14px;
  font-size: 17px;
  font-weight: 600;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  margin-top: 8px;
}
.auth-btn.primary { color: #fff; background: var(--accent); }
.auth-btn.link { color: var(--accent); background: transparent; font-weight: 500; font-size: 15px; }
.auth-msg { min-height: 20px; margin-top: 14px; font-size: 14px; }
.auth-msg.err { color: var(--danger); }
.auth-msg.ok { color: var(--muted); }

/* iPhone "add to home screen" pointer (auth.js iosInstallBanner) */
.ios-install { position: fixed; left: 12px; right: 12px; z-index: 9999; display: flex; flex-direction: column; align-items: center;
  font-size: 15px; line-height: 1.45; pointer-events: none; }
.ios-install.bottom { bottom: calc(10px + env(safe-area-inset-bottom)); }
.ios-install.top { top: calc(6px + env(safe-area-inset-top)); align-items: flex-end; }
.ios-box { position: relative; pointer-events: auto; background: #0f766e; color: #fff; border-radius: 16px;
  padding: 14px 40px 14px 16px; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 420px; }
.ios-x { position: absolute; top: 6px; right: 8px; background: none; border: 0; color: #fff; font-size: 18px; padding: 6px; }
.ios-ico { display: inline-block; border: 1.5px solid #fff; border-radius: 5px; padding: 0 4px; font-size: 13px; }
.ios-small { font-size: 13px; opacity: .85; }
.ios-arrow { color: #0f766e; font-size: 30px; line-height: 1; animation: ios-bob 1s ease-in-out infinite; }
.ios-install.top .ios-arrow { margin-right: 18px; }
@keyframes ios-bob { 50% { transform: translateY(6px); } }
.ios-install.top .ios-arrow { animation-name: ios-bob-up; }
@keyframes ios-bob-up { 50% { transform: translateY(-6px); } }
