/* --- Токены и база --------------------------------------------------- */
:root {
  --bg:            #0a0d14;
  --bg-elev:       #0f131c;
  --bg-elev-2:     #141a25;
  --bg-hover:      #1a2231;
  --border:        #1e2635;
  --border-strong: #2a3446;
  --text:          #e7ebf3;
  --text-dim:      #9aa5b8;
  --text-faint:    #64708a;
  --accent:        #5b8cff;
  --accent-soft:   rgba(91, 140, 255, .14);
  --ok:            #3ddc84;
  --ok-soft:       rgba(61, 220, 132, .14);
  --warn:          #ffb454;
  --warn-soft:     rgba(255, 180, 84, .14);
  --danger:        #ff6b6b;
  --danger-soft:   rgba(255, 107, 107, .14);
  --violet:        #a78bfa;
  --violet-soft:   rgba(167, 139, 250, .14);
  --radius:        10px;
  --radius-sm:     7px;
  --shadow:        0 8px 30px rgba(0, 0, 0, .45);
  --sidebar-w:     248px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body, #root { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

p { margin: 0 0 10px; }

code, .mono { font-family: var(--mono); font-size: 12.5px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #232c3d; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #2e3a4f; }

/* --- Формы ------------------------------------------------------------ */
input, select, textarea, button { font: inherit; color: inherit; }

.input, .select, .textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.textarea { min-height: 120px; resize: vertical; font-family: var(--mono); font-size: 13px; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%), linear-gradient(135deg, var(--text-dim) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }

.label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 500; color: var(--text-dim); }
.hint { margin-top: 6px; font-size: 12px; color: var(--text-faint); }
.field { margin-bottom: 14px; }

/* --- Утилиты ---------------------------------------------------------- */
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.strong { font-weight: 600; }
.upper { text-transform: uppercase; letter-spacing: .08em; font-size: 11px; font-weight: 600; color: var(--text-faint); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; } .gap-2 { gap: 16px; } .gap-3 { gap: 24px; }
.hidden { display: none !important; }
/* --- Оболочка приложения --------------------------------------------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; align-self: start;
  height: 100vh; overflow-y: auto;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 14px; border-bottom: 1px solid var(--border); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #5b8cff, #a78bfa); display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #0a0d14; flex: 0 0 auto; }
.brand-name { font-weight: 600; font-size: 13.5px; line-height: 1.25; }
.brand-sub { font-size: 11px; color: var(--text-faint); }

.nav { padding: 10px 8px 20px; flex: 1 1 auto; }
.nav-group { margin-bottom: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text-dim); cursor: pointer; user-select: none;
  font-size: 13.5px; line-height: 1.2;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: #cfe0ff; font-weight: 500; }
.nav-item .ico { width: 16px; height: 16px; flex: 0 0 auto; opacity: .85; }
.nav-item .count { margin-left: auto; font-size: 11px; color: var(--text-faint); background: var(--bg-elev-2); padding: 1px 6px; border-radius: 20px; }
.nav-item.soon { opacity: .55; }
.nav-sub { margin: 2px 0 6px 26px; display: flex; flex-direction: column; gap: 1px; }
.nav-sub .nav-item { padding: 5px 10px; font-size: 13px; }
.nav-caret { margin-left: auto; transition: transform .15s; opacity: .6; }
.nav-caret.open { transform: rotate(90deg); }

.sidebar-foot { padding: 12px 14px; border-top: 1px solid var(--border); font-size: 11.5px; color: var(--text-faint); }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 22px;
  background: rgba(10, 13, 20, .86);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; }
.topbar .crumb { font-size: 12px; color: var(--text-faint); }

.content { padding: 22px; max-width: 1560px; width: 100%; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-60-40 { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }

@media (max-width: 1200px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-60-40 { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 60; transform: translateX(-100%); transition: transform .2s; width: var(--sidebar-w); }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}
.burger { display: none; }
@media (max-width: 900px) { .burger { display: grid; } }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 14px; padding: 26px; box-shadow: var(--shadow); }
/* --- Карточки ---------------------------------------------------------- */
.card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 13.5px; }
.card-body { padding: 16px; }
.card-body.tight { padding: 10px 16px; }
.card-foot { padding: 11px 16px; border-top: 1px solid var(--border); background: rgba(255, 255, 255, .012); border-radius: 0 0 var(--radius) var(--radius); }

/* --- Кнопки ----------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  background: var(--bg-elev-2); border: 1px solid var(--border-strong);
  cursor: pointer; font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: background .14s, border-color .14s, opacity .14s;
}
.btn:hover { background: var(--bg-hover); border-color: #3a465c; }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #07101f; }
.btn-primary:hover { background: #6f9bff; border-color: #6f9bff; }
.btn-danger { background: transparent; border-color: rgba(255,107,107,.45); color: #ffb3b3; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn-group { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.btn-group .btn { border: 0; border-radius: 0; background: transparent; }
.btn-group .btn + .btn { border-left: 1px solid var(--border-strong); }
.btn-group .btn.on { background: var(--accent-soft); color: #cfe0ff; }

/* --- Значки и статусы -------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 500; background: var(--bg-elev-2); color: var(--text-dim); border: 1px solid var(--border); }
.badge-ok { background: var(--ok-soft); color: #86efac; border-color: rgba(61,220,132,.3); }
.badge-warn { background: var(--warn-soft); color: #fcd34d; border-color: rgba(255,180,84,.3); }
.badge-danger { background: var(--danger-soft); color: #fca5a5; border-color: rgba(255,107,107,.3); }
.badge-accent { background: var(--accent-soft); color: #bfd4ff; border-color: rgba(91,140,255,.3); }
.badge-violet { background: var(--violet-soft); color: #d8ccff; border-color: rgba(167,139,250,.3); }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: var(--text-faint); }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot-warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot-danger { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.dot-off { background: #3c4658; }

/* --- Переключатель ----------------------------------------------------- */
.switch { position: relative; width: 38px; height: 21px; border-radius: 20px; background: #2a3446; border: 1px solid var(--border-strong); cursor: pointer; transition: background .16s; flex: 0 0 auto; padding: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: #8b97ad; transition: transform .16s, background .16s; }
.switch.on { background: var(--accent); border-color: var(--accent); }
.switch.on::after { transform: translateX(17px); background: #fff; }
.switch:disabled { opacity: .45; cursor: not-allowed; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: 0; }
.switch-row .name { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }

/* --- KPI -------------------------------------------------------------- */
.kpi { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 13px 15px; }
.kpi .k-label { font-size: 11.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .06em; }
.kpi .k-value { font-size: 26px; font-weight: 650; line-height: 1.15; margin-top: 4px; letter-spacing: -.02em; }
.kpi .k-note { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
.kpi.accent .k-value { color: #9dbcff; }
.kpi.ok .k-value { color: #86efac; }

/* --- Таблицы ---------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; padding: 9px 12px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint);
  border-bottom: 1px solid var(--border); background: rgba(255,255,255,.012); white-space: nowrap;
}
table.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tbody tr:hover { background: rgba(255,255,255,.022); }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl tr.clickable { cursor: pointer; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }

.score { display: inline-flex; align-items: center; justify-content: center; min-width: 42px; padding: 2px 7px; border-radius: 6px; font-weight: 650; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.score-hi { background: var(--ok-soft); color: #86efac; }
.score-mid { background: var(--warn-soft); color: #fcd34d; }
.score-lo { background: var(--bg-elev-2); color: var(--text-dim); }

/* --- Пустые состояния и заглушки --------------------------------------- */
.empty { padding: 34px 20px; text-align: center; color: var(--text-faint); }
.empty .ico { font-size: 26px; opacity: .5; margin-bottom: 8px; }

.phase-note { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border: 1px dashed var(--border-strong); border-radius: var(--radius); background: rgba(91,140,255,.04); }
.phase-note .badge { flex: 0 0 auto; }

.roadmap { display: flex; flex-direction: column; gap: 0; }
.roadmap-item { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.roadmap-item:last-child { border-bottom: 0; }
.roadmap-num { width: 22px; height: 22px; border-radius: 6px; background: var(--bg-elev-2); color: var(--text-faint); font-size: 11.5px; font-weight: 600; display: grid; place-items: center; flex: 0 0 auto; }
.roadmap-item.done .roadmap-num { background: var(--ok-soft); color: #86efac; }
.roadmap-item.current .roadmap-num { background: var(--accent-soft); color: #bfd4ff; }
.roadmap-item.done .r-title, .roadmap-item.current .r-title { color: var(--text); }
.r-title { font-size: 13px; color: var(--text-dim); }
.r-desc { font-size: 12px; color: var(--text-faint); margin-top: 1px; }

/* --- Таймлайн ---------------------------------------------------------- */
.timeline { position: relative; padding-left: 18px; }
.timeline::before { content: ""; position: absolute; left: 4px; top: 4px; bottom: 4px; width: 1px; background: var(--border); }
.tl-item { position: relative; padding: 6px 0; }
.tl-item::before { content: ""; position: absolute; left: -18px; top: 12px; width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); }
.tl-item.ok::before { background: var(--ok); }
.tl-item.warning::before { background: var(--warn); }
.tl-item.error::before { background: var(--danger); }
.tl-time { font-size: 11.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.tl-text { font-size: 13px; }

/* --- Прочее ------------------------------------------------------------ */
.toast-stack { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { min-width: 240px; max-width: 380px; padding: 11px 14px; border-radius: var(--radius-sm); background: var(--bg-elev-2); border: 1px solid var(--border-strong); box-shadow: var(--shadow); font-size: 13px; }
.toast.err { border-color: rgba(255,107,107,.5); background: #22141a; }
.toast.ok { border-color: rgba(61,220,132,.4); background: #10211a; }

.spinner { width: 15px; height: 15px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.bar { height: 6px; border-radius: 4px; background: var(--bg-elev-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.ok > i { background: var(--ok); }
.bar.warn > i { background: var(--warn); }

.pill-tabs { display: inline-flex; gap: 4px; padding: 3px; background: var(--bg-elev-2); border-radius: 9px; border: 1px solid var(--border); }
.pill-tabs button { padding: 5px 12px; border: 0; background: transparent; color: var(--text-dim); border-radius: 7px; cursor: pointer; font-size: 12.5px; }
.pill-tabs button.on { background: var(--bg-hover); color: var(--text); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--text-faint); }
.kv dd { margin: 0; }

.sep { height: 1px; background: var(--border); margin: 14px 0; }

/* --- Модальные окна ----------------------------------------------------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 150; background: rgba(4, 6, 11, .72); backdrop-filter: blur(3px); display: grid; place-items: start center; padding: 40px 16px; overflow-y: auto; }
.modal { width: 100%; background: var(--bg-elev); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow); }
.modal-body { padding: 18px; max-height: calc(100vh - 220px); overflow-y: auto; }

/* --- Карточка заказа 60/40 ---------------------------------------------- */
.original-text { white-space: pre-wrap; line-height: 1.6; font-size: 13.5px; max-height: 460px; overflow-y: auto; padding-right: 6px; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px 18px; }
.meta-item .m-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); }
.meta-item .m-value { font-size: 14px; margin-top: 2px; }

.score-row { display: grid; grid-template-columns: 110px 1fr 38px; align-items: center; gap: 10px; padding: 5px 0; font-size: 12.5px; }
.score-big { font-size: 40px; font-weight: 700; letter-spacing: -.03em; line-height: 1; }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* --- Диалог ------------------------------------------------------------- */
.thread { display: flex; flex-direction: column; gap: 10px; max-height: 60vh; overflow-y: auto; padding: 4px; }
.msg { max-width: 78%; padding: 9px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; }
.msg.in { align-self: flex-start; background: var(--bg-elev-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; background: rgba(91,140,255,.16); border: 1px solid rgba(91,140,255,.32); border-bottom-right-radius: 4px; }
.msg .msg-meta { font-size: 11px; color: var(--text-faint); margin-top: 5px; display: flex; gap: 8px; }

/* --- Доска Pipeline ----------------------------------------------------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.board-col { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 140px; }
.board-col header { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.board-col .col-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); }
.board-col .col-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.board-card { background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; cursor: pointer; }
.board-card:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.board-card .bc-title { font-size: 12.5px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.board-card .bc-meta { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: 7px; font-size: 11px; color: var(--text-faint); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters .input, .filters .select { width: auto; min-width: 130px; }
