@import url('https://cdn.jsdelivr.net/npm/@fontsource/iosevka/index.css');

:root {
  --bg: #0d0b14;
  --surface: #161222;
  --border: #2a2240;
  --primary: #9333ea;
  --primary-hover: #7c3aed;
  --text: #e9e3f5;
  --text-muted: #8b7fa8;
  --today-bg: #1c1608;
  --today-border: #3d2e00;
  --today-accent: #fbbf24;
  --success-bg: #0a1f10;
  --success-text: #4ade80;
  --error-bg: #1f0a0a;
  --error-text: #f87171;
  --radius: 2px;
  --shadow: none;
}

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

body {
  font-family: 'Iosevka', monospace;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 2px solid var(--primary);
  padding: 0.875rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}

header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
}

header .header-right {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ── Main layout ── */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

/* ── Section labels ── */
.section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* ── Today cards ── */
.meal-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
}

.meal-card {
  background: var(--today-bg);
  border: 1px solid var(--today-border);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
}

.meal-card .meal-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--today-accent);
  margin-bottom: 0.25rem;
}

.meal-card .meal-text {
  font-size: 0.95rem;
  color: var(--text);
  white-space: pre-line;
}

/* ── Week navigation ── */
.week-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.week-nav .week-label {
  flex: 1;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

/* ── Table ── */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.meal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.meal-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.meal-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.meal-table tr:last-child td {
  border-bottom: none;
}

.meal-table tr.today-row td {
  background: var(--today-bg);
}

.day-cell {
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-muted);
  min-width: 100px;
}

.day-cell.is-today {
  color: var(--today-accent);
  font-weight: 700;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.375rem 0.75rem;
  border-radius: 2px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  font-family: inherit;
  line-height: 1;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover {
  background: var(--bg);
  color: var(--text);
}

.btn-full { width: 100%; }

/* ── Page nav links (Today / Week) ── */
.page-nav {
  display: flex;
  gap: 0.25rem;
}

.page-nav a {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.25rem 0.6rem;
  border-radius: 2px;
  transition: background 0.12s, color 0.12s;
}

.page-nav a:hover {
  background: var(--bg);
  color: var(--text);
}

.page-nav a.active {
  color: var(--primary);
  background: var(--today-bg);
}

/* ── Admin table inputs / textareas ── */
.admin-table td { padding: 0.3rem 0.5rem; vertical-align: top; }

.meal-textarea {
  width: 100%;
  min-width: 140px;
  padding: 0.35rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 2px;
  font-size: 0.875rem;
  color: var(--text);
  background: transparent;
  outline: none;
  resize: none;
  overflow: hidden;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
  font-family: inherit;
  line-height: 1.45;
  min-height: 2.2rem;
  display: block;
}

.meal-textarea:hover {
  border-color: var(--border);
  background: var(--bg);
}

.meal-textarea:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

.meal-textarea::placeholder { color: #3d3460; }

/* ── Week table: multiline cell content ── */
.meal-lines { white-space: pre-line; }

/* ── Login overlay ── */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.login-card {
  width: 100%;
  max-width: 360px;
}

.login-card h1 {
  font-size: 1.5rem;
  color: var(--primary);
  margin-bottom: 0.25rem;
}

.login-card .subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 1rem;
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 500;
}

.form-group input[type="password"] {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 0.875rem;
  outline: none;
  font-family: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.form-group input[type="password"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

/* ── Status / error messages ── */
.save-status {
  padding: 0.45rem 0.75rem;
  border-radius: 2px;
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 0.75rem;
}

.save-status.success {
  background: var(--success-bg);
  color: var(--success-text);
}

.save-status.error {
  background: var(--error-bg);
  color: var(--error-text);
}

.inline-error {
  color: var(--error-text);
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
}

.empty-state {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.9rem;
}

/* ── Admin badge ── */
.badge {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  background: #eab308;
  color: #1c1730;
  padding: 0.15em 0.5em;
  border-radius: 2px;
  vertical-align: middle;
  margin-left: 0.4rem;
}

/* ── Toast notification ── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--today-accent);
  padding: 0.6rem 0.875rem;
  font-size: 0.85rem;
  color: var(--text);
  z-index: 50;
  max-width: 280px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
  font-family: inherit;
  flex-shrink: 0;
}
.toast-close:hover { color: var(--text); }

/* ── Free meals separator row ── */
.protein-table tr.free-meals-row td {
  border-top: 2px solid var(--border);
}

/* ── Protein source select (admin) ── */
.protein-select {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.2rem 0.4rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  font-family: 'Iosevka', monospace;
  font-size: 0.8rem;
  cursor: pointer;
  color-scheme: dark;
}
.protein-select:focus {
  outline: none;
  border-color: var(--primary);
}


/* ── Current meal highlight ── */
.meal-card--current {
  border-color: var(--today-accent);
}

.meal-table tr td.meal-cell--current {
  background: rgba(251, 191, 36, 0.08);
}

/* ── Protein table ── */
.protein-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.protein-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.protein-table th.protein-count-col { text-align: center; }

.protein-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.protein-table tr:last-child td { border-bottom: none; }

.protein-count {
  text-align: center;
  font-weight: 600;
  width: 4rem;
}

.protein-controls {
  text-align: right;
  white-space: nowrap;
}

.btn-sm {
  padding: 0.15rem 0.5rem;
  font-size: 0.85rem;
}

.protein-ok    { color: #4ade80; }
.protein-under { color: #fbbf24; }
.protein-over  { color: #f87171; }

/* ── Utilities ── */
.hidden { display: none !important; }

/* ── Responsive ── */
@media (max-width: 640px) {
  header { padding: 0.75rem 1rem; }
  main { padding: 1rem 0.5rem; }
  .card { padding: 1rem; }

  /* Flip table: each row becomes a card, columns become label+value rows */
  .meal-table,
  .meal-table tbody,
  .meal-table tr,
  .meal-table td {
    display: block;
  }

  .meal-table thead { display: none; }

  .meal-table tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    overflow: hidden;
  }

  .meal-table tr.today-row {
    border-color: var(--today-border);
  }

  .meal-table td {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
  }

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

  /* Inject the column label via data-label */
  .meal-table td::before {
    content: attr(data-label);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    min-width: 100px;
    flex-shrink: 0;
  }

  /* Day cell: styled as row header, no label prefix */
  .day-cell {
    background: var(--bg);
    font-size: 0.9rem;
    font-weight: 700;
    min-width: unset;
  }

  .day-cell.is-today { background: var(--today-bg); }
  .day-cell::before { display: none; }

  /* Admin: stack label above textarea in each cell */
  .admin-table td {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }

  .admin-table td::before { min-width: unset; }

  .meal-textarea { min-width: unset; }
}
