:root {
  --bg: #f4f7f6;
  --card: #ffffff;
  --ink: #1b2523;
  --muted: #5d6b68;
  --line: #dfe6e4;
  --brand: #0f766e;
  --brand-soft: #e3f3f1;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf1e2;
  --bad: #b91c1c;
  --bad-soft: #fde8e8;
  --radius: 16px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 19px;
  line-height: 1.4;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand); color: #fff;
}
.top h1 { margin: 0; font-size: 22px; font-weight: 700; }
.iconbtn { background: none; border: 0; font-size: 26px; padding: 4px 8px; color: #fff; }

main { padding: 14px 14px 24px; max-width: 640px; margin: 0 auto; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 600;
}
.tabs a span { font-size: 24px; }
.tabs a.on { color: var(--brand); background: var(--brand-soft); }

.offline { background: var(--warn-soft); color: var(--warn); padding: 10px 16px; font-size: 16px; text-align: center; }

h2 { font-size: 21px; margin: 18px 4px 10px; }
.sub { color: var(--muted); font-size: 16px; margin: 0 4px 12px; }

.card {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05); border: 2px solid transparent;
}

/* özet */
.summary { display: flex; align-items: center; gap: 16px; }
.ring { width: 76px; height: 76px; flex: none; }
.summary .big { font-size: 26px; font-weight: 800; }
.summary .small { color: var(--muted); font-size: 16px; }

/* doz kartı */
.dose { display: flex; align-items: center; gap: 12px; }
.dose .time { font-size: 22px; font-weight: 800; min-width: 64px; color: var(--brand); }
.dose .info { flex: 1; min-width: 0; }
.dose .name { font-size: 21px; font-weight: 700; overflow-wrap: anywhere; }
.dose .meta { color: var(--muted); font-size: 16px; }
.dose.late { border-color: var(--bad); }
.dose.late .time { color: var(--bad); }
.dose.done { background: var(--ok-soft); }
.dose.done .time { color: var(--ok); }
.dose.skipped { background: #eef0f0; }
.tag { display: inline-block; font-size: 14px; font-weight: 700; padding: 2px 8px; border-radius: 99px; margin-top: 4px; }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.ok { background: var(--ok); color: #fff; }
.tag.gray { background: #dfe3e3; color: #444; }

.btn {
  border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 700; font-size: 19px;
  background: var(--brand); color: #fff; min-height: 56px;
}
.btn.take { min-width: 104px; font-size: 20px; }
.btn.ghost { background: transparent; color: var(--brand); border: 2px solid var(--brand); }
.btn.light { background: var(--brand-soft); color: var(--brand); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.block { width: 100%; }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 16px; padding: 8px 4px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; }
.dose-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 0; }

/* form */
label.f { display: block; font-weight: 700; margin: 14px 2px 6px; }
.hint { font-weight: 400; color: var(--muted); font-size: 15px; }
input[type=text], input[type=number], input[type=time], input[type=datetime-local], input[type=password], textarea {
  width: 100%; padding: 14px; border: 2px solid var(--line); border-radius: 12px; background: #fff; font-size: 20px;
}
input:focus, textarea:focus { outline: none; border-color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 2px solid var(--line); background: #fff; border-radius: 99px; padding: 10px 16px; font-size: 17px; font-weight: 600;
}
.chip.on { border-color: var(--brand); background: var(--brand); color: #fff; }
.times { display: flex; flex-direction: column; gap: 8px; }
.timerow { display: flex; gap: 8px; align-items: center; }
.timerow input { flex: 1; }
.timerow .x { flex: none; width: 52px; height: 52px; border-radius: 12px; border: 0; background: var(--bad-soft); color: var(--bad); font-size: 22px; }

/* şeker */
.sugar-input { font-size: 40px !important; text-align: center; font-weight: 800; }
.sval { font-size: 26px; font-weight: 800; min-width: 70px; }
.sval small { font-size: 14px; font-weight: 600; color: var(--muted); }
.lvl-ok { color: var(--ok); }
.lvl-warn { color: var(--warn); }
.lvl-bad { color: var(--bad); }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .info { flex: 1; }
.chart { width: 100%; height: auto; display: block; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats b { display: block; font-size: 24px; }
.stats span { color: var(--muted); font-size: 14px; }

/* geçmiş */
.day { display: flex; align-items: center; gap: 12px; }
.day .d { flex: 1; font-weight: 700; }
.day .d small { display: block; font-weight: 400; color: var(--muted); font-size: 15px; }
.pill { font-weight: 800; padding: 4px 12px; border-radius: 99px; font-size: 17px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.none { background: #eef0f0; color: var(--muted); }
.daydetail { margin-top: 10px; font-size: 16px; }
.daydetail div { padding: 4px 0; }
.dots { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.dots div { aspect-ratio: 1; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; }

/* ilaç listesi */
.med .name { font-size: 21px; font-weight: 700; }
.med .meta { color: var(--muted); font-size: 16px; }
.stock-low { color: var(--bad); font-weight: 700; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 22px 22px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
}
.sheet h3 { margin: 0 0 6px; font-size: 22px; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: #1b2523; color: #fff; padding: 12px 20px; border-radius: 99px; font-size: 17px; max-width: 90vw; text-align: center;
}

.center { text-align: center; }
.login { max-width: 360px; margin: 40px auto; text-align: center; }
.login .logo { font-size: 64px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty .e { font-size: 48px; }
.note { font-size: 15px; color: var(--muted); padding: 0 4px; }

/* randevu */
.appt-mini { display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit; border-color: var(--brand); }
.appt-mini .e { font-size: 30px; }
.appt .when { color: var(--brand); font-size: 17px; }
.appt .name { font-size: 21px; font-weight: 700; margin: 2px 0; }
.appt.dim { opacity: .6; }
.meta { color: var(--muted); font-size: 16px; }

/* şeker ayarları */
.set-row { display: flex; align-items: center; gap: 10px; }
.set-row > div { flex: 1; }
.chev { font-size: 28px; color: var(--muted); }
.limit { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.limit span { flex: 1; font-size: 17px; }
.limit input { width: 110px !important; flex: none; text-align: center; padding: 10px !important; }

/* rapor */
.report { background: #fff; border-radius: var(--radius); padding: 16px; }
.report h3 { font-size: 19px; margin: 18px 0 8px; border-bottom: 2px solid var(--brand); padding-bottom: 4px; }
.report table { width: 100%; border-collapse: collapse; font-size: 15px; margin-bottom: 10px; }
.report th, .report td { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: left; vertical-align: top; }
.report th { background: var(--brand-soft); font-size: 14px; }
.report tr.tot td { font-weight: 700; border-top: 2px solid var(--line); }
.report table.kv td:nth-child(odd) { color: var(--muted); }
.report small { color: var(--muted); }
.rmeta { color: var(--muted); font-size: 16px; margin: 0 0 6px; }
.rfoot { color: var(--muted); font-size: 13px; margin-top: 18px; }
.rchart { max-width: 520px; margin: 6px 0 12px; }

@media print {
  .top, .tabs, .noprint, .offline, .toast, .modal { display: none !important; }
  body { background: #fff; padding: 0; font-size: 11pt; }
  main { max-width: none; padding: 0; }
  .report { padding: 0; }
  .report table { font-size: 10pt; }
  tr, .rchart { break-inside: avoid; }
}
.err { color: var(--bad); background: var(--bad-soft); border-radius: 10px; padding: 10px 12px; margin: 10px 0 0; font-weight: 700; font-size: 17px; }

/* sesli okuma, fotoğraf, amaç, arama */
.iconbtn2 { background: var(--brand-soft); border: 0; border-radius: 10px; font-size: 16px; font-weight: 700; color: var(--brand); padding: 6px 12px; margin-top: 6px; min-height: 40px; }
.thumb { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; flex: none; background: #eef0f0; }
.thumb.big { width: 96px; height: 96px; }
.bigphoto { width: 100%; border-radius: 16px; display: block; }
.photorow { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.filebtn { display: inline-flex; align-items: center; }
.purpose { display: inline-block; background: #eef2ff; color: #3730a3; font-size: 14px; font-weight: 700; padding: 2px 10px; border-radius: 99px; margin: 2px 0; }
.medhead { display: flex; gap: 12px; align-items: center; }
.btn.call { display: flex; align-items: center; justify-content: center; text-decoration: none; }
.btn.call.wa { background: #15803d; }
.dose .thumb { width: 48px; height: 48px; }
.tcol { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: none; }
.btn.call { white-space: nowrap; }

/* kutudan / reçeteden okuma */
.readbtns { margin-top: 8px; }
.readbtns .btn { font-size: 16px; padding: 10px 8px; min-height: 48px; }
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.82); display: flex; align-items: center; justify-content: center; color: #fff; text-align: center; padding: 20px; }
.busy p { font-size: 19px; font-weight: 700; margin: 16px 0 0; }
.spin { width: 52px; height: 52px; margin: 0 auto; border-radius: 50%; border: 6px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.scan { position: relative; width: 100%; max-width: 480px; }
.scan video { width: 100%; border-radius: 16px; display: block; background: #000; }
.scan .cam { position: relative; }
.scan .frame { position: absolute; inset: 18% 15%; border: 4px solid #4ade80; border-radius: 14px; pointer-events: none; }
.scan p { font-size: 18px; margin: 14px 0; }
.scan .btn.ghost { color: #fff; border-color: #fff; min-width: 160px; }
.readrow { display: flex; align-items: center; gap: 12px; }
.readrow .info { flex: 1; min-width: 0; }
.readrow .name { font-size: 19px; font-weight: 700; overflow-wrap: anywhere; }
.readrow.done { background: var(--ok-soft); }
