/* assets/css/style.css */
:root {
  --c-cals:    #185FA5; --c-cals-bg: #E6F1FB;
  --c-fat:     #854F0B; --c-fat-bg:  #FAEEDA;
  --c-prot:    #3B6D11; --c-prot-bg: #EAF3DE;
  --c-carbs:   #534AB7; --c-carbs-bg:#EEEDFE;
  --c-fiber:   #0F6E56; --c-fiber-bg:#E1F5EE;
  --c-danger:  #A32D2D; --c-danger-bg:#FCEBEB;
  --c-warn:    #854F0B; --c-warn-bg: #FAEEDA;
  --c-ok:      #3B6D11; --c-ok-bg:   #EAF3DE;
  --border:    rgba(0,0,0,0.12);
  --radius:    8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --nav-h:     56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: #1a1a1a;
  background: #f5f4f0;
  padding-top: var(--nav-h);
  padding-bottom: 72px;
}

/* NAV */
.main-nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1100px; margin: 0 auto;
  height: 100%;
  display: flex; align-items: center; gap: 20px;
  padding: 0 16px;
}
.nav-brand { font-size: 16px; font-weight: 600; text-decoration: none; color: inherit; }
.nav-links { display: flex; gap: 4px; }
.nav-link {
  padding: 6px 12px; border-radius: var(--radius);
  text-decoration: none; color: #555; font-size: 13px;
}
.nav-link:hover { background: #f0efe8; }
.nav-link.active { background: #1a1a1a; color: #fff; }
.nav-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.nav-name { font-size: 13px; color: #555; }

/* CONTAINER */
.container { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }
.page-title { font-size: 20px; font-weight: 600; margin-bottom: 20px; }

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); cursor: pointer;
  font-size: 13px; font-weight: 500; text-decoration: none;
  background: #fff; color: #1a1a1a; transition: background 0.12s;
}
.btn:hover { background: #f0efe8; }
.btn-primary { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }
.btn-primary:hover { background: #333; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: #f0efe8; }
.btn-danger { background: var(--c-danger-bg); color: var(--c-danger); border-color: #f09595; }
.btn-danger:hover { background: #f7c1c1; }
.btn-ai { background: #EEEDFE; color: #534AB7; border-color: #AFA9EC; }
.btn-ai:hover { background: #CECBF6; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon { padding: 8px 12px; font-size: 16px; }
.btn-icon-sm {
  padding: 2px 6px; font-size: 13px; border: none;
  background: none; cursor: pointer; color: #888; border-radius: 4px;
}
.btn-icon-sm:hover { background: #f0efe8; color: #333; }
.btn-icon-sm.btn-danger:hover { background: var(--c-danger-bg); color: var(--c-danger); }
.btn-add-inline {
  font-size: 12px; color: #185FA5; background: none; border: none;
  cursor: pointer; padding: 2px 6px; border-radius: 4px;
}
.btn-add-inline:hover { background: #E6F1FB; }
.disabled { opacity: 0.4; pointer-events: none; }

/* FORMS */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: #555; margin-bottom: 4px; font-weight: 500; }
.form-group input[type=text],
.form-group input[type=password],
.form-group input[type=number],
.form-group input[type=date],
.form-group input[type=time],
.form-group textarea,
.form-group select {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; font-family: inherit;
  background: #fff; color: #1a1a1a;
  transition: border-color 0.12s;
}
.form-group input:focus, .form-group textarea:focus {
  outline: none; border-color: #185FA5;
  box-shadow: 0 0 0 3px rgba(24,95,165,0.1);
}
.form-group textarea { resize: vertical; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 40px; }
.pw-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 16px;
}

/* ALERTS */
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  margin-bottom: 16px; font-size: 14px;
}
.alert-error   { background: var(--c-danger-bg); color: var(--c-danger); border: 1px solid #f09595; }
.alert-success { background: var(--c-ok-bg); color: var(--c-ok); border: 1px solid #97C459; }

/* LOGIN */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding-top: 0; }
.login-wrap { width: 100%; max-width: 380px; padding: 20px; }
.login-card {
  background: #fff; border-radius: var(--radius-lg);
  border: 1px solid var(--border); padding: 36px 32px;
  box-shadow: var(--shadow-sm);
}
.login-logo { font-size: 48px; text-align: center; margin-bottom: 8px; }
.login-card h1 { text-align: center; font-size: 22px; margin-bottom: 4px; }
.login-sub { text-align: center; color: #666; font-size: 13px; margin-bottom: 24px; }

/* DATE NAV */
.date-nav {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.date-nav-center { flex: 1; text-align: center; }
.date-heading { font-size: 18px; font-weight: 600; }
.today-link { font-size: 12px; color: #185FA5; text-decoration: none; }
.today-link:hover { text-decoration: underline; }

/* NUTRITION SUMMARY */
.nutrition-summary {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px;
  margin-bottom: 16px;
}
.n-card {
  background: #f0efe8; border-radius: var(--radius-lg);
  padding: 12px 10px; text-align: center;
  border: 1px solid transparent;
}
.n-label { font-size: 11px; color: #666; margin-bottom: 2px; }
.n-value { font-size: 24px; font-weight: 600; line-height: 1.2; }
.n-unit  { font-size: 11px; color: #888; }
.n-small { font-size: 10px; color: #888; margin-top: 2px; }
.n-goal-reached { color: #3B6D11 !important; font-weight: 500; }
.btn-suggest { background: none; border: none; cursor: pointer; font-size: 13px; padding: 0 2px; vertical-align: middle; margin-left: 2px; }
.btn-suggest:hover { transform: scale(1.2); }
.n-warning { font-size: 10px; color: #854F0B; margin-top: 2px; }
.cal-bar-wrap { height: 6px; background: #d0e8f7; border-radius: 3px; margin: 6px 0 3px; overflow: hidden; }
.cal-bar { height: 6px; border-radius: 3px; background: #378ADD; transition: width 0.5s ease; }
.n-cals.ok   .cal-bar { background: #639922; }
.n-cals.warn .cal-bar { background: #378ADD; }
.n-cals.low  .cal-bar { background: #E24B4A; }

.prot-bar-wrap { height: 6px; background: #d8edcc; border-radius: 3px; margin: 6px 0 3px; overflow: hidden; }
.prot-bar { height: 6px; border-radius: 3px; background: #639922; transition: width 0.5s ease; }
.n-prot.ok   .prot-bar { background: #3B6D11; }
.n-prot.warn .prot-bar { background: #BA7517; }
.n-prot.low  .prot-bar { background: #EF9F27; }

.fat-bar-wrap { height: 6px; background: #e0dfd8; border-radius: 3px; margin: 6px 0 3px; overflow: hidden; }
.fat-bar { height: 6px; border-radius: 3px; background: #FAC775; transition: width 0.5s ease; }
.n-fat.danger  .fat-bar { background: #E24B4A; }
.n-fat.warning .fat-bar { background: #EF9F27; }
.n-cals  { background: var(--c-cals-bg);  border-color: #B5D4F4; }
.n-cals .n-value { color: var(--c-cals); }
.n-fat   { background: var(--c-fat-bg);   border-color: #FAC775; }
.n-fat .n-value  { color: var(--c-fat); }
.n-fat.danger    { background: #FCEBEB; border-color: #F09595; }
.n-fat.danger .n-value { color: var(--c-danger); }
.n-prot  { background: var(--c-prot-bg);  border-color: #C0DD97; }
.n-prot .n-value { color: var(--c-prot); }
.n-carbs { background: var(--c-carbs-bg); border-color: #CECBF6; }
.n-carbs .n-value{ color: var(--c-carbs); }
.n-fiber { background: var(--c-fiber-bg); border-color: #9FE1CB; }
.n-fiber .n-value{ color: var(--c-fiber); }

/* SYMPTOM BAR */
.symptom-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.sym-label { font-size: 13px; color: #555; }
.sym-btn {
  padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 500;
  border: 1px solid var(--border); background: #fff; cursor: pointer;
  transition: all 0.12s; color: #555;
}
.sym-btn:hover { background: #f0efe8; }
.sym-btn.active-ok  { background: var(--c-ok-bg); color: var(--c-ok); border-color: #97C459; }
.sym-btn.active-bad { background: var(--c-danger-bg); color: var(--c-danger); border-color: #F09595; }
.weight-badge { font-size: 12px; color: #555; background: #f0efe8; padding: 4px 10px; border-radius: 20px; }

/* DAY NOTE */
.day-note {
  background: #FAEEDA; border: 1px solid #FAC775; border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 14px; font-size: 13px; color: #633806;
}

/* MEALS TABLE */
.meals-table-wrap {
  background: #fff; border-radius: var(--radius-lg);
  border: 1px solid var(--border); overflow: hidden;
  margin-bottom: 14px;
}
.meals-table { width: 100%; border-collapse: collapse; }
.meals-table th {
  background: #f8f7f3; padding: 10px 12px;
  text-align: left; font-size: 12px; color: #666; font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.meals-table td {
  padding: 8px 12px; vertical-align: middle;
  border-bottom: 1px solid rgba(0,0,0,0.05); font-size: 13px;
}
.meals-table tr:last-child td { border-bottom: none; }
.meal-type-cell { font-weight: 600; color: #333; font-size: 12px; white-space: nowrap; }
.meal-desc { color: #1a1a1a; }
.meal-empty { color: #aaa; font-style: italic; }
.empty-text { margin-right: 12px; }
.meal-empty-row td { padding-top: 6px; padding-bottom: 6px; }
.meal-add-row td { padding: 3px 12px; }
.num-col { text-align: right; font-variant-numeric: tabular-nums; }
.fat-high { color: #854F0B; font-weight: 600; }
.action-col { text-align: right; white-space: nowrap; }
.totals-row td {
  background: #f8f7f3; padding: 10px 12px;
  border-top: 2px solid var(--border); font-size: 13px;
}
.totals-val { font-weight: 700; }
.totals-val.danger { color: var(--c-danger); }
.totals-val.warning { color: var(--c-fat); }

/* DAY EXTRAS */
.day-extras { margin-bottom: 20px; }
.day-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 0; }
.btn-clear-day { color: #A32D2D !important; border-color: #F09595 !important; }
.btn-clear-day:hover { background: #FCEBEB !important; }
.btn-danger-sm {
  color: #A32D2D !important;
}
.btn-danger-sm:hover { background: #FCEBEB; color: #A32D2D !important; }
.extras-form {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; margin-top: 10px;
}
.extras-grid {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px;
  align-items: start; margin-bottom: 12px;
}

/* MODAL */
.modal-overlay {
  display: flex; align-items: center; justify-content: center;
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.45);
}
.modal-card {
  background: #fff; border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  width: 100%; max-width: 560px; max-height: 90vh;
  display: flex; flex-direction: column;
  margin: 16px;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: #888; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}
.macros-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px;
  margin: 14px 0;
}
.macro-input label { font-size: 11px; color: #555; display: block; margin-bottom: 3px; }
.macro-input input { width: 100%; text-align: center; }
.macro-input .unit { font-size: 10px; color: #888; display: block; text-align: center; margin-top: 2px; }
.ai-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.ai-status { font-size: 12px; color: #666; }
.spinner {
  display: inline-block; width: 12px; height: 12px;
  border: 2px solid #AFA9EC; border-top-color: #534AB7;
  border-radius: 50%; animation: spin 0.8s linear infinite;
  vertical-align: middle; margin-right: 4px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.live-totals {
  background: #f8f7f3; border-radius: var(--radius);
  padding: 10px 14px; font-size: 13px; display: flex;
  gap: 16px; align-items: center; flex-wrap: wrap;
}
.live-item { color: #555; }
.live-item b { color: #1a1a1a; }

/* STATS FILTER */
.stats-filter-card {
  background: #fff;
  border: 1px solid rgba(0,0,0,0.10);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.filter-tabs { display: flex; gap: 4px; margin-bottom: 14px; background: #f0efe8; border-radius: 8px; padding: 3px; width: fit-content; }
.filter-tab {
  padding: 6px 18px; border-radius: 6px; font-size: 13px; font-weight: 500;
  text-decoration: none; color: #666; border: none; background: transparent;
  transition: all 0.12s;
}
.filter-tab:hover { color: #333; }
.filter-tab.active { background: #fff; color: #1a1a1a; box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
.month-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.month-btn {
  padding: 5px 14px; border-radius: 6px; font-size: 12px; font-weight: 500;
  text-decoration: none; color: #555;
  border: 1px solid rgba(0,0,0,0.10); background: #fafaf8;
  transition: all 0.12s;
}
.month-btn:hover { background: #f0efe8; color: #1a1a1a; }
.month-btn.active { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }
.range-form { margin: 0; }
.range-inputs { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.range-field { display: flex; flex-direction: column; gap: 4px; }
.range-field label { font-size: 11px; color: #888; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.range-field input { padding: 7px 10px; border: 1px solid rgba(0,0,0,0.15); border-radius: 8px; font-size: 14px; font-family: inherit; background: #fafaf8; }
.range-field input:focus { outline: none; border-color: #185FA5; background: #fff; }
.tbl-note { cursor: help; font-size: 12px; }
.stats-table tfoot .totals-row td { background: #f8f7f3; padding: 8px 10px; border-top: 2px solid rgba(0,0,0,0.1); font-size: 13px; }

/* STATS PAGE */
.stats-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin-bottom: 20px;
}
.stat-card {
  background: #fff; border-radius: var(--radius-lg);
  border: 1px solid var(--border); padding: 16px;
}
.stat-label { font-size: 12px; color: #666; margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 700; }
.card-warning { background: var(--c-warn-bg); border-color: #FAC775; }
.card-danger  { background: var(--c-danger-bg); border-color: #F09595; }
.text-danger  { color: var(--c-danger); }
.insight-box {
  background: #FAEEDA; border: 1px solid #FAC775; border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 16px; font-size: 14px; color: #633806;
  line-height: 1.6;
}
.chart-card {
  background: #fff; border-radius: var(--radius-lg);
  border: 1px solid var(--border); padding: 18px;
  margin-bottom: 14px;
}
.chart-card h3 { font-size: 13px; font-weight: 600; color: #555; margin-bottom: 12px; }
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.chart-legend { font-size: 11px; color: #666; margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.leg-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.leg-line { display: inline-block; width: 20px; height: 0; border-top: 2px dashed currentColor; vertical-align: middle; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table th {
  padding: 8px 10px; font-size: 11px; font-weight: 600;
  color: #888; border-bottom: 2px solid var(--border);
  text-transform: uppercase; letter-spacing: 0.04em;
  text-align: left;
}
.stats-table th.num-col { text-align: right; }
.stats-table td { padding: 8px 10px; border-bottom: 1px solid rgba(0,0,0,0.05); vertical-align: middle; }
.stats-table tbody tr:hover { background: rgba(0,0,0,0.02); }
.stats-table a { color: var(--color-text-primary, #1a1a1a); text-decoration: none; font-weight: 500; }
.stats-table a:hover { text-decoration: underline; }
.row-bad { background: rgba(252,235,235,0.5); }
.row-ok  { background: rgba(234,243,222,0.4); }
.fat-danger { color: var(--c-danger); font-weight: 700; }
.fat-warn   { color: var(--c-fat); }
.sym-ok  { background: var(--c-ok-bg); color: var(--c-ok); padding: 2px 8px; border-radius: 12px; font-size: 11px; }
.sym-bad { background: var(--c-danger-bg); color: var(--c-danger); padding: 2px 8px; border-radius: 12px; font-size: 11px; }
.sym-dia { background: #FAEEDA; color: #854F0B; padding: 2px 8px; border-radius: 12px; font-size: 11px; }
.table-scroll { overflow-x: auto; }

/* ADMIN */
.admin-card {
  background: #fff; border-radius: var(--radius-lg);
  border: 1px solid var(--border); padding: 20px;
  margin-bottom: 16px;
}
.admin-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.admin-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.form-check label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th { padding: 8px 12px; text-align: left; font-size: 12px; color: #666; border-bottom: 2px solid var(--border); background: #f8f7f3; }
.admin-table td { padding: 10px 12px; border-bottom: 1px solid rgba(0,0,0,0.05); vertical-align: middle; }
.action-td { white-space: nowrap; }
.badge { padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.badge-admin { background: #EEEDFE; color: #534AB7; }
.badge-user  { background: #f0efe8; color: #666; }

/* RESPONSIVE */
@media (max-width: 700px) {
  .nutrition-summary { grid-template-columns: repeat(3, 1fr); }
  .macros-grid { grid-template-columns: repeat(3, 1fr); }
  .chart-row { grid-template-columns: 1fr; }
  .admin-form-grid { grid-template-columns: 1fr; }
  .extras-grid { grid-template-columns: 1fr; }
  .meals-table th:nth-child(n+5), .meals-table td:nth-child(n+5) { display: none; }
}
