/* ==========================================================================
   Weight Tracker - Modern Dark Theme & Responsive Layout
   ========================================================================== */

:root {
  --bg-app: #121214;
  --bg-card: #18181b;
  --bg-card-subtle: #1e1e24;
  --bg-elevated: #222228;
  --border-color: #2e2e36;
  --border-subtle: #27272a;
  --border-focus: #38bdf8;
  
  --text-primary: #f4f4f6;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  
  --accent-primary: #0284c7;
  --accent-hover: #0369a1;
  --accent-active: #075985;
  --accent-glow: rgba(56, 189, 248, 0.25);
  
  --trend-down: #34d399; /* Weight loss */
  --trend-up: #fb7185;   /* Weight gain */
  --trend-neutral: #a1a1aa;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-full: 9999px;
  
  --transition-fast: 0.15s ease;
  --transition-base: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
  --shadow-fab: 0 8px 24px rgba(2, 132, 199, 0.45);
}

/* Base Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
  padding: 0;
}

/* App Viewport Container */
.app-container {
  width: 100%;
  max-width: 440px;
  min-height: 100vh;
  background-color: var(--bg-card);
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  position: relative;
  display: flex;
  flex-direction: column;
  padding-bottom: 96px; /* Space for FAB */
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.6);
}

@media (min-width: 441px) {
  body {
    padding: 24px 16px;
    background: radial-gradient(circle at 50% 10%, #1a1a22 0%, #101014 100%);
  }
  .app-container {
    min-height: calc(100vh - 48px);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    overflow: hidden;
  }
}

/* ==========================================================================
   Home Page Layout
   ========================================================================== */
.home-page {
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  flex: 1;
}

/* Top Bar / Hero Card */
.hero-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  position: relative;
  width: 100%;
  min-height: 40px;
}

.hero-card.empty {
  justify-content: flex-end;
}

.hero-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hero-label {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.hero-value-wrap {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.hero-value {
  font-size: 2.85rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1.1;
}

.hero-unit {
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.hero-trend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 4px;
}

.hero-trend.loss {
  color: var(--trend-down);
}

.hero-trend.gain {
  color: var(--trend-up);
}

.hero-trend-icon {
  width: 16px;
  height: 16px;
  display: inline-block;
  vertical-align: middle;
}

/* Settings Icon Button */
.settings-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: #38bdf8;
  padding: 8px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.settings-btn:hover {
  background-color: var(--bg-card-subtle);
  transform: rotate(25deg);
  color: #7dd3fc;
}

.settings-btn:active {
  transform: rotate(45deg) scale(0.95);
}

.settings-btn svg {
  width: 26px;
  height: 26px;
}

/* ==========================================================================
   Empty State (Screenshot 4)
   ========================================================================== */
.home-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  min-height: 52vh;
  padding: 32px 20px;
  gap: 12px;
}

.empty-state-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.empty-state-desc {
  font-size: 0.98rem;
  font-weight: 400;
  color: var(--text-secondary);
  max-width: 250px;
  line-height: 1.45;
}

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

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

.chart-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.chart-wrapper {
  position: relative;
  width: 100%;
  height: 160px;
}

.svg-chart {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* SVG Chart Tooltip */
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transform: translate(-50%, -120%);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  opacity: 0;
  z-index: 10;
  white-space: nowrap;
}

.chart-tooltip.visible {
  opacity: 1;
}

/* Weekly Grouped History */
.history-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.week-group {
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background-color: var(--bg-card);
}

.week-header {
  background-color: var(--bg-card-subtle);
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.week-range {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
}

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

.week-avg {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.week-avg strong {
  color: var(--text-primary);
  font-weight: 600;
}

.week-delta {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background-color: rgba(255, 255, 255, 0.05);
}

.week-delta.loss {
  color: var(--trend-down);
  background-color: rgba(52, 211, 153, 0.12);
}

.week-delta.gain {
  color: var(--trend-up);
  background-color: rgba(251, 113, 133, 0.12);
}

.week-delta.neutral {
  color: var(--trend-neutral);
}

/* Daily Entries */
.entries-list {
  display: flex;
  flex-direction: column;
}

.entry-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  cursor: pointer;
  position: relative;
  transition: background-color var(--transition-fast);
  border-bottom: 1px solid var(--border-color);
}

.entry-item:last-child {
  border-bottom: none;
}

.entry-item:hover {
  background-color: var(--bg-card-subtle);
}

.entry-item:active {
  background-color: var(--bg-elevated);
}

/* Text style matching the logging modal date picker trigger exactly */
.entry-date {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-secondary);
  line-height: 1.5;
}

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

.entry-weight {
  font-size: 0.96rem;
  font-weight: 600;
  color: var(--text-primary);
}

.entry-edit-icon {
  color: #fbbf24;
  display: flex;
  align-items: center;
  opacity: 0.85;
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.entry-item:hover .entry-edit-icon {
  transform: scale(1.15);
  opacity: 1;
}

/* Floating Action Button (FAB) */
.fab-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
}

.fab-btn {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-full);
  background-color: #0ea5e9;
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(14, 165, 233, 0.45);
  transition: transform var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast);
}

.fab-btn:hover {
  background-color: #0284c7;
  transform: scale(1.08);
  box-shadow: 0 10px 28px rgba(14, 165, 233, 0.55);
}

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

.fab-btn svg {
  width: 28px;
  height: 28px;
  stroke-width: 2.5;
}

/* ==========================================================================
   Modals & Mobile Sheet Layout (Log Weight & Settings)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.sheet-dialog {
  background-color: var(--bg-card);
  width: 100%;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-base);
}

/* Mobile: Full Screen Sheet */
@media (max-width: 639px) {
  .sheet-dialog {
    height: 100%;
    min-height: 100vh;
    border-radius: 0;
    transform: translateY(100%);
    padding: 24px 20px;
  }
  .modal-overlay.active .sheet-dialog {
    transform: translateY(0);
  }
}

/* Desktop: Centered Modal */
@media (min-width: 640px) {
  .sheet-dialog {
    max-width: 420px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    transform: scale(0.94) translateY(20px);
    padding: 28px 24px;
    max-height: 90vh;
    overflow-y: auto;
  }
  .modal-overlay.active .sheet-dialog {
    transform: scale(1) translateY(0);
  }
}

/* Modal Top Bar Header */
.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

.sheet-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-fast), transform var(--transition-fast);
}

.close-btn:hover {
  color: var(--text-primary);
  transform: scale(1.1);
}

.close-btn svg {
  width: 24px;
  height: 24px;
}

/* ==========================================================================
   Log Weight Page Elements
   ========================================================================== */
.log-weight-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 40px;
  padding-bottom: 20px;
  flex: 1;
}

/* Big Weight Input Display */
.weight-input-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  width: 100%;
  margin-bottom: 40px;
}

.weight-input-wrapper {
  display: flex;
  align-items: baseline;
  justify-content: center;
  position: relative;
  width: 100%;
}

.weight-number-input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 3.8rem;
  font-weight: 800;
  text-align: right;
  width: 190px;
  letter-spacing: -0.04em;
  caret-color: #0ea5e9;
  font-family: inherit;
}

.weight-number-input::placeholder {
  color: var(--border-color);
  opacity: 0.6;
}

/* Hide number spin buttons */
.weight-number-input::-webkit-outer-spin-button,
.weight-number-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.weight-number-input[type=number] {
  -moz-appearance: textfield;
}

.weight-unit-suffix {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-left: 6px;
}

.weight-input-underline {
  width: 80%;
  max-width: 280px;
  height: 3px;
  background-color: #27272a;
  border-radius: var(--radius-full);
  margin-top: 14px;
  transition: background-color var(--transition-fast);
}

.weight-input-container:focus-within .weight-input-underline {
  background-color: #0ea5e9;
}

/* Date Selector Row */
.date-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 4px;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 32px;
}

.date-label {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-primary);
}

.date-picker-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  line-height: 1.5;
}

.date-picker-trigger:hover {
  background-color: var(--bg-card-subtle);
  color: var(--text-primary);
}

.date-picker-trigger svg {
  width: 16px;
  height: 16px;
  color: #fbbf24;
}

/* Hidden Native Date Input */
.native-date-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

/* Submit Action Button */
.submit-btn {
  width: 100%;
  padding: 15px 20px;
  background-color: #0ea5e9;
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
  margin-top: auto;
}

.submit-btn:hover {
  background-color: #0284c7;
}

.submit-btn:active {
  transform: scale(0.98);
}

/* ==========================================================================
   Settings Page Elements
   ========================================================================== */
.settings-content {
  display: flex;
  flex-direction: column;
  padding-top: 8px;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 4px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  user-select: none;
  transition: background-color var(--transition-fast);
}

.settings-row:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

.settings-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.settings-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 6px;
}

.settings-row-action {
  cursor: pointer;
}

.settings-row-action:hover .settings-label {
  color: #38bdf8;
}

/* Hidden File Input for CSV Import */
.csv-file-input {
  display: none;
}

/* ==========================================================================
   Toast Notification (Matching Design)
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(30px);
  background-color: #1e1e24;
  color: #f4f4f5;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 22px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.92rem;
  font-weight: 600;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.7);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 200;
  white-space: nowrap;
}

.toast-container.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.toast-icon {
  width: 18px;
  height: 18px;
  color: #38bdf8;
  display: flex;
  align-items: center;
}
