/* GelatoCalculator PWA — macOS System Settings look:
 * off-white background, white rounded cards, SF-style system font,
 * flat blue accent, Apple green/orange status colors. */

:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --border: #e5e5ea;
  --input-border: #d2d2d7;
  --text: #1d1d1f;
  --text2: #6e6e73;
  --accent: #007aff;
  --accent-press: #0060df;
  --secondary: #e8e8ed;
  --secondary-press: #dcdce1;
  --danger: #ff3b30;
  --ok-deep: #1fa94a;
  --out-deep: #ef7d0e;
  --radius-card: 16px;
  --radius-ctl: 10px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

/* ---------------------------------------------------------------- header */
.app-header {
  padding: 20px 20px 4px;
  max-width: 1180px;
  margin: 0 auto;
}
.app-header h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.app-header .subtitle {
  color: var(--text2);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 2px;
}

/* ---------------------------------------------------------------- layout */
main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 16px calc(92px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.left-col { display: flex; flex-direction: column; gap: 14px; }

@media (min-width: 980px) {
  main {
    display: grid;
    grid-template-columns: 470px 1fr;
    align-items: start;
    gap: 16px;
  }
  #card-results { position: sticky; top: 16px; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.card h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text2);
}

/* ---------------------------------------------------------------- rows */
.rows-header {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--text2);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}
.rows-header .idx { width: 22px; }
.rows-header .col-item { flex: 1; }
.rows-header .col-weight { width: 92px; }

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 7px 0;
}
.row .idx {
  width: 22px;
  color: var(--text2);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

input, select {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-ctl);
  padding: 9px 11px;
  min-width: 0;
  outline: none;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.18);
}
.item-input { flex: 1; }
.weight-input { width: 92px; text-align: right; }

/* ---------------------------------------------------------------- adjust / recipes */
.adjust-row, .recipe-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.recipe-row + .recipe-row { margin-top: 10px; }
.adjust-row label { color: var(--text2); font-size: 14px; }
#new-total { width: 110px; text-align: right; }
#saved-recipes { flex: 1; min-width: 140px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
  background: var(--secondary);
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, transform 0.05s;
}
.btn:active { background: var(--secondary-press); transform: scale(0.98); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-press); }
.btn.danger-text { color: var(--danger); }
.btn.small { padding: 9px 13px; border-radius: var(--radius-ctl); font-size: 14px; }
.btn.subtle { color: var(--text2); }

/* ---------------------------------------------------------------- action bar */
.actionbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(245, 245, 247, 0.82);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid rgba(0, 0, 0, 0.07);
  max-width: 100%;
  z-index: 20;
}
.actionbar .btn { flex: 1; white-space: nowrap; min-width: 0; }
.actionbar .short { display: none; }
@media (min-width: 980px) {
  .actionbar { justify-content: center; }
  .actionbar .btn { flex: 0 1 220px; }
}
@media (max-width: 560px) {
  .actionbar { gap: 8px; }
  .actionbar .btn { padding: 13px 10px; font-size: 15px; }
  .actionbar .long { display: none; }
  .actionbar .short { display: inline; }
}

/* ---------------------------------------------------------------- gauges */
#gauges {
  display: flex;
  justify-content: space-between;
  gap: 2px;
  margin-bottom: 14px;
}
.gauge {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.gauge svg { width: 100%; max-width: 88px; height: auto; display: block; }
.g-value {
  font-size: 21px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  margin-bottom: 2px;
  min-height: 28px;
}
.g-value.ok { color: var(--ok-deep); }
.g-value.out { color: var(--out-deep); }
.g-value.empty { color: var(--text2); }
.g-title { font-size: 14px; font-weight: 700; margin-top: 4px; }
.g-caption { font-size: 11px; color: var(--text2); margin-top: 1px; }
.g-bound { font-size: 8.5px; fill: var(--text2); }

/* ---------------------------------------------------------------- results text */
.result-text { font-size: 15px; }
.result-text .rline { white-space: pre-wrap; min-height: 1.45em; }
.result-text .rline.hl { color: var(--accent); font-weight: 700; }

/* ---------------------------------------------------------------- toast */
#toast {
  position: fixed;
  bottom: calc(84px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: rgba(29, 29, 31, 0.92);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 30;
  max-width: 86vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
