:root {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dbe3ee;
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-soft: #eef2ff;
  --success: #047857;
  --success-soft: #ecfdf5;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 0%, rgba(79, 70, 229, 0.10), transparent 28rem),
    radial-gradient(circle at 90% 10%, rgba(8, 145, 178, 0.08), transparent 24rem),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(79, 70, 229, 0.28);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 96px;
  padding: 20px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 15px;
  color: #ffffff;
  background: linear-gradient(135deg, #4f46e5, #0891b2);
  box-shadow: 0 12px 28px rgba(79, 70, 229, 0.28);
  font-weight: 800;
  letter-spacing: -0.05em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 2vw, 1.75rem);
  letter-spacing: -0.035em;
}

h2 {
  margin-bottom: 8px;
  font-size: clamp(1.25rem, 2.2vw, 1.7rem);
  letter-spacing: -0.03em;
}

h3 {
  margin-bottom: 6px;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.muted {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

.session-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-pill,
.count-badge {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: #334155;
  background: rgba(255, 255, 255, 0.82);
  font-size: 0.88rem;
  font-weight: 700;
}

main {
  min-height: calc(100vh - 180px);
}

.card,
.center-card,
.hero-panel,
.stat-card {
  border: 1px solid rgba(219, 227, 238, 0.9);
  background: rgba(255, 255, 255, 0.93);
  box-shadow: var(--shadow);
}

.card {
  border-radius: var(--radius);
  padding: 24px;
}

.center-card {
  display: grid;
  min-height: 360px;
  place-items: center;
  align-content: center;
  gap: 14px;
  border-radius: var(--radius);
  color: var(--muted);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid #dbe3ee;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.startup-error {
  max-width: 520px;
  padding: 32px;
  text-align: center;
}

.startup-error p {
  margin-bottom: 0;
  color: var(--danger);
}

.auth-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 460px);
  gap: clamp(28px, 6vw, 88px);
  align-items: center;
  min-height: 620px;
  padding: 36px 4vw 70px;
}

.auth-intro h2 {
  max-width: 680px;
  font-size: clamp(2rem, 4.5vw, 4rem);
  line-height: 1.02;
}

.auth-intro > p:not(.eyebrow) {
  max-width: 600px;
  color: var(--muted);
  font-size: 1.06rem;
  line-height: 1.7;
}

.feature-list {
  display: grid;
  gap: 12px;
  margin: 28px 0 0;
  padding: 0;
  list-style: none;
  color: #334155;
  font-weight: 650;
}

.feature-list li {
  display: flex;
  align-items: center;
  gap: 10px;
}

.feature-list li::before {
  content: "✓";
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  color: var(--success);
  background: var(--success-soft);
  font-size: 0.8rem;
}

.auth-card {
  padding: 10px 28px 30px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 0 -18px 26px;
  padding: 6px;
  border-radius: 14px;
  background: var(--surface-soft);
}

.auth-tab {
  min-height: 42px;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-weight: 750;
}

.auth-tab.is-active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 4px 15px rgba(15, 23, 42, 0.08);
}

.form-heading {
  margin-bottom: 24px;
}

.form-heading p {
  margin-bottom: 0;
  color: var(--muted);
}

label {
  display: block;
  margin: 16px 0 7px;
  color: #334155;
  font-size: 0.86rem;
  font-weight: 750;
}

input,
select {
  width: 100%;
  min-height: 48px;
  padding: 10px 13px;
  border: 1px solid #cbd5e1;
  border-radius: 11px;
  color: var(--text);
  background: #ffffff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:hover,
select:hover {
  border-color: #94a3b8;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.10);
  outline: 0;
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  font-weight: 780;
  line-height: 1;
  text-decoration: none;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:active:not(:disabled) {
  transform: translateY(0);
}

.button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.button-primary {
  width: 100%;
  margin-top: 22px;
  color: #ffffff;
  background: var(--primary);
}

.button-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.button-secondary {
  color: var(--primary-dark);
  border-color: #c7d2fe;
  background: var(--primary-soft);
}

.button-quiet {
  color: #334155;
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.82);
}

.message {
  margin: 16px 0 0;
  padding: 11px 13px;
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.45;
}

.message-error {
  color: var(--danger);
  border: 1px solid #fecaca;
  background: var(--danger-soft);
}

.message-success {
  color: var(--success);
  border: 1px solid #a7f3d0;
  background: var(--success-soft);
}

.dashboard-message {
  position: sticky;
  z-index: 10;
  top: 12px;
  margin: 0 0 14px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.12);
}

.hero-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 30px;
  border-radius: var(--radius);
}

.hero-panel h2 {
  margin-bottom: 5px;
  font-size: clamp(1.65rem, 3vw, 2.35rem);
}

.export-button {
  flex: 0 0 auto;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 14px 0;
}

.stat-card {
  min-width: 0;
  padding: 20px;
  border-radius: 15px;
}

.stat-label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.stat-value {
  display: block;
  overflow: hidden;
  font-size: clamp(1.22rem, 2.2vw, 1.75rem);
  letter-spacing: -0.035em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-date {
  font-size: clamp(1rem, 1.65vw, 1.3rem);
}

.trend-good {
  color: var(--success);
}

.trend-bad {
  color: var(--danger);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.72fr) minmax(0, 1.5fr);
  gap: 14px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-heading h2 {
  margin-bottom: 0;
  font-size: 1.28rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-note {
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.chart-card {
  min-width: 0;
}

.chart-wrap {
  position: relative;
  width: 100%;
  min-height: 260px;
  overflow: hidden;
}

#weight-chart {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  min-height: 24px;
  margin-top: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #475569;
  font-size: 0.82rem;
  font-weight: 700;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.legend-color-0 { background: #4f46e5; }
.legend-color-1 { background: #0891b2; }
.legend-color-2 { background: #059669; }
.legend-color-3 { background: #d97706; }
.legend-color-4 { background: #dc2626; }
.legend-color-5 { background: #7c3aed; }
.legend-color-6 { background: #db2777; }
.legend-color-7 { background: #475569; }

.history-card {
  margin-top: 14px;
  padding: 0;
  overflow: hidden;
}

.history-heading {
  align-items: center;
  margin: 0;
  padding: 24px;
}

.table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 20px;
  border-bottom: 1px solid #edf2f7;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  background: #f8fafc;
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #fafbff;
}

.weight-cell {
  font-weight: 760;
}

.action-heading,
.action-cell {
  width: 1%;
  text-align: right;
}

.icon-button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 750;
}

.danger-button {
  color: var(--danger);
}

.danger-button:hover {
  border-color: #fecaca;
  background: var(--danger-soft);
}

.empty-state {
  padding: 56px 24px 64px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.empty-state p {
  margin-bottom: 0;
  color: var(--muted);
}

.empty-icon {
  display: grid;
  width: 46px;
  height: 46px;
  margin: 0 auto 14px;
  place-items: center;
  border-radius: 14px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 1.3rem;
  font-weight: 800;
}

footer {
  padding: 34px 0 42px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

footer p {
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 900px) {
  .auth-layout {
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 35px 0 70px;
  }

  .auth-intro {
    max-width: 720px;
    text-align: center;
    margin: 0 auto;
  }

  .auth-intro > p:not(.eyebrow) {
    margin-right: auto;
    margin-left: auto;
  }

  .feature-list {
    display: inline-grid;
    text-align: left;
  }

  .auth-card {
    width: min(100%, 500px);
    margin: 0 auto;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .page-shell {
    width: min(100% - 20px, 1180px);
  }

  .site-header {
    align-items: flex-start;
    min-height: 80px;
    padding: 14px 0;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 13px;
  }

  .brand .eyebrow,
  .user-pill {
    display: none;
  }

  .session-controls {
    padding-top: 2px;
  }

  .button-quiet {
    min-height: 40px;
    padding: 9px 12px;
  }

  .auth-layout {
    gap: 30px;
    padding-top: 24px;
  }

  .auth-intro h2 {
    font-size: 2.25rem;
  }

  .auth-intro > p:not(.eyebrow),
  .feature-list {
    font-size: 0.94rem;
  }

  .auth-card,
  .card {
    padding: 20px;
  }

  .auth-card {
    padding-top: 8px;
  }

  .hero-panel {
    display: block;
    padding: 22px;
  }

  .export-button {
    width: 100%;
    margin-top: 18px;
  }

  .stats-grid {
    gap: 10px;
    margin: 10px 0;
  }

  .stat-card {
    padding: 16px;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .history-card {
    padding: 0;
  }

  .history-heading {
    padding: 20px;
  }

  th,
  td {
    padding: 13px 15px;
  }

  .count-badge {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
