/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg: #fafaf9;
  --color-surface: #ffffff;
  --color-border: #e5e5e4;
  --color-text: #1c1917;
  --color-muted: #78716c;
  --color-primary: #ca4a1f;
  --color-primary-dark: #a33818;
  --color-safe: #16a34a;
  --color-warning: #d97706;
  --color-danger: #dc2626;
  --nav-height: 60px;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* Layout */
.page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + 8px);
}

.page-header {
  padding: 20px 16px 0;
}

.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--color-text);
}

.page-content {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

/* Progress bar */
.progress-bar {
  height: 10px;
  background: var(--color-border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.4s ease;
}

.progress-fill--safe    { background: var(--color-safe); }
.progress-fill--warning { background: var(--color-warning); }
.progress-fill--danger  { background: var(--color-danger); }

/* Total display */
.total-display {
  text-align: center;
  padding: 24px 0 8px;
}

.total-display__number {
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
}

.total-display__unit {
  font-size: 1rem;
  color: var(--color-muted);
  margin-left: 4px;
}

.total-display--safe    .total-display__number { color: var(--color-safe); }
.total-display--warning .total-display__number { color: var(--color-warning); }
.total-display--danger  .total-display__number { color: var(--color-danger); }

.limit-label {
  text-align: center;
  font-size: 0.85rem;
  color: var(--color-muted);
  margin-top: -12px;
}

/* Sections */
.section { display: flex; flex-direction: column; gap: 10px; }
.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.8rem;
}

/* Drink grid */
.drink-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}

.drink-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  font-size: inherit;
}

.drink-btn:active { transform: scale(0.96); background: #f5f5f4; }

.drink-btn--add {
  border-style: dashed;
  color: var(--color-muted);
}

.drink-btn__emoji { font-size: 1.5rem; }
.drink-btn__name  { font-size: 0.75rem; font-weight: 500; text-align: center; line-height: 1.2; }
.drink-btn__mg    { font-size: 0.7rem; color: var(--color-muted); }

/* Log list */
.log-list { display: flex; flex-direction: column; gap: 6px; }

.log-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.log-entry__emoji { font-size: 1.4rem; }
.log-entry__info  { flex: 1; display: flex; flex-direction: column; }
.log-entry__name  { font-size: 0.9rem; font-weight: 500; }
.log-entry__time  { font-size: 0.75rem; color: var(--color-muted); }
.log-entry__mg    { font-size: 0.85rem; color: var(--color-muted); white-space: nowrap; }

.log-entry__delete {
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--color-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.log-entry__delete:hover { color: var(--color-danger); background: #fee2e2; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--color-muted);
}
.empty-state__icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state__text { font-size: 0.95rem; }

/* Loading */
.loading { text-align: center; color: var(--color-muted); padding: 24px; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: stretch;
  z-index: 100;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--color-muted);
  font-size: 0.7rem;
  transition: color 0.15s;
}

.nav-item--active { color: var(--color-primary); }

.nav-item__icon { font-size: 1.3rem; }
.nav-item__label { font-size: 0.68rem; }

/* Auth pages */
.auth-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--color-bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-logo   { font-size: 3rem; text-align: center; }
.auth-title  { font-size: 1.4rem; font-weight: 700; text-align: center; }
.auth-subtitle { text-align: center; color: var(--color-muted); font-size: 0.95rem; }

.auth-form { display: flex; flex-direction: column; gap: 14px; }

.auth-link {
  text-align: center;
  font-size: 0.9rem;
  color: var(--color-muted);
}
.auth-link a { color: var(--color-primary); text-decoration: none; font-weight: 500; }

/* Forms */
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-label { font-size: 0.85rem; font-weight: 500; color: var(--color-text); }

.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--color-bg);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--color-primary); }
.form-input--emoji { width: 64px; text-align: center; }

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

.range-input { width: 100%; accent-color: var(--color-primary); }
.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--color-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn--primary  { background: var(--color-primary); color: white; }
.btn--primary:hover:not(:disabled) { background: var(--color-primary-dark); }
.btn--secondary { background: var(--color-border); color: var(--color-text); }
.btn--danger   { background: #fee2e2; color: var(--color-danger); }
.btn--danger:hover { background: #fecaca; }
.btn--full     { width: 100%; }
.btn--sm       { padding: 5px 12px; font-size: 0.85rem; }

/* Alerts */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.alert--error { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 0 8px 8px;
}

@media (min-width: 480px) {
  .modal-overlay { align-items: center; }
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-width: 480px) {
  .modal { border-radius: var(--radius); }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal__title { font-size: 1.1rem; font-weight: 600; }
.modal__close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-muted);
  padding: 0 4px;
  line-height: 1;
}

.modal-form { display: flex; flex-direction: column; gap: 14px; }

/* History */
.history-list { display: flex; flex-direction: column; gap: 6px; }

.history-day__header {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  text-align: left;
  font-size: inherit;
}

.history-day__date  { font-weight: 600; min-width: 70px; font-size: 0.9rem; }
.history-day__bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--color-border);
  border-radius: 99px;
  overflow: hidden;
}
.history-day__bar {
  height: 100%;
  background: var(--color-primary);
  border-radius: 99px;
}
.history-day__total { font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.history-day__count { font-size: 0.75rem; color: var(--color-muted); white-space: nowrap; }
.history-day__chevron { color: var(--color-muted); font-size: 0.75rem; }

/* Settings */
.settings-list { display: flex; flex-direction: column; gap: 6px; }
.settings-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.settings-item__emoji { font-size: 1.3rem; }
.settings-item__name  { flex: 1; font-size: 0.9rem; font-weight: 500; }
.settings-item__mg    { font-size: 0.8rem; color: var(--color-muted); }

.account-info { margin-bottom: 10px; }
.text-muted { color: var(--color-muted); font-size: 0.9rem; }

/* Not found */
.not-found {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}
.not-found__icon  { font-size: 3rem; }
.not-found__title { font-size: 4rem; font-weight: 800; color: var(--color-muted); }
.not-found__text  { color: var(--color-muted); margin-bottom: 8px; }
