/* Очередь бафов — тёмная минималистичная тема */

:root {
  --bg: #0d1117;
  --panel: #141b24;
  --panel-2: #1b2431;
  --panel-3: #222d3c;
  --border: #28313d;
  --text: #e6edf3;
  --muted: #8b98a7;
  --accent: #4f9cf9;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --scroll-thumb: #2b3644;
  --scroll-thumb-hover: #3d4c5f;
  --scroll-track: #0d1117;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-image: radial-gradient(900px 400px at 10% -10%, rgba(79, 156, 249, .08), transparent 60%);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--panel-3); padding: 1px 5px; border-radius: 6px; font-size: .9em; }

h1, h2, h3 { font-weight: 600; letter-spacing: -.01em; }

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 18px; }
.main { flex: 1 0 auto; padding: 22px 18px 40px; }

.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------- шапка --- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(13, 17, 23, .88);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.topbar-inner {
  display: flex; align-items: center; gap: 16px;
  min-height: 58px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px;
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(160deg, #4f9cf9, #1f6feb);
  display: grid; place-items: center;
}
.brand-mark svg { width: 18px; height: 18px; fill: #fff; }
.brand-text { font-size: 16px; }

.mainnav { display: flex; gap: 4px; margin-left: 8px; flex-wrap: wrap; }
.mainnav a {
  color: var(--muted); padding: 6px 10px; border-radius: 9px; font-size: 14px;
}
.mainnav a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
.mainnav a.is-current { color: var(--text); background: var(--panel-3); }

.userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.userchip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 5px; border-radius: 999px;
  background: var(--panel-2); color: var(--text); font-size: 14px; max-width: 240px;
}
.userchip:hover { text-decoration: none; background: var(--panel-3); }
.userchip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto;
  background: var(--panel-3); display: grid; place-items: center;
  font-size: 13px; color: var(--accent); font-weight: 600;
}
.rolebadge {
  font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  background: rgba(79, 156, 249, .18); color: var(--accent);
  padding: 2px 6px; border-radius: 6px;
}

.inline { display: inline; margin: 0; }

/* ------------------------------------------------- переключатель языка --- */

.topbar-tools {
  margin-left: auto; display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; justify-content: flex-end;
}

.langswitch {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 2px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border);
}

.langbtn {
  border: 0; background: transparent; color: var(--muted);
  font-family: inherit; font-size: 12.5px; font-weight: 650;
  letter-spacing: .04em; line-height: 1;
  padding: 5px 9px; border-radius: 999px; cursor: pointer;
  transition: .15s ease;
}
.langbtn:hover { color: var(--text); background: var(--panel-3); }
.langbtn.is-active { color: #fff; background: var(--accent); }
.langbtn.is-active:hover { background: var(--accent); color: #fff; }

/* --------------------------------------------------------------- кнопки --- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 14px;
  font-family: inherit; cursor: pointer; transition: .15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-3); text-decoration: none; }
.btn.primary { background: linear-gradient(180deg, #2f81f7, #1f6feb); border-color: #2f81f7; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(248, 81, 73, .4); background: rgba(248, 81, 73, .08); }
.btn.danger:hover { background: rgba(248, 81, 73, .16); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }

.iconbtn {
  display: inline-grid; place-items: center;
  width: 28px; height: 28px; min-width: 28px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--muted);
  font-size: 13px; cursor: pointer; padding: 0; transition: .15s ease;
}
.iconbtn:hover { color: var(--text); background: var(--panel-3); text-decoration: none; }
.iconbtn.ok:hover { color: var(--ok); border-color: rgba(63, 185, 80, .5); }
.iconbtn.danger:hover { color: var(--danger); border-color: rgba(248, 81, 73, .5); }
.iconbtn:disabled { opacity: .35; cursor: default; }

/* ------------------------------------------------------------ переключатель */

.qswitch {
  display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap;
}
.qtab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--muted); font-size: 14px; font-weight: 500;
}
.qtab:hover { text-decoration: none; color: var(--text); border-color: #38465a; }
.qtab.is-active {
  color: var(--text); border-color: rgba(79, 156, 249, .55);
  background: linear-gradient(180deg, rgba(79, 156, 249, .16), rgba(79, 156, 249, .05));
  box-shadow: inset 0 0 0 1px rgba(79, 156, 249, .12);
}
.qicon { width: 16px; height: 16px; fill: currentColor; opacity: .8; }
.qcount {
  font-size: 11px; background: var(--panel-3); color: var(--muted);
  border-radius: 999px; padding: 1px 7px; min-width: 20px; text-align: center;
}
.qtab.is-active .qcount { background: rgba(79, 156, 249, .25); color: #cfe3ff; }

/* --------------------------------------------------------------- панели --- */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 14px;
}
.panel-title { font-size: 17px; margin: 0 0 2px; }
.page-title { font-size: 22px; margin: 0 0 16px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pill {
  font-size: 12px; color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px;
}

/* ------------------------------------------------------------- прокрутка --- */

/* Firefox: тонкий тёмный ползунок вместо светлого системного */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

/* Chrome, Edge, Opera, Safari */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--scroll-track); }
::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border: 2px solid var(--scroll-track);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); }
::-webkit-scrollbar-corner { background: var(--scroll-track); }

/* внутри таблиц трек совпадает с фоном панели */
.table-scroll { scrollbar-color: var(--scroll-thumb) var(--panel); }
.table-scroll::-webkit-scrollbar-track { background: var(--panel); }
.table-scroll::-webkit-scrollbar-thumb { border-color: var(--panel); }

/* --------------------------------------------------------------- таблицы -- */

.table-wrap { overflow: auto; border-radius: 12px; }

/* длинные очереди: свой скролл + липкая шапка, описание и форма очереди остаются на месте */
.table-scroll {
  max-height: clamp(260px, calc(100vh - 330px), 720px);
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 14px;
}
.table th, .table td {
  padding: 9px 10px; text-align: left; vertical-align: middle;
  border-bottom: 1px solid var(--border);
}
.table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--panel-2); color: var(--muted);
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .03em; white-space: nowrap;
  box-shadow: inset 0 -1px 0 var(--border);
}
.table thead th:first-child { border-top-left-radius: 12px; }
.table thead th:last-child { border-top-right-radius: 12px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: rgba(255, 255, 255, .02); }

.qtable .pos { width: 44px; color: var(--muted); font-variant-numeric: tabular-nums; }
.qtable .nick { font-weight: 600; }
.qtable .wait { white-space: nowrap; color: #b9c6d4; }
.manual { color: var(--warn); margin-left: 2px; }
.stats-table .num { color: var(--text); }
.table.compact th, .table.compact td { padding: 7px 10px; }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; }
.is-muted { opacity: .5; }

.status-row.s-done { opacity: .55; }
.status-row.s-done .nick { font-weight: 500; }
.status-row.s-work td { background: rgba(210, 153, 34, .10); }
.status-row.s-work td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.status-row.s-next td { background: rgba(63, 185, 80, .09); }
.status-row.s-next td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
.status-row.dragging { opacity: .9; outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--panel-3); }

.badge {
  display: inline-block; font-size: 11.5px; font-weight: 600;
  padding: 3px 8px; border-radius: 999px; white-space: nowrap;
  border: 1px solid transparent;
}
.badge-work { background: rgba(210, 153, 34, .18); color: #f0c04b; border-color: rgba(210, 153, 34, .35); }
.badge-next { background: rgba(63, 185, 80, .16); color: #56d364; border-color: rgba(63, 185, 80, .32); }
.badge-done { background: rgba(139, 152, 167, .14); color: var(--muted); border-color: rgba(139, 152, 167, .25); }
.badge-none { background: transparent; color: var(--muted); border-color: var(--border); }

/* -------------------------------------------------------- drag and drop ---- */

.dragcol { width: 34px; padding-left: 8px !important; padding-right: 0 !important; }
.draghandle {
  display: grid; place-items: center; width: 26px; height: 26px;
  border-radius: 7px; cursor: grab; color: #55637a;
  touch-action: none; -webkit-user-select: none; user-select: none;
}
.draghandle:hover { background: var(--panel-3); color: var(--text); }
.draghandle:active { cursor: grabbing; }
.draghandle svg { width: 16px; height: 16px; fill: currentColor; }
.drags-label { display: none; }

/* -------------------------------------- свёрнутые записи до «В работе» ----- */

.collapse-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 0 10px;
}
.qtable tr.is-before-work { display: none; }
.table-wrap.show-before .qtable tr.is-before-work { display: table-row; }

/* кнопка «стереть всё» под таблицей */
.dangerbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 12px; padding-top: 12px;
  border-top: 1px dashed var(--border);
}

/* нарастающий итог: свой скролл, как у очереди */
.stats-scroll {
  max-height: clamp(220px, calc(100vh - 420px), 520px);
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.rowact { width: 1%; white-space: nowrap; }
.rowbtns { display: flex; gap: 4px; align-items: center; justify-content: flex-end; }
.rowbtns form { display: inline-flex; margin: 0; align-items: center; gap: 4px; }
.tiny-check {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tiny-check input { width: 13px; height: 13px; margin: 0; }

/* ------------------------------------------------------------ моё участие -- */

.mybox {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px; margin-bottom: 14px;
  border-radius: 12px; border: 1px solid rgba(79, 156, 249, .35);
  background: linear-gradient(180deg, rgba(79, 156, 249, .12), rgba(79, 156, 249, .04));
}
.mybox-text { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.joinform {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; margin-bottom: 14px;
  border-radius: 12px; border: 1px dashed var(--border); background: var(--panel-2);
}

/* --------------------------------------------------------------- формы ---- */

.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.field > span { font-weight: 500; }
.field input, .field select, .field textarea {
  font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--panel-3); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 11px; min-width: 0;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 156, 249, .18);
}
.field input[type="number"] { width: 130px; }
.field.grow { flex: 1 1 220px; }
.field small { font-size: 11.5px; }

.stack { display: flex; flex-direction: column; gap: 12px; }

.form-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px; align-items: start;
}
.form-grid .span2 { grid-column: 1 / -1; }
.form-grid input[type="file"] { padding: 7px; background: var(--panel-2); }

.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid2 > .panel { margin-bottom: 0; }

/* ------------------------------------------------------- сообщения/страницы */

.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.flash {
  padding: 10px 14px; border-radius: 10px; font-size: 14px;
  border: 1px solid var(--border); background: var(--panel-2);
}
.flash-ok { border-color: rgba(63, 185, 80, .4); background: rgba(63, 185, 80, .12); color: #7ee787; }
.flash-warn { border-color: rgba(210, 153, 34, .4); background: rgba(210, 153, 34, .12); color: #f0c04b; }
.flash-error { border-color: rgba(248, 81, 73, .4); background: rgba(248, 81, 73, .12); color: #ff9b94; }

.authcard {
  max-width: 420px; margin: 30px auto;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px; box-shadow: var(--shadow);
}
.auth-title { font-size: 22px; margin: 0 0 4px; }
.auth { display: flex; flex-direction: column; }
.auth .main { display: flex; flex-direction: column; justify-content: center; }

.hint { color: var(--muted); font-size: 12.5px; margin: 12px 0 0; line-height: 1.6; }
.code-pill {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  background: var(--panel-3); border: 1px solid var(--border);
  padding: 3px 8px; border-radius: 7px; letter-spacing: .06em; font-size: 13px;
}

.foot {
  flex: 0 0 auto; padding: 10px 18px 18px;
}

/* ------------------------------------------------------------ адаптивность */

@media (max-width: 820px) {
  .table-wrap { overflow: visible; }
  /* на телефоне таблицы превращаются в карточки — внутренний скролл не нужен */
  .table-scroll { max-height: none; overflow: visible; scrollbar-gutter: auto; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { display: none; }
  .table tbody tr {
    position: relative;
    border: 1px solid var(--border); border-radius: 14px;
    padding: 10px 12px; margin-bottom: 10px; background: var(--panel-2);
  }
  .table tbody tr:hover td { background: transparent; }
  .table td {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 4px 0; border: 0; text-align: right;
  }
  .table td::before {
    content: attr(data-label); color: var(--muted);
    font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
    text-align: left; flex: 0 0 auto;
  }
  .table td[data-label=""]::before { content: none; }
  .qtable .pos { display: none; }
  .qtable .nick { font-size: 16px; }
  .status-row.s-work td:first-child,
  .status-row.s-next td:first-child { box-shadow: none; }
  .status-row.s-work { border-color: rgba(210, 153, 34, .5); }
  .status-row.s-next { border-color: rgba(63, 185, 80, .45); }

  /* ручка перетаскивания: отдельной строкой в карточке, крупная и заметная */
  .table td.dragcol {
    position: static; width: auto; margin-top: 8px;
    padding: 10px 0 0; border-top: 1px dashed var(--border);
    justify-content: flex-start; gap: 8px;
  }
  .table td.dragcol::before { content: attr(data-label); }
  .draghandle {
    display: inline-flex; align-items: center; gap: 8px;
    width: auto; height: 36px; padding: 0 14px;
    border-radius: 999px; border: 1px solid var(--border);
    background: var(--panel-3); color: var(--text);
  }
  .draghandle svg { width: 14px; height: 14px; }
  .drags-label {
    display: inline; font-size: 12px; letter-spacing: .03em;
    text-transform: uppercase; color: var(--muted);
  }
  .table td.rowact { padding-top: 10px; border-top: 1px dashed var(--border); margin-top: 6px; }

  /* нарастающий итог на телефоне тоже прокручивается внутри блока */
  .stats-scroll {
    max-height: 58vh; overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .collapse-bar { margin-bottom: 8px; }
  .collapse-bar .muted { display: none; }

  .form-grid, .grid2 { grid-template-columns: minmax(0, 1fr); }
  .panel { padding: 14px 12px; border-radius: 12px; }
  .main { padding: 16px 12px 30px; }
  .mainnav { order: 3; width: 100%; margin-left: 0; overflow-x: auto; padding-bottom: 2px; }

  /* шапка компактнее: убираем лишний воздух между логотипом, языком и профилем */
  .topbar-inner { gap: 8px 10px; min-height: 46px; padding-top: 6px; padding-bottom: 6px; }
  .brand { gap: 8px; }
  .brand-mark { width: 26px; height: 26px; border-radius: 8px; }
  .brand-mark svg { width: 15px; height: 15px; }
  .topbar-tools { gap: 6px; }
  .langswitch { padding: 1px; }
  .langbtn { padding: 4px 7px; font-size: 11.5px; }
  .userbox { margin-left: 0; gap: 6px; }
  .userchip { padding: 3px 8px 3px 3px; gap: 6px; font-size: 13px; max-width: 150px; }
  .userchip-name { max-width: 110px; }
  .avatar { width: 22px; height: 22px; font-size: 12px; }
  .rolebadge { display: none; }
  .userbox .btn.small { padding: 5px 9px; font-size: 12.5px; }
  .field input[type="number"] { width: 100%; }
  .mybox, .joinform { flex-direction: column; align-items: stretch; }
  .joinform .field, .joinform .btn { width: 100%; }
  .actions { width: 100%; }
  .panel-head .actions .btn { flex: 1 1 auto; }
}

@media (max-width: 520px) {
  .brand-text { display: none; }
  .authcard { margin: 10px auto; padding: 18px; }
  .qtab { padding: 8px 11px; font-size: 13px; }
  .table td::before { font-size: 11px; }
  .mainnav a { padding: 5px 8px; font-size: 13px; }
  .userchip { max-width: 120px; }
  .userchip-name { max-width: 88px; }
  .langbtn { padding: 4px 6px; }
  .wrap { padding: 0 12px; }
}
