/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.7);
  --bg-card-hover: rgba(22, 31, 48, 0.85);
  --border-glass: rgba(255, 255, 255, 0.06);
  --border-glow: rgba(99, 102, 241, 0.3);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent: #818cf8;
  --accent-bright: #a78bfa;
  --accent-glow: rgba(129, 140, 248, 0.25);
  --success: #34d399;
  --success-glow: rgba(52, 211, 153, 0.2);
  --warning: #fbbf24;
  --warning-glow: rgba(251, 191, 36, 0.2);
  --danger: #f87171;
  --danger-glow: rgba(248, 113, 113, 0.2);
  --info: #38bdf8;

  --font: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 64px rgba(0, 0, 0, 0.5);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(
      ellipse 60% 40% at 10% 20%,
      rgba(99, 102, 241, 0.08) 0%,
      transparent 70%
    ),
    radial-gradient(
      ellipse 50% 50% at 90% 80%,
      rgba(168, 85, 247, 0.06) 0%,
      transparent 70%
    ),
    radial-gradient(
      ellipse 40% 30% at 50% 50%,
      rgba(52, 211, 153, 0.04) 0%,
      transparent 70%
    );
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

/* ===== HEADER ===== */
.header {
  padding: 24px 0 16px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border-glass);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.logo {
  font-size: 1.6rem;
  font-weight: 800;
  background: linear-gradient(
    135deg,
    var(--accent),
    var(--accent-bright),
    var(--success)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 400;
  margin-left: 12px;
}

.today-date {
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--bg-card);
  padding: 6px 14px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-glass);
}

/* ===== CARDS ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius);
  padding: 24px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.card:hover {
  border-color: var(--border-glow);
  box-shadow:
    var(--shadow),
    0 0 30px var(--accent-glow);
}

/* ===== DASHBOARD STATS ===== */
.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
}

.stat-icon {
  font-size: 2rem;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: rgba(129, 140, 248, 0.1);
  flex-shrink: 0;
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.2;
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.stat-unit {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  display: inline-block;
  margin-top: 2px;
  width: fit-content;
}

.bmi-underweight {
  background: var(--info);
  color: #0a0e17;
}
.bmi-normal {
  background: var(--success);
  color: #0a0e17;
}
.bmi-overweight {
  background: var(--warning);
  color: #0a0e17;
}
.bmi-obese {
  background: var(--danger);
  color: #fff;
}

/* ===== SECTION TITLES ===== */
.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text-primary);
}

.sub-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 16px 0 10px;
}

/* ===== CHART ===== */
.chart-section {
  margin-bottom: 24px;
}

.chart-container {
  position: relative;
  height: 350px;
  width: 100%;
}

/* ===== TWO COLUMN LAYOUT ===== */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

@media (max-width: 768px) {
  .two-col {
    grid-template-columns: 1fr;
  }
}

/* ===== FORMS ===== */
.form-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.form-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-group input,
.form-group select {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xs);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9rem;
  transition: var(--transition);
  outline: none;
}

.form-group select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  cursor: pointer;
}

.form-group select option {
  background: #1e293b;
  color: var(--text-primary);
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 0.9rem;
}

.form-group select option:hover,
.form-group select option:checked {
  background: var(--accent);
  color: white;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder {
  color: var(--text-muted);
}

/* Date and color-scheme fix for dark inputs */
input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7);
}

/* ===== BUTTONS ===== */
.btn {
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 11px 24px;
  border: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-bright));
  color: white;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.2);
  padding: 5px 10px;
  font-size: 0.75rem;
}

.btn-danger:hover {
  background: var(--danger-glow);
}

/* ===== GOAL RESULT ===== */
.goal-result {
  margin-top: 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.goal-result.hidden {
  display: none;
}

.goal-detail {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xs);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
}

.goal-detail.highlight {
  grid-column: span 2;
  background: linear-gradient(
    135deg,
    rgba(129, 140, 248, 0.1),
    rgba(167, 139, 250, 0.08)
  );
  border-color: var(--border-glow);
}

.goal-detail-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.goal-detail-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 2px;
}

.goal-warning {
  grid-column: span 2;
  padding: 12px 16px;
  border-radius: var(--radius-xs);
  font-size: 0.82rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.goal-warning.hidden {
  display: none;
}

.goal-warning.warn {
  background: var(--warning-glow);
  color: var(--warning);
  border: 1px solid rgba(251, 191, 36, 0.3);
}

.goal-warning.danger {
  background: var(--danger-glow);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.3);
}

/* ===== WEIGHT TABLE ===== */
.weight-history-scroll {
  max-height: 340px;
  overflow-y: auto;
}

.weight-history-scroll::-webkit-scrollbar {
  width: 5px;
}

.weight-history-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.weight-history-scroll::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 10px;
}

.weight-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.weight-table th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-glass);
  position: sticky;
  top: 0;
  background: var(--bg-card);
}

.weight-table td {
  padding: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
}

.weight-table tr {
  transition: var(--transition);
}

.weight-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.weight-change-down {
  color: var(--success);
  font-weight: 600;
}

.weight-change-up {
  color: var(--danger);
  font-weight: 600;
}

/* ===== FOOD LOG ===== */
.food-form {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 12px;
  align-items: end;
}

@media (max-width: 768px) {
  .food-form {
    grid-template-columns: 1fr;
  }
}

.file-input {
  display: none;
}

.file-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed var(--border-glass);
  border-radius: var(--radius-xs);
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: var(--transition);
  white-space: nowrap;
}

.file-label:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== CALORIE SUMMARY BAR ===== */
.calorie-summary {
  margin: 20px 0;
}

.calorie-bar-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.calorie-bar-bg {
  width: 100%;
  height: 20px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  overflow: hidden;
}

.calorie-bar-fill {
  height: 100%;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--success), var(--accent));
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 0;
  position: relative;
}

.calorie-bar-fill.over {
  background: linear-gradient(90deg, var(--warning), var(--danger));
}

.calorie-bar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ===== FOOD ENTRIES ===== */
.food-entries {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.food-entry {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  transition: var(--transition);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.food-entry:hover {
  border-color: rgba(255, 255, 255, 0.1);
}

.food-entry-photo {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-glass);
  flex-shrink: 0;
}

.food-entry-photo.no-photo {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  font-size: 1.4rem;
}

.food-entry-info {
  flex: 1;
}

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

.food-entry-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.food-entry-calories {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.food-entry-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px;
  transition: var(--transition);
  opacity: 0;
}

.food-entry:hover .food-entry-delete {
  opacity: 1;
}

.food-entry-delete:hover {
  color: var(--danger);
}

/* ===== EMPTY STATES ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 10px;
  opacity: 0.5;
}

/* ===== FOOTER ===== */
.footer {
  text-align: center;
  padding: 24px 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  border-top: 1px solid var(--border-glass);
  margin-top: 16px;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 24px;
  border-radius: var(--radius-xs);
  font-size: 0.85rem;
  font-weight: 500;
  color: white;
  z-index: 9999;
  animation:
    toastIn 0.35s ease,
    toastOut 0.35s ease 2.5s forwards;
  box-shadow: var(--shadow-lg);
}

.toast.success {
  background: linear-gradient(135deg, #059669, #34d399);
}
.toast.error {
  background: linear-gradient(135deg, #dc2626, #f87171);
}
.toast.info {
  background: linear-gradient(135deg, #2563eb, #38bdf8);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translateY(20px);
  }
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.3s ease;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-glow);
  border-radius: var(--radius);
  padding: 36px;
  max-width: 460px;
  width: 90%;
  box-shadow: var(--shadow-lg), 0 0 40px var(--accent-glow);
}

.modal-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.modal-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 14px;
  text-align: center;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  gap: 16px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.loading-overlay.hidden {
  display: none;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-glass);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===== SETTINGS BUTTON ===== */
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xs);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1rem;
  transition: var(--transition);
  color: var(--text-secondary);
}

.btn-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
  }

  .subtitle {
    margin-left: 0;
    display: block;
  }

  .stat-card {
    padding: 16px;
  }

  .stat-value {
    font-size: 1.4rem;
  }

  .chart-container {
    height: 260px;
  }

  .goal-result {
    grid-template-columns: 1fr;
  }

  .goal-detail.highlight {
    grid-column: span 1;
  }

  .goal-warning {
    grid-column: span 1;
  }
}
