/* ── CSS Variables ─────────────────────────────────────── */
:root {
  --color-bg: #FDF8F5;
  --color-surface: #FFFFFF;
  --color-primary: #E8A0B4;
  --color-primary-light: #F5D0DC;
  --color-primary-dark: #D4799A;
  --color-accent: #C4A8D4;
  --color-accent-light: #EDE4F5;
  --color-text: #3D3340;
  --color-text-secondary: #8A7A8F;
  --color-border: #EDE4EA;
  --color-success: #A8D4B8;
  --color-success-bg: #EDF7F1;
  --color-danger: #E8A0A0;
  --color-inactive: #C8C0CC;

  --radius-card: 16px;
  --radius-btn: 12px;
  --radius-full: 9999px;
  --shadow-card: 0 2px 16px rgba(61, 51, 64, 0.07);
  --shadow-fab: 0 4px 24px rgba(232, 160, 180, 0.45);

  --font: -apple-system, 'PingFang SC', 'Helvetica Neue', sans-serif;
  --nav-h: 64px;
  --header-h: 80px;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: var(--font); cursor: pointer; border: none; background: none; }
a { text-decoration: none; color: inherit; }
input { font-family: var(--font); }

/* ── App Shell ──────────────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}
.page-content {
  flex: 1;
  padding: 0 0 calc(var(--nav-h) + 16px);
  overflow-x: hidden;
}

/* ── Bottom Nav ─────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--nav-h);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 16px;
  min-height: 48px;
  justify-content: center;
  color: var(--color-text-secondary);
  transition: color .2s;
  flex: 1;
}
.nav-item.active { color: var(--color-primary-dark); }
.nav-icon { width: 22px; height: 22px; display: flex; align-items: center; }
.nav-icon svg { width: 100%; height: 100%; }
.nav-label { font-size: 11px; font-weight: 500; letter-spacing: .02em; }

/* ── Page Header ────────────────────────────────────────── */
.page-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 20px 20px 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.page-header__inner { max-width: 440px; margin: 0 auto; }
.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -.01em;
}
.page-subtitle {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

/* ── Progress Chips ─────────────────────────────────────── */
.progress-bar-row {
  display: flex;
  gap: 8px;
  padding: 14px 20px 0;
  flex-wrap: wrap;
}
.progress-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  background: var(--color-primary-light);
  border: 1.5px solid transparent;
  transition: background .25s, border-color .25s;
}
.progress-chip--done {
  background: var(--color-success-bg);
  border-color: var(--color-success);
}
.progress-chip__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-primary-dark);
}
.progress-chip--done .progress-chip__label { color: #4e9e6a; }
.progress-chip__count {
  font-size: 12px;
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
}

/* ── Slot Sections ──────────────────────────────────────── */
.sections { padding: 16px 20px; display: flex; flex-direction: column; gap: 20px; }
.slot-section {
  background: var(--color-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.slot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--color-border);
}
.slot-title { font-size: 14px; font-weight: 700; color: var(--color-text); }
.slot-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  background: var(--color-bg);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-variant-numeric: tabular-nums;
}
.med-list { display: flex; flex-direction: column; }

/* ── Medicine Item (today) ──────────────────────────────── */
.med-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  gap: 12px;
  border-bottom: 1px solid var(--color-border);
  transition: background .2s;
}
.med-item:last-child { border-bottom: none; }
.med-item--taken { background: #fdfbf9; }
.med-info { flex: 1; min-width: 0; }
.med-name {
  font-size: 15px;
  font-weight: 600;
  display: block;
  transition: color .2s, opacity .2s;
}
.med-item--taken .med-name {
  color: var(--color-text-secondary);
  text-decoration: line-through;
  opacity: .7;
}
.med-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--color-text-secondary);
  flex-wrap: wrap;
}
.med-notes {
  background: var(--color-accent-light);
  color: var(--color-accent);
  padding: 1px 7px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 500;
}

/* ── Check Button ───────────────────────────────────────── */
.check-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--color-surface);
  color: transparent;
  transition: border-color .2s, background .2s, color .2s, transform .15s;
  -webkit-tap-highlight-color: transparent;
}
.check-btn:active { transform: scale(.92); }
.check-btn--checked {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.check-btn--loading { opacity: .6; pointer-events: none; }
.check-icon { width: 18px; height: 18px; }

/* ── Medicine Cards (management) ────────────────────────── */
.med-card-list { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.med-card {
  background: var(--color-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: opacity .2s;
}
.med-card--inactive { opacity: .55; }
.med-card__body {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 16px 14px;
  gap: 8px;
}
.med-card__info { flex: 1; min-width: 0; }
.med-card__name { font-size: 16px; font-weight: 700; display: block; margin-bottom: 6px; }
.med-card__tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}
.tag--dosage { background: var(--color-primary-light); color: var(--color-primary-dark); }
.tag--notes { background: var(--color-accent-light); color: var(--color-accent); }
.tag--slot { background: var(--color-bg); color: var(--color-text-secondary); border: 1px solid var(--color-border); }
.med-card__actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }

/* ── Icon Buttons ───────────────────────────────────────── */
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  transition: background .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn--edit:hover, .icon-btn--edit:active { background: var(--color-accent-light); color: var(--color-accent); }
.icon-btn--pause:hover, .icon-btn--pause:active { background: #fff3e0; color: #e89a40; }
.icon-btn--play:hover, .icon-btn--play:active { background: var(--color-success-bg); color: #4e9e6a; }
.icon-btn--delete:hover, .icon-btn--delete:active { background: #fdeaea; color: var(--color-danger); }

/* ── FAB ────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + 20px);
  right: max(20px, calc(50% - 220px));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-fab);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  transition: transform .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.fab:active { transform: scale(.94); background: var(--color-primary-dark); }
.fab svg { width: 26px; height: 26px; }

/* ── Drawer ─────────────────────────────────────────────── */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(61, 51, 64, 0.35);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  backdrop-filter: blur(2px);
}
.drawer-overlay.active { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  width: 100%;
  max-width: 480px;
  background: var(--color-surface);
  border-radius: 24px 24px 0 0;
  z-index: 210;
  padding: 0 20px calc(20px + env(safe-area-inset-bottom));
  transition: transform .3s cubic-bezier(.32,.72,0,1);
  max-height: 92dvh;
  max-height: 92vh;
  overflow-y: auto;
}
.drawer.open { transform: translateX(-50%) translateY(0); }
.drawer__handle {
  width: 40px;
  height: 4px;
  background: var(--color-border);
  border-radius: var(--radius-full);
  margin: 14px auto 20px;
}
.drawer__title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--color-text);
}
.drawer__footer {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

/* ── Form ───────────────────────────────────────────────── */
.drawer-form { display: flex; flex-direction: column; gap: 16px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--color-text); }
.form-input {
  height: 48px;
  padding: 0 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-btn);
  font-size: 15px;
  color: var(--color-text);
  background: var(--color-bg);
  outline: none;
  transition: border-color .2s;
}
.form-input:focus { border-color: var(--color-primary); }
.form-input::placeholder { color: var(--color-inactive); }

/* ── Slot Picker ────────────────────────────────────────── */
.slot-picker { display: flex; flex-wrap: wrap; gap: 10px; }
.slot-chip { cursor: pointer; }
.slot-chip input { display: none; }
.slot-chip span {
  display: inline-flex;
  align-items: center;
  padding: 8px 18px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--color-border);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  background: var(--color-bg);
  transition: background .15s, border-color .15s, color .15s;
  min-height: 40px;
}
.slot-chip input:checked + span {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  color: var(--color-primary-dark);
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border-radius: var(--radius-btn);
  font-size: 15px;
  font-weight: 600;
  transition: background .15s, opacity .15s, transform .12s;
  -webkit-tap-highlight-color: transparent;
  flex: 1;
}
.btn:active { transform: scale(.97); }
.btn--primary {
  background: var(--color-primary);
  color: #fff;
}
.btn--primary:hover { background: var(--color-primary-dark); }
.btn--ghost {
  background: var(--color-bg);
  color: var(--color-text-secondary);
  border: 1.5px solid var(--color-border);
}
.btn--sm { min-height: 40px; font-size: 14px; padding: 0 18px; flex: none; }

/* ── Empty State ────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 64px 32px;
  text-align: center;
  gap: 10px;
}
.empty-state__icon {
  width: 64px;
  height: 64px;
  color: var(--color-primary-light);
  margin-bottom: 8px;
}
.empty-state__icon svg { width: 100%; height: 100%; }
.empty-state__text { font-size: 17px; font-weight: 700; color: var(--color-text); }
.empty-state__hint { font-size: 13px; color: var(--color-text-secondary); margin-bottom: 6px; }

/* ── History ────────────────────────────────────────────── */
.history-list { padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.history-card {
  background: var(--color-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.history-card__header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  gap: 8px;
  min-height: 56px;
  -webkit-tap-highlight-color: transparent;
}
.history-card__date-wrap { display: flex; align-items: baseline; gap: 8px; }
.history-card__date { font-size: 15px; font-weight: 700; }
.history-card__weekday { font-size: 12px; color: var(--color-text-secondary); }
.history-card__right { display: flex; align-items: center; gap: 8px; }
.history-card__ratio {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
  background: var(--color-bg);
  padding: 2px 10px;
  border-radius: var(--radius-full);
}
.history-card__ratio.ratio--full {
  background: var(--color-success-bg);
  color: #4e9e6a;
}
.history-card__chevron {
  width: 20px;
  height: 20px;
  color: var(--color-inactive);
  transition: transform .25s;
  display: flex;
  align-items: center;
}
.history-card__chevron svg { width: 100%; height: 100%; }
.history-card--open .history-card__chevron { transform: rotate(180deg); }

.history-card__body {
  max-height: 0;
  overflow: hidden;
  transition: max-height .3s cubic-bezier(.4,0,.2,1);
  border-top: 0 solid var(--color-border);
}
.history-card--open .history-card__body {
  max-height: 800px;
  border-top-width: 1px;
}
.history-slot { padding: 12px 18px; border-bottom: 1px solid var(--color-border); }
.history-slot:last-child { border-bottom: none; }
.history-slot__label {
  font-size: 12px;
  font-weight: 700;
  color: var(--color-primary-dark);
  display: block;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.history-med-list { display: flex; flex-direction: column; gap: 6px; }
.history-med-item {
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: .55;
}
.history-med-item--taken { opacity: 1; }
.history-check {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: transparent;
}
.history-check--on {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.history-check svg { width: 10px; height: 10px; }
.history-med-name { font-size: 14px; font-weight: 500; flex: 1; }
.history-med-dosage { font-size: 12px; color: var(--color-text-secondary); }
.history-med-time { font-size: 12px; color: var(--color-text-secondary); margin-left: auto; font-variant-numeric: tabular-nums; }

/* ── Login ──────────────────────────────────────────────── */
.login-body {
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  min-height: 100vh;
  padding: 24px;
}
.login-wrap { width: 100%; max-width: 360px; }
.login-card {
  background: var(--color-surface);
  border-radius: 24px;
  padding: 40px 32px 36px;
  box-shadow: 0 8px 40px rgba(61, 51, 64, 0.1);
}
.login-dot-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 36px;
}
.login-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-primary-light);
}
.login-dot:nth-child(2) { background: var(--color-primary); width: 12px; height: 12px; }
.login-dot:nth-child(3) { background: var(--color-accent-light); }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-field { display: flex; flex-direction: column; gap: 6px; }
.login-input {
  height: 52px;
  padding: 0 18px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-btn);
  font-size: 16px;
  color: var(--color-text);
  background: var(--color-bg);
  outline: none;
  text-align: center;
  letter-spacing: .2em;
  transition: border-color .2s;
}
.login-input:focus { border-color: var(--color-primary); }
.login-input--error { border-color: var(--color-danger); }
.login-error { font-size: 13px; color: var(--color-danger); text-align: center; }
.login-btn {
  height: 52px;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-btn);
  font-size: 16px;
  font-weight: 700;
  transition: background .15s, transform .12s;
  -webkit-tap-highlight-color: transparent;
}
.login-btn:active { transform: scale(.97); background: var(--color-primary-dark); }

/* ── Scrollbar (desktop) ────────────────────────────────── */
@media (pointer: fine) {
  ::-webkit-scrollbar { width: 4px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--color-primary-light); border-radius: 2px; }
}

/* ── Safe area (notch phones) ───────────────────────────── */
.bottom-nav { padding-bottom: calc(env(safe-area-inset-bottom) + 4px); height: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
