:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev2: #1e222b;
  --border: #2a2f3a;
  --text: #e8eaed;
  --text-muted: #8b93a1;
  --green: #22c55e;
  --green-dim: #16321f;
  --amber: #f5a524;
  --amber-dim: #3a2c10;
  --red: #ef4444;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  color: inherit;
  background: none;
}

input {
  font-family: inherit;
  color: inherit;
}

.text-input {
  width: 100%;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 16px;
  margin-bottom: 14px;
  min-height: 48px;
}

.btn {
  min-height: 48px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  padding: 12px 18px;
  transition: transform .08s ease, opacity .15s ease, background .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-block { display: block; width: 100%; margin-top: 10px; }
.btn-primary { background: var(--green); color: #08150c; }
.btn-secondary { background: var(--bg-elev2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid rgba(239,68,68,.4); }
.danger-text { color: var(--red); }
.btn-round { width: 48px; height: 48px; border-radius: 50%; padding: 0; font-size: 22px; line-height: 1; }

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  font-size: 20px;
  border-radius: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: var(--bg-elev2); }

.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.error-text { color: var(--red); font-size: 14px; margin-top: 8px; }

/* Login */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
  padding-bottom: calc(24px + var(--safe-bottom));
}
.login-box {
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-box h1 {
  font-size: 28px;
  margin-bottom: 4px;
}
.login-box p { margin-bottom: 20px; }

/* App shell */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  padding-top: calc(14px + var(--safe-top));
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.app-title { font-size: 18px; margin: 0; font-weight: 700; }

.sync-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--amber);
  flex-shrink: 0;
  transition: background .3s ease;
}
.sync-dot.synced { background: var(--green); }

.ios-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-elev2);
  border-bottom: 1px solid var(--border);
  padding: calc(10px + var(--safe-top)) calc(16px + var(--safe-right)) 10px calc(16px + var(--safe-left));
  font-size: 13px;
  color: var(--text-muted);
}

.screen {
  flex: 1;
  padding: 16px;
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  padding-bottom: calc(96px + var(--safe-bottom));
  overflow-y: auto;
}

.section-title {
  font-size: 15px;
  color: var(--text-muted);
  margin: 24px 0 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.cards-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.cards-grid.single-row {
  margin-top: 12px;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform .08s ease, background .2s ease;
}
.card:active { transform: scale(0.98); }

.card.state-ready { border-color: rgba(34,197,94,.4); background: linear-gradient(180deg, var(--green-dim), var(--bg-elev)); }
.card.state-soon { border-color: rgba(245,165,36,.4); background: linear-gradient(180deg, var(--amber-dim), var(--bg-elev)); }
.card.state-resting { opacity: .6; }

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.card-title { font-weight: 700; font-size: 16px; }
.card-status { font-size: 20px; line-height: 1; }
.card-sub { font-size: 13px; color: var(--text-muted); margin-top: 8px; }

.daily-block { margin-top: 8px; }

.daily-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  gap: 10px;
}
.daily-label { font-weight: 600; font-size: 15px; flex-shrink: 0; }

.segmented {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: flex-end;
}
.seg-btn {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
}
.seg-btn.active {
  background: var(--green);
  color: #08150c;
  border-color: var(--green);
}

.water-controls { display: flex; align-items: center; gap: 10px; }
.water-plus { min-height: 44px; padding: 10px 18px; }

.water-progress-wrap { padding: 0 4px; margin-bottom: 10px; }
.water-progress-bar {
  height: 10px;
  border-radius: 6px;
  background: var(--bg-elev2);
  overflow: hidden;
  margin-bottom: 6px;
}
.water-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #22c55e);
  width: 0%;
  transition: width .25s ease;
}
.water-progress-text { font-size: 13px; color: var(--text-muted); text-align: right; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  font-weight: 600;
  font-size: 15px;
}
.checkbox-row input[type="checkbox"] {
  width: 24px;
  height: 24px;
  accent-color: var(--green);
}

/* History */
.week-summary {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 16px;
  font-size: 14px;
  line-height: 1.6;
}
.week-summary strong { color: var(--text); }

.history-day {
  margin-bottom: 18px;
}
.history-day-title {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
}
.history-item {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}
.history-item.tappable:active { background: var(--bg-elev2); }
.history-meta { color: var(--text-muted); font-size: 13px; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  z-index: 20;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  min-height: 56px;
}
.nav-btn.active { color: var(--green); }
.nav-icon { font-size: 20px; }

/* Bottom sheets */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: flex-end;
  z-index: 100;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%;
  background: var(--bg-elev);
  border-radius: 20px 20px 0 0;
  padding: 12px 20px calc(20px + var(--safe-bottom));
  animation: slideUp .18s ease;
  max-height: 80vh;
  overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 3px;
  margin: 4px auto 14px;
}
.sheet-title { font-size: 17px; margin: 0 0 16px; text-align: center; }

.sheet-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}
.sheet-btn {
  min-height: 56px;
  border-radius: 14px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  font-size: 17px;
  font-weight: 700;
}
.sheet-btn:active { background: var(--green-dim); border-color: var(--green); }
.sheet-btn.light { color: #7dd3fc; }
.sheet-btn.medium { color: var(--amber); }
.sheet-btn.heavy { color: var(--red); }

.settings-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin: 4px 0 6px;
}

.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 14px;
  z-index: 200;
  animation: fadeIn .15s ease;
}
