/* КАРМАН Analytics — тёмный интерфейс, акцент — жёлтый КАРМАН. Mobile first. */
:root {
  --bg: #0f0f10;
  --surface: #1a1a1c;
  --surface-2: #232326;
  --line: #2e2e33;
  --text: #f4f4f2;
  --muted: #9b9ba1;
  --yellow: #ffd200;
  --yellow-dim: #6b5a0a;
  --green: #3ecf8e;
  --red: #ff5a5f;
  --orange: #ffb020;
  --radius: 16px;
  --gap: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, select, input { font: inherit; color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 10px;
  background: rgba(15, 15, 16, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; flex-direction: column; line-height: 1; }
.brand__name { font-weight: 900; font-size: 22px; letter-spacing: 0.06em; color: var(--yellow); }
.brand__sub { font-size: 12px; color: var(--muted); letter-spacing: 0.2em; text-transform: uppercase; margin-top: 3px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; }

.select, .input {
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 30px 8px 12px;
  min-height: 38px;
  max-width: 46vw;
  background-image: linear-gradient(45deg, transparent 50%, var(--yellow) 50%), linear-gradient(135deg, var(--yellow) 50%, transparent 50%);
  background-position: calc(100% - 16px) 16px, calc(100% - 11px) 16px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.input { padding-right: 12px; background-image: none; }
.select:focus, .input:focus { outline: 2px solid var(--yellow); outline-offset: 1px; }

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 16px;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 7px 14px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tab--active { background: var(--yellow); color: #111; border-color: var(--yellow); font-weight: 700; }

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 16px calc(env(safe-area-inset-bottom) + 40px);
}

.loader, .empty { color: var(--muted); padding: 30px 0; text-align: center; }

.banner {
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: var(--gap);
  background: #2a2208;
  border: 1px solid var(--yellow-dim);
  color: #ffe680;
}
.banner--error { background: #2a1011; border-color: #6b2426; color: #ffb3b5; }
.banner--demo { background: #14213a; border-color: #28406b; color: #b7cdf5; }

.section { margin: 22px 0 8px; }
.section__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.section__title { font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin: 0; font-weight: 700; }

.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--1 { grid-template-columns: 1fr; }
@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--1 { grid-template-columns: 1fr; }
}
/* Карточки смен длинные: на телефоне по одной в ряд, на широком экране — по две. */
.grid--shifts { grid-template-columns: 1fr; }
@media (min-width: 720px) {
  .grid--shifts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}
.card--click { cursor: pointer; }
.card--click:active { transform: scale(0.99); }

.metric__label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
.metric__value { font-size: 24px; font-weight: 800; margin: 6px 0 2px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric--big .metric__value { color: var(--yellow); font-size: 28px; }
.metric__secondary { font-size: 13px; color: var(--muted); }
.metric__compare { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; font-size: 12px; margin-top: 6px; }

.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

.trend { font-weight: 700; font-size: 12px; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.trend--good { color: var(--green); background: rgba(62, 207, 142, 0.12); }
.trend--bad { color: var(--red); background: rgba(255, 90, 95, 0.12); }
.trend--flat, .trend--none { color: var(--muted); background: var(--surface-2); }

.row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.row:last-child { border-bottom: 0; }
.row__label { color: var(--muted); font-size: 13px; }
.row__value { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.row__sub { font-size: 12px; font-weight: 400; color: var(--muted); }
.row__value .chip { margin: 4px 0 0; }

.title { font-size: 17px; font-weight: 800; margin: 0; }
.title-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.big-value { font-size: 26px; font-weight: 800; color: var(--yellow); font-variant-numeric: tabular-nums; }

.chip { display: inline-block; font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); margin: 2px 4px 2px 0; white-space: nowrap; }
.chip--ok { color: var(--green); border-color: rgba(62, 207, 142, 0.4); }
.chip--warn { color: var(--orange); border-color: rgba(255, 176, 32, 0.4); }
.chip--bad { color: var(--red); border-color: rgba(255, 90, 95, 0.4); }
.chip--yellow { color: #111; background: var(--yellow); border-color: var(--yellow); font-weight: 700; }

.person { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.person__name { font-weight: 700; }
.person__role { color: var(--muted); font-size: 12px; }
.person__times { text-align: right; font-variant-numeric: tabular-nums; flex-shrink: 0; }
/* Текст не выходит за карточку: длинные имена и пометки переносятся, время прихода/ухода — одной строкой. */
.person > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.shift-time { white-space: nowrap; font-weight: 700; }
.row__value { min-width: 0; }
.row__value .chip, .person__times .chip { white-space: normal; }
.title-line > :first-child { min-width: 0; overflow-wrap: anywhere; }
.title-line > .chip { flex-shrink: 0; }

.alert { border-left: 4px solid var(--orange); }
.alert--critical { border-left-color: var(--red); }
.alert--info { border-left-color: #4b8bff; }
.alert__title { font-weight: 800; margin-bottom: 4px; }

.medal { font-size: 26px; line-height: 1; margin-right: 8px; }
.rank-head { display: flex; align-items: center; }

.chart { width: 100%; height: auto; display: block; }
.chart__bar { fill: var(--yellow-dim); }
.chart__bar--peak { fill: var(--yellow); }
.chart__label { fill: var(--muted); font-size: 10px; }
.chart__grid { stroke: var(--line); stroke-width: 1; }

.bar-row { margin: 8px 0; }
.bar-row__head { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin-bottom: 4px; }
.bar { width: 100%; height: 8px; display: block; }
.bar__track { fill: var(--surface-2); }
.bar__fill { fill: var(--yellow); }

.insight { padding: 10px 0; border-bottom: 1px solid var(--line); }
.insight:last-child { border-bottom: 0; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-size: 12px; font-weight: 700; }

.form-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.form-row label { color: var(--text); }
.form-row .input { width: 110px; text-align: right; }
.form-row .input--wide { width: 180px; text-align: left; }
.form-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--yellow); }
.btn { border: 0; border-radius: 12px; padding: 12px 16px; background: var(--yellow); color: #111; font-weight: 800; cursor: pointer; width: 100%; margin-top: 14px; }
.btn:disabled { opacity: 0.5; }
.note { color: var(--muted); font-size: 12px; margin-top: 8px; }
.hidden { display: none; }

/* Настраиваемые блоки главного экрана */
.layout { display: grid; gap: var(--gap); grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 720px) { .layout { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.block { min-width: 0; display: flex; flex-direction: column; }
.block > .card { flex: 1; }
.block--section { grid-column: 1 / -1; }
.block--large { grid-column: span 2; }
.block .section { margin: 10px 0 0; }
.block--editing > .card, .block--editing > .section { outline: 1px dashed var(--yellow-dim); outline-offset: 2px; border-radius: var(--radius); }
.block--dragging { opacity: 0.55; }
.block__tools { display: flex; gap: 4px; margin-bottom: 6px; }
.tool { min-width: 34px; min-height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); cursor: pointer; }
.tool:disabled { opacity: 0.35; cursor: default; }
.tool--drag { cursor: grab; touch-action: none; margin-right: auto; font-size: 18px; }
.tool--danger { color: var(--red); }
.btn--small { width: auto; margin-top: 8px; padding: 9px 12px; font-size: 14px; }
.btn--ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); font-weight: 600; }
.toolbar--end { justify-content: flex-end; margin-bottom: 8px; }
.toolbar .select { margin-top: 8px; }
.editbar, .editor { margin-bottom: var(--gap); }
.editor { border-color: var(--yellow); }
.editor .select { max-width: 60vw; }

/* Главный экран: сотрудники с продажами и по должностям */
.list-card .person:first-child { border-top: 0; }
.staff-group .title-line { margin-bottom: 4px; }
.staff-group .person__times b { font-weight: 700; }
.staff-time { white-space: nowrap; }

/* Вход на сайт кодом от бота */
.login { max-width: 440px; margin: 32px auto; }
.login__title { margin: 0 0 8px; font-size: 20px; }
.login .input { width: 100%; max-width: 100%; margin: 12px 0; text-align: left; font-size: 17px; }
.login__code { letter-spacing: 0.3em; text-align: center !important; font-variant-numeric: tabular-nums; }

/* Вкладка «Индикаторы» */
.ind-group { margin-top: 14px; }
.ind-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.ind-row:last-child { border-bottom: 0; }
.ind-row__name { flex: 1; min-width: 0; font-size: 14px; }
.ind-row__value { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ind-row__prev { display: block; margin-top: 2px; font-size: 12px; font-weight: 400; color: var(--muted); white-space: normal; }
.ind-preview { margin-top: 12px; }
.input--search { width: 100%; max-width: 100%; margin: 8px 0; text-align: left; }
.checklist { max-height: 240px; overflow-y: auto; margin: 4px 0; border-top: 1px solid var(--line); }
.check { display: flex; align-items: center; gap: 10px; padding: 7px 2px; font-size: 14px; cursor: pointer; border-bottom: 1px dashed var(--line); }
.check input { flex: none; width: 18px; height: 18px; accent-color: var(--yellow); }

/* Раздел «Кнопки»: редактор кнопок Telegram и предпросмотр клавиатуры */
.btn-edit { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin: 10px 0; background: var(--surface-2); }
.btn-edit .select { max-width: 55vw; }
.spacer { flex: 1; }
textarea { font: inherit; color: inherit; }
.input--area { display: block; width: 100%; max-width: 100%; min-height: 110px; padding: 10px 12px; margin: 6px 0; resize: vertical; line-height: 1.4; }
.label--block { display: block; margin-top: 10px; }
.tg-kb { display: flex; flex-direction: column; gap: 4px; padding: 8px; margin: 6px 0 10px; border-radius: 12px; background: #17212b; }
.tg-kb__row { display: flex; gap: 4px; }
.tg-kb__btn { flex: 1; min-width: 0; padding: 8px 6px; border-radius: 8px; background: rgba(255, 255, 255, 0.1); color: #fff; font-size: 13px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
