:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-strong: #eef5f1;
  --ink: #16211d;
  --muted: #61706a;
  --line: #d9e3de;
  --primary: #16745b;
  --primary-dark: #0f5947;
  --teal: #0b8793;
  --amber: #b7791f;
  --red: #b42318;
  --blue: #3157a4;
  --shadow: 0 18px 45px rgba(28, 50, 43, 0.1);
}

* {
  box-sizing: border-box;
}

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

body:has(.auth-screen:not(.hidden)) {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: #10251f;
}

.auth-panel {
  display: grid;
  gap: 16px;
  width: min(440px, 100%);
  border: 1px solid #ffffff26;
  border-radius: 8px;
  background: #ffffff;
  padding: 24px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.3);
}

.auth-panel h2 {
  margin: 0 0 6px;
}

.auth-panel > button[type="submit"] {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 900;
}

.auth-brand {
  color: var(--ink);
}

.app-shell.locked {
  filter: blur(4px);
  pointer-events: none;
  user-select: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  background: linear-gradient(160deg, #17352d 0%, #20483e 48%, #2f5f52 100%);
  color: #f4fbf8;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
}

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

.brand-logo {
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid #ffffff2b;
  background: #0b1110;
}

.auth-brand .brand-logo {
  border-color: var(--line);
}

.brand h1,
.brand p,
.topbar h2,
.section-title h2,
.panel h3 {
  margin: 0;
}

.brand h1 {
  font-size: 1.25rem;
}

.brand p,
.privacy-note span,
.muted,
small {
  color: var(--muted);
}

.sidebar .brand p,
.privacy-note span {
  color: #c9ddd5;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #e5f1ec;
  text-align: left;
  padding: 0 12px;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.22);
  color: #ffffff;
}

.privacy-note {
  margin-top: auto;
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
}

.main-content {
  padding: 24px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar-title {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.user-chip {
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--primary-dark);
  padding: 4px 10px;
  font-size: 0.85rem;
  font-weight: 800;
}

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

.topbar-actions {
  display: flex;
  gap: 10px;
}

.menu-btn {
  display: none;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.15rem;
  font-weight: 900;
  box-shadow: var(--shadow);
}

.btn-icon {
  line-height: 1;
}

.icon-btn.danger {
  color: var(--red);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 20px;
}

.section-title {
  display: grid;
  gap: 4px;
}

.score-band,
.panel,
.metric-card,
.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.score-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px;
  background: linear-gradient(135deg, #ffffff 0%, #e7f5ef 100%);
}

.score-band strong {
  display: block;
  font-size: clamp(2.5rem, 7vw, 5rem);
  line-height: 1;
}

.score-band span {
  color: var(--muted);
}

.score-ring {
  display: grid;
  place-items: center;
  flex: 0 0 132px;
  height: 132px;
  border-radius: 50%;
  background: conic-gradient(var(--primary) 0deg, var(--primary) var(--score), #dce8e3 var(--score));
  color: var(--primary-dark);
  font-size: 1.35rem;
  font-weight: 900;
}

.score-ring::before {
  content: "";
  position: absolute;
}

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

.metric-card {
  display: grid;
  gap: 8px;
  padding: 18px;
}

.metric-card span {
  color: var(--muted);
  font-weight: 700;
}

.metric-card strong {
  font-size: 1.65rem;
}

.metric-card.warning strong {
  color: var(--red);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 20px;
}

.panel {
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-header.full {
  grid-column: 1 / -1;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-weight: 800;
}

.file-link {
  width: fit-content;
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
  padding: 0;
}

.attachment-card {
  display: grid;
  gap: 4px;
  width: fit-content;
  max-width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef5f1;
}

.file-status {
  min-height: 40px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #f8fbfa;
  color: var(--muted);
  padding: 10px 12px;
  font-weight: 700;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  color: var(--ink);
  padding: 11px 12px;
}

textarea {
  resize: vertical;
}

.full {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.form-actions button,
.secondary-btn {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  padding: 0 18px;
  font-weight: 900;
}

.secondary-btn {
  border: 1px solid var(--line);
  background: #f8fbfa;
  color: var(--primary);
}

.secondary-btn.danger-action {
  border-color: #f0b8b8;
  background: #fff5f5;
  color: #9b1c1c;
}

.security-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(8, 20, 17, 0.45);
}

.security-dialog {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(8, 20, 17, 0.25);
}

.security-dialog h3,
.security-dialog p {
  margin: 0;
}

.habit-list,
.risk-list,
.timeline,
.risk-table {
  display: grid;
  gap: 10px;
}

.habit-row,
.risk-row,
.timeline-item,
.risk-table-row {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe9e4;
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--primary));
}

.emergency-preview {
  display: grid;
  gap: 12px;
}

.emergency-preview > div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.emergency-preview span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.emergency-preview strong {
  font-size: 1.2rem;
}

.emergency-preview p {
  margin: 0;
}

.backup-actions {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.file-restore {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdfc;
}

.habit-row {
  grid-template-columns: auto 1fr auto;
  align-items: center;
}

.habit-row input {
  width: 20px;
  height: 20px;
}

.habit-row strong,
.risk-row strong,
.timeline-item strong {
  color: var(--ink);
}

.large .habit-row {
  min-height: 54px;
}

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 900;
}

.badge.normal {
  background: #ddf5e9;
  color: #0f6b4f;
}

.badge.watch {
  background: #fff0cc;
  color: #8a5a00;
}

.badge.high {
  background: #ffe0dc;
  color: #a12a1f;
}

.badge.critical {
  background: #f9d0d0;
  color: #7f1d1d;
}

.notice {
  padding: 14px 16px;
  color: #5e480a;
  background: #fff8e5;
  border-color: #f2d58a;
}

.risk-table-row {
  grid-template-columns: 1fr 100px 110px 1.2fr;
  align-items: center;
}

.empty {
  color: var(--muted);
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.bmi-result {
  display: grid;
  gap: 12px;
}

.bmi-score {
  font-size: clamp(3rem, 10vw, 5rem);
  line-height: 1;
  font-weight: 900;
  color: var(--primary-dark);
}

.chart-grid {
  display: grid;
  gap: 10px;
  overflow-x: auto;
}

.legend.energy {
  background: var(--amber);
}

.legend.weight {
  background: var(--blue);
}

.line-chart-wrap {
  min-width: 620px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
  padding: 10px;
}

.line-chart {
  display: block;
  width: 100%;
  height: auto;
}

.chart-axis {
  stroke: #9aaaa4;
  stroke-width: 1.5;
}

.chart-label {
  fill: var(--muted);
  font-size: 16px;
  text-anchor: middle;
}

.chart-line {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.energy-line {
  stroke: var(--amber);
}

.weight-line {
  stroke: var(--blue);
}

.chart-dot {
  stroke: #ffffff;
  stroke-width: 2;
}

.energy-dot {
  fill: var(--amber);
}

.weight-dot {
  fill: var(--blue);
}

.chart-caption {
  color: var(--muted);
  font-size: 0.9rem;
}

.legend {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin: 0 4px;
  vertical-align: middle;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 8;
    inset: 0 auto 0 0;
    width: min(320px, 86vw);
    height: 100vh;
    transform: translateX(-105%);
    transition: transform 180ms ease;
    overflow-y: auto;
  }

  .nav-open .sidebar {
    transform: translateX(0);
  }

  .nav-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 7;
    background: rgba(9, 23, 18, 0.45);
  }

  .nav-list {
    grid-template-columns: 1fr;
  }

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

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

  .menu-btn {
    display: grid;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 6;
    padding: 10px 0;
    background: var(--bg);
  }
}

@media (max-width: 680px) {
  .main-content,
  .sidebar {
    padding: 14px;
  }

  .score-band {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
  }

  .content-grid,
  .metric-grid,
  .form-grid,
  .risk-table-row {
    grid-template-columns: 1fr;
  }

  .nav-item,
  .form-actions button,
  .secondary-btn,
  input,
  select,
  textarea {
    min-height: 46px;
  }

  .panel {
    padding: 14px;
  }

  .topbar-actions {
    grid-column: auto;
    width: auto;
    justify-content: end;
    gap: 6px;
  }

  .icon-btn {
    width: 38px;
    height: 38px;
    font-size: 1rem;
  }

  .topbar-title h2 {
    font-size: 1.05rem;
    line-height: 1.15;
  }

  .user-chip,
  #syncStatus {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .score-ring {
    flex-basis: auto;
    width: 120px;
    height: 120px;
  }
}
