:root {
  color-scheme: light;
  --canvas: #f4f4f4;
  --canvas-light: #ffffff;
  --canvas-dark: #000000;
  --surface-elevated: #16181a;
  --ink: #191c1f;
  --body: #1f2226;
  --mute: #505a63;
  --stone: #8d969e;
  --faint: #c9c9cd;
  --line: #e2e2e7;
  --line-dark: rgba(255, 255, 255, 0.12);
  --primary: #494fdf;
  --primary-deep: #3a40c4;
  --danger: #e23b4a;
  --danger-soft: #fff0f1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, Arial, Helvetica, sans-serif;
  letter-spacing: 0.01em;
}

body:has(dialog[open]) {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: var(--canvas-dark);
}

.login-card {
  display: grid;
  gap: 18px;
  width: min(440px, 100%);
  border-radius: 20px;
  background: var(--canvas-light);
  padding: 32px;
}

.login-card h1 {
  margin: 0;
  font-family: "Inter Display", Inter, Arial, Helvetica, sans-serif;
  font-size: 48px;
  line-height: 1;
  letter-spacing: -0.03em;
}

.login-kicker {
  margin: 0;
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.form-error {
  min-height: 20px;
  color: #8b0000;
  font-size: 14px;
  font-weight: 700;
}

.form-success {
  min-height: 20px;
  color: #0d6b3f;
  font-size: 14px;
  font-weight: 700;
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
}

.link-button {
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--primary);
  padding: 0;
  font-weight: 800;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
  white-space: normal;
}

.link-button:hover {
  color: var(--primary-deep);
}

.app-shell {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  min-height: 100vh;
  background: var(--canvas);
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--canvas-dark);
  color: #fff;
  padding: 32px 20px;
}

.sidebar h1 {
  margin: 0 0 24px;
  font-family: "Inter Display", Inter, Arial, Helvetica, sans-serif;
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
}

.user-panel {
  display: grid;
  gap: 5px;
  margin-top: auto;
  padding: 16px;
  border: 1px solid var(--line-dark);
  border-radius: 20px;
  background: var(--surface-elevated);
}

.user-panel span {
  color: #fff;
  font-weight: 800;
}

.user-panel small {
  color: rgba(255, 255, 255, 0.72);
  overflow-wrap: anywhere;
}

.user-panel .secondary-button {
  justify-self: start;
  min-height: 40px;
  margin-top: 8px;
  padding: 8px 16px;
  border-color: #fff;
}

.tabs {
  display: grid;
  gap: 10px;
}

.tab-button {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line-dark);
  border-radius: 999px;
  background: var(--surface-elevated);
  color: rgba(255, 255, 255, 0.72);
  padding: 12px 18px;
  text-align: left;
  font-weight: 700;
}

.tab-button.active {
  background: var(--canvas-light);
  border-color: var(--canvas-light);
  color: var(--canvas-dark);
}

.main-panel {
  min-width: 0;
  padding: 48px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 24px;
  margin: 0 0 24px;
}

h2,
h3,
h4,
p {
  margin-top: 0;
}

h2 {
  margin-bottom: 8px;
  font-family: "Inter Display", Inter, Arial, Helvetica, sans-serif;
  font-size: clamp(40px, 6vw, 72px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
}

h3 {
  margin-bottom: 0;
  font-family: "Inter Display", Inter, Arial, Helvetica, sans-serif;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

h4 {
  margin-bottom: 0;
  font-size: 18px;
  font-weight: 700;
}

p {
  margin-bottom: 0;
  color: var(--mute);
  font-size: 16px;
  line-height: 1.5;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button {
  min-height: 48px;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 12px 24px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.primary-button {
  background: var(--canvas-dark);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary);
}

.secondary-button {
  background: var(--canvas-light);
  border-color: var(--ink);
  color: var(--ink);
}

.secondary-button:hover {
  background: var(--canvas-dark);
  color: #fff;
}

.danger-button {
  background: var(--danger-soft);
  color: #8b0000;
}

.danger-button:hover {
  background: var(--danger);
  color: #fff;
}

.icon-button {
  width: 48px;
  padding: 0;
  background: var(--canvas-light);
  border-color: var(--line);
  color: var(--ink);
}

.table-wrap {
  overflow-x: auto;
  background: var(--canvas-light);
  border: 1px solid var(--line);
  border-radius: 20px;
}

table {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 18px 20px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--canvas-light);
  color: var(--stone);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

td {
  color: var(--body);
  font-size: 15px;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #fafafa;
}

.photo-placeholder {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  border-radius: 12px;
  background: var(--canvas-dark);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}

.photo-thumbnail {
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--canvas-dark);
}

.photo-placeholder.large {
  width: 112px;
  height: 112px;
  border-radius: 20px;
  font-size: 42px;
}

.photo-placeholder.small,
.photo-thumbnail.small {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  font-size: 18px;
}

.photo-thumbnail.large {
  width: 112px;
  height: 112px;
  border-radius: 20px;
}

.image-control {
  display: grid;
  grid-template-columns: minmax(180px, 260px) 150px;
  align-items: stretch;
  gap: 14px;
  width: min(430px, 100%);
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--canvas);
  padding: 12px;
}

.image-control:focus-visible {
  outline: 3px solid rgba(73, 79, 223, 0.24);
  outline-offset: 2px;
}

.image-control-preview {
  width: 100%;
  height: 260px;
  overflow: hidden;
  border-radius: 18px;
  background: var(--canvas-dark);
}

.image-control-preview .photo-placeholder.large,
.image-control-preview .photo-thumbnail.large {
  width: 100%;
  height: 100%;
  border-radius: 0;
}

.image-control-actions {
  display: grid;
  gap: 8px;
  align-content: end;
}

.image-control-actions .secondary-button,
.image-control-actions .danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1;
  text-align: center;
}

.file-input {
  display: none;
}

.details-heading {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.details-heading h3 {
  overflow-wrap: anywhere;
}

.details-heading .photo-placeholder.large,
.details-heading .photo-thumbnail.large {
  width: 144px;
  height: 144px;
  border-radius: 24px;
}

.ingredient-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.meal-ingredients-column {
  width: 180px;
  max-width: 180px;
}

.meal-ingredient-list {
  display: grid;
  gap: 6px;
  align-content: start;
}

.meal-ingredient-list .pill {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill {
  border-radius: 999px;
  background: var(--canvas);
  color: var(--ink);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 700;
}

.missing {
  background: #fff4df;
  color: #7a4d00;
}

.empty-state {
  display: none;
  margin: 18px 0 0;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--canvas-light);
}

.empty-state.visible {
  display: block;
}

.modal {
  width: min(720px, calc(100vw - 48px));
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 24px);
  overflow-x: hidden;
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: transparent;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.68);
}

.modal-card {
  display: grid;
  gap: 20px;
  min-width: 0;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--canvas-light);
  border-radius: 20px;
  padding: 32px;
}

.modal-card.wide {
  width: 100%;
  min-width: 0;
}

.modal-header,
.modal-actions,
.meal-builder-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.modal-header {
  min-width: 0;
}

.modal-header > :first-child {
  min-width: 0;
}

.modal-header .icon-button {
  flex: 0 0 auto;
  margin-left: auto;
}

.modal-actions,
.meal-builder-header {
  align-items: center;
}

.modal-actions {
  justify-content: flex-end;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--body);
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--canvas-light);
  color: var(--ink);
  padding: 14px 16px;
}

textarea {
  min-height: 132px;
  resize: vertical;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(73, 79, 223, 0.24);
  outline-offset: 2px;
}

.meal-lines {
  display: grid;
  gap: 12px;
}

.meal-line,
.day-line {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 148px 48px;
  align-items: end;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--canvas);
}

.meal-line-photo {
  align-self: center;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:focus-visible {
  outline: 3px solid rgba(73, 79, 223, 0.24);
  outline-offset: -3px;
}

.details-section {
  display: grid;
  gap: 12px;
}

.cooking-checklist {
  display: grid;
  gap: 10px;
}

.cooking-check {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 16px;
  background: #fff;
  box-shadow: rgba(0, 0, 0, 0.03) 0 2px 4px;
  cursor: pointer;
  transition: border-color 160ms ease, transform 160ms ease;
  min-width: 0;
}

.cooking-check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.cooking-check:hover {
  border-color: rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

.cooking-check:has(input:focus-visible) {
  outline: 2px solid #18e299;
  outline-offset: 2px;
}

.cooking-copy {
  color: var(--ink);
  font-weight: 600;
  letter-spacing: -0.2px;
  min-width: 0;
}

.cooking-copy small {
  display: block;
  margin-top: 3px;
  color: var(--mute);
  font-size: 13px;
  font-weight: 400;
}

.check-pill {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 42px;
  min-height: 42px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 9999px;
  background: #fff;
  color: #0d0d0d;
  box-shadow: rgba(0, 0, 0, 0.06) 0 1px 2px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.check-pill::before {
  content: "\2713";
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
  border-radius: 9999px;
  background: #f5f5f5;
  font-size: 13px;
  line-height: 1;
}

.check-pill::after {
  content: "Check";
}

.cooking-check input:checked + .check-pill {
  border-color: #18e299;
  background: #18e299;
}

.cooking-check input:checked + .check-pill::before {
  content: "\2713";
  background: #0d0d0d;
  color: #fff;
}

.cooking-check input:checked + .check-pill::after {
  content: "Done";
}

.preparation-text {
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--canvas);
  padding: 16px;
}

.helper-text {
  margin: -8px 0 0;
  font-size: 14px;
}

.helper-text.hidden {
  display: none;
}

.meal-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--line);
  min-width: 0;
}

.meal-summary span {
  display: grid;
  gap: 4px;
  min-height: 78px;
  background: var(--canvas-light);
  padding: 16px;
  min-width: 0;
}

.meal-summary strong {
  color: var(--stone);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.meal-summary output {
  color: var(--ink);
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    align-content: start;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    border-right: 0;
    padding: 14px;
  }

  .sidebar h1 {
    margin-bottom: 14px;
    font-size: 24px;
  }

  .user-panel {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    margin-top: 14px;
    padding: 12px;
  }

  .user-panel small {
    grid-column: 1 / 2;
  }

  .user-panel .secondary-button {
    grid-column: 2 / 3;
    grid-row: 1 / 3;
    margin-top: 0;
  }

  .tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .tab-button {
    min-height: 44px;
    padding: 9px 12px;
    text-align: center;
  }

  .main-panel {
    padding: 16px 10px 24px;
  }

  .view-header {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 10px;
    margin-bottom: 16px;
  }

  h2 {
    font-size: 32px;
  }

  .view-header p {
    font-size: 13px;
    line-height: 1.35;
  }

  .view-header .primary-button {
    width: auto;
    min-height: 44px;
    padding: 10px 14px;
    font-size: 14px;
  }

  th,
  td {
    padding: 14px 16px;
  }

  .form-grid,
  .meal-summary {
    grid-template-columns: 1fr;
  }

  .modal-card {
    padding: 22px;
  }

  .modal-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .image-control {
    grid-template-columns: 1fr;
    width: 100%;
    min-height: 240px;
  }

  .image-control-preview {
    height: 240px;
  }

  .image-control-actions {
    align-content: stretch;
  }

  .meal-line,
  .day-line {
    grid-template-columns: 1fr;
  }

  .meal-line-photo {
    display: none;
  }

  .meal-line .icon-button,
  .day-line .icon-button {
    width: 100%;
  }
}
