:root {
  --bg-primary: #111827;
  --bg-secondary: #1f2937;
  --bg-card: #182234;
  --border-color: #2d3748;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-sub: #6b7280;
  --accent-gold: #f59e0b;
  --accent-gold-dim: rgba(245, 158, 11, 0.35);
  --accent-gold-bold: #fbbf24;
  --accent-blue: #38bdf8;
  --accent-blue-fill: rgba(56, 189, 248, 0.15);
  --header-bg: #84cc16; /* soft green banner */
  --header-text: #1a2e05;
  --button-primary: #3b82f6;
  --button-hover: #2563eb;
  --danger-color: #ef4444;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-sub: #94a3b8;
  --accent-gold: #d97706;
  --accent-gold-dim: rgba(217, 119, 6, 0.25);
  --accent-gold-bold: #b45309;
  --accent-blue: #0284c7;
  --accent-blue-fill: rgba(2, 132, 199, 0.12);
  --header-bg: #bef264;
  --header-text: #1a2e05;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* App Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--border-color);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.app-title {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.icon-btn:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

/* Main Container */
.container {
  flex: 1;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Segmented Control Tabs */
.segmented-control {
  display: flex;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  padding: 4px;
  gap: 4px;
}

.segment-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: 9999px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.segment-btn.active {
  background-color: #334155;
  color: #ffffff;
  font-weight: 600;
}

[data-theme="light"] .segment-btn.active {
  background-color: #e2e8f0;
  color: #0f172a;
}

/* Chart Card */
.chart-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 16px;
  position: relative;
  min-height: 420px;
  display: flex;
  flex-direction: column;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.chart-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.unit-badge {
  font-size: 0.8rem;
  padding: 4px 8px;
  border-radius: 6px;
  background-color: var(--bg-secondary);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  cursor: pointer;
}

.chart-wrapper {
  position: relative;
  flex: 1;
  width: 100%;
  height: 360px;
}

/* Floating Selected Info Box */
.stat-pill {
  position: absolute;
  bottom: 24px;
  right: 24px;
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px 16px;
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  font-size: 0.85rem;
  z-index: 10;
  min-width: 180px;
}

[data-theme="light"] .stat-pill {
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}

.stat-pill .date-row {
  font-size: 0.8rem;
  color: var(--text-sub);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}

.stat-pill .val-highlight {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}

.stat-pill .percentile-tag {
  color: var(--accent-gold-bold);
  font-weight: 600;
}

.stat-pill .source-tag {
  font-size: 0.7rem;
  color: var(--text-sub);
  margin-top: 6px;
}

/* History Card */
.history-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 16px;
}

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

.history-card-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.entries-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}

.entry-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.15s ease;
}

.entry-row:hover {
  background-color: rgba(56, 189, 248, 0.08);
  border-color: rgba(56, 189, 248, 0.4);
}

.entry-row.selected {
  background-color: rgba(56, 189, 248, 0.15);
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 1px var(--accent-blue);
}

.entry-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.entry-date {
  font-size: 0.85rem;
  font-weight: 600;
}

.entry-note {
  font-size: 0.75rem;
  color: var(--text-sub);
}

.entry-right {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.entry-val {
  font-size: 0.95rem;
  font-weight: 700;
}

.entry-pct {
  font-size: 0.8rem;
  color: var(--accent-gold-bold);
  font-weight: 500;
}

/* Action Buttons / FAB */
.fab-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 40;
}

.fab-btn {
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background-color: var(--button-primary);
  color: #ffffff;
  border: none;
  font-size: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 20px -3px rgba(59, 130, 246, 0.4);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.fab-btn:active {
  transform: scale(0.92);
}

/* Modal Bottom Sheets */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal-sheet {
  background-color: var(--bg-secondary);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header-banner {
  background-color: var(--header-bg);
  color: var(--header-text);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 20px 20px 0 0;
}

.modal-header-banner h2 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.modal-header-banner button {
  background: none;
  border: none;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--header-text);
  cursor: pointer;
}

.modal-body {
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.form-input {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px;
  color: var(--text-main);
  font-size: 1rem;
  outline: none;
}

.form-input:focus {
  border-color: var(--button-primary);
}

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

.form-row .form-group {
  flex: 1;
}

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}
