:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #edf4f7;
  --text: #172026;
  --muted: #64717a;
  --line: #d9e0e4;
  --green: #24745d;
  --green-2: #5a9f83;
  --blue: #286f9c;
  --amber: #b77928;
  --danger: #b74141;
  --purple: #7554b7;
  --slate: #596774;
  --shadow: 0 18px 45px rgba(23, 32, 38, 0.08);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 64px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand, .topbar nav, .topbar form { display: flex; align-items: center; gap: 14px; }

.brand { font-weight: 800; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
}

.topbar nav a, .topbar nav button {
  color: var(--muted);
  background: transparent;
  border: 0;
  font: inherit;
  cursor: pointer;
}

.topbar nav a:hover, .topbar nav button:hover { color: var(--text); }

.shell {
  width: min(1480px, calc(100% - 40px));
  margin: 18px auto 48px;
}

.page-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: 12px;
}

h1, h2 { margin: 0; line-height: 1.08; letter-spacing: 0; }
h1 { font-size: clamp(30px, 4vw, 52px); }
h2 { font-size: 20px; }
.muted { color: var(--muted); margin: 6px 0 0; }

.workbench-head {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.workbench-top {
  display: grid;
  grid-template-columns: minmax(260px, .85fr) minmax(620px, 1.45fr);
  gap: 18px;
  align-items: end;
}

.workbench-title h1 {
  font-size: clamp(28px, 3vw, 42px);
}

.compact-form { justify-self: end; width: 100%; }

.summary-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.summary-strip div {
  display: grid;
  gap: 3px;
  min-height: 76px;
  padding: 10px 14px;
  border-right: 1px solid var(--line);
  background: #fbfcfb;
}

.summary-strip div:last-child { border-right: 0; }

.summary-strip span,
.summary-strip em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.summary-strip strong {
  font-size: 27px;
  line-height: 1;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.status-count {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.status-count:hover { transform: translateY(-1px); }
.status-count:has(input:checked) { box-shadow: inset 0 0 0 2px currentColor; }
.status-count input {
  width: 16px;
  min-width: 16px;
  height: 16px;
  min-height: 16px;
  margin: 0;
  accent-color: currentColor;
}
.status-count span {
  display: grid;
  min-width: 0;
  gap: 1px;
}
.status-count b,
.status-count em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-count em {
  color: currentColor;
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  opacity: .72;
}
.status-count strong { font-size: 18px; line-height: 1; }

tr.hidden-by-status { display: none; }

.urgent-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding-top: 2px;
}

.urgent-strip span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.urgent-strip strong {
  flex: 0 0 auto;
  max-width: 280px;
  overflow: hidden;
  padding: 6px 9px;
  border-radius: 999px;
  background: #fff7ed;
  color: #8a4a16;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.urgent-strip b { color: var(--danger); }

.period-form {
  display: flex;
  align-items: end;
  gap: 10px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.period-form.compact-form {
  padding: 0;
  border: 0;
  background: transparent;
}

.filling-form select { min-width: 320px; }
.filling-form input { min-width: 86px; width: 86px; }

.actions-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.action-toolbar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf8;
}

label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
input, select {
  min-height: 40px;
  min-width: 110px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}

.button.primary { background: var(--green); color: #fff; border-color: var(--green); }

.button.ai-calc-button {
  background: #172026;
  color: #fff;
  border-color: #172026;
}

.button.ghost-button {
  min-width: 54px;
  padding: 0 11px;
  background: #fff;
}

.button.pdf-ghost {
  background: #fff7ed;
  color: #8a4a16;
  border-color: #fed7aa;
}

.alert {
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid #e7b4b4;
  border-radius: 8px;
  background: #fff3f3;
  color: var(--danger);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpis.wide {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

.metric, .panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric { padding: 18px; }
.metric span { display: block; color: var(--muted); font-weight: 700; }
.metric strong { display: block; margin-top: 6px; font-size: 34px; line-height: 1; }
.metric em {
  display: block;
  min-height: 18px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
}
.metric em.up { color: var(--green); }
.metric em.down { color: var(--danger); }
.metric em.neutral { color: var(--muted); }
.metric.accent { background: var(--surface-2); border-color: #cad8ce; }

.up { color: var(--green); font-weight: 800; }
.down { color: var(--danger); font-weight: 800; }
.neutral { color: var(--muted); font-weight: 800; }

.panel { padding: 18px; margin-bottom: 18px; }

.panel-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.ai-report {
  background: linear-gradient(180deg, #ffffff, #f8fbfa);
}

.ai-calculation {
  background: linear-gradient(180deg, #ffffff, #f7fbff);
  border-color: #cfe2f2;
}

.calc-kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(100px, 1fr));
  gap: 8px;
}

.calc-kpis div {
  display: grid;
  gap: 3px;
  min-width: 100px;
  padding: 12px 14px;
  border: 1px solid #cfe2f2;
  border-radius: 8px;
  background: #f2f8fc;
}

.calc-kpis span,
.calc-kpis em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.calc-kpis strong {
  font-size: 30px;
  line-height: 1;
}

.ai-score {
  display: grid;
  place-items: center;
  min-width: 118px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef6f3;
}

.ai-score span,
.ai-score em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.ai-score strong {
  font-size: 34px;
  line-height: 1;
}

.ai-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(260px, .85fr);
  gap: 14px;
}

.ai-summary,
.ai-points,
.opportunity-list div {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ai-report h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.ai-summary p,
.ai-summary strong {
  display: block;
  margin: 0;
}

.ai-summary strong {
  margin-top: 10px;
  color: var(--green);
}

.ai-points ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 18px;
}

.ai-actions,
.ai-opportunities {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.ai-actions .table-wrap {
  max-height: none;
}

.ai-actions table {
  min-width: 860px;
}

.ai-actions th,
.ai-actions td {
  text-align: left;
  white-space: normal;
}

.ai-actions td:nth-child(2) {
  white-space: nowrap;
}

.ai-priority {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #fff7ed;
  color: #8a4a16;
  font-size: 12px;
  font-weight: 900;
}

.opportunity-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.opportunity-list div {
  display: grid;
  gap: 5px;
}

.opportunity-list span,
.opportunity-list em {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
}

.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.triple {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.trend {
  display: grid;
  grid-template-columns: repeat(12, minmax(48px, 1fr));
  gap: 10px;
  height: 180px;
  align-items: end;
}

.trend-item {
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 6px;
  height: 100%;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.trend-bar {
  align-self: end;
  width: 100%;
  border-radius: 8px 8px 2px 2px;
  background: linear-gradient(180deg, var(--amber), var(--green-2));
}

.trend-item b { color: var(--text); font-size: 12px; }
.trend-item em { color: var(--muted); font-size: 11px; font-style: normal; }

.comparison {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.comparison div {
  min-height: 90px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.comparison span,
.comparison em {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
}

.comparison strong {
  display: block;
  margin: 6px 0;
  font-size: 22px;
  line-height: 1.1;
}

.daily-bars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(22px, 1fr));
  gap: 8px;
  height: 210px;
  align-items: end;
}

.daily-item {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 6px;
  height: 100%;
  text-align: center;
}

.daily-item span {
  align-self: end;
  min-height: 4px;
  border-radius: 8px 8px 2px 2px;
  background: linear-gradient(180deg, var(--green), var(--blue));
}

.daily-item small {
  color: var(--muted);
  font-size: 11px;
}

.year-bars {
  display: grid;
  grid-template-columns: repeat(12, minmax(54px, 1fr));
  gap: 12px;
  min-height: 230px;
  align-items: end;
}

.year-month {
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 7px;
  height: 230px;
  text-align: center;
}

.year-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  align-items: end;
  min-height: 150px;
}

.year-pair span {
  align-self: end;
  min-height: 4px;
  border-radius: 8px 8px 2px 2px;
}

.year-pair .prior,
.legend .prior {
  background: var(--amber);
}

.year-pair .current,
.legend .current {
  background: var(--green);
}

.year-month small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.year-month strong {
  font-size: 12px;
}

.legend {
  display: flex;
  justify-content: flex-end;
  gap: 16px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  display: inline-block;
  width: 18px;
  height: 10px;
  border-radius: 999px;
}

.hour-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.hour-cell {
  display: grid;
  gap: 4px;
  min-height: 58px;
  padding: 10px;
  border: 1px solid rgba(39, 111, 159, 0.25);
  border-radius: 8px;
  background: rgba(39, 111, 159, calc(0.08 + (var(--heat) * 0.34)));
}

.hour-cell span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.hour-cell strong {
  font-size: 18px;
  line-height: 1;
}

.bar-list { display: grid; gap: 14px; }
.bar-list.compact { gap: 11px; }
.bar-row { display: grid; gap: 7px; }
.bar-label { display: flex; justify-content: space-between; gap: 14px; font-weight: 800; }
.bar-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-meta { color: var(--muted); font-size: 12px; }
.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7ebe8;
}
.bar-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}
.bar-track.machine span { background: var(--blue); }
.bar-track.group span { background: var(--amber); }
.bar-track.place span { background: var(--green-2); }
.bar-track.customer span { background: var(--danger); }

.mini-table {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.mini-table div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.mini-table span {
  overflow: hidden;
  color: var(--text);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-table strong {
  color: var(--danger);
}

.mini-table em {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.action-list b {
  display: inline-block;
  min-width: 42px;
  color: var(--blue);
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status.empty, .status-count.empty { background: #fee2e2; border-color: #fecaca; color: #991b1b; }
.status.fill, .status-count.fill { background: #fef3c7; border-color: #fde68a; color: #92400e; }
.status.max, .status-count.max { background: #ede9fe; border-color: #ddd6fe; color: #5b21b6; }
.status.ok, .status-count.ok { background: #dcfce7; border-color: #bbf7d0; color: #166534; }
.status.over, .status-count.over { background: #dbeafe; border-color: #bfdbfe; color: #1d4ed8; }
.status.slow, .status-count.slow { background: #f1f5f9; border-color: #cbd5e1; color: #475569; }

.row-empty td:first-child { box-shadow: inset 4px 0 #dc2626; }
.row-fill td:first-child { box-shadow: inset 4px 0 #d97706; }
.row-max td:first-child { box-shadow: inset 4px 0 #7c3aed; }
.row-ok td:first-child { box-shadow: inset 4px 0 #16a34a; }
.row-over td:first-child { box-shadow: inset 4px 0 #2563eb; }
.row-slow td:first-child { box-shadow: inset 4px 0 #64748b; }

.strong {
  color: var(--green);
  font-weight: 900;
}

.change-up { color: var(--green); }
.change-down { color: var(--danger); }
.change-zero { color: var(--muted); }

.filling-table table { min-width: 1060px; }
.filling-table td:nth-child(3) { min-width: 260px; }
.filling-table th:nth-child(3),
.filling-table td:nth-child(3) {
  text-align: left;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: auto;
  max-height: 620px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table { width: 100%; border-collapse: collapse; min-width: 760px; }
.compact-table table { min-width: 520px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; white-space: normal; }
thead th { position: sticky; top: 0; background: #f8faf8; color: var(--muted); font-size: 12px; text-transform: uppercase; }
tbody tr:hover { background: #f9fbf9; }

.sort-button {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  text-align: inherit;
  text-transform: inherit;
}

th:first-child .sort-button,
th:nth-child(3) .sort-button {
  justify-content: flex-start;
}

.sort-button::after {
  content: "-";
  color: #9aa5ad;
  font-size: 11px;
}

th[aria-sort="ascending"] .sort-button::after { content: "^"; color: var(--green); }
th[aria-sort="descending"] .sort-button::after { content: "v"; color: var(--green); }

.auth-shell {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 140px);
}

.auth-card {
  width: min(440px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-card form, .form-stack { display: grid; gap: 14px; }
.auth-card input, .form-stack input { width: 100%; }
.field-validation-error, .validation-summary-errors { color: var(--danger); font-size: 13px; }
.auth-links { display: flex; justify-content: space-between; gap: 12px; color: var(--green); font-weight: 700; }
.checkbox-line { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.checkbox-line input { min-width: auto; width: auto; min-height: auto; }

@media (max-width: 920px) {
  .page-head, .period-form { align-items: stretch; flex-direction: column; }
  .workbench-top { grid-template-columns: 1fr; align-items: stretch; }
  .compact-form { justify-self: stretch; }
  .period-form.compact-form {
    align-items: end;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .compact-form label:first-child { flex: 1 1 320px; }
  .compact-form label:not(:first-child) { flex: 1 1 84px; }
  .compact-form .actions-field { flex: 1 1 100%; }
  .action-toolbar { flex-wrap: wrap; }
  .summary-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .summary-strip div { border-bottom: 1px solid var(--line); }
  .summary-strip div:nth-child(3),
  .summary-strip div:nth-child(6) { border-right: 0; }
  .summary-strip div:nth-child(n + 4) { border-bottom: 0; }
  .status-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ai-grid,
  .opportunity-list { grid-template-columns: 1fr; }
  .filling-form select,
  .filling-form input { width: 100%; min-width: 0; }
  .kpis, .kpis.wide, .split, .triple { grid-template-columns: 1fr; }
  .trend { grid-template-columns: repeat(6, minmax(44px, 1fr)); height: 260px; }
  .year-bars { grid-template-columns: repeat(6, minmax(44px, 1fr)); }
  .hour-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .topbar { padding: 0 16px; }
  .topbar nav { gap: 10px; font-size: 13px; }
  .brand span:last-child { display: none; }
  .shell { width: min(100% - 24px, 1480px); margin-top: 18px; }
  .workbench-head { padding: 12px; }
  .workbench-title h1 { font-size: 27px; }
  .period-form.compact-form { flex-direction: column; }
  .compact-form label:first-child,
  .compact-form label:not(:first-child),
  .compact-form .actions-field,
  .compact-form .button {
    flex: 1 1 auto;
    width: 100%;
  }
  .action-toolbar { display: grid; grid-template-columns: 1fr 1fr; }
  .action-toolbar .primary,
  .action-toolbar .ai-calc-button { grid-column: span 2; }
  .summary-strip { grid-template-columns: 1fr; }
  .summary-strip div,
  .summary-strip div:nth-child(2),
  .summary-strip div:nth-child(3),
  .summary-strip div:nth-child(6) {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .summary-strip div:last-child { border-bottom: 0; }
  .status-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { gap: 10px; }
  .metric strong { font-size: 28px; }
  .comparison { grid-template-columns: 1fr; }
  .daily-bars { gap: 5px; }
  .year-bars { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .year-month { height: 190px; }
  .hour-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
