:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #1d4ed8;
  --primary-text: #ffffff;
  --accent: #0ea5e9;
  --danger: #dc2626;
  --ok: #16a34a;
  --cell: #1f2937;
  --cell-text: #ffffff;
  --radius: 18px;
  --tab-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --card: #151d2e;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #273145;
    --primary: #3b82f6;
    --accent: #38bdf8;
    --cell: #0f172a;
    --cell-text: #e5e7eb;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; }

.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.appbar h1 { margin: 0; font-size: 18px; font-weight: 700; }
.gear-btn {
  width: 40px; height: 40px; border: 0; border-radius: 20px;
  background: var(--bg); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
}

main {
  padding: 14px 14px calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  max-width: 560px; margin: 0 auto;
}
.view.hidden { display: none; }
.hidden { display: none !important; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.hint.center { text-align: center; }
h2 { font-size: 17px; margin: 0; }
h3 { margin: 0 0 12px; font-size: 18px; }
.eyebrow {
  margin: 16px 4px 8px; font-size: 12px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.eyebrow:first-child { margin-top: 4px; }

.day-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.circle-btn {
  width: 44px; height: 44px; border-radius: 22px; border: 0;
  background: var(--card); font-size: 26px; line-height: 1; flex: 0 0 auto;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.day-pill {
  flex: 1; border: 0; background: var(--card); border-radius: 999px;
  padding: 12px 8px; font-weight: 600; font-size: 15px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.day-pill:active, .circle-btn:active, .time-pill:active { opacity: .8; }
.today-chip {
  flex: 0 0 auto; border: 0; background: var(--primary); color: var(--primary-text);
  border-radius: 999px; padding: 10px 12px; font-weight: 700; font-size: 13px;
}

.time-pill {
  display: block; width: 100%; border: 3px solid var(--border);
  background: var(--card); border-radius: 22px; padding: 22px 16px;
  font-size: 36px; font-weight: 700; color: var(--primary); letter-spacing: -1px;
}
.time-pill small { font-size: 18px; font-weight: 600; color: var(--muted); }

.quick { display: flex; gap: 6px; margin: 10px 0 4px; }
.quick button {
  flex: 1; padding: 8px 4px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); font-size: 13px; font-weight: 600;
}

.cats { display: flex; gap: 8px; }
.cats button {
  flex: 1; border: 1px solid var(--border); background: var(--card);
  padding: 12px 8px; border-radius: 999px; font-weight: 600; font-size: 15px; color: var(--muted);
}
.cats button.active {
  background: var(--primary); color: var(--primary-text); border-color: var(--primary);
}

.save-btn { width: 100%; margin-top: 16px; padding: 16px; font-size: 16px; border-radius: 16px; }

.day-entries { list-style: none; padding: 0; margin: 12px 0 0; }
.day-entries li {
  background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 10px; cursor: pointer;
}
.day-entries .t { font-weight: 700; flex: 1; }
.day-entries .n { font-size: 13px; color: var(--muted); }

.ring-card { text-align: center; padding: 20px 16px 24px; }
.ring-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.ring-head .l { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.ring-head .r { font-size: 18px; font-weight: 700; }
.ring-wrap { position: relative; width: 200px; height: 200px; margin: 8px auto 0; }
.ring-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-wrap .bg { fill: none; stroke: #dbe3ef; stroke-width: 14; }
@media (prefers-color-scheme: dark) {
  .ring-wrap .bg { stroke: #273145; }
}
.ring-wrap .fg { fill: none; stroke: var(--primary); stroke-width: 14; stroke-linecap: round; transition: stroke-dashoffset .4s; }
.ring-wrap .fg.done { stroke: var(--ok); }
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.ring-center .pct { font-size: 40px; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.ring-center .left { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-top: 6px; }

.today-card { text-align: center; padding: 22px; }
.today-card .l { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.today-card .v { font-size: 40px; font-weight: 800; color: var(--primary); letter-spacing: -1px; margin-top: 4px; }
.today-card .v small { font-size: 18px; color: var(--muted); font-weight: 600; }

.cal-card { padding: 14px; }
.cal-month { background: none; border: 0; font-weight: 700; font-size: 16px; text-transform: capitalize; }
.text-nav { background: none; border: 0; font-size: 24px; width: 40px; height: 40px; color: var(--muted); }
.cal-sum { font-size: 22px; font-weight: 800; margin: 4px 4px 12px; }
.cal-weekdays, .cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
}
.cal-weekdays span { text-align: center; font-size: 11px; color: var(--muted); font-weight: 600; }
.cal-cell {
  aspect-ratio: 1; border: 0; border-radius: 12px; background: var(--cell); color: var(--cell-text);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0; min-height: 44px;
}
.cal-cell.empty { background: transparent; }
.cal-cell .n { font-size: 12px; font-weight: 600; opacity: .7; line-height: 1; }
.cal-cell .h { font-size: 10px; font-weight: 800; margin-top: 2px; line-height: 1; }
.cal-cell.has { background: var(--primary); color: #fff; }
.cal-cell.has-kls { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-cell.today { outline: 2px solid var(--primary); outline-offset: 1px; }
.cal-cell.sel { outline: 2px solid var(--text); outline-offset: 1px; }

.month-break { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.month-break .v { font-size: 20px; font-weight: 800; }
.month-break .l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.month-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.month-title-row .m { font-weight: 700; text-transform: capitalize; }
.goal-pill {
  background: var(--primary); color: #fff; border-radius: 999px;
  padding: 6px 10px; font-size: 13px; font-weight: 700; white-space: nowrap;
}

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--bg); padding: 4px; border-radius: 12px; }
.segmented button {
  border: 0; background: transparent; padding: 10px 4px; border-radius: 9px;
  font-size: 13px; font-weight: 500; color: var(--muted);
}
.segmented button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--bg); border-radius: 10px; padding: 10px; text-align: center; }
.stat .v { font-size: 20px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }

.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 40px; height: 40px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--bg); font-size: 22px; line-height: 1;
}
.stepper span { min-width: 36px; text-align: center; font-size: 20px; font-weight: 600; }

textarea, input[type=text], input[type=password], input[type=date], input[type=month], input[type=number], select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); -webkit-appearance: none; appearance: none;
}
textarea { resize: vertical; }

.btn {
  flex: 1; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--card); font-weight: 600; font-size: 15px; width: 100%;
}
.btn:active { opacity: .7; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; width: auto; flex: 0 0 auto; }
.btn.block {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px; text-align: left; text-decoration: none; color: inherit;
}
.btn.block.danger { width: 100%; }

.history { list-style: none; padding: 0; margin: 0; }
.history li {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px; display: flex; align-items: center;
  gap: 12px; cursor: pointer; justify-content: space-between;
}
.history .m { font-weight: 600; text-transform: capitalize; }
.history .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.history .h { font-size: 20px; font-weight: 700; text-align: right; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); font-weight: 600; }
.badge.kls { background: rgba(14,165,233,.15); color: var(--accent); }
.badge.type { background: rgba(29,78,216,.12); color: var(--primary); }
.badge.teren { background: rgba(29,78,216,.12); color: var(--primary); }
.empty { text-align: center; color: var(--muted); padding: 16px; font-size: 14px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; height: var(--tab-h); border: 0; background: none; color: var(--muted);
  font-size: 13px; font-weight: 600;
}
.tabbar button.active { color: var(--primary); }

dialog {
  border: 0; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  width: 100%; max-width: 560px; margin: auto auto 0; background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .field-label { margin-top: 12px; }
.time-input { display: flex; align-items: center; gap: 8px; }
.time-input input { width: 80px; text-align: center; }
.time-input select { width: 80px; text-align: center; }
.time-input span { color: var(--muted); font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 500; transition: all .25s; z-index: 20; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
