/* Windows 11 (Fluent) look. Light/dark follow prefers-color-scheme, which
   Electron drives from nativeTheme.themeSource (Settings → Theme). */
:root {
  color-scheme: light;
  --bg: #f3f3f3;
  --card: #ffffff;
  --card-2: #f9f9f9;
  --stroke: rgba(0, 0, 0, 0.07);
  --stroke-strong: rgba(0, 0, 0, 0.14);
  --text: #1a1a1a;
  --text-secondary: #5f5f5f;
  --accent: #005fb8;
  --accent-hover: #1a6fc0;
  --accent-text: #ffffff;
  --control: #fdfdfd;
  --control-hover: #f5f5f5;
  --control-bottom: rgba(0, 0, 0, 0.16);
  --nav-hover: rgba(0, 0, 0, 0.04);
  --nav-active: rgba(0, 0, 0, 0.06);
  --danger: #c42b1c;
  --ok: #0f7b0f;
  --warn: #9d5d00;
  --chart-weight: #005fb8;
  --chart-flow: #c06a1b;
  --chart-target: #8a8a8a;
  --chart-grid: rgba(0, 0, 0, 0.07);
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
  --dialog-shadow: 0 32px 64px rgba(0, 0, 0, 0.19), 0 2px 21px rgba(0, 0, 0, 0.15);
  --radius: 8px;
  --font: 'Segoe UI Variable Text', 'Segoe UI', system-ui, sans-serif;
  --font-display: 'Segoe UI Variable Display', 'Segoe UI', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #202020;
    --card: #2b2b2b;
    --card-2: #323232;
    --stroke: rgba(255, 255, 255, 0.07);
    --stroke-strong: rgba(255, 255, 255, 0.14);
    --text: #ffffff;
    --text-secondary: #c2c2c2;
    --accent: #60cdff;
    --accent-hover: #58bbe8;
    --accent-text: #000000;
    --control: #2d2d2d;
    --control-hover: #343434;
    --control-bottom: rgba(255, 255, 255, 0.09);
    --nav-hover: rgba(255, 255, 255, 0.05);
    --nav-active: rgba(255, 255, 255, 0.08);
    --danger: #ff99a4;
    --ok: #6ccb5f;
    --warn: #fce100;
    --chart-weight: #60cdff;
    --chart-flow: #f0a35e;
    --chart-target: #9a9a9a;
    --chart-grid: rgba(255, 255, 255, 0.08);
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    --dialog-shadow: 0 32px 64px rgba(0, 0, 0, 0.5), 0 2px 21px rgba(0, 0, 0, 0.4);
  }
}
/* Web version: Settings → Theme forces dark (see src/web/api-web.js). */
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #202020;
  --card: #2b2b2b;
  --card-2: #323232;
  --stroke: rgba(255, 255, 255, 0.07);
  --stroke-strong: rgba(255, 255, 255, 0.14);
  --text: #ffffff;
  --text-secondary: #c2c2c2;
  --accent: #60cdff;
  --accent-hover: #58bbe8;
  --accent-text: #000000;
  --control: #2d2d2d;
  --control-hover: #343434;
  --control-bottom: rgba(255, 255, 255, 0.09);
  --nav-hover: rgba(255, 255, 255, 0.05);
  --nav-active: rgba(255, 255, 255, 0.08);
  --danger: #ff99a4;
  --ok: #6ccb5f;
  --warn: #fce100;
  --chart-weight: #60cdff;
  --chart-flow: #f0a35e;
  --chart-target: #9a9a9a;
  --chart-grid: rgba(255, 255, 255, 0.08);
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  --dialog-shadow: 0 32px 64px rgba(0, 0, 0, 0.5), 0 2px 21px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.43 var(--font);
  overflow: hidden;
  user-select: none;
}
h1 {
  font: 600 28px/1.3 var(--font-display);
  margin: 0;
}
h2 {
  font: 600 16px/1.4 var(--font);
  margin: 0 0 12px;
}
h3 {
  font: 600 14px/1.4 var(--font);
  margin: 24px 0 8px;
}
input,
textarea,
select,
button {
  font: inherit;
  color: inherit;
}
[hidden] {
  display: none !important;
}
.muted {
  color: var(--text-secondary);
}
.small {
  font-size: 12px;
}
.center {
  text-align: center;
}
.row {
  display: flex;
  align-items: center;
}
.row.gap {
  gap: 8px;
}
.row.between {
  justify-content: space-between;
  gap: 12px;
}

/* ---------- Title bar ---------- */
.titlebar {
  height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 calc(140px + 16px) 0 16px; /* leave room for caption buttons */
  -webkit-app-region: drag;
}
.app-icon {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: linear-gradient(135deg, #8a5a3b, #3b2416);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}
.app-name {
  font-size: 12px;
}
.conn-pill {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--stroke);
}
.conn-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
}
.conn-pill.connected .dot {
  background: var(--ok);
}
.conn-pill.connecting .dot,
.conn-pill.reconnecting .dot {
  background: var(--warn);
  animation: pulse 1s infinite alternate;
}
.title-btn {
  -webkit-app-region: no-drag;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  font-size: 12px;
}
.title-btn:hover {
  background: var(--nav-hover);
}
.title-btn .icon {
  width: 16px;
  height: 16px;
}
.battery {
  padding-left: 8px;
  border-left: 1px solid var(--stroke-strong);
}
@keyframes pulse {
  to {
    opacity: 0.3;
  }
}

/* ---------- Shell / nav ---------- */
.shell {
  display: flex;
  height: calc(100% - 44px);
}
.nav {
  width: 200px;
  padding: 4px 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-spacer {
  flex: 1;
}
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  text-align: left;
  cursor: default;
}
.nav-item:hover {
  background: var(--nav-hover);
}
.nav-item.active {
  background: var(--nav-active);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 11px;
  bottom: 11px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}
.icon {
  display: block;
  flex: none;
}
[data-icon] {
  display: inline-flex;
}
.content {
  flex: 1;
  min-width: 0;
  background: var(--card-2);
  border-top-left-radius: 8px;
  border-left: 1px solid var(--stroke);
  border-top: 1px solid var(--stroke);
  overflow: auto;
}
.page {
  display: none;
  padding: 24px 28px 28px;
  min-height: 100%;
}
.page.active {
  display: block;
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

/* ---------- Cards & controls ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 32px;
  padding: 5px 14px;
  border-radius: 5px;
  border: 1px solid var(--stroke-strong);
  border-bottom-color: var(--control-bottom);
  background: var(--control);
  cursor: default;
  white-space: nowrap;
}
.btn:hover:not(:disabled) {
  background: var(--control-hover);
}
.btn:active:not(:disabled) {
  opacity: 0.8;
}
.btn:disabled {
  opacity: 0.45;
}
.btn.accent {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
}
.btn.accent:hover:not(:disabled) {
  background: var(--accent-hover);
}
.btn.danger {
  color: var(--danger);
}
.btn.big {
  min-height: 44px;
  min-width: 120px;
  font-size: 15px;
}
:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}
.badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--nav-active);
}
.badge.sim {
  background: rgba(192, 106, 27, 0.15);
  color: var(--chart-flow);
}
input[type='number'],
textarea,
select {
  background: var(--control);
  border: 1px solid var(--stroke-strong);
  border-bottom: 1px solid var(--control-bottom);
  border-radius: 5px;
  padding: 5px 10px;
  min-height: 32px;
  user-select: text;
}
input[type='number']:focus,
textarea:focus {
  outline: none;
  border-bottom: 2px solid var(--accent);
}
input[type='number'] {
  width: 84px;
  text-align: right;
}
textarea {
  width: 100%;
  resize: vertical;
}
select {
  min-width: 220px;
}

/* Fluent toggle switch */
.switch {
  appearance: none;
  flex: none;
  width: 40px;
  height: 20px;
  margin: 0;
  border-radius: 10px;
  border: 1px solid var(--text-secondary);
  position: relative;
  transition: background 0.15s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: left 0.15s;
}
.switch:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.switch:checked::after {
  left: 23px;
  background: var(--accent-text);
}

/* ---------- Brew page ---------- */
.brew-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-rows: auto minmax(260px, 1fr);
  gap: 16px;
  /* viewport − title bar − page padding − content border */
  height: calc(100vh - 44px - 52px - 1px);
  min-height: 560px;
}
.hero {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.hint-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 60%;
  text-align: right;
}
.conn-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.weight-wrap {
  text-align: center;
}
.weight {
  font: 600 104px/1 var(--font-display);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  margin-top: 4px;
}
.weight .unit {
  font-size: 40px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 8px;
}
.weight.negative {
  color: var(--text-secondary);
}
.armed {
  margin-top: 6px;
  color: var(--accent);
  font-size: 13px;
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--stroke);
  border-bottom: 1px solid var(--stroke);
}
.stat {
  text-align: center;
  padding: 10px 6px;
}
.stat + .stat {
  border-left: 1px solid var(--stroke);
}
.stat-value {
  font: 600 32px/1.25 var(--font-display);
  font-variant-numeric: tabular-nums;
}
.stat-value .unit {
  font-weight: 400;
  color: var(--text-secondary);
}
.controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}
.recipe {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.field.column {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  margin-top: 12px;
}
.input-unit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}
.input-unit input {
  color: var(--text);
}
#targetWater {
  font-size: 18px;
}
.progress {
  height: 6px;
  border-radius: 3px;
  background: var(--nav-active);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.2s;
}
.progress-bar.over {
  background: var(--chart-flow);
}
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
}
.chart-card {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.sw {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}
.sw.weight {
  background: var(--chart-weight);
}
.sw.flow {
  background: var(--chart-flow);
}
.sw.target {
  background: repeating-linear-gradient(90deg, var(--chart-target) 0 4px, transparent 4px 7px);
}
.chart-box {
  position: relative;
  flex: 1;
  min-height: 200px;
}
.chart-box.small {
  flex: none;
  height: 260px;
  margin-top: 8px;
}
.chart-box canvas {
  position: absolute;
  inset: 0;
}
.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  pointer-events: none;
}

/* ---------- History ---------- */
.history-grid {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.list-card {
  padding: 6px;
  max-height: calc(100vh - 44px - 140px);
  overflow: auto;
}
.history-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  border-radius: 5px;
  position: relative;
}
.history-item:hover {
  background: var(--nav-hover);
}
.history-item.active {
  background: var(--nav-active);
}
.history-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}
.history-item .hi-title {
  font-weight: 600;
}
.history-item .hi-sub {
  font-size: 12px;
  color: var(--text-secondary);
}
.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-secondary);
}
.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.detail-head h2 {
  margin: 0;
}
.detail-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 16px;
}
.detail-stats .ds {
  background: var(--card-2);
  border: 1px solid var(--stroke);
  border-radius: 6px;
  padding: 8px 12px;
}
.detail-stats .ds.wide {
  grid-column: span 2;
}
.detail-stats .ds b {
  display: block;
  font: 600 18px/1.3 var(--font-display);
  font-variant-numeric: tabular-nums;
}

/* ---------- Settings ---------- */
.settings {
  max-width: 860px;
}
.settings h3:first-child {
  margin-top: 0;
}
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: 6px;
  margin-bottom: 4px;
}
.setting.column {
  flex-direction: column;
  align-items: stretch;
}
.log {
  margin: 0;
  height: 180px;
  overflow: auto;
  font: 12px/1.5 Consolas, 'Cascadia Mono', monospace;
  background: var(--card-2);
  border: 1px solid var(--stroke);
  border-radius: 5px;
  padding: 8px 10px;
  user-select: text;
  white-space: pre-wrap;
}

/* ---------- Dialog ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  display: grid;
  place-items: center;
  z-index: 10;
}
.dialog {
  width: 460px;
  max-width: calc(100% - 32px);
  background: var(--card);
  border: 1px solid var(--stroke-strong);
  border-radius: 8px;
  box-shadow: var(--dialog-shadow);
  padding: 24px 24px 0;
}
.dialog h2 {
  font: 600 20px/1.4 var(--font-display);
}
.scanning {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 13px;
}
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--nav-active);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.device-list {
  margin: 14px 0;
  min-height: 140px;
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--stroke);
  border-radius: 6px;
  padding: 4px;
}
.device {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 5px;
  padding: 8px 10px;
  text-align: left;
}
.device:hover {
  background: var(--nav-hover);
}
.device.selected {
  background: var(--nav-active);
  box-shadow: inset 3px 0 0 var(--accent);
}
.device .d-name {
  flex: 1;
}
.device .d-id {
  font-size: 11px;
  color: var(--text-secondary);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 20px -24px 0;
  padding: 20px 24px;
  background: var(--card-2);
  border-top: 1px solid var(--stroke);
  border-radius: 0 0 8px 8px;
}
.dialog-actions .btn {
  min-width: 110px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--stroke-strong);
  border-radius: 8px;
  box-shadow: var(--dialog-shadow);
  padding: 10px 16px;
  z-index: 20;
  max-width: 70%;
}

@media (max-width: 1100px) {
  .weight {
    font-size: 84px;
  }
  .brew-grid {
    grid-template-columns: minmax(0, 1fr) 280px;
  }
}

/* ---------- Guided brew ---------- */
.recipe-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.recipe-head h2 {
  margin: 0;
}
.small-btn {
  min-height: 28px;
  padding: 3px 10px;
  font-size: 12px;
}
.guide-banner {
  border: 1px solid var(--stroke-strong);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 10px 14px;
  background: var(--card-2);
}
.guide-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.guide-step {
  font: 600 22px/1.3 var(--font-display);
}
.guide-sub {
  font-size: 13px;
  margin-top: 2px;
}
.pace {
  flex: none;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}
.pace.ok {
  background: rgba(15, 123, 15, 0.14);
  color: var(--ok);
}
.pace.ahead,
.pace.behind {
  background: rgba(192, 106, 27, 0.16);
  color: var(--chart-flow);
}
.guide-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow: auto;
}
.guide-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.guide-steps li {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 13px;
}
.guide-steps li .t,
.guide-steps li .w {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.guide-steps li.done {
  opacity: 0.5;
}
.guide-steps li.current {
  background: var(--nav-active);
  box-shadow: inset 3px 0 0 var(--accent);
  font-weight: 600;
}

/* ---------- Calculator ---------- */
.calc-grid {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.calc-inputs {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.calc-inputs select {
  min-width: 0;
  width: 210px;
}
.calc-inputs .warn {
  color: var(--chart-flow);
}
.calc-result .row h2 {
  margin: 0;
}
.calc-notes {
  margin: 12px 0 4px;
  padding-left: 18px;
  font-size: 13px;
  color: var(--text-secondary);
}
.calc-notes li + li {
  margin-top: 4px;
}
.steps-table,
.eq-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 13px;
}
.steps-table th,
.eq-table th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 6px 8px;
  border-bottom: 1px solid var(--stroke);
}
.steps-table td,
.eq-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--stroke);
  vertical-align: middle;
}
.steps-table td:first-child,
.steps-table td:last-child {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.steps-table td:last-child {
  text-align: right;
}
.ds .sub {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
}

/* ---------- Equipment ---------- */
.eq-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}
.eq-table input[type='text'],
.eq-table input[type='number'],
.eq-table select {
  width: 100%;
  min-width: 0;
  background: var(--control);
  border: 1px solid var(--stroke-strong);
  border-bottom: 1px solid var(--control-bottom);
  border-radius: 5px;
  padding: 4px 8px;
  min-height: 30px;
  user-select: text;
}
.eq-table input[type='number'] {
  width: 64px;
  text-align: right;
}
.eq-table .del {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 4px;
  width: 28px;
  height: 28px;
}
.eq-table .del:hover {
  background: var(--nav-hover);
  color: var(--danger);
}
.eq-table .badge {
  margin-left: 6px;
  white-space: nowrap;
}
@media (max-width: 1200px) {
  .eq-grid,
  .calc-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Guided brew layout: the recipe card scrolls inside instead of growing the row */
.brew-grid .recipe {
  contain: size;
  overflow: auto;
}
.guiding .weight {
  font-size: 76px;
}
.guiding .weight .unit {
  font-size: 32px;
}
.guiding .hero > .center.small {
  display: none;
}
.guiding .hero {
  gap: 10px;
}

/* Equipment: full-width tables, stacked */
.eq-grid {
  grid-template-columns: minmax(0, 1fr);
  max-width: 1100px;
}
.eq-table td:first-child {
  width: 40%;
}
.eq-table select {
  width: auto;
  min-width: 130px;
}
.guiding .recipe > label.field {
  display: none;
}

/* ---------- Beans ---------- */
.bean-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  border-radius: 5px;
  position: relative;
}
.bean-item:hover {
  background: var(--nav-hover);
}
.bean-item.active {
  background: var(--nav-active);
  box-shadow: inset 3px 0 0 var(--accent);
}
.bean-item.archived {
  opacity: 0.55;
}
.bean-item .hi-title {
  font-weight: 600;
}
.bean-item .hi-sub {
  font-size: 12px;
  color: var(--text-secondary);
}
.progress.mini {
  height: 4px;
  margin: 6px 0 2px;
}
.bean-form {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px 24px;
  margin: 14px 0 8px;
}
.bean-form input,
.bean-form select {
  width: 170px;
  min-width: 0;
  background: var(--control);
  border: 1px solid var(--stroke-strong);
  border-bottom: 1px solid var(--control-bottom);
  border-radius: 5px;
  padding: 5px 10px;
  min-height: 32px;
  user-select: text;
  text-align: left;
}
.fresh {
  display: inline-block;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--nav-active);
}
.fresh.peak {
  color: var(--ok);
  background: rgba(15, 123, 15, 0.14);
}
.fresh.resting,
.fresh.almost,
.fresh.fading,
.fresh.old {
  color: var(--chart-flow);
  background: rgba(192, 106, 27, 0.15);
}
.best-brew {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding: 8px 12px;
  border: 1px solid var(--stroke);
  border-radius: 6px;
  background: var(--card-2);
  font-size: 13px;
}
.cup-head {
  margin-top: 22px;
}
.cup-head h3 {
  margin: 0;
}
.cup-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 16px;
  align-items: center;
  margin-top: 10px;
}
.cup-radar svg {
  width: 100%;
  max-height: 340px;
}
.cup-side {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cup-total {
  font: 600 44px/1.1 var(--font-display);
  font-variant-numeric: tabular-nums;
}
.grade {
  align-self: flex-start;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--nav-active);
}
.grade.outstanding,
.grade.excellent {
  color: var(--ok);
  background: rgba(15, 123, 15, 0.14);
}
.grade.verygood {
  color: var(--accent);
  background: var(--nav-active);
}
.grade.belowspecialty {
  color: var(--chart-flow);
  background: rgba(192, 106, 27, 0.15);
}
.cup-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 10px;
}
.cup-row {
  display: grid;
  grid-template-columns: 120px 80px auto;
  align-items: center;
  gap: 12px;
  border: 0;
  background: transparent;
  padding: 6px 10px;
  border-radius: 5px;
  text-align: left;
}
.cup-row:hover {
  background: var(--nav-hover);
}
.cup-row .grade {
  align-self: center;
  justify-self: start;
}
.cup-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--stroke-strong);
  border-radius: 8px;
  background: var(--card-2);
}
.cup-form input[type='date'],
.cup-form select {
  background: var(--control);
  border: 1px solid var(--stroke-strong);
  border-radius: 5px;
  padding: 4px 8px;
  min-height: 30px;
  min-width: 0;
}
.cup-form textarea {
  width: 100%;
}
.row.wrap {
  flex-wrap: wrap;
}
.cup-sliders {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 6px 24px;
}
.cup-slider {
  display: grid;
  grid-template-columns: 110px 1fr 44px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.cup-slider b {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.cup-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
}
.cup-counts .field {
  gap: 8px;
  font-size: 13px;
}
input[type='range'] {
  accent-color: var(--accent);
  width: 100%;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chips.static {
  font-size: 13px;
}
.chip {
  border: 1px solid var(--stroke-strong);
  background: var(--control);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 12px;
}
.chip:hover {
  background: var(--control-hover);
}
.chip.on {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
}

/* ---------- Quick rating ---------- */
.rate-box {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--stroke);
}
.rate-box h3 {
  margin-top: 0;
}
.rate-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
}
.rate-inputs {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stars {
  display: flex;
  gap: 4px;
}
.star {
  border: 0;
  background: transparent;
  padding: 2px;
  color: var(--text-secondary);
  border-radius: 4px;
}
.star .icon {
  width: 28px;
  height: 28px;
}
.star.on {
  color: #e3a008;
}
.star.on .icon path {
  fill: #e3a008;
}
.rate-slider {
  display: grid;
  grid-template-columns: 90px 1fr 90px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.rate-slider span:last-child {
  text-align: right;
}
.rate-compass svg {
  width: 100%;
}
.suggest ul {
  margin: 10px 0 6px;
  padding-left: 18px;
  font-size: 13px;
}
.suggest li + li {
  margin-top: 4px;
}
.suggest .next {
  font-weight: 600;
  margin-bottom: 8px;
}
.toast.clickable {
  cursor: pointer;
  border-color: var(--accent);
}

/* ---------- Rating charts (SVG) ---------- */
.rc-svg text {
  font: 11px var(--font);
  fill: var(--text-secondary);
}
.rc-svg .rc-label {
  fill: var(--text);
  font-size: 11px;
}
.rc-svg .rc-val {
  fill: var(--text-secondary);
  font-size: 10px;
}
.rc-svg .rc-quad {
  font-size: 10px;
  fill: var(--text-secondary);
}
.rc-svg .rc-tick {
  font-size: 9px;
}
.rc-grid {
  stroke: var(--chart-grid);
  stroke-width: 1;
}
.rc-axis {
  stroke: var(--stroke-strong);
  stroke-width: 1.5;
}
.rc-ring {
  fill: none;
  stroke: var(--chart-grid);
}
.rc-ideal {
  fill: rgba(15, 123, 15, 0.12);
  stroke: var(--ok);
  stroke-dasharray: 3 3;
}
.rc-svg .rc-ideal-text {
  fill: var(--ok);
  font-size: 10px;
}
.rc-dot {
  fill: var(--accent);
  stroke: var(--card);
  stroke-width: 2;
}
.rc-arrow {
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}
.rc-shape {
  fill: var(--chart-weight);
  fill-opacity: 0.22;
  stroke: var(--chart-weight);
  stroke-width: 2;
}
.rc-shape-cmp {
  fill: none;
  stroke: var(--chart-flow);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
}
.rc-vertex {
  fill: var(--chart-weight);
}
@media (max-width: 1300px) {
  .rate-grid,
  .cup-summary {
    grid-template-columns: minmax(0, 1fr);
  }
}
.rate-compass svg {
  display: block;
  max-width: 330px;
  margin: 0 auto;
}
.cup-radar svg {
  display: block;
  max-width: 520px;
  margin: 0 auto;
}
.sim-off {
  border: 1px solid transparent;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}
.sim-off:hover {
  border-color: var(--chart-flow);
}

/* ---------- Web version ---------- */
.web .titlebar {
  padding-right: 16px; /* no Electron caption buttons */
}
.sync-pill {
  font-size: 12px;
  color: var(--text-secondary);
}
.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  flex: none;
}
.sync-pill.ok .sync-dot {
  background: var(--ok);
}
.sync-pill.syncing .sync-dot {
  background: var(--accent);
  animation: pulse 0.8s infinite alternate;
}
.sync-pill.error .sync-dot,
.sync-pill.offline .sync-dot {
  background: var(--chart-flow);
}
.sync-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 16px;
}
.sync-grid .field {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  font-size: 13px;
}
.sync-grid input {
  min-width: 240px;
  background: var(--control);
  border: 1px solid var(--stroke-strong);
  border-bottom: 1px solid var(--control-bottom);
  border-radius: 5px;
  padding: 5px 10px;
  min-height: 32px;
  user-select: text;
}

/* ---------- Phone layout ---------- */
@media (max-width: 760px) {
  body {
    overflow: auto;
    font-size: 15px;
  }
  .titlebar {
    padding: 0 12px;
    height: 48px;
    position: sticky;
    top: 0;
    z-index: 6;
    background: var(--bg);
  }
  .app-name,
  #btnWidget {
    display: none;
  }
  .conn-pill {
    max-width: 52vw;
    overflow: hidden;
    white-space: nowrap;
  }
  #syncPillText {
    display: none;
  }
  .shell {
    display: block;
    height: auto;
  }
  .nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    z-index: 7;
    flex-direction: row;
    justify-content: space-around;
    gap: 0;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    background: var(--card);
    border-top: 1px solid var(--stroke-strong);
  }
  .nav-spacer {
    display: none;
  }
  .nav-item {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    height: 54px;
    padding: 4px 2px;
    font-size: 10.5px;
    text-align: center;
  }
  .nav-item.active::before {
    left: 30%;
    right: 30%;
    top: 0;
    bottom: auto;
    width: auto;
    height: 3px;
  }
  .content {
    border: 0;
    border-radius: 0;
    overflow: visible;
    padding-bottom: calc(70px + env(safe-area-inset-bottom));
  }
  .page {
    padding: 12px;
  }
  h1 {
    font-size: 24px;
  }
  .page-head {
    flex-wrap: wrap;
    gap: 10px;
  }
  .brew-grid,
  .history-grid,
  .calc-grid,
  .eq-grid,
  .rate-grid,
  .cup-summary {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    min-height: 0;
  }
  .brew-grid .recipe {
    contain: none;
    overflow: visible;
  }
  .card {
    padding: 14px;
  }
  .weight,
  .guiding .weight {
    font-size: 64px;
  }
  .weight .unit {
    font-size: 26px;
  }
  .stat-value {
    font-size: 24px;
  }
  .controls .btn.big {
    flex: 1 1 40%;
    min-width: 0;
  }
  .hero > .center.small {
    display: none;
  }
  .hero-top {
    flex-wrap: wrap;
  }
  .hint-wrap {
    max-width: none;
    text-align: left;
  }
  .guide-step {
    font-size: 18px;
  }
  .chart-box {
    min-height: 220px;
  }
  .chart-card {
    min-height: 300px;
  }
  .legend {
    gap: 10px;
    font-size: 11px;
  }
  .list-card {
    max-height: 40vh;
  }
  .field {
    flex-wrap: wrap;
  }
  .calc-inputs select,
  select {
    min-width: 0;
    max-width: 100%;
  }
  .setting {
    flex-wrap: wrap;
  }
  .detail-head {
    flex-wrap: wrap;
  }
  .detail-stats .ds.wide {
    grid-column: span 1;
  }
  .eq-table {
    display: block;
    overflow-x: auto;
  }
  .bean-form {
    grid-template-columns: minmax(0, 1fr);
  }
  .bean-form input,
  .bean-form select {
    width: 60%;
  }
  .cup-slider {
    grid-template-columns: 96px 1fr 40px;
  }
  .rate-slider {
    grid-template-columns: 64px 1fr 72px;
  }
  .sync-grid input {
    min-width: 0;
    width: 100%;
  }
  .sync-grid .field {
    width: 100%;
  }
  .toast {
    bottom: calc(78px + env(safe-area-inset-bottom));
    max-width: 92%;
  }
  .dialog {
    padding: 18px 16px 0;
  }
}
@media (max-width: 760px) {
  .conn-pill .battery {
    display: none;
  }
}
@media (max-width: 760px) {
  /* Keep on/off switches on the same line as their label */
  .setting:has(> .switch),
  .toggle-row {
    flex-wrap: nowrap;
  }
}
