/* ============================================================
   Kitchen Timer — styles
   ------------------------------------------------------------
   INDUSTRIAL look: workshop control panel, not a website.
   - square corners (2 px radius max), steel borders, subtle bevels
   - amber digits on recessed LED-style displays, monospace font
   - spaced uppercase labels, "machine" buttons
   - warning = amber, finished = red + diagonal hazard stripes
   Kitchen constraints: BIG, high contrast, readable from 2 m,
   touch targets ≥ 64 px.
   ============================================================ */

:root {
  --bg:           #141619;
  --panel:        #1e2226;
  --panel-2:      #282d33;
  --border:       #3d444c;
  --border-light: #525a63;
  --text:         #e8eaed;
  --text-2:       #8b9299;
  --amber:        #ffb000;   /* industrial amber (displays, accent) */
  --green:        #3fbf4f;
  --red:          #e02c2c;
  --orange:       #ff8c00;
  --mono: Consolas, "Cascadia Mono", "Courier New", monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;               /* no bounce; scrolling is internal */
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  touch-action: manipulation;     /* removes double-tap zoom */
}

/* "Machine" button: beveled plate, uppercase, square corners */
button {
  font-family: inherit;
  color: var(--text);
  background: linear-gradient(#2e343a, #23282d);
  border: 1px solid var(--border);
  border-radius: 2px;
  cursor: pointer;
  min-height: 64px;               /* minimum touch target */
  min-width: 64px;
  font-size: 20px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 2px 0 rgba(0, 0, 0, 0.45);
}
button:active {
  transform: translateY(1px);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
  filter: brightness(1.15);
}

input, select, textarea {
  font-family: inherit;
  font-size: 20px;
  color: var(--text);
  background: #101214;
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 12px;
  min-height: 56px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

[hidden] { display: none !important; }

/* Sober scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: var(--bg); }

/* ============================================================
   MAIN SCREEN
   ============================================================ */

#main-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* --- Top bar: nameplate + clock --- */
#topbar {
  flex: 0 0 44px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: linear-gradient(#181b1e, #121417);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: var(--text-2);
}
#topbar-name { color: var(--amber); font-weight: 800; }
#topbar-title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#topbar-clock {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 2px;
}

/* --- Top ~75%: timer list --- */
#timer-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#empty-message {
  position: absolute;
  top: 34%;
  width: 100%;
  text-align: center;
  font-size: clamp(22px, 4vw, 36px);
  text-transform: uppercase;
  letter-spacing: 4px;
  color: var(--text-2);
  pointer-events: none;
}

/* --- Timer row: steel plate + color bar on the left --- */
.timer-row {
  position: relative;
  display: grid;
  grid-template-columns: 86px 1fr auto auto auto;
  align-items: center;
  gap: 14px;
  min-height: 115px;
  padding: 7px 12px 7px 28px;     /* room for the left color bar */
  background: linear-gradient(#22262b, #1c2024);
  border: 1px solid var(--border);
  border-radius: 2px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 2px 0 rgba(0, 0, 0, 0.4);
  flex-shrink: 0;
}
/* Color bar (food visual cue) */
.timer-row::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 10px;
  background: var(--color, var(--border));
}

.timer-icon { font-size: 55px; text-align: center; line-height: 1; }
.icon-img { width: 62px; height: 62px; object-fit: contain; vertical-align: middle; }

.custom-badge {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-2);
  background: #101214;
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 8px 2px;
  text-align: center;
}

.timer-label {
  font-size: clamp(26px, 4vw, 38px);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Table badge — always visible, clickable (opens the numpad to
   set/change/clear the timer's table). "—" + dashed border when unset. */
.table-badge {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  min-width: 72px;
  font-family: var(--mono);
  font-size: 31px;
  font-weight: 700;
  color: var(--amber);
  background: #101214;
  border: 1px solid var(--border-light);
  border-radius: 2px;
  padding: 10px 14px;
}
.table-badge:active { filter: brightness(1.4); }
.table-badge.empty { color: var(--text-2); border-style: dashed; }

/* Countdown: recessed display, amber digits, ≥ 48 px.
   Clickable: opens the +/− time adjustment.
   `align-self: stretch`: same height as the row's ✕ / OK buttons. */
.timer-time {
  cursor: pointer;
  align-self: stretch;
  display: flex;
  align-items: center;
  font-family: var(--mono);
  font-size: clamp(58px, 9.6vw, 96px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  color: var(--amber);
  background: #0a0c0d;
  border: 1px solid #000;
  border-radius: 2px;
  padding: 0 14px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.85), 0 1px 0 rgba(255, 255, 255, 0.05);
}
.timer-time:active { filter: brightness(1.4); }

/* The ✕ opens a floating confirmation menu (never deletes directly).
   Stretched to the countdown's height, kept SQUARE via aspect-ratio.
   Red by default: it is a destructive control. */
.btn-cancel-row {
  align-self: stretch;
  height: auto;
  width: auto;
  aspect-ratio: 1 / 1;
  min-width: 64px;
  min-height: 64px;
  font-size: 34px;
  background: linear-gradient(#e84545, #c02020);
  border-color: #7a1010;
}

/* --- Warning state: last minute --- */
.timer-row.warning { border-color: var(--orange); animation: pulse 1s ease-in-out infinite; }
.timer-row.warning .timer-time { color: var(--orange); }
@keyframes pulse { 50% { filter: brightness(1.5); } }

/* --- Finished state: flashing red + hazard stripes + OK button --- */
.timer-row.finished {
  background: #4a1214;
  border-color: var(--red);
  animation: blink 0.6s steps(2, jump-none) infinite;
}
.timer-row.finished::before {
  width: 16px;
  background: repeating-linear-gradient(-45deg, var(--amber) 0 10px, #141619 10px 20px);
}
.timer-row.finished .timer-time { color: var(--red); }
@keyframes blink { 50% { background: #260809; } }

/* Same height as the countdown display (consistent row) */
.btn-ok {
  min-width: max(28vw, 168px);
  align-self: stretch;
  height: auto;
  min-height: 64px;
  font-size: 53px;
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(#f5f5f5, #d5d5d5);
  color: #7a0000;
  border: 1px solid #888;
}

/* --- Bottom ~25%: action bar --- */
#action-bar {
  flex: 0 0 clamp(110px, 22dvh, 190px);
  display: flex;
  gap: 12px;
  padding: 10px;
  background: linear-gradient(#181b1e, #131518);
  border-top: 1px solid var(--border);
}

#btn-add {
  flex: 1;
  font-size: clamp(38px, 6.5vw, 62px);
  font-weight: 900;
  letter-spacing: 3px;
  background: linear-gradient(#ffc23d, #eda200);
  color: #1a1200;
  border: 1px solid #8a6200;
}

/* Same height as the Add button (both fill the bar) */
#btn-settings {
  flex: 0 0 clamp(110px, 16vw, 170px);
  font-size: clamp(38px, 6vw, 56px);
}

/* ============================================================
   OVERLAYS (fullscreen)
   ============================================================ */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  padding-top: max(12px, env(safe-area-inset-top));
  overflow: hidden;
}

.btn-cancel-overlay {
  flex-shrink: 0;
  height: 72px;
  font-size: 26px;
}

/* --- Table selector --- */
#table-block {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.table-label {
  font-size: 20px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-2);
}
/* Table field: recessed display, empty ("—") by default.
   Tapping it opens the numpad. */
#table-field {
  flex: 0 0 clamp(140px, 24vw, 220px);
  height: 64px;
  font-family: var(--mono);
  font-size: 30px;
  font-weight: 700;
  color: var(--text-2);
  background: #0a0c0d;
  border: 1px solid var(--border);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.85);
}
#table-field.selected { color: var(--amber); border-color: var(--border-light); }

/* --- Foods / durations tabs --- */
#add-tabs { flex-shrink: 0; display: flex; gap: 10px; }
.tab { flex: 1; height: 68px; font-size: 24px; opacity: 0.55; }
.tab.active {
  opacity: 1;
  background: linear-gradient(#ffc23d, #eda200);
  color: #1a1200;
  border-color: #8a6200;
}

/* --- Panels --- */
.panel { flex: 1; overflow-y: auto; }

.category-title {
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--text-2);
  border-left: 4px solid var(--amber);
  padding-left: 10px;
  margin: 16px 4px 8px;
}
.category-title:first-child { margin-top: 0; }

.foods-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

/* Food tile: steel plate + color strip on top */
.food-btn {
  min-height: 118px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: linear-gradient(#23282d, #1d2126);
  border: 1px solid var(--border);
  border-top: 5px solid var(--color, var(--border));
  padding: 8px;
  text-transform: none;
}
.food-btn .icon { font-size: 38px; line-height: 1.1; }
.food-btn .icon .icon-img { width: 44px; height: 44px; }
.food-btn .name {
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 1px;
  text-align: center;
  text-transform: uppercase;
}
.food-btn .duration {
  font-family: var(--mono);
  font-size: 15px;
  color: var(--text-2);
  font-weight: 700;
}

/* --- Duration presets + free duration --- */
#durations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.duration-btn {
  min-height: 100px;
  font-size: 38px;
  font-weight: 900;
  font-family: var(--mono);
  background: linear-gradient(#23282d, #1d2126);
  border: 1px solid var(--border);
  border-top: 5px solid var(--amber);
}

#custom-block {
  margin-top: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
#custom-display {
  grid-column: 1 / -1;
  text-align: center;
  font-family: var(--mono);
  font-size: clamp(48px, 9vw, 72px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  color: var(--amber);
  background: #0a0c0d;
  border: 1px solid #000;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.85);
}
#custom-steppers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
#custom-steppers button { height: 72px; font-size: 22px; font-family: var(--mono); }
#btn-start-custom {
  height: 100%;
  min-height: 154px;
  font-size: 30px;
  letter-spacing: 2px;
  background: linear-gradient(#4fd35f, #2e9e3c);
  color: #002208;
  border-color: #1d6b28;
}

/* ============================================================
   SETTINGS
   ============================================================ */

.settings-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.settings-header h1 {
  margin: 0;
  font-size: 26px;
  text-transform: uppercase;
  letter-spacing: 4px;
}
#btn-close-settings { height: 68px; padding: 0 24px; font-size: 22px; }

#settings-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 24px;
}

.section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 14px;
}
.section h2 {
  margin: 0 0 12px;
  font-size: 15px;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--text-2);
  border-left: 4px solid var(--amber);
  padding-left: 10px;
}

.choice-row { display: flex; gap: 10px; flex-wrap: wrap; }
.choice-row button { flex: 1; min-height: 72px; font-size: 18px; }
.choice-row button small { font-weight: 400; color: var(--text-2); text-transform: none; letter-spacing: 0; }
.choice-row button.active {
  background: linear-gradient(#ffc23d, #eda200);
  color: #1a1200;
  border-color: #8a6200;
}
.choice-row button.active small { color: #1a1200; }

.btn-large { width: 100%; min-height: 68px; font-size: 20px; margin-top: 10px; }

/* Duration presets (chips) */
#duration-presets-list { display: flex; flex-wrap: wrap; gap: 10px; }
.duration-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 8px 8px 8px 18px;
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
}
.duration-chip button { min-height: 52px; min-width: 52px; font-size: 20px; }

.add-duration-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.add-duration-row input { width: 110px; text-align: center; font-family: var(--mono); }
.add-duration-row button { flex: 1; }
.add-duration-row span { color: var(--text-2); font-weight: 700; }

/* Food editor */
.food-card {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 10px 10px 10px 22px;
  margin-bottom: 10px;
}
.food-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 8px;
  background: var(--color, transparent);
}
.food-card.disabled-card { opacity: 0.45; }
.food-card .icon-btn { font-size: 28px; width: 64px; }
.food-card .icon-btn .icon-img { width: 40px; height: 40px; }
.food-card .name-input { flex: 2 1 180px; min-width: 140px; }
.food-card .label-input { flex: 1 1 120px; min-width: 100px; text-transform: uppercase; }
.food-card .minutes-input { width: 90px; text-align: center; font-family: var(--mono); }
.food-card .unit { color: var(--text-2); font-weight: 700; }
.food-card .color-btn { width: 64px; border: 2px solid var(--border-light); }
.food-card select { min-width: 120px; }
.food-card .toggle-btn { min-width: 130px; font-size: 16px; }
.food-card .toggle-btn.on {
  background: linear-gradient(#4fd35f, #2e9e3c);
  color: #002208;
  border-color: #1d6b28;
}
.food-card .delete-btn { background: linear-gradient(#5a2321, #471a18); border-color: #6b2a26; }

/* Icon manager */
#icons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 4px;
}
.icon-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 10px;
}
.icon-card img { width: 56px; height: 56px; object-fit: contain; }
.icon-card .icon-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  text-align: center;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.icon-card .delete-btn {
  min-height: 48px;
  min-width: 100%;
  font-size: 18px;
  background: linear-gradient(#5a2321, #471a18);
  border-color: #6b2a26;
}
.no-icons { color: var(--text-2); font-size: 18px; margin: 0 0 8px; }

/* Table numbers */
.stepper-row { display: flex; align-items: center; gap: 14px; }
.stepper-row button { flex: 0 0 84px; height: 72px; font-size: 32px; font-family: var(--mono); }
.stepper-row span {
  flex: 1;
  text-align: center;
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--amber);
  background: #0a0c0d;
  border: 1px solid #000;
  padding: 10px 0;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.85);
}

/* Alarm */
#volume-slider { width: 100%; height: 56px; accent-color: var(--amber); background: transparent; border: none; box-shadow: none; }

#restaurant-input { width: 100%; }

.io-message { min-height: 24px; margin: 12px 0 0; font-size: 18px; font-weight: 700; }
.io-message.error { color: #ff6b6b; }
.io-message.success { color: var(--green); }

/* ============================================================
   CENTERED DIALOG BOXES (import, delete, adjust, numpad,
   icon/color pickers, AI prompt)
   ============================================================ */

.overlay-center {
  z-index: 20;
  background: rgba(0, 0, 0, 0.78);
  align-items: center;
  justify-content: center;
}
.dialog-box {
  background: var(--panel);
  border: 1px solid var(--border-light);
  border-radius: 2px;
  padding: 20px;
  width: min(560px, 94vw);
  max-height: 88dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
}
.dialog-box h2 {
  margin: 0;
  font-size: 20px;
  text-transform: uppercase;
  letter-spacing: 3px;
}
.dialog-box .subtitle {
  margin: 4px 0 0;
  font-size: 14px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text-2);
}
.dialog-box p { font-size: 20px; margin: 0; }
.dialog-box .secondary { background: linear-gradient(#2e343a, #23282d); }
#btn-import-replace { background: linear-gradient(#e84545, #c02020); border-color: #7a1010; }
#btn-import-merge { background: linear-gradient(#4fd35f, #2e9e3c); color: #002208; border-color: #1d6b28; }

/* Delete confirmation floating menu */
.delete-box { width: min(440px, 94vw); }
#delete-label {
  font-size: 22px !important;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-2);
  text-align: center;
}
#btn-delete-confirm {
  background: linear-gradient(#e84545, #c02020);
  border-color: #7a1010;
}

/* Time adjust box (+/− 1 and 5 min) */
.adjust-box { width: min(460px, 94vw); }
#adjust-label {
  font-size: 20px !important;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-2);
}
#adjust-display {
  font-family: var(--mono);
  font-size: 60px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--amber);
  background: #0a0c0d;
  border: 1px solid #000;
  padding: 8px 0;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.85);
}
#adjust-delta {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  min-height: 30px;
}
#adjust-delta.delta-zero { color: var(--text-2); }
#adjust-delta.delta-plus { color: var(--green); }
#adjust-delta.delta-minus { color: var(--red); }
#adjust-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
#adjust-grid button {
  height: 76px;
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 700;
}
#btn-adjust-confirm {
  background: linear-gradient(#4fd35f, #2e9e3c);
  color: #002208;
  border-color: #1d6b28;
}

/* Numpad (table number) */
.numpad-box { width: min(420px, 94vw); }
#numpad-display {
  font-family: var(--mono);
  font-size: 56px;
  font-weight: 700;
  text-align: center;
  color: var(--amber);
  background: #0a0c0d;
  border: 1px solid #000;
  padding: 8px 0;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.85);
}
#numpad-display.error { color: var(--red); animation: pulse 0.3s 2; }
#numpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
#numpad-grid button {
  height: 76px;
  font-family: var(--mono);
  font-size: 32px;
  font-weight: 700;
}
#btn-numpad-ok {
  background: linear-gradient(#4fd35f, #2e9e3c);
  color: #002208;
  border-color: #1d6b28;
}

#emoji-grid, #custom-icons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
}
#emoji-grid button { font-size: 30px; }
#custom-icons-grid button { padding: 6px; }
#custom-icons-grid .icon-img { width: 48px; height: 48px; }
#color-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
#color-grid button { border: 2px solid var(--border-light); }

/* AI prompt box */
.prompt-box { width: min(680px, 96vw); }
.prompt-help { font-size: 17px !important; color: var(--text-2); }
#prompt-text {
  width: 100%;
  height: clamp(180px, 34dvh, 320px);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.45;
  resize: vertical;
  user-select: text;              /* copyable zone */
}
#btn-copy-prompt {
  background: linear-gradient(#ffc23d, #eda200);
  color: #1a1200;
  border-color: #8a6200;
}
