/* Colours and radii follow docs/design/DESIGN.md. */
:root {
  --bg: #000000;
  --surface: #1c1c1e;
  --fill: #2c2c2e;
  --fill3: #545458;
  --line: rgba(255, 255, 255, 0.14);
  --ink: #f5f5f7;
  --ink2: #b6b6bd;
  --ink3: #9a9aa1;
  --accent: #f2f0eb;
  --on-accent: #0b0b0c;
  --warn: #ffd25e;
  --warn-tint: #33290e;
  --danger: #ff6b62;
  --danger-tint: #3a1715;
  --protein: #ff8a9b;
  --carbs: #f0c674;
  --fat: #a3c585;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, "PingFang TC", "Noto Sans TC", sans-serif;
  font-variant-numeric: tabular-nums;
}

#app { display: flex; flex-direction: column; height: 100vh; }
h1 { margin: 0; font-size: 28px; }
h2 { margin: 0; font-size: 17px; }
p { margin: 0; }

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 24px;
  border-bottom: 1px solid var(--line);
}
header strong { font-size: 20px; white-space: nowrap; }
header span { display: flex; align-items: center; gap: 12px; color: var(--ink2); }

.tabs { display: flex; gap: 2px; padding: 3px; border-radius: 22px; background: var(--surface); }
.button.tab {
  min-height: 38px;
  min-width: 110px;
  border-radius: 19px;
  background: transparent;
  color: var(--ink2);
  font-size: 15px;
}
.button.tab[aria-pressed="true"] { background: var(--fill3); color: var(--ink); }

.columns {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}
.panel { background: var(--surface); border-radius: 24px; overflow: auto; }

.queue { padding: 4px 16px 16px; }
.queue-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--ink3);
  font-size: 13px;
}
.row {
  display: flex;
  flex-direction: column;
  width: 100%;
  border: 0;
  border-radius: 16px;
  padding: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.row[aria-current="true"] { background: var(--fill); }
.row-name { font-size: 17px; font-weight: 600; }
.row-sub { font-size: 13px; color: var(--ink3); }
.row-sub.warn { color: var(--warn); }
.queue h2 { font-size: 13px; font-weight: 400; color: var(--ink3); padding: 12px 12px 4px; }
.merge-list { max-height: 40vh; overflow: auto; margin: 12px 0; }
.merge-list .row[aria-pressed="true"] { background: var(--fill3); }
dialog input[type="text"] { margin-top: 4px; }
dialog p { color: var(--ink2); margin-bottom: 12px; }

.detail, .detail form { display: flex; flex-direction: column; gap: 16px; }
.detail { padding: 24px; overflow-wrap: anywhere; }
.detail > * { flex-shrink: 0; }
.empty { margin: auto; font-size: 17px; color: var(--ink2); }
.subtitle { color: var(--ink2); }
.banner {
  background: var(--warn-tint);
  color: var(--warn);
  border-radius: 18px;
  padding: 12px 16px;
}

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--fill); border-radius: 18px; padding: 16px; display: flex; flex-direction: column; }
.tile span { font-size: 13px; color: var(--ink2); }
.tile strong { font-size: 30px; }
.tile.kcal strong, .tile.carbs strong { color: var(--carbs); }
.tile.protein strong { color: var(--protein); }
.tile.fat strong { color: var(--fat); }

table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { font-size: 13px; font-weight: 400; color: var(--ink3); }
th, td { padding: 6px 4px; text-align: right; vertical-align: top; }
th:first-child, td:first-child { text-align: left; }
tbody tr + tr { border-top: 1px solid var(--line); }
table.edit td:first-child { vertical-align: middle; }
table.unweighed tr > :nth-child(2) { visibility: hidden; }

dl { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 4px; margin: 0; }
dt { color: var(--ink3); }
dd { margin: 0; color: var(--ink2); }

.form-grid { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px; align-items: center; }
.field { display: flex; flex-direction: column; }
.field small { color: var(--warn); font-size: 12px; text-align: right; }
.note { display: flex; flex-direction: column; gap: 4px; color: var(--ink3); font-size: 13px; }

input[type="text"], select, textarea {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 16px;
  padding: 10px 12px;
  background: var(--fill);
  color: var(--ink);
  font: inherit;
  font-size: 17px;
}
textarea { resize: vertical; }
input.numeric { text-align: right; }
input.changed { color: var(--warn); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.actions { display: flex; justify-content: flex-end; gap: 8px; }
.actions.bottom {
  position: sticky;
  bottom: -24px;
  margin: auto -24px -24px;
  padding: 12px 24px 24px;
  background: var(--surface);
}

.button {
  min-height: 50px;
  border: 0;
  border-radius: 25px;
  padding: 0 24px;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.button.primary { background: var(--accent); color: var(--on-accent); padding: 0 40px; }
.button.secondary { background: var(--fill); color: var(--ink); }
.button.danger { background: var(--danger-tint); color: var(--danger); }
.button.text { min-height: 44px; padding: 0 8px; background: transparent; color: var(--ink); font-size: 15px; }
.button:disabled { opacity: 0.4; cursor: default; }

.screen {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
}

dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 34px;
  padding: 24px 16px;
  background: var(--surface);
  color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { font-size: 22px; margin-bottom: 12px; }
dialog textarea { margin-bottom: 12px; }
.reasons { background: var(--fill); border-radius: 24px; padding: 0 16px; margin-bottom: 12px; font-size: 17px; }
.reasons label { display: flex; justify-content: space-between; align-items: center; min-height: 56px; }
.reasons label + label { border-top: 1px solid var(--line); }
.reasons input { width: 22px; height: 22px; accent-color: var(--accent); }
.checks { margin-bottom: 0; }
dialog .checks { max-height: 50vh; overflow: auto; margin-bottom: 12px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset legend { color: var(--ink3); font-size: 13px; padding: 0 0 4px; }
fieldset small { color: var(--warn); font-size: 12px; }
.detail > .row, .detail > div > .row { background: var(--fill); margin-bottom: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 12px 20px;
  border-radius: 18px;
  background: var(--fill3);
  font-size: 15px;
  z-index: 1;
}
.toast.error { background: var(--danger-tint); color: var(--danger); }

@media (max-width: 800px) {
  #app { height: auto; min-height: 100vh; }
  .columns { grid-template-columns: minmax(0, 1fr); }
  .queue { max-height: 40vh; }
  .detail { overflow: visible; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  header { padding: 8px 16px; flex-wrap: wrap; }
  .actions .button { padding: 0 16px; }
}
