/* Палитрата е същата като в двигателя (engine/palette.js). */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #e3e6ea;
  --grid: #7a8493;
  --text: #14181f;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;

  --low-bg: #dcfce7;   --low-fg: #14532d;
  --high-bg: #fee2e2;  --high-fg: #7f1d1d;
  --miss-bg: #eceef1;  --miss-fg: #6b7280;
  --dev-bg: #fef3c7;   --dev-fg: #78350f;

  /* Квадратчетата на легендата са 15x12 пиксела — бледият цвят на клетките
     на такъв размер не се разчита. Затова са с наситен вариант от същия
     цвят, а самите клетки остават светли, за да се чете текстът в тях. */
  --low-mark: #6ee7a0;
  --high-mark: #f79b9b;
  --miss-mark: #c2c8d1;
  --dev-mark: #f6cb52;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
}

[hidden] { display: none !important; }

/* ----------------------------------------------------------------- лента */
.top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 22px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { cursor: pointer; }
.brand-name { display: block; font-size: 17px; font-weight: 600; }
.brand-sub { display: block; font-size: 12px; color: var(--muted); }
.top nav { display: flex; align-items: center; gap: 14px; }
.top nav button.link {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font: inherit; padding: 4px 2px;
}
.top nav button.link:hover { color: var(--accent); }
.who { color: var(--text); font-weight: 600; }

/* ----------------------------------------------------------------- макет */
.wrap { max-width: 1000px; margin: 22px auto; padding: 0 18px; }
.wide { max-width: 1700px; margin: 22px auto; padding: 0 18px; }
.centred { max-width: 420px; margin: 8vh auto; padding: 0 18px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px 0; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 18px 20px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 14px; font-size: 16px; }
.card h1 { margin: 0 0 4px; font-size: 20px; }
.sub { margin: 0 0 18px; color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.head-row { display: flex; align-items: center; justify-content: space-between;
            gap: 16px; flex-wrap: wrap; }

.grid-two { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.grid-three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 760px) {
  .grid-two, .grid-three { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------- полета */
label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--muted); }
label.inline-label { display: inline-block; margin: 0; }

input[type=text], input[type=email], input[type=password], input[type=search],
input[type=file], input[type=number], select {
  width: 100%; padding: 8px 10px; font: inherit;
  border: 1px solid var(--line); border-radius: 7px; background: var(--card);
  color: var(--text);
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input[type=range] { width: 100%; }
.inline input, .inline select { width: auto; }

button, .button {
  font: inherit; padding: 8px 15px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line); background: #eef0f3; color: var(--text);
  text-decoration: none; display: inline-block;
}
button:hover, .button:hover { background: #e6e9ee; }
button[disabled] { opacity: 0.55; cursor: default; }
.accent { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.accent:hover:not([disabled]) { background: var(--accent-dark); }
.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 5px 9px; }
.ghost:hover { background: #f0f2f5; color: var(--text); }
.danger:hover { color: #b91c1c; }
.inline { display: inline-flex; gap: 5px; align-items: center; }

.alert { padding: 10px 13px; border-radius: 8px; margin: 0 0 14px; }
.error { background: var(--high-bg); color: var(--high-fg); }
.notice { background: var(--low-bg); color: var(--low-fg); }
.copy { width: 100%; margin-top: 8px; font-family: ui-monospace, Consolas, monospace;
        font-size: 12px; }

/* Показва се, докато браузърът чете файловете и смята. */
.busy { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.spinner {
  width: 16px; height: 16px; border: 2px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------------------------------------------------- таблици */
.list { width: 100%; border-collapse: collapse; }
.list th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 600;
  padding: 7px 9px; border-bottom: 1px solid var(--line);
}
.list td { padding: 7px 9px; border-bottom: 1px solid var(--line); }
.list tr:last-child td { border-bottom: none; }
.list .num { text-align: right; }
.list tr.off td { color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; }
.link-cell { color: var(--accent); cursor: pointer; text-decoration: underline; }

.tag { font-size: 12px; padding: 2px 8px; border-radius: 20px; }
.tag.ok { background: var(--low-bg); color: var(--low-fg); }
.tag.wait { background: var(--dev-bg); color: var(--dev-fg); }
.tag.off { background: var(--miss-bg); color: var(--miss-fg); }

/* ------------------------------------------------- лентата над матрицата */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  padding-bottom: 14px; margin-bottom: 4px; border-bottom: 1px solid var(--line);
}
.toolbar .group { display: flex; align-items: center; gap: 7px; }
.toolbar .label { color: var(--muted); font-size: 13px; }
.toolbar input[type=range] { width: 100px; }
.toolbar input[type=search] { width: 160px; }
.toolbar select { width: auto; }

.seg {
  padding: 6px 13px; border: 1px solid var(--line); background: var(--card);
  color: var(--muted); font-weight: 600;
}
.seg.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* -------------------------------------------------------------- матрица */
/* Заглавният ред стои горе при превъртане.
   За да сработи position: sticky, областта трябва сама да превърта — затова
   има таван на височината. Без него sticky се лепи за област, която никога
   не превърта вертикално, и просто не се вижда. */
.matrix-scroll {
  overflow: auto;
  max-height: calc(100vh - 220px);
  min-height: 240px;
}
.matrix { border-collapse: collapse; width: 100%; font-size: 13px; }
.matrix th, .matrix td {
  /* Плътна решетка, както в Excel — по искане на потребителя. */
  border: 1px solid var(--grid);
  padding: 5px 8px; white-space: nowrap;
}
.matrix thead th {
  background: #eef0f3; font-size: 12px;
  position: sticky; top: 0; z-index: 2;
  /* При border-collapse рамките на залепен ред изчезват при превъртане —
     затова се рисуват със сянка, която пътува с клетката. */
  box-shadow: inset 0 0 0 1px var(--grid);
  border-color: transparent;
}
.matrix .pos { text-align: left; white-space: normal; min-width: 320px; }
.matrix .unit { text-align: left; color: var(--muted); }
.matrix .num { text-align: right; }
.matrix .participant { font-weight: 600; }

.matrix .low { background: var(--low-bg); color: var(--low-fg); }
.matrix .high { background: var(--high-bg); color: var(--high-fg); }
.matrix .missing { background: var(--miss-bg); color: var(--miss-fg); text-align: center; }
.matrix .deviating { background: var(--dev-bg); color: var(--dev-fg); }

.legend { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
          font-size: 12px; color: var(--muted); margin: 12px 0 0; }
.legend .right { margin-left: auto; }
.swatch { display: inline-block; width: 15px; height: 12px; border: 1px solid var(--grid);
          border-radius: 2px; }
.swatch.low { background: var(--low-mark); }
.swatch.high { background: var(--high-mark); }
.swatch.missing { background: var(--miss-mark); }
.swatch.deviating { background: var(--dev-mark); }

/* ------------------------------------------------------------ долна лента */
.chips { display: flex; flex-wrap: wrap; gap: 9px; padding: 0 2px 26px; }
.chip { background: var(--card); border: 1px solid var(--line);
        padding: 6px 12px; border-radius: 20px; font-size: 13px; }
.chip.strong { background: #eaf0fe; border-color: #cfdcfb; color: var(--accent-dark); font-weight: 600; }
.chip.warn { background: var(--dev-bg); border-color: #f3dfa4; color: var(--dev-fg); }

/* -------------------------------------------------------------- графики */
.tabs { display: flex; align-items: center; gap: 8px; }
.tab {
  padding: 7px 15px; border-radius: 7px; border: 1px solid transparent;
  color: var(--muted); font-weight: 600; background: none; cursor: pointer;
}
.tab:hover { background: #f0f2f5; color: var(--text); }
.tab.on { background: var(--bg); border-color: var(--line); color: var(--accent); }

.who-is-who { display: flex; flex-wrap: wrap; gap: 16px; margin: 14px 0 0; font-size: 13px; }
.key { display: inline-flex; align-items: center; }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(430px, 1fr));
          gap: 18px; align-items: start; }
@media (max-width: 940px) { .charts { grid-template-columns: 1fr; } }
.chart h3 { margin: 0 0 3px; font-size: 15px; }
.chart .note { margin: 0 0 12px; color: var(--muted); font-size: 12px; }
.chart svg { display: block; max-width: 100%; height: auto; }

/* Показалец, че програмата смята.
   Стои извън #view, защото върху #view се прилага filter, а filter прави
   нов контекст и „fixed“ вътре в него престава да е спрямо екрана. */
#thinking {
  position: fixed; z-index: 60;
  display: flex; align-items: center; gap: 10px;
  background: var(--accent); color: #fff; font-weight: 600;
  border-radius: 20px; padding: 8px 16px; font-size: 13px;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.35);
}
#thinking[hidden] { display: none; }
#thinking .spinner { border-color: rgba(255, 255, 255, 0.35); border-top-color: #fff; }

/* Докато смята, съдържанието посивява и не приема натискания — вижда се, че
   показаното е старо и че програмата работи. */
#view {
  transition: filter 0.15s ease, opacity 0.15s ease;
}
body.thinking #view {
  filter: grayscale(1);
  opacity: 0.5;
  pointer-events: none;
  user-select: none;
}

/* -------------------------------------------------------- преглед на двойки */
.pair {
  border: 1px solid var(--line); border-radius: 9px;
  padding: 12px 14px; margin-bottom: 10px; background: var(--card);
}
.pair.done { border-color: var(--low-bg); background: #fbfdfb; }
.pair.split { border-color: var(--high-bg); background: #fdfbfb; }
.pair-side { padding: 3px 0; }
.pair-side .who { font-weight: normal; color: var(--muted); font-size: 12px; }
.pair .diff { background: var(--dev-bg); color: var(--dev-fg);
              padding: 1px 6px; border-radius: 4px; font-weight: 600; }
.pair-foot { display: flex; align-items: center; gap: 8px;
             margin-top: 10px; flex-wrap: wrap; }
.pair-foot .score { color: var(--muted); font-size: 12px; margin-right: auto; }
#pending:not(:empty) {
  display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 5px;
  background: var(--dev-bg); color: var(--dev-fg);
  border-radius: 10px; font-size: 11px; line-height: 17px; text-align: center;
}
