:root {
  --bg: #f4f5fb; --card: #fff; --text: #1e1f2b; --muted: #6b6f85; --line: #e3e5ef;
  --accent: #4f46e5; --dep: #3b82f6; --ele: #f59e0b; --irr: #ef4444; --anx: #8b5cf6; --sleep: #94a3b8;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12131a; --card: #1c1e28; --text: #eceef5; --muted: #9a9eb5; --line: #2c2f3d; --accent: #818cf8; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button, input, textarea, select { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
/* iOS nedidina ekrano, kai laukelio šriftas ≥ 16px */
input, textarea, select { font-size: 16px; }
button { touch-action: manipulation; }
.iconbtn:disabled { opacity: .35; }

/* ---------- Prisijungimas ---------- */
body.logged-out .tabs { display: none; }
.login form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.login input { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: transparent; }
.login .btn { padding: 12px; }
.login .btn:disabled { opacity: .6; }
#loginMsg { font-size: .95rem; margin: 12px 0 0; }
#loginMsg.error { color: #dc2626; font-weight: 500; }
.linkbtn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 6px; font-size: .9rem; }
.top { position: sticky; top: 0; z-index: 5; background: var(--accent); color: #fff; padding: 14px 16px; padding-top: calc(14px + env(safe-area-inset-top)); }
.top h1 { margin: 0; font-size: 1.15rem; font-weight: 600; }
main { max-width: 640px; margin: 0 auto; padding: 12px 16px; }

.card { background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 3px rgb(0 0 0 / .06); }
.card h3 { margin: 0 0 10px; font-size: .95rem; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.muted { color: var(--muted); font-size: .85rem; }

.datebar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.datebar strong { text-align: center; flex: 1; }
.iconbtn { border: 0; background: var(--card); border-radius: 10px; width: 42px; height: 42px; font-size: 1.3rem; cursor: pointer; box-shadow: 0 1px 3px rgb(0 0 0 / .06); }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg button { border: 1px solid var(--line); background: transparent; border-radius: 10px; padding: 10px 2px; font-size: .82rem; cursor: pointer; }
.seg button.on { color: #fff; border-color: transparent; }

.sleep { display: flex; align-items: center; gap: 10px; }
.sleep input { width: 90px; text-align: center; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: transparent; font-size: 1.1rem; }

.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.check:last-child { border-bottom: 0; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 7px 12px; cursor: pointer; font-size: .85rem; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

textarea { width: 100%; min-height: 90px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: transparent; resize: vertical; }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .wd { text-align: center; font-size: .72rem; color: var(--muted); padding: 4px 0; }
.cal .day { background: var(--card); border-radius: 8px; min-height: 58px; padding: 4px; cursor: pointer; border: 2px solid transparent; display: flex; flex-direction: column; gap: 3px; }
.cal .day.today { border-color: var(--accent); }
.cal .day.empty { background: transparent; cursor: default; }
.cal .num { font-size: .75rem; font-weight: 600; }
.cal .bars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; align-items: end; height: 22px; }
.cal .bars i { display: block; border-radius: 2px; min-height: 2px; }
.cal .sl { font-size: .62rem; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .8rem; margin: 10px 0; }
.legend span { display: flex; align-items: center; gap: 5px; }

.chart svg { width: 100%; height: auto; display: block; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--bg); border-radius: 10px; padding: 10px; }
.stat b { display: block; font-size: 1.2rem; }

.row { display: flex; gap: 8px; margin-top: 8px; }
.row input { flex: 1; min-width: 0; padding: 9px; border: 1px solid var(--line); border-radius: 10px; background: transparent; }
.btn { border: 0; background: var(--accent); color: #fff; border-radius: 10px; padding: 10px 14px; cursor: pointer; font-weight: 500; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: #dc2626; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.item { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.item button { border: 0; background: none; color: #dc2626; font-size: 1.1rem; cursor: pointer; }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs button { border: 0; background: none; padding: 8px 0 10px; font-size: .72rem; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.tabs button span { font-size: 1.2rem; }
.tabs button.on { color: var(--accent); font-weight: 600; }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #222; color: #fff; padding: 8px 14px; border-radius: 999px; font-size: .85rem; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }

#report { display: none; }
@media print {
  body { background: #fff; color: #000; padding: 0; }
  .top, main, .tabs, #toast { display: none !important; }
  #report { display: block; font-size: 11px; }
  #report table { width: 100%; border-collapse: collapse; }
  #report th, #report td { border: 1px solid #999; padding: 3px 4px; text-align: center; }
  #report td.n { text-align: left; }
  #report svg { width: 100%; height: auto; }
}
