/* ============================================================
   Medical Diet Selection System — Creative UI
   ============================================================ */

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0f1117;
  --bg2:          #161b27;
  --surface:      #1e2535;
  --surface2:     #252d3d;
  --border:       #2e3a50;
  --border-light: #3a4a63;

  --accent:       #4f8ef7;
  --accent-h:     #3a7af0;
  --accent-glow:  rgba(79,142,247,.25);

  --green:        #22c55e;
  --green-bg:     rgba(34,197,94,.12);
  --red:          #ef4444;
  --red-bg:       rgba(239,68,68,.12);
  --amber:        #f59e0b;
  --amber-bg:     rgba(245,158,11,.12);
  --cyan:         #06b6d4;
  --cyan-bg:      rgba(6,182,212,.12);
  --purple:       #a855f7;
  --purple-bg:    rgba(168,85,247,.12);

  --text:         #e2e8f0;
  --text-muted:   #7a8ba6;
  --text-dim:     #4a5a72;

  --radius-sm:    6px;
  --radius:       10px;
  --radius-lg:    16px;
  --shadow:       0 4px 24px rgba(0,0,0,.4);
  --shadow-sm:    0 2px 8px rgba(0,0,0,.3);
  --transition:   .15s ease;
}

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ---------- Accessibility ---------- */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  background: linear-gradient(135deg, #0d1b3e 0%, #1a2a5e 50%, #0d1b3e 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 32px rgba(0,0,0,.5);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: .9rem;
}

.brand-icon {
  width: 46px;
  height: 46px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  box-shadow: 0 0 20px var(--accent-glow);
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  background: linear-gradient(90deg, #fff, #a5c8ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.brand-text p {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: .1rem;
}

/* Header stat chips */
.header-stats { display: flex; gap: .6rem; align-items: center; }

.stat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius);
  padding: .45rem .9rem;
  min-width: 70px;
  backdrop-filter: blur(8px);
}

.stat-chip.highlight {
  background: linear-gradient(135deg, rgba(79,142,247,.2), rgba(124,58,237,.2));
  border-color: rgba(79,142,247,.4);
  box-shadow: 0 0 16px rgba(79,142,247,.15);
}

.stat-num   { font-size: 1.25rem; font-weight: 800; color: #fff; line-height: 1; }
.stat-label { font-size: .68rem; color: var(--text-muted); margin-top: .15rem; text-transform: uppercase; letter-spacing: .05em; }

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
.app-main {
  max-width: 1440px;
  margin: 1.5rem auto;
  padding: 0 1.25rem 3rem;
}

/* ============================================================
   CONTROLS BAR
   ============================================================ */
.controls-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: .85rem 1.1rem;
  margin-bottom: 1.1rem;
  box-shadow: var(--shadow-sm);
}

/* Search */
.search-wrap {
  display: flex;
  align-items: center;
  flex: 1 1 220px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 .7rem;
  gap: .5rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-icon { font-size: .9rem; color: var(--text-muted); flex-shrink: 0; }

#search-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: .55rem 0;
  font-size: .9rem;
  color: var(--text);
  outline: none;
}
#search-input::placeholder { color: var(--text-dim); }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: .85rem;
  padding: .2rem .3rem;
  border-radius: 4px;
  transition: color var(--transition);
  flex-shrink: 0;
}
.btn-icon:hover { color: var(--text); }

/* Category filter */
.filter-wrap select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .55rem .85rem;
  font-size: .875rem;
  background: var(--bg2);
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
  appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237a8ba6' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .6rem center;
}
.filter-wrap select:focus { border-color: var(--accent); }

/* Action buttons */
.action-wrap { display: flex; gap: .5rem; flex-wrap: wrap; margin-left: auto; }

.btn {
  padding: .52rem 1rem;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(.96); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); color: var(--text); }

.btn-add {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid rgba(34,197,94,.3);
}
.btn-add:hover { background: rgba(34,197,94,.2); box-shadow: 0 0 12px rgba(34,197,94,.2); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  box-shadow: 0 4px 16px rgba(79,142,247,.3);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-h), #6d28d9);
  box-shadow: 0 4px 20px rgba(79,142,247,.45);
}

/* ============================================================
   TABLE WRAPPER
   ============================================================ */
.table-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: auto;
  max-height: calc(100vh - 290px);
}

/* ============================================================
   TABLE
   ============================================================ */
#food-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

#food-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

#food-table thead tr {
  background: var(--surface2);
  border-bottom: 2px solid var(--border);
}

#food-table th {
  padding: .8rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
}

.col-check { width: 44px; text-align: center; }
.col-item  { min-width: 160px; }
.col-cat   { min-width: 110px; }
.col-num   { width: 90px; text-align: right; }
.col-qty   { width: 160px; }

/* Body rows */
#food-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
#food-table tbody tr:last-child { border-bottom: none; }
#food-table tbody tr:hover { background: var(--surface2); }

#food-table tbody tr.selected {
  background: linear-gradient(90deg, rgba(79,142,247,.08), transparent);
  border-left: 3px solid var(--accent);
}
#food-table tbody tr.selected:hover {
  background: linear-gradient(90deg, rgba(79,142,247,.14), transparent);
}

#food-table td {
  padding: .7rem 1rem;
  vertical-align: middle;
}

/* Checkbox */
#food-table input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
}

/* Item name */
.item-name {
  font-weight: 500;
  color: var(--text);
}

/* Category badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .22rem .6rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.badge-veg     { background: var(--green-bg);  color: var(--green);  border: 1px solid rgba(34,197,94,.25); }
.badge-nonveg  { background: var(--red-bg);    color: var(--red);    border: 1px solid rgba(239,68,68,.25); }
.badge-bev     { background: var(--cyan-bg);   color: var(--cyan);   border: 1px solid rgba(6,182,212,.25); }
.badge-dessert { background: var(--amber-bg);  color: var(--amber);  border: 1px solid rgba(245,158,11,.25); }

/* Numeric cells */
.num-cell {
  text-align: right;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: .85rem;
}

/* ============================================================
   QUANTITY STEPPER
   ============================================================ */
.qty-wrap {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg2);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.qty-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.qty-wrap.qty-disabled { opacity: .35; pointer-events: none; }

.qty-btn {
  background: var(--surface2);
  border: none;
  width: 30px;
  height: 34px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
  line-height: 1;
  padding: 0;
}
.qty-btn:hover:not(:disabled) {
  background: var(--accent);
  color: #fff;
}
.qty-btn:disabled { cursor: not-allowed; }

.qty-wrap .qty-input {
  width: 70px;
  border: none;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  text-align: center;
  padding: .35rem .3rem;
  font-size: .85rem;
  color: var(--text);
  outline: none;
}
.qty-wrap .qty-input::placeholder { color: var(--text-dim); }
.qty-wrap .qty-input:disabled { opacity: 1; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
}
.empty-state span { font-size: 3rem; display: block; margin-bottom: .75rem; opacity: .6; }
.empty-state p { font-size: .95rem; }
.hidden { display: none !important; }

/* ============================================================
   SUMMARY BAR
   ============================================================ */
.summary-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: .85rem 1.1rem;
  margin-top: .85rem;
  box-shadow: var(--shadow-sm);
}

#summary-text {
  color: var(--text-muted);
  font-weight: 600;
  font-size: .875rem;
}

.summary-nutrients { display: flex; gap: .6rem; flex-wrap: wrap; }

.nutrient-pill {
  display: flex;
  align-items: center;
  gap: .35rem;
  border-radius: 999px;
  padding: .3rem .8rem;
  font-size: .8rem;
  font-weight: 700;
  border: 1px solid transparent;
}
.nutrient-pill.fats    { background: rgba(239,68,68,.12);   color: #f87171; border-color: rgba(239,68,68,.2); }
.nutrient-pill.carbs   { background: rgba(245,158,11,.12);  color: #fbbf24; border-color: rgba(245,158,11,.2); }
.nutrient-pill.protein { background: rgba(34,197,94,.12);   color: #4ade80; border-color: rgba(34,197,94,.2); }
.nutrient-pill.cal     { background: rgba(79,142,247,.12);  color: #93c5fd; border-color: rgba(79,142,247,.2); }
.nutrient-pill .pill-label { font-weight: 400; opacity: .75; }

/* ============================================================
   ADD FOOD MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
  backdrop-filter: blur(6px);
}
.modal-overlay.hidden { display: none !important; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 64px rgba(0,0,0,.6);
  width: 100%;
  max-width: 520px;
  overflow: hidden;
  animation: modal-in .2s cubic-bezier(.34,1.56,.64,1);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(-20px) scale(.95); }
  to   { opacity: 1; transform: translateY(0)     scale(1);   }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.5rem;
  background: linear-gradient(135deg, rgba(79,142,247,.1), rgba(124,58,237,.1));
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-close {
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: .9rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: .3rem .5rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.modal-close:hover { background: var(--red-bg); color: var(--red); border-color: rgba(239,68,68,.3); }

/* Form */
#add-food-form { padding: 1.3rem 1.5rem; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .9rem;
}

.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group.full-width { grid-column: 1 / -1; }

.form-group label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.required { color: var(--red); }

.form-group input,
.form-group select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .55rem .75rem;
  font-size: .9rem;
  background: var(--bg2);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.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-dim); }
.form-group input.invalid,
.form-group select.invalid { border-color: var(--red); box-shadow: 0 0 0 3px rgba(239,68,68,.15); }

.form-error {
  margin-top: .75rem;
  padding: .6rem .85rem;
  background: var(--red-bg);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: var(--radius);
  color: #f87171;
  font-size: .85rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .6rem;
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: .75rem 1.2rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 600;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  z-index: 300;
  animation: toast-in .25s cubic-bezier(.34,1.56,.64,1);
  border: 1px solid transparent;
}
.toast.success {
  background: var(--green-bg);
  color: var(--green);
  border-color: rgba(34,197,94,.3);
}
.toast.error {
  background: var(--red-bg);
  color: var(--red);
  border-color: rgba(239,68,68,.3);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(16px) scale(.9); }
  to   { opacity: 1; transform: translateY(0)    scale(1);  }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
.table-wrapper::-webkit-scrollbar { width: 6px; height: 6px; }
.table-wrapper::-webkit-scrollbar-track { background: var(--bg2); }
.table-wrapper::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 999px; }
.table-wrapper::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .brand-text p { display: none; }
  .controls-bar { gap: .5rem; }
  .action-wrap  { margin-left: 0; width: 100%; justify-content: flex-end; }
  .table-wrapper { max-height: calc(100vh - 340px); }
  #food-table th.col-num,
  #food-table td.num-cell { display: none; }
}

@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-group.full-width { grid-column: 1; }
  .stat-chip { min-width: 60px; padding: .35rem .6rem; }
  .stat-num  { font-size: 1.05rem; }
}

/* ============================================================
   PATIENT DETAILS PANEL
   ============================================================ */
.patient-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem 1.1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

/* subtle left accent bar */
.patient-panel::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--accent), var(--purple));
  border-radius: 4px 0 0 4px;
}

.patient-panel-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .85rem;
}

.patient-panel-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.patient-panel-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
}

.patient-fields {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .75rem;
}

.patient-field {
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.patient-field.wide {
  grid-column: span 2;
}

.patient-field label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.patient-field input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem .75rem;
  font-size: .875rem;
  background: var(--bg2);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.patient-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.patient-field input::placeholder { color: var(--text-dim); }

@media (max-width: 900px) {
  .patient-fields { grid-template-columns: 1fr 1fr; }
  .patient-field.wide { grid-column: span 2; }
}

@media (max-width: 480px) {
  .patient-fields { grid-template-columns: 1fr; }
  .patient-field.wide { grid-column: span 1; }
}

/* ============================================================
   PATIENT HISTORY SECTION
   ============================================================ */
.history-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-top: 1rem;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  padding: .9rem 1.25rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

.history-title-wrap {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.history-icon  { font-size: 1.1rem; }
.history-title {
  font-size: .85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text);
}

.history-count {
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(79,142,247,.3);
  border-radius: 999px;
  padding: .15rem .6rem;
  font-size: .72rem;
  font-weight: 700;
}

.history-actions {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
}

#history-search {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .45rem .75rem;
  font-size: .85rem;
  background: var(--bg2);
  color: var(--text);
  outline: none;
  width: 220px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
#history-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
#history-search::placeholder { color: var(--text-dim); }

/* History list grid */
.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: .85rem;
  padding: 1rem 1.25rem;
  max-height: 420px;
  overflow-y: auto;
}

.history-list::-webkit-scrollbar { width: 5px; }
.history-list::-webkit-scrollbar-track { background: var(--bg2); }
.history-list::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 999px; }

/* Empty state */
.history-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
}
.history-empty span { font-size: 2.5rem; display: block; margin-bottom: .5rem; opacity: .5; }
.history-empty p    { font-size: .9rem; }

/* History card */
.history-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  position: relative;
  overflow: hidden;
}
.history-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--accent), var(--purple));
  border-radius: 3px 0 0 3px;
}
.history-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
  transform: translateY(-2px);
}

.hcard-name {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: .3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hcard-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem .75rem;
  font-size: .75rem;
  color: var(--text-muted);
  margin-bottom: .6rem;
}

.hcard-meta span { display: flex; align-items: center; gap: .25rem; }

.hcard-pills {
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
  margin-bottom: .7rem;
}

.hcard-pill {
  font-size: .7rem;
  font-weight: 600;
  padding: .18rem .55rem;
  border-radius: 999px;
  border: 1px solid transparent;
}
.hcard-pill.fats    { background: var(--red-bg);    color: #f87171; border-color: rgba(239,68,68,.2); }
.hcard-pill.carbs   { background: var(--amber-bg);  color: #fbbf24; border-color: rgba(245,158,11,.2); }
.hcard-pill.protein { background: var(--green-bg);  color: #4ade80; border-color: rgba(34,197,94,.2); }
.hcard-pill.cal     { background: var(--cyan-bg);   color: var(--cyan); border-color: rgba(6,182,212,.2); }

.hcard-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hcard-items {
  font-size: .72rem;
  color: var(--text-dim);
}

.hcard-delete {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: .85rem;
  padding: .2rem .35rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.hcard-delete:hover { color: var(--red); background: var(--red-bg); }

/* Save history button */
.btn-save-hist {
  background: var(--purple-bg);
  color: var(--purple);
  border: 1px solid rgba(168,85,247,.3);
}
.btn-save-hist:hover { background: rgba(168,85,247,.2); box-shadow: 0 0 12px rgba(168,85,247,.2); }

/* ── History View Modal ──────────────────────────────────────── */
.modal-wide { max-width: 720px; }

.history-modal-body {
  padding: 1.25rem 1.5rem;
  max-height: 60vh;
  overflow-y: auto;
}
.history-modal-body::-webkit-scrollbar { width: 5px; }
.history-modal-body::-webkit-scrollbar-track { background: var(--bg2); }
.history-modal-body::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 999px; }

.hview-patient {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem .75rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  margin-bottom: 1rem;
  font-size: .875rem;
}
.hview-patient-row { display: flex; flex-direction: column; gap: .15rem; }
.hview-patient-row.full { grid-column: 1 / -1; }
.hview-label { font-size: .7rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.hview-value { color: var(--text); font-weight: 500; }

.hview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}
.hview-table th {
  background: var(--surface2);
  padding: .55rem .75rem;
  text-align: left;
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}
.hview-table td {
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.hview-table tr:last-child td { border-bottom: none; }
.hview-table tr:hover td { background: var(--surface2); }
.hview-table .td-num { text-align: right; color: var(--text-muted); }
.hview-totals td { font-weight: 700; color: var(--accent); background: rgba(79,142,247,.06) !important; }

/* ============================================================
   MEAL TABS
   ============================================================ */
.meal-tabs {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
  margin-bottom: .75rem;
}

.meal-tab {
  padding: .45rem 1rem;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  transition: all var(--transition);
  white-space: nowrap;
}
.meal-tab:hover { border-color: var(--accent); color: var(--text); }
.meal-tab.active {
  background: linear-gradient(135deg, var(--accent), var(--purple));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px rgba(79,142,247,.35);
}

/* ============================================================
   MEAL SECTION GROUP ROWS
   ============================================================ */
.meal-group-row {
  background: var(--surface2) !important;
  border-bottom: 1px solid var(--border) !important;
  border-left: none !important;
  cursor: pointer;
  user-select: none;
}
.meal-group-row:hover { background: var(--border) !important; }

.meal-group-cell {
  padding: .6rem 1rem !important;
  display: flex;
  align-items: center;
  gap: .6rem;
}

.meal-group-label {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text);
}

.meal-group-badge {
  font-size: .7rem;
  font-weight: 600;
  padding: .15rem .55rem;
  border-radius: 999px;
  margin-left: .25rem;
}
.meal-badge-breakfast { background: rgba(245,158,11,.15); color: var(--amber); border: 1px solid rgba(245,158,11,.25); }
.meal-badge-lunch     { background: rgba(34,197,94,.12);  color: var(--green); border: 1px solid rgba(34,197,94,.2); }
.meal-badge-snacks    { background: rgba(6,182,212,.12);  color: var(--cyan);  border: 1px solid rgba(6,182,212,.2); }
.meal-badge-dinner    { background: rgba(168,85,247,.12); color: var(--purple);border: 1px solid rgba(168,85,247,.2); }

.meal-group-chevron {
  margin-left: auto;
  font-size: .75rem;
  color: var(--text-muted);
  transition: transform var(--transition);
}
.meal-group-chevron.collapsed { transform: rotate(-90deg); }

.meal-group-select {
  font-size: .72rem;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: 1px solid rgba(79,142,247,.3);
  border-radius: 999px;
  padding: .15rem .55rem;
  cursor: pointer;
  transition: background var(--transition);
}
.meal-group-select:hover { background: var(--accent-glow); }

/* Diet Log link chip */
.diet-log-link {
  text-decoration: none;
  cursor: pointer;
  transition: box-shadow var(--transition);
}
.diet-log-link:hover {
  box-shadow: 0 0 0 2px rgba(255,255,255,.4);
}

/* ============================================================
   DAY PLANNER BAR
   ============================================================ */
.day-planner-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: .75rem 1.1rem;
  margin-top: .75rem;
  box-shadow: var(--shadow-sm);
}

.dp-left {
  display: flex;
  align-items: center;
  gap: .6rem;
}

.dp-icon  { font-size: 1.1rem; }
.dp-label {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  white-space: nowrap;
}

#plan-date {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .45rem .7rem;
  font-size: .875rem;
  background: var(--bg2);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}
#plan-date:focus { border-color: var(--accent); }

.dp-right {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
}

.dp-hint {
  font-size: .78rem;
  color: var(--text-dim);
  font-style: italic;
}

.btn-save-day {
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: #fff;
  box-shadow: 0 4px 14px rgba(79,142,247,.3);
}
.btn-save-day:hover {
  background: linear-gradient(135deg, var(--accent-h), #6d28d9);
  box-shadow: 0 4px 18px rgba(79,142,247,.45);
}

/* ============================================================
   DAY PLANS PANEL
   ============================================================ */
.day-plans-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-top: .75rem;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.dpp-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .8rem 1.1rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

.dpp-title {
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text);
}

.dpp-count {
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(79,142,247,.3);
  border-radius: 999px;
  padding: .15rem .6rem;
  font-size: .72rem;
  font-weight: 700;
}

.dpp-list {
  padding: .85rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  max-height: 420px;
  overflow-y: auto;
}

.dpp-list::-webkit-scrollbar { width: 5px; }
.dpp-list::-webkit-scrollbar-track { background: var(--bg2); }
.dpp-list::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 999px; }

.dpp-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}
.dpp-empty span { font-size: 2rem; display: block; margin-bottom: .4rem; opacity: .5; }
.dpp-empty p    { font-size: .875rem; }

/* Day card */
.day-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.day-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem .9rem;
  background: linear-gradient(90deg, rgba(79,142,247,.1), transparent);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}

.day-card-date {
  font-size: .9rem;
  font-weight: 700;
  color: var(--accent);
}

.day-card-meta {
  font-size: .75rem;
  color: var(--text-muted);
  display: flex;
  gap: .75rem;
  align-items: center;
}

.day-card-actions {
  display: flex;
  gap: .4rem;
  align-items: center;
}

.btn-day-load {
  font-size: .72rem;
  padding: .2rem .55rem;
  border-radius: 999px;
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(79,142,247,.3);
  cursor: pointer;
  transition: background var(--transition);
}
.btn-day-load:hover { background: rgba(79,142,247,.2); }

.btn-day-delete {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: .85rem;
  padding: .2rem .35rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.btn-day-delete:hover { color: var(--red); background: var(--red-bg); }

/* Meal groups inside day card */
.day-card-body {
  padding: .6rem .9rem;
}

.day-meal-group { margin-bottom: .5rem; }

.day-meal-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: .25rem;
}

.day-meal-items {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
}

.day-item-chip {
  font-size: .75rem;
  padding: .18rem .55rem;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
}

/* ── Date Save Bar ───────────────────────────────────────────── */
.date-save-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  background: linear-gradient(135deg, rgba(79,142,247,.08), rgba(168,85,247,.08));
  border: 1px solid rgba(79,142,247,.25);
  border-radius: var(--radius-lg);
  padding: .75rem 1.1rem;
  margin-bottom: .75rem;
}

.dsb-left {
  display: flex;
  align-items: center;
  gap: .6rem;
}
.dsb-icon  { font-size: 1.2rem; }
.dsb-label {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--accent);
  white-space: nowrap;
}
#plan-date {
  border: 1px solid rgba(79,142,247,.4);
  border-radius: var(--radius);
  padding: .45rem .75rem;
  font-size: .9rem;
  background: var(--bg2);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
#plan-date:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.dsb-right {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.dsb-saved-count {
  font-size: .8rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Update dpp-header to have actions */
.dpp-title-wrap {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.dpp-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
