/* Colour tokens (HSL triplets). Only defined here; components use hsl(var(--x)). */
:root {
  --background: 60 9% 97%;
  --foreground: 240 6% 10%;
  --card: 0 0% 100%;
  --card-foreground: 240 6% 10%;
  --border: 40 6% 88%;
  --primary: 213 68% 45%;
  --primary-foreground: 0 0% 100%;
  --secondary: 40 8% 94%;
  --muted: 40 8% 94%;
  --muted-foreground: 40 3% 38%;
  --accent: 213 80% 95%;
  --destructive: 0 61% 46%;
  --ring: 213 68% 50%;
  --good: 120 100% 22%;
  --bad: 0 61% 44%;
  --warn-bg: 41 96% 92%;
  --warn-fg: 30 80% 28%;
  --past: 40 8% 50%;
  --radius: 0.75rem;

  /* chart series (validated categorical palette, light steps) */
  --series-1: 213 68% 50%;
  --series-2: 17 82% 56%;
  --series-3: 159 73% 40%;
  --series-4: 41 100% 46%;
  --series-5: 337 70% 70%;
  --series-6: 120 100% 26%;
  --series-7: 249 48% 44%;
  --series-8: 0 73% 59%;
  color-scheme: light;
}

.dark {
  --background: 240 5% 8%;
  --foreground: 60 9% 96%;
  --card: 240 4% 12%;
  --card-foreground: 60 9% 96%;
  --border: 240 4% 20%;
  --primary: 213 77% 60%;
  --primary-foreground: 240 6% 8%;
  --secondary: 240 4% 17%;
  --muted: 240 4% 17%;
  --muted-foreground: 50 6% 72%;
  --accent: 213 40% 20%;
  --destructive: 0 72% 65%;
  --ring: 213 77% 60%;
  --good: 120 60% 55%;
  --bad: 0 72% 68%;
  --warn-bg: 35 50% 16%;
  --warn-fg: 41 96% 70%;
  --past: 240 4% 60%;

  --series-1: 213 77% 56%;
  --series-2: 17 70% 50%;
  --series-3: 159 73% 36%;
  --series-4: 40 100% 39%;
  --series-5: 338 61% 58%;
  --series-6: 120 100% 26%;
  --series-7: 247 69% 72%;
  --series-8: 0 72% 65%;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

h2 {
  font-size: 1rem;
  margin: 0 0 0.75rem;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  vertical-align: -3px;
}

.muted {
  color: hsl(var(--muted-foreground));
}
.small {
  font-size: 0.85rem;
}
.good {
  color: hsl(var(--good));
}
.bad {
  color: hsl(var(--bad));
}
.good .icon,
.bad .icon {
  margin-right: 4px;
}

/* ---------- layout ---------- */

.header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: hsl(var(--background) / 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid hsl(var(--border));
}
.brand {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 650;
}
.brand .icon {
  color: hsl(var(--primary));
}
.header-right {
  display: flex;
  gap: 8px;
  align-items: center;
}
.status {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 0.85rem;
}

.main {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: hsl(var(--card));
  border-top: 1px solid hsl(var(--border));
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  min-height: 56px;
  border: 0;
  background: none;
  color: hsl(var(--muted-foreground));
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}
.tab .icon {
  width: 22px;
  height: 22px;
}
.tab.active {
  color: hsl(var(--primary));
  font-weight: 600;
}

.card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 14px;
}
.card.empty {
  text-align: center;
  padding: 28px 14px;
}

/* ---------- controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid hsl(var(--border));
  background: hsl(var(--secondary));
  color: hsl(var(--foreground));
  font: inherit;
  cursor: pointer;
}
.btn-sm {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.85rem;
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn.active {
  border-color: hsl(var(--primary));
  background: hsl(var(--accent));
}
.btn.danger {
  color: hsl(var(--destructive));
}
.btn:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

input,
select {
  font: inherit;
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 6px);
  padding: 8px 10px;
  min-height: 40px;
  width: 100%;
  min-width: 0;
}
input[type='checkbox'] {
  width: 18px;
  height: 18px;
  min-height: 0;
  accent-color: hsl(var(--primary));
  flex: none;
  margin: 0;
}
input[type='checkbox'].big {
  width: 22px;
  height: 22px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: hsl(var(--muted-foreground));
}
.field > input,
.field > select {
  color: hsl(var(--foreground));
}
.inline {
  display: flex;
  gap: 6px;
  align-items: center;
}
.inline .muted {
  white-space: nowrap;
}
.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.row3 {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 8px;
}
.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.switch {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
  cursor: pointer;
}

.notice {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: hsl(var(--muted));
  font-size: 0.9rem;
}
.notice span {
  flex: 1;
}
.notice.warn {
  background: hsl(var(--warn-bg));
  color: hsl(var(--warn-fg));
}

/* ---------- hero ---------- */

.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.hero {
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.hero .unit {
  font-size: 1rem;
  font-weight: 500;
  margin-left: 4px;
  color: hsl(var(--muted-foreground));
}
.badge {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  background: hsl(var(--muted));
  white-space: nowrap;
}
.level-cheap {
  color: hsl(var(--good));
}
.level-expensive {
  color: hsl(var(--bad));
}

/* ---------- machine picker ---------- */

.machines {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.machine {
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  padding: 10px 12px;
}
.machine.on {
  border-color: hsl(var(--primary) / 0.6);
  background: hsl(var(--accent) / 0.5);
}
.mrow {
  display: flex;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  min-height: 40px;
}
.mtext {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.mtext small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.micon {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex: none;
  color: hsl(var(--foreground));
  background: hsl(var(--muted));
  box-shadow: inset 0 -3px 0 var(--c);
}
.msub {
  margin-top: 10px;
  padding-left: 34px;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.chip {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  background: hsl(var(--card));
  cursor: pointer;
  font-size: 0.9rem;
}
.chip small {
  color: hsl(var(--muted-foreground));
}
.chip.checked {
  border-color: hsl(var(--primary));
}

.times {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

/* ---------- plan result ---------- */

.summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.big-num {
  font-size: 1.5rem;
  font-weight: 700;
}
.items {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.item {
  border: 1px solid hsl(var(--border));
  border-left: 4px solid var(--c);
  border-radius: calc(var(--radius) - 2px);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.item-head {
  display: flex;
  gap: 10px;
  align-items: center;
}
.item-time {
  font-size: 1.15rem;
  font-weight: 650;
}
.item-time .icon {
  color: hsl(var(--muted-foreground));
}
.instr {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px;
  border-radius: calc(var(--radius) - 4px);
  background: hsl(var(--muted));
}
.instr > .icon {
  margin-top: 2px;
}
.item-cost {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 0.9rem;
}
details summary {
  cursor: pointer;
  color: hsl(var(--primary));
  font-size: 0.9rem;
  padding: 4px 0;
}

table.alts,
table.modes {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-top: 6px;
}
.alts th,
.alts td,
.modes th,
.modes td {
  text-align: left;
  padding: 6px 4px;
  border-bottom: 1px solid hsl(var(--border));
}
.alts th,
.modes th {
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  font-size: 0.8rem;
}
.alts .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.alts tr.chosen td {
  font-weight: 600;
}
.alts tr.chosen .icon {
  width: 14px;
  height: 14px;
  margin-right: 4px;
}
.modes td:nth-child(2),
.modes td:nth-child(3) {
  width: 84px;
}
.modes td:last-child {
  width: 40px;
}
.modes input {
  min-height: 36px;
  padding: 6px 8px;
}

/* ---------- prices ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.stat .icon {
  width: 14px;
  height: 14px;
}

/* ---------- machines ---------- */

.intro {
  margin: 0;
}
.mcard summary {
  display: flex;
  gap: 12px;
  align-items: center;
  list-style: none;
  color: hsl(var(--foreground));
  font-size: 1rem;
}
.mcard summary::-webkit-details-marker {
  display: none;
}
.mcard[open] summary {
  margin-bottom: 12px;
}
.icon-pick {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* ---------- chart ---------- */

.chart-host {
  margin-top: 10px;
}
.chart-wrap {
  position: relative;
}
.chart {
  display: block;
  width: 100%;
  height: auto;
  touch-action: pan-y;
  overflow: visible;
}
.chart .grid {
  stroke: hsl(var(--border));
  stroke-width: 1;
}
.chart .grid.zero {
  stroke: hsl(var(--muted-foreground));
}
.chart .daysep {
  stroke: hsl(var(--muted-foreground));
  stroke-dasharray: 2 3;
}
.chart .tick {
  fill: hsl(var(--muted-foreground));
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.chart .tick.day {
  font-weight: 600;
}
.chart .line {
  fill: none;
  stroke: hsl(var(--series-1));
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chart .area {
  fill: hsl(var(--series-1) / 0.1);
}
.chart .past {
  fill: hsl(var(--past) / 0.12);
}
.chart .now {
  stroke: hsl(var(--foreground));
  stroke-width: 1.5;
}
.chart .now-label {
  fill: hsl(var(--foreground));
  font-weight: 600;
}
.chart .lane-label {
  fill: hsl(var(--foreground));
  font-size: 11px;
}
.chart .crossline {
  stroke: hsl(var(--muted-foreground));
  stroke-width: 1;
}
.chart .crossdot {
  fill: hsl(var(--series-1));
  stroke: hsl(var(--card));
  stroke-width: 2;
}
.chart .hit {
  fill: transparent;
  cursor: crosshair;
}
.tooltip {
  position: absolute;
  transform: translate(-50%, calc(-100% - 10px));
  pointer-events: none;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  box-shadow: 0 4px 16px hsl(240 10% 10% / 0.15);
  white-space: nowrap;
  z-index: 2;
}
.tip-time {
  font-weight: 600;
}
.tip-val {
  font-size: 0.95rem;
  font-weight: 700;
}
.tip-run {
  margin-top: 2px;
}

.spin {
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 420px) {
  .times,
  .row3 {
    grid-template-columns: 1fr;
  }
  .hero {
    font-size: 2.2rem;
  }
  .msub {
    padding-left: 0;
  }
}

.sources {
  margin: 0;
  padding-left: 18px;
}
.sources a {
  color: hsl(var(--primary));
  overflow-wrap: anywhere;
}
.modes td small {
  display: block;
  margin-top: 2px;
}

/* ---------- runs ---------- */

.machine.running {
  border-style: dashed;
}
.dot-running {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: hsl(var(--good));
  flex: none;
  margin: 0 6px;
}
.mfoot {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}
.startform {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid hsl(var(--border));
}
.startform input[type='time'] {
  width: auto;
  flex: 1;
}
.runs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}
.run {
  display: flex;
  gap: 10px;
  align-items: center;
}
.run-text {
  flex: 1;
  min-width: 0;
}
.run-cost {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.progress {
  height: 6px;
  border-radius: 3px;
  background: hsl(var(--muted));
  margin-top: 6px;
  overflow: hidden;
}
.progress span {
  display: block;
  height: 100%;
  background: var(--c);
  border-radius: 3px;
}
.item .mark {
  align-self: flex-start;
}

.row3.row2 {
  grid-template-columns: 1fr 1fr;
}
