:root {
  --bg: #0f1115;
  --bg2: #151821;
  --panel: #1a1e29;
  --panel2: #212636;
  --line: #2a3043;
  --text: #e7e9ee;
  --muted: #8d93a5;
  --accent: #6d8cff;
  --accent2: #8fa6ff;
  --ok: #3ecf8e;
  --warn: #f5b942;
  --bad: #ff6b6b;
  --violet: #b18cff;
  --orange: #ff9f5a;
  --blue: #5aa9ff;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  --radius: 14px;
  --radius-s: 9px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f5f8;
  --bg2: #eceef3;
  --panel: #ffffff;
  --panel2: #f6f7fa;
  --line: #e2e5ec;
  --text: #1b1f2a;
  --muted: #6b7285;
  --accent: #4a6cf7;
  --accent2: #3957d9;
  --shadow: 0 8px 30px rgba(20, 30, 60, .08);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 "Segoe UI", Inter, system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent2); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 2px solid var(--bg); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; height: 100vh; }
.side {
  background: var(--bg2);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 16px 12px;
  gap: 4px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; font-weight: 700; font-size: 16px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  display: grid; place-items: center; color: #fff; font-size: 15px;
}
.nav {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 10px; cursor: pointer;
  color: var(--muted); user-select: none; transition: background .15s, color .15s;
}
.nav:hover { background: var(--panel); color: var(--text); }
.nav.active { background: var(--panel2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .cnt {
  margin-left: auto; min-width: 22px; padding: 1px 7px; border-radius: 20px;
  background: var(--accent); color: #fff; font-size: 12px; text-align: center; font-weight: 600;
}
.nav .cnt.bad { background: var(--bad); }
.nav .cnt.violet { background: var(--violet); }
.side .grow { flex: 1; }
.side .tgstate { font-size: 12px; color: var(--muted); padding: 8px 11px; display: flex; gap: 8px; align-items: center; }

.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.top {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 22px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.top h1 { font-size: 18px; margin: 0; font-weight: 650; white-space: nowrap; }
.top .search { flex: 1; max-width: 460px; margin-left: auto; position: relative; }
.top .search input { width: 100%; padding-left: 34px; }
.top .search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; color: var(--muted); }
.iconbtn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); display: grid; place-items: center; cursor: pointer; color: var(--muted);
}
.iconbtn:hover { color: var(--text); border-color: var(--accent); }
.iconbtn svg { width: 18px; height: 18px; }
.burger { display: none; }
.content { flex: 1; overflow-y: auto; padding: 22px; }

/* ---------- basics ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 650; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 10px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.gauto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 14px; }
.spacer { flex: 1; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: ui-monospace, Consolas, monospace; }

input, select, textarea {
  background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: 8px 11px; outline: none; transition: border-color .15s, box-shadow .15s; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
textarea { resize: vertical; min-height: 70px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { font-size: 14px; color: var(--text); }
label.check { display: flex; gap: 9px; align-items: center; cursor: pointer; }
label.check input { width: 17px; height: 17px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 8px 14px; border-radius: var(--radius-s); border: 1px solid var(--line);
  background: var(--panel2); cursor: pointer; font-weight: 550; white-space: nowrap;
  transition: transform .05s, background .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }
.btn.ok { background: color-mix(in srgb, var(--ok) 18%, var(--panel2)); border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.btn.bad { background: color-mix(in srgb, var(--bad) 15%, var(--panel2)); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn svg { width: 16px; height: 16px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: color-mix(in srgb, var(--c, var(--muted)) 17%, transparent); color: var(--c, var(--muted));
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-talk { --c: var(--muted); }
.st-new { --c: var(--blue); }
.st-work { --c: var(--warn); }
.st-review { --c: var(--violet); }
.st-rework { --c: var(--orange); }
.st-done { --c: var(--ok); }
.st-closed { --c: var(--muted); }
.st-hot { --c: var(--bad); }
.w-running { --c: var(--ok); }
.w-crashed, .w-error { --c: var(--bad); }
.w-stopped { --c: var(--muted); }
.w-stopping { --c: var(--warn); }
.w-night { --c: var(--violet); }

.pulse .dot { animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 currentColor; } 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tab { padding: 9px 13px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.seg { display: inline-flex; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.15); }

/* ---------- stats ---------- */
.stat { display: flex; flex-direction: column; gap: 4px; cursor: pointer; transition: transform .12s, border-color .15s; }
.stat:hover { transform: translateY(-2px); border-color: var(--c, var(--accent)); }
.stat .num { font-size: 28px; font-weight: 700; color: var(--c, var(--text)); line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }

.acc-card { display: flex; flex-direction: column; gap: 10px; }
.acc-card .head { display: flex; align-items: center; gap: 10px; }
.acc-card .name { font-weight: 650; cursor: pointer; }
.acc-card .name:hover { color: var(--accent2); }
.progress { height: 7px; background: var(--panel2); border-radius: 10px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--violet)); border-radius: 10px; transition: width .4s; }

.feed { display: flex; flex-direction: column; }
.feed .ev { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.feed .ev:last-child { border-bottom: 0; }
.feed .ev .t { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.feed .ev .x { cursor: pointer; }
.feed .ev .x:hover { color: var(--accent2); }

/* ---------- board ---------- */
.board { display: grid; grid-template-columns: repeat(6, minmax(200px, 1fr)); gap: 12px; align-items: start; overflow-x: auto; padding-bottom: 8px; }
.column { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 200px; transition: border-color .15s, background .15s; }
.column.drop { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--bg2)); }
.column .ch { display: flex; align-items: center; gap: 8px; padding: 4px 4px 10px; font-weight: 650; }
.column .ch .n { color: var(--muted); font-weight: 500; }
.ocard {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 11px;
  margin-bottom: 9px; cursor: pointer; transition: transform .1s, border-color .15s, box-shadow .15s;
  border-left: 3px solid var(--c, var(--line));
}
.ocard:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.ocard.dragging { opacity: .5; }
.ocard .id { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.ocard .nm { font-weight: 600; margin: 3px 0 7px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ocard .meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); align-items: center; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; }
.timer.late { color: var(--bad); }
.timer.soon { color: var(--orange); }
.unread { display: inline-flex; align-items: center; gap: 3px; background: var(--bad); color: #fff; border-radius: 20px; padding: 0 7px; font-size: 11px; font-weight: 700; line-height: 18px; white-space: nowrap; flex: none; }
.unread svg { width: 11px; height: 11px; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--panel2); }

/* ---------- drawer ---------- */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; opacity: 0; pointer-events: none; transition: opacity .2s; }
.drawer-bg.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); z-index: 21;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  transform: translateX(100%); transition: transform .25s cubic-bezier(.2,.8,.2,1);
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer .dh { padding: 16px 18px 10px; border-bottom: 1px solid var(--line); }
.drawer .dh .title { font-size: 17px; font-weight: 650; margin: 4px 0 8px; }
.drawer .db { flex: 1; overflow-y: auto; padding: 16px 18px; }
.drawer .df { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 7px 12px; font-size: 13px; }
.kv .k { color: var(--muted); }
.task { white-space: pre-wrap; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; max-height: 320px; overflow-y: auto; font-size: 13px; }

.files { display: flex; flex-direction: column; gap: 6px; }
.file { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); }
.file .fn { flex: 1; min-width: 0; }
.file svg { width: 18px; color: var(--muted); flex: none; }
.drop-zone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 22px; text-align: center; color: var(--muted);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.drop-zone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); color: var(--text); }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 82%; padding: 9px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; font-size: 13.5px; }
.msg.customer { background: var(--panel2); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.we { background: color-mix(in srgb, var(--accent) 22%, var(--panel)); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 12px; }
.msg .mt2 { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; }
.msg .ai { color: var(--violet); font-weight: 600; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 44px; max-height: 160px; }
.chats { display: grid; grid-template-columns: 330px 1fr; gap: 14px; height: calc(100vh - 120px); }
.chat-list { overflow-y: auto; padding: 6px; }
.chat-item { padding: 10px; border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; }
.chat-item:hover { background: var(--panel2); }
.chat-item.active { background: var(--panel2); box-shadow: inset 3px 0 0 var(--accent); }
.chat-pane { display: flex; flex-direction: column; min-height: 0; }
.chat-pane .chat { flex: 1; overflow-y: auto; padding: 4px; }

/* ---------- log ---------- */
.log {
  font: 12.5px/1.5 ui-monospace, Consolas, monospace; background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; height: 460px; overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}
.log .l-system { color: var(--accent2); }
.log .l-stderr, .log .l-err { color: var(--bad); }
.log .l-ok { color: var(--ok); }

/* ---------- bars ---------- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; min-width: 0; }
.bars .b .v { width: 100%; border-radius: 6px 6px 2px 2px; background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 40%, transparent)); min-height: 2px; transition: height .4s; }
.bars .b .v.alt { background: linear-gradient(180deg, var(--ok), color-mix(in srgb, var(--ok) 40%, transparent)); }
.bars .b .d { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.funnel { display: flex; flex-direction: column; gap: 8px; }
.funnel .fr { display: grid; grid-template-columns: 150px 1fr 70px; gap: 10px; align-items: center; font-size: 13px; }
.funnel .fb { height: 22px; border-radius: 6px; background: var(--panel2); overflow: hidden; }
.funnel .fb > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--violet)); }

/* ---------- toast & modal ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--c, var(--accent));
  border-radius: 12px; padding: 11px 14px; box-shadow: var(--shadow); max-width: 360px; cursor: pointer;
  animation: tin .25s ease-out;
}
.toast .tt { font-weight: 650; margin-bottom: 2px; }
@keyframes tin { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: min(480px, 100%); box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto; }
.modal h3 { margin: 0 0 14px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent),
              radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--violet) 18%, transparent), transparent), var(--bg); }
.login { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; }
.login input { font-size: 16px; }
.login .brand { justify-content: center; padding-bottom: 6px; font-size: 20px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty svg { width: 42px; height: 42px; opacity: .5; margin-bottom: 6px; }

/* ---------- модерация ---------- */
.mod-head { gap: 18px; }
.mod-head label.switch b { font-size: 15px; }
.mod-balance { gap: 2px; text-align: right; padding: 8px 14px; border-radius: 10px; background: color-mix(in srgb, var(--ok) 12%, var(--panel2)); cursor: pointer; }
.mod-balance b { font-size: 20px; color: var(--ok); }
.mod-grid { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); align-items: start; }
.mod-card { border-left: 3px solid var(--violet); }
.mod-card.taken { border-left-color: var(--orange); }
.mod-title { font-weight: 650; font-size: 15px; }
.mod-earn { color: var(--ok); font-weight: 650; }
.mod-note { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font-size: 13px; white-space: pre-wrap; }
.mod-note.warn { border-color: color-mix(in srgb, var(--orange) 50%, var(--line)); }
.mod-card details summary { cursor: pointer; color: var(--muted); font-size: 13px; user-select: none; }
.mod-card details summary:hover { color: var(--text); }
.mod-card details > .task, .mod-card details > .files { margin-top: 8px; }
.tbl.works td, .tbl.works th { white-space: nowrap; }
.price-card { max-width: 640px; }
.price-input { width: 200px; font-size: 22px; font-weight: 650; padding: 10px 14px; }
.price-rub { font-size: 22px; font-weight: 650; margin-right: 6px; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: var(--shadow); }
  .burger { display: grid; }
  .content { padding: 14px; }
  .top { padding: 10px 14px; }
  .top .search { max-width: none; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .chats { grid-template-columns: 1fr; height: auto; }
  .kv { grid-template-columns: 110px 1fr; }
  .board { grid-template-columns: repeat(6, 260px); }
  .mod-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .top .search { display: none; }
  .top h1 { flex: 1; }
}
