/* AllStaff panel. Plain working look (Sofya 18.11): neutral colours, not the glazburi brand of the proposal.
   Dark by default, light by the switch at the bottom of the menu (stored per browser). Layout follows the
   mockups in uchebnik.html section 5: menu on the left, page head with the main button on the right, cards. */
:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --text: #e7e9ee;
  --muted: #9ba3af;
  --line: #2c313b;
  --accent: #3b82f6;
  --accent-text: #ffffff;
  --link: #7fb0ff;
  --ok: #8fd6a4;
  --error: #f3a3a3;
  --warn: #f0d58a;
  --chip-green: rgba(120, 200, 145, 0.18);
  --chip-yellow: rgba(240, 210, 130, 0.18);
  --chip-red: rgba(240, 150, 150, 0.18);
  --chip-blue: rgba(130, 170, 240, 0.18);
  --chip-grey: rgba(160, 168, 180, 0.16);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #eef0f3;
  --text: #1b1f24;
  --muted: #5d6672;
  --line: #dde1e6;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --link: #1d4ed8;
  --ok: #1f7a3d;
  --error: #b42323;
  --warn: #8a6100;
  --chip-green: #e3f4e8;
  --chip-yellow: #fbf1d3;
  --chip-red: #fbe3e3;
  --chip-blue: #e3ecfb;
  --chip-grey: #eceef1;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1 { margin: 0 0 4px; font-size: 24px; font-weight: 600; overflow-wrap: anywhere; }
h2 { margin: 28px 0 10px; font-size: 18px; font-weight: 600; }
a { color: var(--link); }
.muted { color: var(--muted); }
.ok { color: var(--ok); }
.error { color: var(--error); }

/* ---------- frame: menu on the left ---------- */
body:has(> header.top) {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  grid-template-areas: "side msgs" "side main";
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}
.top {
  grid-area: side;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 12px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.top .brand { font-weight: 700; font-size: 17px; padding: 0 10px; }
.top nav { display: flex; flex-direction: column; gap: 2px; }
.top nav a { color: var(--muted); text-decoration: none; padding: 8px 10px; border-radius: 6px; }
.top nav a:hover { color: var(--text); background: var(--panel-2); }
.top nav a.on { color: var(--text); background: var(--panel-2); font-weight: 600; }
.top .foot { margin-top: auto; display: grid; gap: 8px; padding: 0 10px; font-size: 14px; }
.messages { grid-area: msgs; list-style: none; margin: 0; padding: 16px 32px 0; display: grid; gap: 6px; max-width: 1240px; }
.messages li { padding: 8px 12px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); }
.messages .success { border-color: var(--ok); }
.messages .error { border-color: var(--error); color: var(--error); }
.messages .warning { color: var(--muted); font-size: 14px; padding: 4px 12px; }
.home { grid-area: main; padding: 24px 32px 48px; max-width: 1240px; width: 100%; }

/* page head: name on the left, the main button on the right */
.page-head { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head .row { margin-top: 0; }

/* ---------- controls ---------- */
input, select, textarea {
  padding: 9px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; }
button, a.button {
  display: inline-block;
  padding: 9px 16px;
  background: var(--accent);
  color: var(--accent-text);
  border: 1px solid var(--accent);
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
button.quiet, a.button.quiet { background: var(--panel); color: var(--text); border-color: var(--line); font-weight: 400; }
button.quiet:hover, a.button.quiet:hover { background: var(--panel-2); }
button.link { background: none; border: 0; color: var(--muted); padding: 0; font-weight: 400; text-align: left; }
button.link:hover { color: var(--text); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }
.row input { flex: 1 1 160px; min-width: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; }
.actions .row { margin-top: 0; flex: 1 1 320px; }
.inline { display: inline; }
.filters { margin: 16px 0; }

/* ---------- blocks ---------- */
.card { margin: 16px 0; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.card > h3, .card > strong:first-child { display: block; margin: 0 0 12px; font-size: 16px; font-weight: 600; }
.card label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 16px; align-items: start; }
.cards > * { min-width: 0; }  /* a wide table scrolls inside its column instead of pushing the page sideways */
.cards > .card { margin: 0; }
/* day totals («написали сегодня», «ответили») */
.sum { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 0 0 16px; }
.sum > div { padding: 12px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: 14px; }
.sum b { display: block; color: var(--text); font-size: 22px; font-weight: 600; }

/* tables */
.grid { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14.5px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.grid th { text-align: left; color: var(--muted); font-weight: 500; background: var(--panel-2); }
.grid th, .grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
/* a phone number stays on one line (Sofya 19.11: «телефон в две строчки — некрасиво») */
.grid td.tel { white-space: nowrap; }
.pages { display: flex; gap: 16px; color: var(--muted); }

/* status chips: a word on a pastel ground, never colour alone */
.state, .chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; background: var(--chip-grey); color: var(--text); max-width: 100%; overflow-wrap: break-word; }
/* short chips in table cells keep their words whole; long notes wrap between words */
.grid .chip, .grid .state { white-space: nowrap; }
.chip-green, .state-active { background: var(--chip-green); }
.chip-yellow, .state-restricted, .state-logging_in { background: var(--chip-yellow); }
.chip-red, .state-logged_out, .state-error { background: var(--chip-red); }
.chip-blue { background: var(--chip-blue); }
/* task states */
.chip-running { background: var(--chip-blue); }
.chip-paused { background: var(--chip-yellow); }
.chip-done { background: var(--chip-green); }
.chip-draft { background: var(--chip-grey); }
/* dialog states */
.chip-st-agent { background: var(--chip-yellow); }
.chip-st-human { background: var(--chip-blue); }
.chip-st-attention { background: var(--chip-red); }
.chip-st-stopped { background: var(--chip-grey); }
.chip .dot { width: 9px; height: 9px; margin-right: 2px; }
/* conversation wide, facts narrow */
.cards.two { grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); }
@media (max-width: 980px) { .cards.two { grid-template-columns: 1fr; } }
.todo { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.todo li { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.todo .n { flex: none; width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--panel-2); font-weight: 600; }
.todo li.done .n { background: var(--chip-green); }
.todo .t { flex: 1 1 280px; }
.steps { margin: 14px 0 0; padding-left: 18px; display: grid; gap: 4px; }
.form input:not([type="checkbox"]):not([type="file"]) { width: 100%; }
.row.tight { margin-top: 0; gap: 6px; flex-wrap: nowrap; }
.small { font-size: 13.5px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
.result { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.lock { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; background: var(--chip-blue); color: var(--text); }

/* ---------- forms ---------- */
.form .field { display: grid; gap: 6px; margin-bottom: 14px; }
.form .field > label { color: var(--muted); font-size: 14px; }
.form .field.check { grid-template-columns: auto 1fr; align-items: center; }
.form .field.check > label { order: 2; }
.form .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.form .field > input:not([type="checkbox"]), .form .field > select { width: 100%; }
/* weekdays as toggle tiles (Alexey's screenshot 18.11): the whole tile is the checkbox caption */
#id_weekdays { display: flex; flex-wrap: wrap; gap: 6px; }
.form .days label:has(> input[type="checkbox"]) {
  display: inline-flex; align-items: center; justify-content: center; min-width: 38px; padding: 7px 6px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); cursor: pointer; font-size: 14px;
}
.form .days label:has(> input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.form .days label:has(> input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.form .days input[type="checkbox"] { position: absolute; opacity: 0; width: 1px; height: 1px; }
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.presets button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.speed-sum { margin: 4px 0 8px; padding: 10px 12px; background: var(--panel-2); border-radius: 8px; }
.speed-sum:empty { display: none; }
.form ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
/* a checkbox and its caption on one line, whatever wraps them (Django 5 draws <div>s, not <ul>; 18.11) */
.card label:has(> input[type="checkbox"]) {
  display: flex; gap: 10px; align-items: center; justify-content: flex-start;
  color: var(--text); font-size: 15px; cursor: pointer;
}
input[type="checkbox"] { flex: none; width: 18px; height: 18px; margin: 0; padding: 0; accent-color: var(--accent); }

/* ---------- marks left of «Участник» (Alexey 16.11): pastel, with the word in title ---------- */
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; background: #8a93a6; vertical-align: middle; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }
.dot-agent { background: #f2d98d; }
.dot-human { background: #a9c7f2; }
.dot-attention { background: #f2a9a9; }
.dot-stopped { background: #8a93a6; }
.dot-green { background: #a8dcb5; }
.dot-yellow { background: #f2d98d; }
.dot-red { background: #f2a9a9; }
.marks { display: inline-flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.marks span { display: inline-flex; gap: 6px; align-items: center; }

/* ---------- dialog ---------- */
.chat { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.msg { padding: 10px 14px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.msg-agent, .msg-human { margin-left: 48px; background: var(--chip-blue); }
.msg-person { margin-right: 48px; }
.msg .who { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.msg .text { overflow-wrap: anywhere; }

/* ---------- login ---------- */
.login { max-width: 360px; margin: 12vh auto 0; padding: 32px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.login form { display: grid; gap: 14px; margin-top: 20px; }
.login label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
.login-wide { max-width: 440px; }
/* the QR code always on white: phone cameras read dark-on-light, the dark theme would hide it */
.qr { width: 216px; margin: 14px auto 8px; padding: 8px; background: #ffffff; border-radius: 8px; line-height: 0; }
.qr svg { width: 200px; height: 200px; }
.secret { font-family: ui-monospace, Consolas, monospace; overflow-wrap: anywhere; }

/* ---------- phone: the menu becomes a strip on top ---------- */
@media (max-width: 760px) {
  body:has(> header.top) { display: block; }
  .top { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .top nav { flex-direction: row; flex-wrap: wrap; }
  .top .foot { margin-top: 0; margin-left: auto; grid-auto-flow: column; padding: 0; }
  .messages { padding: 12px 16px 0; }
  .home { padding: 20px 16px 40px; }
  .grid { display: block; overflow-x: auto; }
  dl.facts { grid-template-columns: 1fr; gap: 2px; }
  dl.facts dd { margin-bottom: 8px; }
  .form .pair { grid-template-columns: 1fr; }
}
