/* Обложка Bitrix24 CRM — светлая рабочая область, графитовый сайдбар,
   цвета стадий приходят из настроек портала (meta), а не из этого файла. */

:root {
  --ink: #1c2733;
  --ink-2: #66778a;
  --accent: #2066c9;
  --accent-soft: #e3edfa;
  --bg: #eef1f5;
  --surface: #ffffff;
  --line: #dde4ec;
  --side: #1c2733;
  --side-ink: #aebbc9;
  --danger: #c0392b;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
}

#layout { display: flex; min-height: 100vh; }

/* ---------- сайдбар ---------- */

#sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--side);
  color: var(--side-ink);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 16px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; letter-spacing: -.5px;
}
.brand-title { color: #fff; font-weight: 600; font-size: 15px; line-height: 1.1; }
.brand-sub { font-size: 11px; margin-top: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; margin: 2px 0;
  border-radius: 8px;
  color: var(--side-ink); text-decoration: none;
  font-weight: 500;
}
.nav-item svg { width: 17px; height: 17px; fill: currentColor; stroke: currentColor; flex: 0 0 17px; }
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }

.sidebar-foot { margin-top: auto; padding: 10px 8px 2px; font-size: 11px; line-height: 1.5; }
.sidebar-foot a { color: var(--side-ink); }

/* ---------- рабочая область ---------- */

#view { flex: 1; min-width: 0; padding: 22px 26px 40px; }

.page-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 21px; font-weight: 650; letter-spacing: -.2px; }
.page-head .total { color: var(--ink-2); font-size: 13px; }
.page-head .spacer { flex: 1; }

.toolbar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 14px;
}
.toolbar label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--ink-2); }
.toolbar input, .toolbar select {
  font: inherit; font-size: 13px;
  color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px;
  padding: 6px 8px; background: #fff;
  min-width: 0;
}
.toolbar input:focus, .toolbar select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.toolbar .search { width: 240px; }
.toolbar .grow { flex: 1; }

button, .btn {
  font: inherit; font-size: 13px; font-weight: 550;
  border: 1px solid var(--line); border-radius: 7px;
  background: #fff; color: var(--ink);
  padding: 7px 12px; cursor: pointer;
}
button:hover, .btn:hover { border-color: var(--accent); color: var(--accent); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { color: #fff; opacity: .92; }
.btn-ghost { border-color: transparent; color: var(--ink-2); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 7px 14px; }
.seg button.on { background: var(--accent); color: #fff; }

/* ---------- таблица ---------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
}
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 12px; text-align: left; white-space: nowrap; }
th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--ink-2); font-weight: 600;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface);
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent); }
th .arrow { font-size: 9px; }
td { border-bottom: 1px solid #f0f3f7; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f6f9fd; }
tbody tr:last-child td { border-bottom: 0; }
td.num { text-align: right; }
td .dim { color: var(--ink-2); }
.cell-title { font-weight: 550; max-width: 480px; overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 550; color: #fff;
  background: var(--ink-2);
  vertical-align: middle;
  white-space: nowrap;
}

.pager { display: flex; align-items: center; gap: 10px; margin-top: 12px; color: var(--ink-2); font-size: 13px; }
.pager .spacer { flex: 1; }

.note { color: var(--ink-2); font-size: 12px; margin: 8px 2px; }

/* ---------- состояния ---------- */

.state { padding: 46px 20px; text-align: center; color: var(--ink-2); }
.state .big { font-size: 15px; font-weight: 550; color: var(--ink); margin-bottom: 6px; }
.error-box {
  background: #fdf1ef; border: 1px solid #f2c9c3; color: var(--danger);
  border-radius: var(--radius); padding: 12px 14px; margin: 10px 0;
}

.skeleton td span {
  display: inline-block; height: 12px; border-radius: 6px;
  background: linear-gradient(90deg, #edf1f6 25%, #f7f9fc 50%, #edf1f6 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- канбан ---------- */

.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 14px; align-items: flex-start; }
.kan-col {
  flex: 0 0 272px; width: 272px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.kan-head {
  padding: 10px 12px 9px;
  border-bottom: 3px solid var(--line);
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
}
.kan-name { font-weight: 600; font-size: 13px; }
.kan-count { color: var(--ink-2); font-size: 12px; flex: 0 0 auto; }
.kan-cards { padding: 8px; display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 290px); overflow-y: auto; }
.kan-card {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; cursor: pointer; background: #fff;
}
.kan-card:hover { border-color: var(--accent); box-shadow: 0 1px 4px rgba(32, 102, 201, .12); }
.kan-card .t { font-weight: 550; font-size: 13px; margin-bottom: 4px; }
.kan-card .m { color: var(--ink-2); font-size: 12px; display: flex; justify-content: space-between; gap: 8px; }
.kan-card .money { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.kan-more { margin: 0 8px 8px; }

/* ---------- сводка ---------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer;
}
.tile:hover { border-color: var(--accent); }
.tile .n { font-size: 26px; font-weight: 700; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--ink-2); font-size: 12px; margin-top: 2px; }

.chart-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px;
}
.chart-card h2 { margin: 0 0 12px; font-size: 14px; font-weight: 650; }
.bar-row { display: grid; grid-template-columns: 220px 1fr 70px; gap: 10px; align-items: center; padding: 4px 0; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .track { background: #f0f3f7; border-radius: 6px; height: 14px; overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 6px; background: var(--accent); min-width: 2px; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* ---------- карточка (drawer) ---------- */

#drawerBackdrop {
  position: fixed; inset: 0; background: rgba(19, 28, 38, .45); z-index: 40;
}
#drawer[hidden], #drawerBackdrop[hidden] { display: none; }
#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41;
  width: min(560px, 94vw);
  background: var(--surface);
  box-shadow: -8px 0 28px rgba(19, 28, 38, .18);
  display: flex; flex-direction: column;
  animation: slide-in .18s ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  #drawer { animation: none; }
  .skeleton td span { animation: none; }
}

.drawer-head {
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; gap: 10px;
}
.drawer-head .kind { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-2); }
.drawer-head h2 { margin: 2px 0 0; font-size: 17px; font-weight: 650; line-height: 1.25; }
.drawer-head .x { margin-left: auto; flex: 0 0 auto; }
.drawer-body { overflow-y: auto; padding: 6px 18px 24px; flex: 1; }

.fgroup { margin-top: 16px; }
.fgroup h3 {
  margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--ink-2); font-weight: 650;
}
.frow { display: grid; grid-template-columns: 170px 1fr; gap: 10px; padding: 6px 0; border-bottom: 1px solid #f2f5f9; font-size: 13px; }
.frow:last-child { border-bottom: 0; }
.frow .k { color: var(--ink-2); }
.frow .v { min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.frow .v a { color: var(--accent); text-decoration: none; }
.frow .v a:hover { text-decoration: underline; }

.rel-item {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin: 6px 0;
  cursor: pointer; font-size: 13px;
}
.rel-item:hover { border-color: var(--accent); }
.rel-item .money { font-weight: 600; flex: 0 0 auto; }

.drawer-actions { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.drawer-actions a { text-decoration: none; display: inline-flex; align-items: center; }

/* ---------- вход ---------- */

.login-wrap { display: flex; justify-content: center; padding-top: 12vh; }
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px 30px 26px; width: 320px; text-align: center;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.login-card h1 { margin: 4px 0 0; font-size: 18px; }
.login-card p { margin: 0 0 6px; color: var(--ink-2); font-size: 13px; }
.login-card input {
  font: inherit; width: 100%; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 8px;
}
.login-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.login-card button { width: 100%; padding: 9px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 16px; }

/* ---------- адаптив ---------- */

@media (max-width: 860px) {
  #layout { flex-direction: column; }
  #sidebar {
    width: auto; height: auto; position: sticky; top: 0; z-index: 30;
    flex: none;
    flex-direction: row; flex-wrap: nowrap; align-items: center; gap: 2px;
    padding: 6px 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .brand { padding: 2px 6px 2px 2px; flex: 0 0 auto; }
  .brand-mark { width: 28px; height: 28px; font-size: 13px; }
  .brand-text, .sidebar-foot { display: none; }
  .nav-item { flex: 0 0 auto; padding: 8px 10px; }
  #view { padding: 12px 12px 28px; }
  .page-head h1 { font-size: 18px; }

  .toolbar { padding: 8px 10px; }
  .toolbar label { flex: 1 1 45%; }
  .toolbar input, .toolbar select, .toolbar .search { width: 100%; }

  th.hide-m, td.hide-m { display: none; }
  th, td { padding: 8px 9px; }
  td { white-space: normal; }
  .cell-title { max-width: none; white-space: normal; overflow: visible; text-overflow: clip; }
  .badge { white-space: normal; border-radius: 10px; }
  .bar-row .name { white-space: normal; }

  .kan-col { flex-basis: 246px; width: 246px; }
  .kan-cards { max-height: none; }
  .kanban { margin: 0 -12px; padding: 0 12px 14px; }

  .tiles { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .tile .n { font-size: 21px; }
  .frow { grid-template-columns: 1fr; gap: 2px; }
  .bar-row { grid-template-columns: 96px 1fr 56px; font-size: 12px; }
  .drawer-head, .drawer-body { padding-left: 14px; padding-right: 14px; }
}
