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

/* ── Keyframes ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(.94); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position:  400px 0; }
}
@keyframes countUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

:root {
  --rose:     #f43f5e;
  --rose-lt:  #fff1f2;
  --rose-md:  #fda4af;
  --purple:   #a855f7;
  --purple-lt:#faf5ff;
  --text:     #1e1b2e;
  --muted:    #6b7280;
  --border:   #e5e7eb;
  --card-bg:  #ffffff;
  --bg:       #fdf2f8;
  --radius:   14px;
  --shadow:   0 2px 12px rgba(244,63,94,.08);
}

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

/* ── Header ── */
header {
  background: linear-gradient(135deg, var(--rose) 0%, var(--purple) 100%);
  padding: 20px 24px;
  color: #fff;
  animation: fadeIn .4s ease both;
}
.header-inner { display: flex; align-items: center; gap: 12px; max-width: 700px; margin: 0 auto; }
.logo { font-size: 2rem; }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.3px; flex: 1; }

.user-chip { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.5);
  object-fit: cover;
}
.avatar-fallback {
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.25);
  font-weight: 700; font-size: .9rem; color: #fff;
}
.user-name { font-size: .88rem; font-weight: 600; color: rgba(255,255,255,.9); }
.logout-btn {
  color: rgba(255,255,255,.85);
  text-decoration: none;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .3px;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1.5px solid rgba(255,255,255,.4);
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.logout-btn:hover {
  background: rgba(255,255,255,.15);
  color: #fff;
  border-color: rgba(255,255,255,.7);
}

/* ── Banner ── */
.banner.visible {
  animation: fadeUp .4s ease both;
}
.banner {
  max-width: 700px;
  margin: 20px auto 0;
  padding: 16px 20px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #fdf4ff, #fff1f2);
  border: 1.5px solid var(--rose-md);
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: .95rem;
}
.banner .banner-icon { font-size: 1.8rem; flex-shrink: 0; }
.banner strong { display: block; font-size: 1.1rem; color: var(--rose); }
.banner .sub { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.banner.late { border-color: #f59e0b; background: #fffbeb; }
.banner.late strong { color: #d97706; }

/* ── Main layout ── */
main {
  max-width: 700px;
  margin: 24px auto;
  padding: 0 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Skeleton loader ── */
.skeleton {
  background: linear-gradient(90deg, #f0e6f0 25%, #fde8f0 50%, #f0e6f0 75%);
  background-size: 400px 100%;
  animation: shimmer 1.2s infinite linear;
  border-radius: 8px;
  color: transparent !important;
  user-select: none;
  pointer-events: none;
}
.skeleton * { visibility: hidden; }

/* ── Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: transform .2s ease, box-shadow .2s ease;
  opacity: 0;
}
.stat-card.visible {
  animation: fadeUp .4s ease both;
  opacity: 1;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(244,63,94,.12); }
.stat-card .label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-card .value { font-size: 1.7rem; font-weight: 700; color: var(--rose); margin-top: 4px; line-height: 1; animation: countUp .35s ease both; }
.stat-card .unit  { font-size: .8rem; color: var(--muted); margin-top: 2px; }

/* ── Card ── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  opacity: 0;
}
.card.visible {
  animation: fadeUp .45s ease both;
  opacity: 1;
}
.card h2 { font-size: 1.05rem; font-weight: 700; margin-bottom: 18px; color: var(--text); }

/* ── Form ── */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
label { font-size: .82rem; font-weight: 600; color: var(--muted); }
.req { color: var(--rose); }
input[type="date"],
input[type="text"] {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  font-size: .95rem;
  color: var(--text);
  background: #fff;
  transition: border-color .15s;
  width: 100%;
}
input:focus { outline: none; border-color: var(--rose-md); }
input:disabled { background: #f9fafb; color: var(--muted); }

.btn-primary {
  background: linear-gradient(135deg, var(--rose), var(--purple));
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 11px 22px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s, transform .15s, box-shadow .2s;
  position: relative;
  overflow: hidden;
}
.btn-primary::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0);
  transition: background .15s;
}
.btn-primary:hover { opacity: .93; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(244,63,94,.35); }
.btn-primary:active { transform: scale(.97); box-shadow: none; }
.btn-primary:active::after { background: rgba(255,255,255,.12); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.btn-ghost {
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  padding: 10px 20px;
  font-size: .9rem;
  cursor: pointer;
  color: var(--muted);
}
.btn-ghost:hover { border-color: var(--rose-md); color: var(--rose); }

.form-error { color: var(--rose); font-size: .85rem; margin-top: 8px; }

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

@keyframes itemIn {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}
.history-item {
  background: var(--rose-lt);
  border-radius: 10px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 10px;
  row-gap: 6px;
  align-items: start;
}
.history-item .dot {
  width: 10px; height: 10px;
  background: var(--rose);
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.history-item .dates { min-width: 0; }
.history-item .dates .primary { font-weight: 600; font-size: .9rem; line-height: 1.3; word-break: break-word; }
.history-item .dates .secondary { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.history-item .meta {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.history-item .cycle-badge {
  background: var(--purple-lt);
  color: var(--purple);
  border-radius: 20px;
  padding: 2px 9px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}
.history-item .actions { display: flex; gap: 4px; margin-left: auto; }
.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: .95rem;
  transition: background .15s, transform .1s;
}
.icon-btn:hover  { background: rgba(0,0,0,.06); }
.icon-btn:active { transform: scale(.88); }

/* ── Empty ── */
.empty-state { color: var(--muted); font-size: .9rem; text-align: center; padding: 24px 0; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn .2s ease both;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px 28px 24px;
  width: min(420px, 90vw);
  box-shadow: 0 8px 32px rgba(0,0,0,.15);
  animation: scaleIn .25s ease both;
}
.modal h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

/* ── PWA install banner ── */
.pwa-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: min(660px, calc(100vw - 32px));
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0,0,0,.14);
  border: 1.5px solid var(--border);
  z-index: 200;
  animation: slideUp .3s ease;
}
@keyframes slideUp {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0);   opacity: 1; }
}
.pwa-banner-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}
.pwa-icon { font-size: 1.8rem; flex-shrink: 0; }
.pwa-text { flex: 1; min-width: 0; }
.pwa-text strong { display: block; font-size: .92rem; color: var(--text); }
.pwa-text span   { font-size: .78rem; color: var(--muted); }
.pwa-install-btn {
  background: linear-gradient(135deg, var(--rose), var(--purple));
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.pwa-install-btn:hover { opacity: .9; }
.pwa-dismiss {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
  line-height: 1;
}
.pwa-dismiss:hover { color: var(--text); }

/* PWA how-to modal */
.pwa-howto-modal { text-align: center; }
.pwa-howto-icon  { font-size: 2.5rem; margin-bottom: 8px; }
.pwa-howto-modal h3 { margin-bottom: 20px; }
.pwa-howto-steps { text-align: left; display: flex; flex-direction: column; gap: 12px; margin-bottom: 8px; }
.pwa-step { display: flex; align-items: flex-start; gap: 12px; font-size: .9rem; line-height: 1.4; }
.pwa-step-num {
  background: linear-gradient(135deg, var(--rose), var(--purple));
  color: #fff; border-radius: 50%;
  width: 24px; height: 24px; min-width: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700;
}

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Responsive ── */
@media (max-width: 480px) {
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .card { padding: 18px 16px; }
}
