:root {
  --bg: #f5f8fc;
  --surface: #ffffff;
  --surface-soft: #eef5ff;
  --text: #111827;
  --muted: #64748b;
  --border: #e3eaf3;
  --primary: #2f80ed;
  --primary-hover: #1769d1;
  --success: #25b47e;
  --danger: #ef4444;
  --ring-bg: #e4eefb;
  --shadow: 0 12px 35px rgba(30, 64, 175, .07);
  --radius: 20px;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111a2b;
  --surface-soft: #17243a;
  --text: #f8fafc;
  --muted: #9aa9bd;
  --border: #25344d;
  --ring-bg: #233550;
  --shadow: 0 14px 40px rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(47, 128, 237, .18);
  outline-offset: 2px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.full { width: 100%; }

/* Auth */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 100px 24px 30px;
  background: radial-gradient(circle at top left, #e8f2ff 0, var(--bg) 38%);
}
.auth-brand {
  position: fixed;
  top: 28px;
  left: 32px;
  display: flex;
  align-items: center;
  gap: 11px;
}
.auth-brand strong, .brand strong { display: block; font-size: 20px; }
.auth-brand span, .brand span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}
.logo-drop {
  width: 43px;
  height: 43px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--surface-soft);
  font-size: 22px;
}
.auth-card {
  width: min(430px, 100%);
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
}
.auth-header { margin-bottom: 26px; }
.eyebrow {
  color: var(--primary);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .11em;
}
.auth-header h1 {
  margin: 9px 0 7px;
  font-size: 34px;
  letter-spacing: -.04em;
}
.auth-header p { margin: 0; color: var(--muted); line-height: 1.55; }

.form-field { margin: 14px 0; }
.form-field label {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 750;
}
.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .18s, box-shadow .18s;
}
.form-field textarea { min-height: 140px; resize: vertical; }
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 128, 237, .11);
  outline: none;
}
.primary-btn, .outline-btn, .link-btn, .quick-btn, .icon-btn {
  transition: transform .16s ease, background .16s ease, border-color .16s ease, color .16s ease;
}
.primary-btn {
  border: 0;
  border-radius: 13px;
  padding: 12px 17px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}
.primary-btn:hover { background: var(--primary-hover); transform: translateY(-1px); }
.outline-btn {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}
.outline-btn:hover { color: var(--text); background: var(--surface-soft); }
.link-btn {
  border: 0;
  padding: 12px;
  background: transparent;
  color: var(--primary);
  font-weight: 750;
}
.auth-note {
  margin: 8px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
}

/* Layout */
.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  z-index: 30;
  inset: 0 auto 0 0;
  width: 245px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 24px;
}
.side-nav { display: grid; gap: 5px; padding: 10px 14px; }
.nav-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 750;
  text-align: left;
}
.nav-btn:hover { background: var(--surface-soft); color: var(--text); }
.nav-btn.active { background: var(--surface-soft); color: var(--primary); }
.nav-icon { width: 18px; text-align: center; font-size: 18px; }
.sidebar-bottom { margin-top: auto; padding: 16px; display: grid; gap: 12px; }
.quote-card {
  position: relative;
  padding: 18px;
  border-radius: 16px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
.quote-card span {
  color: var(--primary);
  font-size: 24px;
  font-weight: 900;
}

.main-content {
  width: calc(100% - 245px);
  margin-left: 245px;
}
.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-actions { display: flex; align-items: center; gap: 13px; }
.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--text);
}
.icon-btn:hover { transform: translateY(-1px); }
.user-chip { display: flex; align-items: center; gap: 9px; font-weight: 750; }
.user-chip > span:first-child {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #dcecff;
  color: var(--primary);
}
.mobile-brand { display: none; font-weight: 900; }

.page {
  display: none;
  max-width: 1500px;
  margin: 0 auto;
  padding: 34px;
}
.page.active { display: block; }
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 23px;
}
.page-head h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: -.04em;
}
.page-head p { margin: 7px 0 0; color: var(--muted); }

.grid { display: grid; gap: 18px; }
.home-grid { grid-template-columns: minmax(0, 1.5fr) minmax(290px, .8fr); }
.stats-grid { grid-template-columns: repeat(4, 1fr); }
.card {
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.section-title h2 { margin: 0; font-size: 20px; }

.progress-card {
  display: grid;
  grid-template-columns: 270px 1fr;
  align-items: center;
  gap: 30px;
}
.progress-ring {
  width: 235px;
  height: 235px;
  margin: auto;
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--primary) var(--progress), var(--ring-bg) 0);
}
.progress-ring::after {
  content: "";
  position: absolute;
  inset: 13px;
  border-radius: 50%;
  background: var(--surface);
}
.progress-inner { position: relative; z-index: 1; text-align: center; }
.progress-amount {
  font-size: 39px;
  font-weight: 900;
  letter-spacing: -.045em;
}
.progress-goal { color: var(--muted); }
.progress-percent { margin-top: 8px; color: var(--primary); font-weight: 900; }

.quick-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 22px;
}
.quick-btn {
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 13px 8px;
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 800;
}
.quick-btn:hover { color: var(--primary); border-color: var(--primary); transform: translateY(-1px); }

.entry-list { display: grid; gap: 9px; }
.entry {
  display: grid;
  grid-template-columns: 42px 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
}
.drop-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--surface-soft);
}
.entry strong { display: block; }
.entry small { color: var(--muted); }
.entry-actions { display: flex; gap: 2px; }
.entry-actions button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 7px;
  border-radius: 8px;
}
.entry-actions button:hover { background: var(--surface-soft); color: var(--text); }
.entry-actions .delete:hover { color: var(--danger); }

.kpi { padding: 18px; }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { margin-top: 7px; font-size: 27px; font-weight: 900; }

.streak-card { display: grid; gap: 12px; }
.streak-top { display: flex; justify-content: space-between; align-items: center; }
.streak-fire { font-size: 28px; }
.streak-number { font-size: 44px; font-weight: 900; letter-spacing: -.05em; }
.week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}
.week-day { text-align: center; color: var(--muted); font-size: 10px; }
.week-dot {
  width: 30px;
  height: 30px;
  margin: 6px auto 3px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-soft);
}
.week-dot.done { background: #bcefdc; color: #08784e; }
.week-dot.today { outline: 2px solid var(--primary); outline-offset: 2px; }

.progress-line {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}
.progress-line span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--success);
}

.chart {
  height: 280px;
  display: flex;
  align-items: end;
  gap: 7px;
  padding: 25px 4px 0;
}
.bar-wrap {
  flex: 1;
  height: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: end;
  gap: 6px;
}
.bar {
  width: min(34px, 78%);
  min-height: 2px;
  border-radius: 7px 7px 2px 2px;
  background: var(--primary);
}
.bar-label, .bar-value {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.table-wrap { overflow-x: auto; }
.history-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}
.history-table th, .history-table td {
  padding: 13px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.history-table th { color: var(--muted); font-size: 12px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px 18px;
}
.full-span { grid-column: 1 / -1; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.switch {
  width: 48px;
  height: 28px;
  position: relative;
  flex: 0 0 auto;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd5e1;
  transition: .2s;
}
.slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: #fff;
  transition: .2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.bottom-nav { display: none; }

/* Modal + toast */
.modal {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .48);
}
.modal-card {
  width: min(430px, calc(100% - 30px));
  position: relative;
  z-index: 1;
  padding: 25px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(0,0,0,.25);
}
.modal-card h2 { margin: 0 0 5px; }
.modal-close {
  position: absolute;
  top: 9px;
  right: 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 29px;
}
.toast {
  position: fixed;
  z-index: 200;
  top: 20px;
  right: 20px;
  max-width: min(360px, calc(100% - 40px));
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--surface);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-12px);
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* Responsive */
.mobile-only { display: none; }

@media (max-width: 1050px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); box-shadow: 25px 0 60px rgba(0,0,0,.16); }
  .main-content { width: 100%; margin-left: 0; }
  .mobile-only { display: grid; }
  .mobile-brand { display: block; }
  .topbar { padding: 0 18px; }
  .home-grid, .progress-card { grid-template-columns: 1fr; }
  .page { padding: 24px 18px 90px; }
  .bottom-nav {
    position: fixed;
    z-index: 40;
    left: 0; right: 0; bottom: 0;
    height: 68px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  .bottom-nav .nav-btn {
    justify-content: center;
    flex-direction: column;
    gap: 2px;
    padding: 5px;
    border-radius: 0;
    text-align: center;
    font-size: 19px;
  }
  .bottom-nav .nav-btn small { font-size: 10px; }
}

@media (max-width: 700px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .quick-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .full-span { grid-column: auto; }
  .page-head { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 520px) {
  .auth-screen { padding: 88px 16px 20px; }
  .auth-brand { left: 18px; top: 20px; }
  .auth-card { padding: 23px; border-radius: 22px; }
  .auth-header h1 { font-size: 30px; }
  .top-name { display: none; }
  .topbar { height: 68px; }
  .page { padding: 20px 14px 88px; }
  .page-head h1 { font-size: 29px; }
  .progress-ring { width: 205px; height: 205px; }
  .progress-card { gap: 18px; }
  .card { padding: 17px; border-radius: 17px; }
  .entry { grid-template-columns: 39px 1fr auto; }
  .entry > .entry-amount { grid-column: 2; }
  .entry-actions { grid-column: 3; grid-row: 1 / span 2; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 22px; }
  .chart { height: 230px; gap: 3px; }
  .bar-label { font-size: 9px; }
}


/* Professional polish */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #60a5fa;
  --success: #16a878;
}

body {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.sidebar {
  background: color-mix(in srgb, var(--surface) 96%, #eff6ff);
}

.brand .logo-drop, .auth-brand .logo-drop {
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, .06);
}

.nav-btn {
  min-height: 45px;
  letter-spacing: -.01em;
}

.nav-btn.active {
  box-shadow: inset 3px 0 0 var(--primary);
}

.topbar {
  backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  position: sticky;
  top: 0;
  z-index: 20;
}

.card {
  box-shadow: 0 8px 28px rgba(15, 23, 42, .045);
  transition: box-shadow .2s ease, transform .2s ease;
}

.card:hover {
  box-shadow: 0 14px 34px rgba(15, 23, 42, .065);
}

.progress-card {
  overflow: hidden;
  position: relative;
}

.progress-card::before {
  content: "";
  position: absolute;
  width: 230px;
  height: 230px;
  right: -95px;
  top: -120px;
  border-radius: 50%;
  background: rgba(37, 99, 235, .045);
  pointer-events: none;
}

.primary-btn {
  min-height: 43px;
  box-shadow: 0 7px 16px rgba(37, 99, 235, .18);
}

.quick-btn {
  min-height: 54px;
}

.kpi-value {
  letter-spacing: -.03em;
}

.modal-card {
  border: 1px solid var(--border);
}

.modal-quick-adds {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 16px 0 18px;
}

.modal-quick {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  border-radius: 11px;
  padding: 9px 5px;
  font-weight: 800;
  font-size: 12px;
}

.modal-quick:hover,
.modal-quick:focus {
  border-color: var(--primary);
  color: var(--primary);
  background: color-mix(in srgb, var(--surface-soft) 80%, var(--primary) 20%);
}

#water-amount::placeholder {
  color: #94a3b8;
}

.empty-state {
  min-height: 150px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 20px;
  border: 1px dashed var(--border);
  border-radius: 15px;
  background: color-mix(in srgb, var(--surface-soft) 45%, transparent);
}

.empty-icon {
  width: 44px;
  height: 44px;
  margin: 0 auto 8px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: var(--surface-soft);
}

@media (max-width: 520px) {
  .modal-quick-adds {
    gap: 6px;
  }
  .modal-quick {
    font-size: 11px;
    padding: 9px 3px;
  }
}


/* History date editing */
#selected-date-add {
  margin-top: 6px;
  text-align: center;
}
