/* ========== iOS-flavoured design tokens ========== */
:root {
  --bg:        #f2f2f7;   /* systemGroupedBackground */
  --surface:   #ffffff;
  --surface-2: #f7f7fa;
  --fill:      #78788014; /* systemFill */
  --line:      #3c3c4320;
  --line-soft: #3c3c4314;

  --text:      #000000;
  --muted:     #3c3c4399;
  --faint:     #3c3c434d;

  --accent:    #0a84ff;   /* systemBlue */
  --accent-sc: #0a84ff14;
  --green:     #34c759;
  --green-sc:  #34c75914;
  --orange:    #ff9500;
  --red:       #ff3b30;
  --purple:    #af52de;
  --gray:      #8e8e93;

  /* Eisenhower */
  --q1: #ff3b30;
  --q2: #0a84ff;
  --q3: #ff9500;
  --q4: #8e8e93;

  --r-sm: 10px;
  --r:    14px;
  --r-lg: 20px;
  --r-xl: 26px;

  --shadow: 0 1px 3px rgba(0,0,0,.04), 0 6px 20px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.12);

  --maxw: 1180px;
  --gutter: 20px;

  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter',
          system-ui, 'Segoe UI', Roboto, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter',
          system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;                /* iOS body */
  line-height: 1.45;
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

/* ========== layout ========== */
.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--gutter);
  width: 100%;
}

header.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(242,242,247,.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto;
  padding: 12px var(--gutter);
  display: flex; align-items: center; gap: 16px;
}
.logo {
  font-family: var(--font-display); font-weight: 700;
  font-size: 22px; letter-spacing: -.03em;
}
.logo span { color: var(--accent); }
.topbar .spacer { flex: 1; }

nav.tabs {
  display: flex; gap: 2px;
  background: var(--fill); border-radius: 11px; padding: 2px;
}
nav.tabs button {
  color: var(--muted); padding: 7px 15px; border-radius: 9px;
  font-weight: 500; font-size: 15px; white-space: nowrap;
  transition: background .18s, color .18s;
}
nav.tabs button[aria-selected="true"] {
  color: var(--text); background: var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,.09);
  font-weight: 600;
}

/* ключове: повітря під шапкою */
main { padding: 32px 0 130px; }
.view[hidden] { display: none; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--fill); display: grid; place-items: center;
  font-size: 17px; color: var(--muted); flex: none;
  transition: background .15s;
}
.icon-btn:active { background: #78788028; }

/* ========== section headers ========== */
.section-head {
  display: flex; align-items: center; gap: 14px;
  margin: 0 0 16px; flex-wrap: wrap;
}
.section-head h2 {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 700; letter-spacing: -.025em;
  margin: 0; color: var(--text);
}
.section-head .rule { flex: 1; }
.section-sub { color: var(--muted); font-size: 15px; margin: -8px 0 18px; }

/* ========== cards ========== */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 22px;
  box-shadow: var(--shadow);
}

/* ========== date strip ========== */
.datestrip-wrap { margin: 0 0 26px; }
.datestrip {
  display: flex; gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding: 4px 2px 14px;
  scrollbar-width: none;
}
.datestrip::-webkit-scrollbar { display: none; }

.daycell {
  flex: 0 0 auto;
  width: 66px;
  scroll-snap-align: center;
  background: var(--surface);
  border-radius: var(--r);
  padding: 11px 6px 12px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
}
.daycell:active { transform: scale(.95); }
.daycell .dow {
  font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--faint); font-weight: 600;
}
.daycell .dnum {
  font-family: var(--font-display); font-size: 21px; font-weight: 600;
  letter-spacing: -.02em; line-height: 1.25; margin-top: 1px;
}
.daycell[aria-selected="true"] {
  background: var(--accent); color: #fff;
  box-shadow: 0 4px 14px rgba(10,132,255,.35);
}
.daycell[aria-selected="true"] .dow { color: #ffffffcc; }
.daycell.today:not([aria-selected="true"]) .dnum { color: var(--accent); }
.daycell.locked { opacity: .45; }

.daycell .ring {
  width: 24px; height: 24px; margin: 7px auto 0;
  border-radius: 50%;
  background: conic-gradient(var(--green) var(--pct,0%), var(--line-soft) 0);
  display: grid; place-items: center;
}
.daycell .ring::after {
  content: ''; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface);
}
.daycell[aria-selected="true"] .ring::after { background: var(--accent); }
.daycell.empty-ring .ring { background: var(--line-soft); }

.strip-hint { font-size: 14px; color: var(--muted); margin: -14px 0 20px; }

/* ========== habits ========== */
.habit-list { display: flex; flex-direction: column; gap: 12px; }

.habit {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px; align-items: center;
  background: var(--surface);
  border-radius: var(--r-lg); padding: 16px 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .12s, box-shadow .15s;
}
.habit:active { transform: scale(.985); }
.habit.done { background: linear-gradient(var(--green-sc), var(--green-sc)), var(--surface); }
.habit.off { opacity: .5; }

.check {
  width: 52px; height: 52px; flex: none;
  border-radius: 16px;
  background: var(--fill);
  display: grid; place-items: center; font-size: 24px;
  transition: transform .12s, background .15s;
  position: relative;
}
.check:active:not(:disabled) { transform: scale(.9); }
.check.on { background: var(--green); color: #fff; }
.check:disabled { opacity: .4; cursor: default; }

/* кільце прогресу для counter/timer */
.check.ring-wrap {
  background: conic-gradient(var(--green) var(--pct,0%), var(--fill) 0);
}
.check.ring-wrap .inner {
  width: 42px; height: 42px; border-radius: 13px;
  background: var(--surface); display: grid; place-items: center;
  font-size: 15px; font-weight: 600;
}
.habit.done .check.ring-wrap .inner { background: #ffffffee; }

.habit-name { font-weight: 600; font-size: 17px; letter-spacing: -.02em; }
.habit-meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.habit-value {
  font-family: var(--font-display); font-size: 15px; font-weight: 600;
  color: var(--accent); margin-top: 3px;
}

.streak-badge { text-align: right; }
.streak-badge .n {
  font-family: var(--font-display); font-size: 26px; font-weight: 700;
  letter-spacing: -.03em; line-height: 1;
}
.streak-badge.hot .n { color: var(--orange); }
.streak-badge .u { font-size: 12px; color: var(--faint); display: block; margin-top: 2px; }

/* ========== heatmap ========== */
.seg {
  display: inline-flex; background: var(--fill);
  border-radius: 10px; padding: 2px; gap: 2px;
}
.seg button {
  padding: 6px 13px; border-radius: 8px; font-size: 14px;
  font-weight: 500; color: var(--muted); white-space: nowrap;
  transition: background .16s, color .16s;
}
.seg button[aria-selected="true"] {
  background: var(--surface); color: var(--text); font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.09);
}

.heat-scroll { overflow-x: auto; scrollbar-width: none; }
.heat-scroll::-webkit-scrollbar { display: none; }
.heat {
  display: grid; grid-auto-flow: column;
  grid-template-rows: repeat(7, var(--cell, 14px));
  gap: var(--cell-gap, 4px);
  justify-content: start;
}
.heat i {
  width: var(--cell, 14px); height: var(--cell, 14px);
  border-radius: 4px; display: block;
  background: var(--line-soft);
}
.heat i[data-lvl="0"] { background: #e5e5ea; }
.heat i[data-lvl="1"] { background: #b8dcff; }
.heat i[data-lvl="2"] { background: #7ec0ff; }
.heat i[data-lvl="3"] { background: #3ba0ff; }
.heat i[data-lvl="4"] { background: var(--accent); }
.heat i.future { opacity: .3; }

.heat-legend {
  display: flex; align-items: center; gap: 8px;
  color: var(--faint); font-size: 13px; margin-top: 16px;
}
.heat-legend .swatch { display: flex; gap: 3px; }
.heat-legend .swatch i { width: 13px; height: 13px; border-radius: 4px; display: block; }

/* ========== tasks ========== */
.quick-add { display: flex; gap: 10px; margin-bottom: 18px; }
.quick-add input { flex: 1; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  background: var(--surface); color: var(--muted);
  padding: 8px 15px; border-radius: 999px;
  font-size: 15px; font-weight: 500;
  box-shadow: var(--shadow);
  transition: all .15s;
}
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; box-shadow: 0 3px 10px rgba(10,132,255,.3); }

.list-card { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden; }

.task {
  display: grid; grid-template-columns: auto 1fr auto;
  gap: 14px; align-items: start;
  padding: 15px 18px;
  border-bottom: .5px solid var(--line-soft);
  cursor: pointer;
  transition: background .12s;
}
.task:last-child { border-bottom: 0; }
.task:active { background: var(--surface-2); }

.task-box {
  width: 24px; height: 24px; margin-top: 1px; flex: none;
  border: 2px solid var(--faint); border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; color: transparent;
  transition: all .15s;
}
.task.done .task-box { background: var(--green); border-color: var(--green); color: #fff; }
.task.done .task-title { text-decoration: line-through; color: var(--faint); }

.task-title { font-weight: 500; font-size: 16.5px; letter-spacing: -.015em; }
.task-sub { display: flex; gap: 9px; align-items: center; margin-top: 4px; font-size: 14px; color: var(--muted); flex-wrap: wrap; }
.pill { padding: 2px 10px; border-radius: 999px; font-size: 13px; background: var(--fill); font-weight: 500; }
.due-over { color: var(--red); font-weight: 600; }
.due-today { color: var(--orange); font-weight: 600; }

.qbadge { font-size: 13px; font-weight: 600; padding: 2px 9px; border-radius: 7px; }
.qbadge.p1 { background: #ff3b3018; color: var(--q1); }
.qbadge.p2 { background: #0a84ff18; color: var(--q2); }
.qbadge.p3 { background: #ff950018; color: var(--q3); }
.qbadge.p4 { background: #8e8e9320; color: #6c6c70; }

.prio { width: 4px; align-self: stretch; border-radius: 3px; min-height: 30px; }
.p1 { background: var(--q1); } .p2 { background: var(--q2); }
.p3 { background: var(--q3); } .p4 { background: var(--q4); }

/* ========== matrix ========== */
.matrix { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.quad {
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column; min-height: 200px;
}
.quad-head { padding: 16px 18px 13px; border-bottom: .5px solid var(--line-soft); }
.quad-head h3 {
  margin: 0; font-family: var(--font-display); font-size: 17px;
  font-weight: 700; letter-spacing: -.02em; color: var(--qc);
}
.quad-head .sub { font-size: 13.5px; color: var(--muted); margin-top: 2px; }
.quad-head .cnt { float: right; font-size: 15px; color: var(--faint); font-weight: 600; }
.quad-body { flex: 1; }
.quad-body .task { padding: 12px 18px; grid-template-columns: auto 1fr; }
.quad-body .task .prio { display: none; }
.quad-empty { padding: 26px 18px; text-align: center; color: var(--faint); font-size: 14px; }

/* ========== stats ========== */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr));
  gap: 14px; margin-bottom: 24px;
}
.stat {
  background: var(--surface); border-radius: var(--r-lg);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.stat .k { color: var(--muted); font-size: 14px; font-weight: 500; }
.stat .v {
  font-family: var(--font-display); font-size: 32px; font-weight: 700;
  letter-spacing: -.035em; margin-top: 6px; line-height: 1;
}
.stat .d { font-size: 13px; color: var(--faint); margin-top: 5px; }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 150px; margin-top: 8px; }
.bars i {
  flex: 1; min-width: 2px; background: var(--accent);
  border-radius: 3px 3px 0 0; display: block; opacity: .85;
}
.bars i.zero { background: var(--line-soft); opacity: 1; }

.hrow {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 0; border-bottom: .5px solid var(--line-soft);
  cursor: pointer;
}
.hrow:last-child { border-bottom: 0; }
.hrow:active { opacity: .6; }
.hbar { flex: 1; height: 8px; background: var(--fill); border-radius: 5px; overflow: hidden; }
.hbar span { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.chev { color: var(--faint); font-size: 18px; }

/* line chart */
.chart-wrap { position: relative; margin-top: 10px; }
.chart { width: 100%; height: 200px; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line-soft); stroke-width: 1; }
.chart .goal-line { stroke: var(--orange); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .series { fill: none; stroke: var(--accent); stroke-width: 2.5;
  stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: url(#grad); }
.chart .dot { fill: var(--accent); }
.chart .lbl { font-size: 11px; fill: var(--faint); }

/* ========== forms ========== */
.btn {
  background: var(--accent); color: #fff;
  padding: 12px 20px; border-radius: 13px; font-weight: 600; font-size: 16px;
  transition: opacity .15s, transform .12s;
}
.btn:active { opacity: .75; transform: scale(.97); }
.btn.ghost { background: var(--fill); color: var(--accent); }
.btn.sm { padding: 8px 15px; font-size: 15px; border-radius: 11px; }
.btn.danger { background: none; color: var(--red); }
.btn.wide { width: 100%; }

input[type=text], input[type=email], input[type=password], input[type=date],
input[type=time], input[type=number], select, textarea {
  background: var(--fill); border: 0;
  border-radius: 12px; padding: 13px 15px; width: 100%;
  font-size: 17px;
}
input:focus, select:focus, textarea:focus {
  outline: none; background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-sc), inset 0 0 0 1.5px var(--accent);
}
label.field { display: block; margin-bottom: 18px; }
label.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 7px; font-weight: 500; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* iOS grouped settings list */
.group {
  background: var(--surface); border-radius: var(--r);
  overflow: hidden; margin-bottom: 22px;
}
.group-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; margin: 0 0 8px 16px;
}
.grow {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border-bottom: .5px solid var(--line-soft);
  min-height: 48px;
}
.grow:last-child { border-bottom: 0; }
.grow .lbl { flex: 1; font-size: 16px; }
.grow .val { color: var(--muted); font-size: 15px; }
.grow input[type=time], .grow select { width: auto; padding: 7px 11px; font-size: 15px; }
.grow.tap { cursor: pointer; }
.grow.tap:active { background: var(--surface-2); }

/* iOS toggle */
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 2; }
.switch .track {
  position: absolute; inset: 0; background: #78788050;
  border-radius: 999px; transition: background .22s;
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.2);
  transition: transform .22s;
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(20px); }

/* segmented picker in forms */
.segmented {
  display: grid; grid-auto-flow: column; gap: 2px;
  background: var(--fill); border-radius: 11px; padding: 2px;
}
.segmented button {
  padding: 9px 6px; border-radius: 9px; font-size: 14.5px;
  font-weight: 500; color: var(--muted);
}
.segmented button[aria-pressed="true"] {
  background: var(--surface); color: var(--text); font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

.day-picker { display: flex; gap: 6px; }
.day-picker button {
  flex: 1; padding: 11px 0; border-radius: 11px;
  background: var(--fill); color: var(--muted);
  font-size: 13.5px; font-weight: 600;
}
.day-picker button[aria-pressed="true"] { background: var(--accent); color: #fff; }

.emoji-row { display: flex; flex-wrap: wrap; gap: 7px; }
.emoji-row button {
  width: 44px; height: 44px; font-size: 21px; border-radius: 13px;
  background: var(--fill);
}
.emoji-row button[aria-pressed="true"] { background: var(--accent); }

.quad-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.quad-pick button {
  text-align: left; padding: 12px 14px; border-radius: 13px;
  background: var(--fill); font-size: 13.5px; line-height: 1.3;
}
.quad-pick button b { display: block; font-size: 15px; margin-bottom: 2px; }
.quad-pick button[aria-pressed="true"] {
  background: color-mix(in srgb, var(--qc) 14%, transparent);
  box-shadow: inset 0 0 0 2px var(--qc);
}

/* ========== modal / sheet ========== */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  display: grid; place-items: center; z-index: 60; padding: 20px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.modal-bg[hidden] { display: none; }
.modal {
  background: var(--bg);
  border-radius: var(--r-xl); padding: 26px;
  width: min(480px, 100%); max-height: 88vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: pop .24s cubic-bezier(.2,.9,.3,1.1);
}
.modal.wide { width: min(620px, 100%); }
@keyframes pop { from { opacity: 0; transform: scale(.94); } }
.modal h3 {
  font-family: var(--font-display); margin: 0 0 20px;
  font-size: 24px; font-weight: 700; letter-spacing: -.03em;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

/* ========== misc ========== */
.empty { text-align: center; padding: 54px 22px; color: var(--muted); }
.empty p { margin: 0 0 16px; font-size: 16px; }
.empty .big { font-size: 44px; margin-bottom: 10px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(30px + env(safe-area-inset-bottom));
  background: rgba(0,0,0,.85); color: #fff;
  backdrop-filter: blur(20px);
  padding: 13px 24px; border-radius: 999px; z-index: 80;
  font-size: 15px; font-weight: 500;
  animation: rise .25s cubic-bezier(.2,.9,.3,1.1);
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 14px); } }
.toast[hidden] { display: none; }

.offline-bar {
  background: var(--orange); color: #fff; text-align: center;
  padding: 8px; font-size: 14px; font-weight: 600;
}
.offline-bar[hidden] { display: none; }

/* ========== auth ========== */
#auth[hidden] { display: none !important; }
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 22px; }
.auth-card { width: min(400px, 100%); padding: 30px; border-radius: var(--r-xl); }
.auth-card .logo { font-size: 34px; margin-bottom: 6px; }
.auth-card .tagline { color: var(--muted); margin: 0 0 26px; font-size: 16px; }
.err { color: var(--red); font-size: 14px; margin-top: 12px; min-height: 20px; }

/* ========== responsive ========== */
@media (max-width: 900px) { .matrix { grid-template-columns: 1fr; } }

@media (max-width: 640px) {
  :root { --gutter: 16px; }
  body { font-size: 16px; }

  .topbar-inner { padding: 10px var(--gutter); gap: 10px; }
  .logo { font-size: 19px; }
  nav.tabs { flex: 1; justify-content: space-between; }
  nav.tabs button { padding: 7px 10px; font-size: 13.5px; flex: 1; text-align: center; }

  main { padding: 24px 0 120px; }
  .card { padding: 18px 16px; border-radius: var(--r); }

  .section-head h2 { font-size: 20px; }

  .daycell { width: 58px; padding: 10px 4px 11px; }
  .daycell .dnum { font-size: 19px; }
  .daycell .ring { width: 21px; height: 21px; }
  .daycell .ring::after { width: 14px; height: 14px; }

  .habit { padding: 14px 15px; gap: 13px; border-radius: var(--r); }
  .check { width: 48px; height: 48px; font-size: 22px; border-radius: 15px; }
  .check.ring-wrap .inner { width: 39px; height: 39px; font-size: 14px; }
  .streak-badge .n { font-size: 23px; }

  .task { padding: 14px 15px; gap: 12px; }
  .quad-body .task { padding: 12px 15px; }

  .stat { padding: 15px 16px; }
  .stat .v { font-size: 27px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 11px; }

  .modal { padding: 22px 18px; border-radius: var(--r-lg); }
  .quad-pick { grid-template-columns: 1fr; }
  .row2 { grid-template-columns: 1fr; }
  .seg button { padding: 6px 10px; font-size: 13.5px; }

  .bars { height: 120px; }
  .chart { height: 180px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
