/* Cito vizitai — iOS / Apple stilius */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --secondary: #8e8e93;
  --tertiary: #aeaeb2;
  --separator: rgba(60, 60, 67, 0.12);
  --fill: rgba(120, 120, 128, 0.12);
  --fill-strong: rgba(120, 120, 128, 0.2);
  --tint: #0c7d74;
  --tint-press: #0a6a62;
  --tint-soft: rgba(12, 125, 116, 0.12);
  --green: #248a3d;
  --green-soft: rgba(52, 199, 89, 0.15);
  --orange: #c93400;
  --orange-soft: rgba(255, 149, 0, 0.15);
  --blue: #0b63ce;
  --blue-soft: rgba(0, 122, 255, 0.12);
  --red: #d70015;
  --r-card: 18px;
  --r-ctl: 14px;
}

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

html { -webkit-text-size-adjust: 100%; background: var(--bg); }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  /* Puslapis visada užpildo visą ekraną, kad meniu neatrodytų „pakibęs" */
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(12px + env(safe-area-inset-top, 0px))
           calc(16px + env(safe-area-inset-right, 0px))
           calc(76px + env(safe-area-inset-bottom, 0px))
           calc(16px + env(safe-area-inset-left, 0px));
}

/* Įdiegus kaip programėlę — oras nuo statuso juostos */
@media (display-mode: standalone) {
  .app { padding-top: calc(18px + env(safe-area-inset-top, 24px)); }
}

/* ---------- Antraštė (Large Title) ---------- */
.pagehead { padding: 10px 4px 18px; }
.pagehead h1 {
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.pagehead .sub {
  color: var(--secondary);
  font-size: 0.95rem;
  font-weight: 500;
  margin-top: 3px;
  letter-spacing: -0.01em;
}

/* ---------- Kortelės (iOS grouped) ---------- */
.card {
  background: var(--card);
  border-radius: var(--r-card);
  padding: 16px;
  margin-bottom: 14px;
}
.card > strong {
  display: block;
  font-size: 0.8rem !important;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--secondary);
  margin-bottom: 4px;
}

/* ---------- Mygtukai ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--r-ctl);
  font-family: inherit;
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  padding: 14px 20px;
  cursor: pointer;
  text-decoration: none;
  transition: transform .12s ease, background .12s ease, opacity .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); opacity: 0.85; }
.btn-primary { background: var(--tint); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--tint-press); }
.btn-secondary { background: var(--tint-soft); color: var(--tint); }
.btn-ghost { background: transparent; color: var(--secondary); padding: 8px 12px; }
.btn-danger-ghost { background: transparent; color: var(--red); padding: 8px 12px; }
.btn-sm { font-size: 0.9rem; padding: 9px 15px; border-radius: 11px; }

/* ---------- Vizito eilutė ---------- */
.visit {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 2px;
  position: relative;
}
.visit + .visit::before {
  content: '';
  position: absolute;
  top: 0; left: 58px; right: 0;
  height: 1px;
  background: var(--separator);
  transform: scaleY(0.5);
}
.visit .time {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  color: var(--tint);
  background: var(--tint-soft);
  border-radius: 9px;
  padding: 5px 8px;
  flex-shrink: 0;
}
.visit .body { flex: 1; min-width: 0; padding-top: 2px; }
.visit .tags { display: flex; flex-wrap: wrap; gap: 5px; }
.visit .comment {
  color: var(--secondary);
  font-size: 0.88rem;
  margin-top: 5px;
  overflow-wrap: break-word;
}
.visit .actions { display: flex; gap: 0; flex-shrink: 0; margin-top: -2px; }

.badge {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  border-radius: 7px;
  padding: 3px 8px;
}
.badge-reg { background: var(--green-soft); color: var(--green); }
.badge-unreg { background: var(--orange-soft); color: var(--orange); }
.badge-proc { background: var(--fill); color: #48484a; }
.badge-cons { background: var(--blue-soft); color: var(--blue); }

.empty { text-align: center; color: var(--secondary); padding: 40px 16px; font-size: 0.95rem; }
.empty svg { width: 42px; height: 42px; opacity: 0.3; margin-bottom: 10px; }

/* ---------- Forma ---------- */
label.fieldlabel {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--secondary);
  margin: 18px 2px 8px;
}

input[type=text], input[type=password], input[type=date], input[type=time], textarea, select {
  width: 100%;
  font-size: 1.02rem;
  font-family: inherit;
  padding: 13px 14px;
  border: none;
  border-radius: 12px;
  background: var(--fill);
  color: var(--text);
  outline: none;
  transition: box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, textarea:focus, select:focus { box-shadow: 0 0 0 2px var(--tint); background: var(--card); }
textarea { resize: vertical; min-height: 68px; line-height: 1.4; }
input::placeholder, textarea::placeholder { color: var(--tertiary); }

/* iOS segmented control */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--fill);
  border-radius: 10px;
  padding: 2px;
  position: relative;
}
.seg input { display: none; }
.seg label {
  text-align: center;
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: -0.01em;
  padding: 9px 8px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  transition: all .18s ease;
  -webkit-user-select: none;
  user-select: none;
  z-index: 1;
}
.seg input:checked + label {
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12), 0 0 1px rgba(0, 0, 0, 0.08);
}
.seg input#f_reg_1:checked + label { color: var(--green); }
.seg input#f_reg_0:checked + label { color: var(--orange); }

/* Pasirinkimų lustai */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip input { display: none; }
.chip span {
  display: inline-block;
  border-radius: 999px;
  padding: 9px 15px;
  font-size: 0.92rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  cursor: pointer;
  background: var(--fill);
  color: var(--text);
  transition: all .15s ease;
  -webkit-user-select: none;
  user-select: none;
}
.chip:active span { transform: scale(0.96); }
.chip input:checked + span {
  background: var(--tint);
  color: #fff;
  font-weight: 600;
}

/* ---------- Modalas (iOS sheet) ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
  z-index: 50;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 51;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 8px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  max-width: 640px;
  margin: 0 auto;
  max-height: calc(94dvh - env(safe-area-inset-top, 0px) - 10px);
  overflow-y: auto;
  transform: translateY(105%);
  transition: transform .32s cubic-bezier(0.32, 0.72, 0, 1);
}
.modal.open { transform: translateY(0); }
.modal::before {
  content: '';
  display: block;
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--fill-strong);
  margin: 4px auto 10px;
}
.modal h2 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; }
.modal .modalhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }

/* ---------- Apatinė navigacija (iOS tab bar) ---------- */
.bottomnav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  transform: translateZ(0);
  will-change: transform;
  background: rgba(249, 249, 249, 0.82);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding: 7px 0 max(env(safe-area-inset-bottom, 0px), 7px);
  z-index: 40;
}
.bottomnav::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: rgba(60, 60, 67, 0.25);
  transform: scaleY(0.5);
}
.navitem {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--secondary);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  padding: 2px 20px;
  -webkit-tap-highlight-color: transparent;
}
.navitem svg { width: 25px; height: 25px; }
.navitem.active { color: var(--tint); font-weight: 600; }

/* ---------- Statistika ---------- */
.statgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--card);
  border-radius: var(--r-card);
  padding: 14px 16px 12px;
}
.stat .num {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.stat .lbl {
  font-size: 0.76rem;
  color: var(--secondary);
  font-weight: 500;
  letter-spacing: -0.005em;
  margin-top: 1px;
}
.stat.reg .num { color: var(--green); }
.stat.unreg .num { color: var(--orange); }

.rangebar {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 0 6px;
  margin-bottom: 10px;
  scrollbar-width: none;
}
.rangebar::-webkit-scrollbar { display: none; }
.rangebar a {
  flex-shrink: 0;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  padding: 8px 15px;
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.rangebar a.active { background: var(--tint); color: #fff; }

/* Grafikas */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 5px; }
.chart .bar-reg { background: var(--tint); border-radius: 3px 3px 0 0; }
.chart .bar-unreg { background: #f5a623; }
.chart .col .bar-unreg:first-child { border-radius: 3px 3px 0 0; }
.chartlabels { display: flex; gap: 3px; margin-top: 7px; }
.chartlabels span { flex: 1; text-align: center; font-size: 0.62rem; color: var(--tertiary); min-width: 5px; overflow: hidden; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 16px; margin-top: 12px; font-size: 0.8rem; color: var(--secondary); font-weight: 500; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }

/* Lentelė */
table.data { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.data th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: var(--secondary);
  padding: 9px 6px;
  border-bottom: 1px solid var(--separator);
}
table.data td {
  padding: 10px 6px;
  border-bottom: 1px solid var(--separator);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
table.data tr:last-child td { border-bottom: none; }
table.data td.num, table.data th.num { text-align: right; }

/* ---------- Pranešimai ---------- */
.toast {
  position: fixed;
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(16px) scale(0.95);
  background: rgba(28, 28, 30, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: -0.01em;
  padding: 12px 24px;
  border-radius: 999px;
  opacity: 0;
  transition: all .3s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 60;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
.toast.error { background: rgba(215, 0, 21, 0.92); }

.alert {
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.92rem;
  font-weight: 500;
  margin-bottom: 12px;
}
.alert-error { background: rgba(215, 0, 21, 0.1); color: var(--red); }
.alert-ok { background: var(--green-soft); color: var(--green); }
.alert-info { background: var(--tint-soft); color: var(--tint); }

/* ---------- Prisijungimas ---------- */
.loginwrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 20px calc(20px + env(safe-area-inset-bottom, 0px));
}
.loginbox { width: 100%; max-width: 380px; }
.loginbox .logo {
  width: 68px; height: 68px;
  border-radius: 16px;
  margin: 0 auto 16px;
  display: block;
}
.loginbox h1 { text-align: center; font-size: 1.5rem; font-weight: 800; letter-spacing: -0.03em; margin-bottom: 4px; }
.loginbox .sub { text-align: center; color: var(--secondary); font-size: 0.92rem; margin-bottom: 22px; }
.loginbox label.fieldlabel:first-of-type { margin-top: 0; }

/* ---------- Nustatymai ---------- */
.proc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 2px;
  position: relative;
}
.proc-row + .proc-row::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: var(--separator);
  transform: scaleY(0.5);
}
.proc-row .name { font-weight: 500; letter-spacing: -0.01em; }
.proc-row.inactive .name { color: var(--tertiary); text-decoration: line-through; }
.proc-row .btn { color: var(--tint); font-weight: 600; }
.proc-row.inactive .btn { color: var(--secondary); }

.inline-form { display: flex; gap: 8px; margin-top: 14px; }
.inline-form input { flex: 1; }

.offline-banner {
  display: none;
  background: var(--orange-soft);
  color: var(--orange);
  font-weight: 600;
  font-size: 0.88rem;
  text-align: center;
  padding: 10px;
  border-radius: 12px;
  margin-bottom: 12px;
}
body.offline .offline-banner { display: block; }

@media (min-width: 480px) {
  .statgrid { grid-template-columns: repeat(4, 1fr); }
  .modal {
    border-radius: 16px;
    bottom: auto; top: 50%; left: 50%; right: auto;
    width: 100%; max-width: 520px;
    padding-top: 18px;
    transform: translate(-50%, -45%) scale(0.97);
    opacity: 0;
    pointer-events: none;
    transition: transform .25s ease, opacity .25s ease;
  }
  .modal.open { transform: translate(-50%, -50%) scale(1); opacity: 1; pointer-events: auto; }
  .modal::before { display: none; }
}
