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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f4f6f9;
  color: #2d3748;
  font-size: 15px;
  line-height: 1.6;
}

/* ── Nav ── */
nav {
  background: #1a202c;
  color: #fff;
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.03em; }
.nav-links { list-style: none; display: flex; gap: 0.25rem; }
.nav-links a {
  color: #a0aec0;
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
  transition: background 0.15s, color 0.15s;
}
.nav-links a:hover { background: #2d3748; color: #fff; }

/* ── Container ── */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ── Flash Messages ── */
.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  font-weight: 500;
}
.flash-success { background: #c6f6d5; color: #22543d; border-left: 4px solid #38a169; }
.flash-error   { background: #fed7d7; color: #742a2a; border-left: 4px solid #e53e3e; }

/* ── Headings ── */
h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 1.5rem; color: #1a202c; }
h2 { font-size: 1.2rem; font-weight: 600; margin: 1.75rem 0 0.75rem; color: #2d3748; }
h3 { font-size: 1rem; font-weight: 600; margin: 1.25rem 0 0.6rem; color: #4a5568; }

.date-label {
  font-size: 0.95rem;
  color: #718096;
  font-weight: 400;
  margin-left: 0.5rem;
}

/* ── Cards ── */
.card-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.card {
  flex: 1;
  min-width: 160px;
  padding: 1.25rem 1.5rem;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.card-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.75; margin-bottom: 0.3rem; }
.card-value { font-size: 2rem; font-weight: 700; }
.card-value span { font-size: 0.85rem; font-weight: 400; }

.card-green  { background: #f0fff4; color: #276749; }
.card-orange { background: #fffaf0; color: #9c4221; }
.card-blue   { background: #ebf8ff; color: #2c5282; }
.card-red    { background: #fff5f5; color: #9b2c2c; }
.card-purple { background: #faf5ff; color: #553c9a; }

/* ── Interpretation ── */
.interpretation {
  background: #edf2f7;
  border-left: 4px solid #667eea;
  padding: 0.6rem 1rem;
  border-radius: 0 8px 8px 0;
  color: #4a5568;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

/* ── Quick Actions ── */
.quick-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}

/* ── Buttons ── */
.btn {
  display: inline-block;
  padding: 0.5rem 1.2rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  text-decoration: none;
  transition: all 0.15s;
}
.btn-primary   { background: #4c51bf; color: #fff; }
.btn-primary:hover { background: #434190; }
.btn-secondary { background: #38a169; color: #fff; }
.btn-secondary:hover { background: #2f855a; }
.btn-outline   { background: transparent; color: #4c51bf; border-color: #4c51bf; }
.btn-outline:hover { background: #ebf4ff; }

/* ── Tables ── */
table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  margin-bottom: 1.5rem;
}
thead tr { background: #edf2f7; }
th, td { padding: 0.65rem 1rem; text-align: left; font-size: 0.875rem; }
th { font-weight: 600; color: #4a5568; text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.06em; }
tbody tr:hover { background: #f7fafc; }
tbody tr:not(:last-child) td { border-bottom: 1px solid #edf2f7; }
.totals-row td { background: #f0fff4; font-weight: 600; }

.capitalize { text-transform: capitalize; }

/* ── Forms ── */
.form-card {
  background: #fff;
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.07);
  max-width: 560px;
  margin-bottom: 2rem;
}
.form-group { margin-bottom: 1.25rem; }
.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: #4a5568;
  margin-bottom: 0.4rem;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.55rem 0.85rem;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #2d3748;
  transition: border-color 0.15s;
  background: #fafafa;
  font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #667eea;
  background: #fff;
}
.optional { color: #a0aec0; font-weight: 400; font-size: 0.8rem; }
.hint { font-size: 0.8rem; color: #718096; margin-bottom: 1rem; }

/* ── Date picker form ── */
.date-picker-form {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.date-picker-form label { font-weight: 600; color: #4a5568; }
.date-picker-form input[type="date"] {
  padding: 0.45rem 0.75rem;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
}

/* ── Empty state ── */
.empty { color: #a0aec0; font-style: italic; margin: 0.5rem 0 1.5rem; font-size: 0.9rem; }

/* ── Bar Chart ── */
.bar-chart { margin-top: 0.75rem; }
.bar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.bar-date { font-size: 0.78rem; color: #718096; width: 80px; flex-shrink: 0; }
.bar {
  background: linear-gradient(90deg, #667eea, #764ba2);
  color: #fff;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  min-width: 80px;
  transition: width 0.3s;
}

/* ── Summary Box ── */
.summary-box { margin-top: 2rem; }

/* ── Footer ── */
footer {
  text-align: center;
  padding: 2rem;
  color: #a0aec0;
  font-size: 0.8rem;
}

/* ── Action Buttons (Edit / Delete in tables) ── */
.actions-cell {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  white-space: nowrap;
}
.actions-cell form { margin: 0; }
.btn-action {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  line-height: 1.4;
  transition: opacity 0.15s;
}
.btn-action:hover { opacity: 0.82; }
.btn-edit   { background: #ebf8ff; color: #2b6cb0; border: 1px solid #bee3f8; }
.btn-delete { background: #fff5f5; color: #c53030; border: 1px solid #fed7d7; }

/* ── Preserve newlines in food descriptions ── */
.prewrap { white-space: pre-wrap; word-break: break-word; }

/* ── Row currently being edited ── */
.row-editing { background: #fefcbf !important; }

/* ── Nutrition preview in edit form ── */
.nutrition-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  background: #f7fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.82rem;
  color: #4a5568;
  margin-bottom: 1.25rem;
}
.nutrition-preview span:first-child { font-weight: 600; width: 100%; }

/* ── field-value in edit form ── */
.field-value { margin: 0.25rem 0 0; font-size: 0.9rem; color: #2d3748; }
.field-value .hint { font-size: 0.78rem; color: #a0aec0; margin-left: 0.4rem; }

/* ── Login Page ── */
body.login-page {
  background: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-wrapper {
  width: 100%;
  max-width: 400px;
  padding: 1rem;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 2.5rem 2rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  text-align: center;
}
.login-logo {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}
.login-title {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}
.login-subtitle {
  color: #718096;
  font-size: 0.9rem;
  margin-bottom: 1.75rem;
}
.login-card .form-group { text-align: left; }
.btn-full { width: 100%; text-align: center; padding: 0.65rem; font-size: 1rem; margin-top: 0.25rem; }

/* ── Nav extras ── */
.nav-sep { width: 1px; background: #4a5568; margin: 0 0.25rem; align-self: stretch; }
.nav-user { color: #e2e8f0; font-size: 0.85rem; padding: 0 0.5rem; display: flex; align-items: center; }
.nav-logout {
  color: #fc8181 !important;
  border: 1px solid #fc8181;
  padding: 0.3rem 0.7rem !important;
  border-radius: 6px;
}
.nav-logout:hover { background: #fc8181 !important; color: #1a202c !important; }

/* ── Responsive ── */
@media (max-width: 600px) {
  nav { flex-direction: column; height: auto; padding: 0.75rem 1rem; gap: 0.5rem; }
  .nav-links { flex-wrap: wrap; justify-content: center; }
  .card-row { flex-direction: column; }
  h1 { font-size: 1.4rem; }
}

/* ── Responsive Tables (stacked card on mobile) ── */
@media (max-width: 680px) {
  /* Wrap overflow for any non-stacked table */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Stacked layout for tables marked responsive */
  table.table-stack thead { display: none; }

  table.table-stack,
  table.table-stack tbody,
  table.table-stack tr,
  table.table-stack td {
    display: block;
    width: 100%;
  }

  table.table-stack tbody tr {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    margin-bottom: 0.75rem;
    padding: 0.25rem 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    overflow: hidden;
  }

  table.table-stack tbody tr:hover { background: #fff; }

  table.table-stack tbody td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.5rem 0.85rem;
    border-bottom: 1px solid #f0f4f8;
    font-size: 0.875rem;
    text-align: right;
  }

  table.table-stack tbody td:last-child { border-bottom: none; }

  table.table-stack tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #718096;
    flex-shrink: 0;
    text-align: left;
    padding-top: 0.1rem;
  }

  /* Food column: left-align long text */
  table.table-stack tbody td.prewrap {
    text-align: left;
    flex-direction: column;
    gap: 0.25rem;
  }

  /* Actions: right-align buttons */
  table.table-stack tbody .actions-cell {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  /* Totals row stays readable */
  table.table-stack tbody tr.totals-row td {
    justify-content: space-between;
  }
}
