:root {
  --bg: #f3f6f4;
  --ink: #14201b;
  --muted: #5c6b64;
  --paper: #fff;
  --line: #e2ebe6;
  --accent: #1c5c45;
  --soft: #eef6f2;
  --charge: #1f6f54;
  --discharge: #b45309;
  --danger: #8f2d2d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 15px/1.45 system-ui, sans-serif;
}

main { width: min(1180px, calc(100% - 20px)); margin: 12px auto 20px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.logout { display: flex; align-items: center; gap: 10px; margin: 0; flex: none; }
.logout span { color: var(--muted); font-size: 0.9rem; }
.logout form { margin: 0; }
a.ghost.link {
  display: inline-block;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 10px;
}
.admin-tabs {
  display: flex;
  gap: 4px;
  width: min(240px, 100%);
  margin: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}
.admin-tabs a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--ink);
}
.admin-tabs a.is-active { background: var(--accent); color: #fff; }
.add-user, .model-form {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 0.8fr) auto;
  gap: 10px;
  align-items: end;
}
.model-form { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
td:has(.train-status) { white-space: normal; vertical-align: middle; }
.train-status {
  box-sizing: border-box;
  width: 26rem;
  height: calc(1.3em * 2 + 12px);
  margin: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.3;
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.train-status.is-ok { color: var(--accent); border-color: var(--accent); }
.train-status.is-error { color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: 0.7; }
.model-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.model-actions form { margin: 0; }
.invite-link { margin: 0 0 12px; }
.invite-link input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}
.add-user input, .add-user select, .model-form input, .model-form select {
  width: 100%;
  margin-top: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}
.users td form { margin: 0; }
.users button { padding: 8px 12px; }
.users .hint { margin: 0; }
.login { max-width: 460px; }
.login input, .login-panel input { width: 100%; margin-top: 4px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.login button { margin-top: 8px; }
.login .hint { margin-top: 0; }
.brand img { width: 32px; height: 32px; flex: none; }
.brand .lede { margin: 0; }
.brand h1 .forecast { font-weight: 550; color: var(--muted); font-size: 0.78em; margin-left: 0.15em; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.15rem; margin-bottom: 2px; }
h3 { margin-top: 14px; margin-bottom: 6px; font-size: 0.95rem; color: var(--ink); font-weight: 650; }
.lede, #attribution { color: var(--muted); margin: 2px 0 0; font-size: 0.9rem; }
.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  margin-top: 12px;
}
.controls { position: sticky; top: 12px; display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.workspace > * { min-width: 0; }
.controls .group-label {
  margin: 2px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 650;
}
.controls .knobs { grid-template-columns: 1fr 1fr; gap: 8px; }
.controls .hours { width: 100%; }
.controls .hours button { flex: 1; }
.controls #run-button { width: 100%; padding: 9px 12px; }
.price-line { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 8px; align-items: end; }
.price-line input[type="file"] { width: 100%; margin-top: 4px; font-size: 0.78rem; }
.controls .file-actions { margin-top: 0; }

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(20, 32, 27, 0.04);
  padding: 10px 12px;
  margin-top: 8px;
}

label { display: block; margin-bottom: 0; font-weight: 600; font-size: 0.82rem; }
.row, .control-row, .file-row { display: flex; gap: 8px; align-items: end; }
.control-row { margin-bottom: 8px; }
.control-row .grow { flex: 1; min-width: 0; }
.head { justify-content: space-between; align-items: flex-start; }

input, button, select { font: inherit; }
#place-input, .knobs input, .controls select, .price-line select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.file-row { margin-top: 8px; flex-wrap: wrap; }
.file-row label { margin: 0; }
.file-row input[type="file"] { margin-top: 2px; font-size: 0.85rem; }
.file-row .unit { width: 110px; }
.file-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.file-actions a { font-size: 0.85rem; }

.knobs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.knobs label { margin: 0; }

.hours {
  display: flex;
  width: fit-content;
  margin: 0;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f3f8f5;
}
.hours button, .choice button { background: transparent; color: var(--ink); padding: 6px 10px; border-radius: 999px; }
.hours .is-active, .choice .is-active { background: var(--accent); color: #fff; }
.choice {
  display: flex;
  width: 100%;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f3f8f5;
}
.choice button { flex: 1; }
.price-extra { display: flex; flex-direction: column; gap: 8px; }
.price-extra[hidden], #price-paste[hidden], #price-file-box[hidden] { display: none; }
.or { margin: 0; color: var(--muted); font-size: 0.8rem; }
#price-unit-field select { margin-top: 4px; }

.hint { color: var(--muted); font-weight: 400; font-size: 0.88rem; margin: 6px 0 0; }
#prices-input {
  width: 100%;
  min-height: 72px;
  margin-top: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  resize: vertical;
}
.paste { margin-top: 6px; }
.paste summary { cursor: pointer; color: var(--muted); }
.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 7px 12px;
  cursor: pointer;
}

ul { list-style: none; margin: 12px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; }
li { padding: 10px 12px; cursor: pointer; }
li:hover { background: var(--soft); }
.is-error { color: var(--danger); }
.is-ok { color: var(--accent); }

#chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.chip {
  flex: 0 1 auto;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--soft);
  white-space: nowrap;
}
.chip span { display: block; color: var(--muted); font-size: 0.72rem; }
.chip strong { display: block; font-size: 0.95rem; }
.chip em { display: none; }

.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.chart-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 6px; }
.chart { height: 180px; margin: 0; }
.chart-wide { height: 220px; margin: 0 0 8px; }
.table-wrap { max-height: 280px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { position: sticky; top: 0; background: #f6faf8; font-size: 0.75rem; color: var(--muted); }
.charge { color: var(--charge); font-weight: 600; }
.origin-dam { color: var(--charge); font-weight: 600; }
.origin-yesterday { color: var(--discharge); font-weight: 600; }
.discharge { color: var(--discharge); font-weight: 600; }
.night { color: #345c8c; }
.off-peak { color: #3d6b54; }
.peak { color: var(--discharge); font-weight: 600; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .controls { position: static; }
  .row, .head, .topbar, .add-user, .model-form, .control-row, .file-row { flex-direction: column; align-items: stretch; }
  .add-user { grid-template-columns: 1fr; }
  .knobs, .controls .knobs { grid-template-columns: 1fr 1fr; }
  .file-row .unit, .controls .file-row .unit { width: auto; }
  .chart-grid, .chart-grid.two { grid-template-columns: 1fr; }
  .chart, .chart-wide { height: 180px; }
}
