:root {
  --bg: #0f1420;
  --card: #181f30;
  --card2: #1f2840;
  --text: #e8ecf5;
  --muted: #8f9bb8;
  --line: #2b3652;
  --accent: #6366f1;
  --danger: #ef4444;
  --ok: #10b981;
  --water: #38bdf8;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; margin: 1.1rem 0 .4rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: .78rem; }
.error { color: #fca5a5; min-height: 1.2em; margin: .4rem 0; font-size: .9rem; }
.spaced { margin-top: .7rem; }
.note { background: #2a2f55; border: 1px solid #3b4280; border-radius: 10px; padding: .5rem .7rem; font-size: .85rem; margin: .6rem 0 0; }

/* ---------- inputs & buttons ---------- */
input, select, button { font: inherit; color: inherit; }
button { touch-action: manipulation; }
input[type=text], input[type=password], input[type=number], input[type=time], input[type=date], select {
  width: 100%;
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .55rem .7rem;
  color-scheme: dark;
}
input[type=color] {
  width: 100%; height: 40px; padding: 2px;
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: .85rem; color: var(--muted); margin-top: .7rem; }
label input, label select { margin-top: .25rem; color: var(--text); }
label.inline { display: inline-flex; align-items: center; gap: .45rem; margin: 0; color: var(--text); }
label.inline input { width: auto; margin: 0; }
label.check { display: flex; margin-top: .55rem; font-size: .9rem; }
label.check input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }

.btn {
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .5rem .9rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: #fecaca; border-color: #7f1d1d; background: #3b1219; }
.btn.icon { padding: .5rem .8rem; font-size: 1.1rem; line-height: 1; }
.btn.small { padding: .25rem .55rem; font-size: .8rem; }
.btn.wide { width: 100%; margin-top: .5rem; }
.btn:disabled { opacity: .4; cursor: default; }

.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; }
.row.gap { gap: .5rem; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: .5rem; }
.brand h1 { letter-spacing: -.02em; font-weight: 800; }
.brand h1 span { color: var(--accent); }
.logo {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--water));
  color: #fff; font-size: 1.25rem; font-weight: 700; line-height: 1;
}
.brand.big { justify-content: center; }
.brand.big h1 { font-size: 1.9rem; }
.brand.big .logo { width: 44px; height: 44px; font-size: 1.6rem; border-radius: 12px; }
.auth-card > p.muted { text-align: center; }
.foot { text-align: center; padding: .5rem 0 1rem; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.6rem;
}
.tabs { display: flex; gap: .4rem; margin: 1.1rem 0 .3rem; }
.tab {
  flex: 1; padding: .5rem; cursor: pointer;
  background: transparent; border: 1px solid var(--line); border-radius: 10px; color: var(--muted);
}
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- layout ---------- */
#app { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: .5rem; }
.topbar-right { display: flex; align-items: center; gap: .5rem; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1rem;
}
.grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; }
.grid .card { margin-bottom: 0; }
.grid + .card { margin-top: 1rem; }

.datebar { display: flex; align-items: center; justify-content: space-between; gap: .6rem 1rem; flex-wrap: wrap; }
.navrow { flex-wrap: wrap; }
#datePick { width: auto; }
#dateTitle { flex: 1; min-width: 0; }

.banner {
  margin-top: .8rem; padding: .5rem .8rem; border-radius: 10px;
  background: #1d3a34; border: 1px solid #285c50; color: #bbf7d0; font-size: .9rem;
}
.banner div + div { margin-top: .15rem; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem 1rem; display: flex; flex-direction: column;
}
.stat-label { color: var(--muted); font-size: .8rem; }
.stat strong { font-size: 1.25rem; margin-top: .15rem; white-space: nowrap; }

/* ---------- 24h timeline ---------- */
.tl-tools { display: flex; align-items: center; gap: .5rem; margin-top: .9rem; }
.zoom-lbl { min-width: 2.6rem; text-align: center; font-size: .85rem; }
.tl-tools .hint { margin-left: auto; }
.tl-scroll {
  overflow-x: auto; margin-top: .6rem; padding-bottom: .4rem;
  -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
}
.tl { position: relative; }
.tl-hours { position: relative; height: 20px; }
.tl-hours span {
  position: absolute; transform: translateX(-50%);
  font-size: .72rem; color: var(--muted);
}
.tl-hours span.half { opacity: .55; font-size: .65rem; }
.tl-hours span:first-child { transform: none; }
.tl-hours span.last { transform: translateX(-100%); }
.tl-track {
  position: relative;
  background-color: var(--card2);
  background-image: repeating-linear-gradient(
    to right,
    var(--line) 0, var(--line) 1px,
    transparent 1px, transparent calc(100% / 24)
  );
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.tl-track.fine {
  background-image:
    repeating-linear-gradient(to right, var(--line) 0, var(--line) 1px, transparent 1px, transparent calc(100% / 24)),
    repeating-linear-gradient(to right, rgba(143,155,184,.18) 0, rgba(143,155,184,.18) 1px, transparent 1px, transparent calc(100% / 48));
}
.blk {
  position: absolute;
  border: 0; border-radius: 8px;
  padding: 0 .5rem; color: #fff; text-align: left;
  font-size: .8rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
  min-width: 8px;
}
.blk:hover { filter: brightness(1.15); }
.blk.done { opacity: .45; text-decoration: line-through; }
.blk.cont { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.blk.wrapsOut { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.blk.changed { outline: 2px dashed rgba(255,255,255,.7); outline-offset: -3px; }
.now {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: #fbbf24; z-index: 3; pointer-events: none;
}
.now::before {
  content: ""; position: absolute; top: -1px; left: -4px;
  width: 10px; height: 10px; border-radius: 50%; background: #fbbf24;
}
.tl-empty {
  position: sticky; left: 0; width: 100%; height: 100%;
  display: grid; place-items: center;
  color: var(--muted); font-size: .9rem; pointer-events: none; text-align: center;
}
.tl-empty span { position: absolute; left: 50%; transform: translateX(-50%); }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-top: .7rem; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .3rem; }

/* ---------- hover / tap card ---------- */
.tip {
  position: fixed; z-index: 50;
  width: max-content; max-width: min(320px, calc(100vw - 16px));
  background: #0b0f1a; border: 1px solid var(--line);
  border-radius: 12px; padding: .7rem .85rem;
  box-shadow: 0 8px 28px rgba(0,0,0,.55);
  font-size: .9rem; pointer-events: none;
}
.tip.pinned { pointer-events: auto; }
.tip-h { display: flex; align-items: center; gap: .5rem; font-size: 1rem; }
.tip-t { margin-top: .25rem; font-variant-numeric: tabular-nums; }
.tip-m { margin-top: .15rem; color: var(--muted); font-size: .8rem; }
.tip-b { display: flex; gap: .5rem; margin-top: .7rem; }
.tip-b .btn { flex: 1; }

/* ---------- progress bars ---------- */
.bar { height: 10px; background: var(--card2); border-radius: 99px; overflow: hidden; margin: .7rem 0; }
.bar-fill { height: 100%; width: 0; background: var(--ok); transition: width .25s; }
.bar.water .bar-fill { background: var(--water); }

/* ---------- checklist ---------- */
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li {
  display: flex; align-items: center; gap: .7rem;
  padding: .55rem .2rem; border-bottom: 1px solid var(--line);
}
.checklist li:last-child { border-bottom: 0; }
.checklist input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--ok); flex: none; }
.checklist .grow { flex: 1; min-width: 0; }
.checklist .t { font-weight: 600; overflow-wrap: anywhere; }
.checklist .meta { font-size: .78rem; color: var(--muted); }
.checklist li.done .t { text-decoration: line-through; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.empty { color: var(--muted); padding: .8rem 0; }
.hidden-box { margin-top: .8rem; padding-top: .6rem; border-top: 1px dashed var(--line); }
.hidden-box h3 { margin: 0 0 .3rem; color: var(--muted); font-weight: 600; }
.hid { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; font-size: .85rem; color: var(--muted); }
.hid .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* ---------- water ---------- */
.water-big { font-size: 1.8rem; font-weight: 700; margin-top: .5rem; }
.water-btns { margin-bottom: .6rem; }
#waterCustom { width: 140px; }
.goal-row { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.goal-row input { width: 110px; margin: 0; }

/* ---------- all items list ---------- */
.all-list { margin-top: .6rem; }
.all-item { padding: .55rem .2rem; border-bottom: 1px solid var(--line); }
.all-item:last-child { border-bottom: 0; }
.all-top { display: flex; align-items: center; gap: .7rem; }
.all-item .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.exc { display: flex; align-items: center; gap: .5rem; margin: .35rem 0 0 1.5rem; font-size: .8rem; color: var(--muted); }
.exc span { flex: 1; min-width: 0; }

/* ---------- dialogs ---------- */
dialog {
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.3rem; width: min(520px, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem); overflow-y: auto;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: .9rem 0 0; padding: .7rem .8rem .9rem; }
legend { color: var(--muted); font-size: .85rem; padding: 0 .3rem; }
.days { display: flex; gap: .35rem; flex-wrap: wrap; }
.days label {
  margin: 0; padding: .35rem .6rem; cursor: pointer;
  border: 1px solid var(--line); border-radius: 8px; color: var(--text); font-size: .85rem;
}
.days input { display: none; }
.days label:has(input:checked) { background: var(--accent); border-color: var(--accent); }
.form-actions { margin-top: .9rem; gap: .6rem; }
#daysDlg { width: min(560px, calc(100vw - 2rem)); }
.off-form { border: 1px solid var(--line); border-radius: 10px; padding: 0 .8rem .8rem; }
.off-form .btn { margin-top: .3rem; }
.off-list { margin-top: .5rem; }
.off-item { display: flex; align-items: center; gap: .6rem; padding: .45rem 0; border-bottom: 1px solid var(--line); font-size: .88rem; }
.off-item:last-child { border-bottom: 0; }
.off-item .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.off-item input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--ok); flex: none; }
.off-item.muted-row { color: var(--muted); }
label.off-item { margin: 0; color: var(--text); cursor: pointer; }
#builtinList h3 { margin: .9rem 0 .2rem; color: var(--muted); }

/* ---------- floating add button (phones) ---------- */
.fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%;
  border: 0; background: var(--accent); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: 0 6px 18px rgba(0,0,0,.5); z-index: 20; cursor: pointer;
  display: none;
}

/* ================= PHONES / NARROW WINDOWS ================= */
@media (max-width: 800px) {
  .grid { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  body { font-size: 16px; }
  input[type=text], input[type=password], input[type=number], input[type=time], input[type=date], select { font-size: 16px; }
  h1 { font-size: 1.15rem; }
  #app {
    padding: .7rem .6rem calc(88px + env(safe-area-inset-bottom));
    padding-left: max(.6rem, env(safe-area-inset-left));
    padding-right: max(.6rem, env(safe-area-inset-right));
  }
  .topbar { margin-bottom: .7rem; }
  .topbar .lbl { display: none; }
  .topbar-right { gap: .35rem; }
  .user-item { flex-wrap: wrap; }
  .card { padding: .85rem; margin-bottom: .8rem; border-radius: 12px; }

  .datebar { gap: .5rem; }
  .navrow { width: 100%; }
  #datePick { flex: 1; min-width: 0; }
  #dateTitle { width: 100%; flex: none; font-size: 1.05rem; }
  .add-top { display: none; }
  .fab:not(.hidden) { display: block; }

  .tl-tools .hint { display: none; }
  .tl-tools { justify-content: flex-start; }

  .stats { gap: .5rem; }
  .stat { padding: .55rem .6rem; border-radius: 12px; }
  .stat-label { font-size: .7rem; }
  .stat strong { font-size: 1rem; }

  .water-big { font-size: 1.6rem; }
  .water-btns .btn { flex: 1 1 calc(50% - .5rem); }
  #waterCustom { flex: 1; width: auto; min-width: 0; }

  /* dialogs become bottom sheets */
  dialog {
    width: 100%; max-width: 100%;
    margin: auto 0 0 0;
    max-height: 94dvh;
    border-radius: 18px 18px 0 0;
    padding: 1.1rem 1rem calc(1.1rem + env(safe-area-inset-bottom));
  }
  #daysDlg { width: 100%; }
  .form-actions .btn { min-height: 46px; }
  .two { gap: .6rem; }

  /* tap card is a bottom sheet */
  .tip {
    left: 8px !important; right: 8px;
    top: auto !important;
    bottom: calc(8px + env(safe-area-inset-bottom));
    width: auto; max-width: none;
    padding: .9rem 1rem;
    z-index: 60;
  }
}

/* bigger touch targets on any touch screen */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn.small { min-height: 38px; padding: .3rem .75rem; }
  .btn.icon { min-width: 48px; }
  .tab { min-height: 44px; }
  .days label { padding: .55rem .8rem; }
  .blk { font-size: .85rem; }
  .checklist li { padding: .7rem .2rem; }
  .checklist input[type=checkbox] { width: 26px; height: 26px; }
  .off-item input[type=checkbox] { width: 24px; height: 24px; }
}

/* keep two-column date/time fields inside their box */
.two > label { min-width: 0; }
.two input { min-width: 0; max-width: 100%; }

/* ================= ACCOUNTS / SERVER (Build 2) ================= */
.center { text-align: center; }
.end { align-items: flex-end; justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.pad-top { padding-top: 1.6rem; }

.loading { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; }
.loading .logo { width: 52px; height: 52px; font-size: 1.9rem; border-radius: 14px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; transform: scale(.94); } }

.save-state { font-size: .78rem; white-space: nowrap; padding: .2rem .55rem; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.save-state.ok::before { content: "✓ "; color: var(--ok); }
.save-state.pending { color: var(--text); }
.save-state.error { color: #fecaca; border-color: #7f1d1d; background: #3b1219; }

.banner.info { display: flex; align-items: center; justify-content: space-between; gap: .8rem; flex-wrap: wrap;
  background: #23284a; border-color: #3b4280; color: var(--text); margin: 0 0 1rem; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 80;
  max-width: min(520px, calc(100vw - 24px));
  background: #0b0f1a; border: 1px solid var(--accent); border-radius: 12px;
  padding: .7rem 1rem; box-shadow: 0 8px 28px rgba(0,0,0,.55);
  font-size: .9rem; cursor: pointer; overflow-wrap: anywhere;
}

.acc-who { margin: .6rem 0 0; }
#accNameForm label { margin-top: .4rem; }
#accNameForm .btn { margin-bottom: 1px; }
#accDlg .stack { margin-top: .4rem; }
#usersDlg { width: min(640px, calc(100vw - 2rem)); }
.user-item { display: flex; align-items: center; gap: .6rem; padding: .6rem 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.user-item:last-child { border-bottom: 0; }
.user-item.muted-row { opacity: .6; }
.badge { display: inline-block; font-size: .7rem; padding: .05rem .45rem; border-radius: 99px; margin-left: .25rem;
  background: #2a2f55; border: 1px solid #3b4280; color: #c7d2fe; vertical-align: middle; }
.badge.off { background: #3b1219; border-color: #7f1d1d; color: #fecaca; }
.badge.warn { background: #3a2e12; border-color: #7c5d16; color: #fde68a; }
.badge.you { background: #1d3a34; border-color: #285c50; color: #bbf7d0; }
#uPassLbl .row input { margin-top: 0; }
#uPassLbl .row { margin-top: .25rem; }
#uPassLbl .btn { flex: none; }

@media (max-width: 700px) {
  #usersDlg { width: 100%; }
  .save-state { font-size: .7rem; padding: .15rem .45rem; }
  .pad-top { padding-top: .2rem; }
  .toast { bottom: calc(88px + env(safe-area-inset-bottom)); }
}
