/* ============================================================
   BLACK STORE CRM — design system
   Industrial control-room minimalism: graphite, thin rules,
   one signal accent, condensed technical type.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg:        #0A0B0D;
  --bg-1:      #0F1114;
  --bg-2:      #14171C;
  --bg-3:      #1A1E24;
  --bg-4:      #22272F;

  --line:      rgba(255,255,255,.065);
  --line-2:    rgba(255,255,255,.11);
  --line-3:    rgba(255,255,255,.18);

  --fg:        #EDEEF0;
  --fg-2:      #A0A7B2;
  --fg-3:      #6C7480;
  --fg-4:      #4A515B;

  --white:     #FFFFFF;
  --red:       #FF5C5C;
  --amber:     #FFB547;
  --green:     #4ADE80;
  --blue:      #6BA6FF;
  --violet:    #A78BFA;

  --r-sm: 6px;
  --r:    10px;
  --r-lg: 14px;

  --font-display: "Bahnschrift", "DIN Alternate", "Franklin Gothic Medium", "Arial Narrow", sans-serif;
  --font-body: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", "SF Mono", monospace;

  --rail-w: 64px;
  --topbar-h: 56px;
}

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 13.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* grain + vignette atmosphere */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: .028;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; padding: 0; }
a { color: inherit; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.09); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.18); background-clip: content-box; }

/* ============================ shell ============================ */

.app {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ---------------------------- rail ---------------------------- */

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 0 10px;
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  z-index: 30;
}

.rail-brand {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  color: var(--white);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  margin-bottom: 14px;
  background: linear-gradient(160deg, #1C2027, #0E1013);
}

.rail-nav { display: flex; flex-direction: column; gap: 2px; width: 100%; align-items: center; }

.rail-btn {
  position: relative;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  color: var(--fg-3);
  transition: color .16s, background .16s;
}
.rail-btn:hover { color: var(--fg); background: rgba(255,255,255,.045); }
.rail-btn.is-active { color: var(--white); background: rgba(255,255,255,.075); }
.rail-btn.is-active::before {
  content: "";
  position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
  width: 2px; height: 18px; border-radius: 2px; background: var(--white);
}
.rail-btn .dot {
  position: absolute; top: 7px; right: 7px;
  min-width: 15px; height: 15px; padding: 0 4px;
  border-radius: 99px;
  background: var(--red); color: #fff;
  font-family: var(--font-mono); font-size: 9.5px; font-weight: 700;
  display: grid; place-items: center;
  box-shadow: 0 0 0 2px var(--bg-1);
}

.rail-foot { margin-top: auto; }
.rail-user { display: block; border-radius: 50%; }

/* tooltip */
.rail-btn::after {
  content: attr(data-label);
  position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%) translateX(-4px);
  background: var(--bg-4); color: var(--fg);
  font-family: var(--font-display); font-size: 11.5px; letter-spacing: .04em;
  padding: 5px 9px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2);
  white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity .14s, transform .14s;
  z-index: 60;
}
.rail-btn:hover::after { opacity: 1; transform: translateY(-50%) translateX(0); }

/* -------------------------- workspace ------------------------- */

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
}

.topbar-left { display: flex; align-items: baseline; gap: 12px; min-width: 0; }

.topbar-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
}

.topbar-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right { display: flex; align-items: center; gap: 8px; }

.store-switch {
  display: flex;
  padding: 2px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.store-switch button {
  padding: 5px 11px;
  border-radius: 4px;
  font-family: var(--font-display);
  font-size: 11.5px;
  letter-spacing: .03em;
  color: var(--fg-3);
  transition: color .14s, background .14s;
  white-space: nowrap;
}
.store-switch button:hover { color: var(--fg); }
.store-switch button.is-active { background: var(--bg-4); color: var(--white); }

.views { flex: 1 1 auto; min-height: 0; position: relative; }
.view { display: none; height: 100%; min-height: 0; }
.view.is-active { display: flex; }

/* ========================== primitives ========================= */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 32px; padding: 0 13px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-2);
  background: var(--bg-3);
  color: var(--fg);
  font-family: var(--font-display);
  font-size: 12px; font-weight: 500; letter-spacing: .03em;
  white-space: nowrap;
  transition: background .14s, border-color .14s, color .14s, transform .08s;
}
.btn:hover { background: var(--bg-4); border-color: var(--line-3); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--white); border-color: var(--white); color: #0A0B0D; font-weight: 600; }
.btn-primary:hover { background: #E4E6E9; border-color: #E4E6E9; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--fg-2); }
.btn-ghost:hover { background: rgba(255,255,255,.05); color: var(--fg); border-color: transparent; }
.btn-danger { color: var(--red); border-color: rgba(255,92,92,.28); background: rgba(255,92,92,.07); }
.btn-danger:hover { background: rgba(255,92,92,.14); border-color: rgba(255,92,92,.45); }
.btn-sm { height: 27px; padding: 0 9px; font-size: 11px; }
.btn-icon { width: 32px; padding: 0; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label {
  font-family: var(--font-display);
  font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--fg-3);
}

.input, .select, .textarea {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  color: var(--fg);
  font-size: 13px;
  outline: none;
  transition: border-color .14s, background .14s;
}
.textarea { height: auto; min-height: 68px; padding: 8px 10px; resize: vertical; line-height: 1.45; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--line-3); background: var(--bg-3); }
.input::placeholder, .textarea::placeholder { color: var(--fg-4); }
.select { appearance: none; padding-right: 26px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236C7480' stroke-width='1.4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
.select option { background: var(--bg-3); }

.avatar {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--bg-4);
  border: 1px solid var(--line-2);
  font-family: var(--font-display);
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  color: var(--fg-2);
  flex: 0 0 auto;
  user-select: none;
}
.avatar.sm { width: 22px; height: 22px; font-size: 9px; }
.avatar.lg { width: 42px; height: 42px; font-size: 14px; }
.avatar.tone-1 { background: #1E2A3A; color: #8FB8F0; border-color: #2A3B52; }
.avatar.tone-2 { background: #2A2438; color: #B9A6F0; border-color: #3B3350; }
.avatar.tone-3 { background: #1F2E28; color: #86D9B0; border-color: #2C4238; }
.avatar.tone-4 { background: #33261E; color: #E8B48A; border-color: #4A3729; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 20px; padding: 0 7px;
  border-radius: 4px;
  font-family: var(--font-display);
  font-size: 10.5px; font-weight: 500; letter-spacing: .04em;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge-new      { color: var(--blue);  background: rgba(107,166,255,.10); border-color: rgba(107,166,255,.22); }
.badge-unread   { color: var(--red);   background: rgba(255,92,92,.10);  border-color: rgba(255,92,92,.22); }
.badge-noreply  { color: var(--amber); background: rgba(255,181,71,.10); border-color: rgba(255,181,71,.22); }
.badge-work     { color: var(--green); background: rgba(74,222,128,.10); border-color: rgba(74,222,128,.22); }
.badge-wait     { color: var(--violet);background: rgba(167,139,250,.10);border-color: rgba(167,139,250,.22); }
.badge-attn     { color: var(--red);   background: rgba(255,92,92,.14);  border-color: rgba(255,92,92,.34); }
.badge-closed   { color: var(--fg-3);  background: rgba(255,255,255,.04);border-color: var(--line-2); }
.badge-neutral  { color: var(--fg-2);  background: rgba(255,255,255,.05);border-color: var(--line-2); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px;
  border-radius: 4px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--line);
  font-size: 11px; color: var(--fg-2);
  white-space: nowrap;
}
.chip button { color: var(--fg-4); font-size: 13px; line-height: 1; }
.chip button:hover { color: var(--red); }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--fg-3); }
.dim { color: var(--fg-4); }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; height: 100%; padding: 40px 20px;
  color: var(--fg-4); text-align: center;
}
.empty svg { opacity: .5; }
.empty-title { font-family: var(--font-display); font-size: 13px; color: var(--fg-3); letter-spacing: .03em; }
.empty-sub { font-size: 12px; max-width: 280px; }

/* =========================== dialogs =========================== */

.dlg-layout {
  display: grid;
  grid-template-columns: 336px minmax(0,1fr) 312px;
  height: 100%;
  min-height: 0;
}
.dlg-layout.no-card { grid-template-columns: 336px minmax(0,1fr); }

/* ---- list column ---- */
.dlg-list {
  display: flex; flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--bg-1);
}

.dlg-tabs {
  display: flex; gap: 2px;
  padding: 10px 10px 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.dlg-tabs::-webkit-scrollbar { display: none; }
.dlg-tab {
  position: relative;
  padding: 7px 9px 9px;
  font-family: var(--font-display);
  font-size: 11.5px; letter-spacing: .03em;
  color: var(--fg-3);
  white-space: nowrap;
  border-bottom: 1.5px solid transparent;
  transition: color .14s, border-color .14s;
}
.dlg-tab:hover { color: var(--fg); }
.dlg-tab.is-active { color: var(--white); border-bottom-color: var(--white); }
.dlg-tab .n {
  font-family: var(--font-mono); font-size: 10px;
  color: var(--fg-4); margin-left: 4px;
}
.dlg-tab.is-active .n { color: var(--fg-2); }

.dlg-filters {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}
.dlg-filters .select { height: 27px; font-size: 11.5px; flex: 1 1 88px; min-width: 88px; }

.dlg-scroll { flex: 1 1 auto; overflow-y: auto; min-height: 0; }

.dlg-item {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0,1fr) auto;
  gap: 10px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background .12s;
}
.dlg-item:hover { background: rgba(255,255,255,.028); }
.dlg-item.is-active { background: rgba(255,255,255,.055); }
.dlg-item.is-active::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: var(--white);
}
.dlg-item.is-unread .dlg-name { color: var(--white); font-weight: 600; }
.dlg-item.is-unread .dlg-preview { color: var(--fg-2); }

.dlg-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.dlg-row1 { display: flex; align-items: center; gap: 6px; min-width: 0; }
.dlg-name {
  font-family: var(--font-display);
  font-size: 13px; font-weight: 500; letter-spacing: .01em;
  color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dlg-preview {
  font-size: 12px; color: var(--fg-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dlg-meta { display: flex; align-items: center; gap: 5px; margin-top: 2px; flex-wrap: wrap; }

.dlg-side { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.dlg-time { font-family: var(--font-mono); font-size: 10.5px; color: var(--fg-4); white-space: nowrap; }
.dlg-unread {
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 99px; background: var(--red); color: #fff;
  font-family: var(--font-mono); font-size: 10px; font-weight: 700;
  display: grid; place-items: center;
}

.src-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--font-display);
  font-size: 10px; letter-spacing: .05em; text-transform: uppercase;
  color: var(--fg-3);
}
.src-dot { width: 6px; height: 6px; border-radius: 2px; flex: 0 0 auto; }
.src-telegram .src-dot { background: #4FA8E0; }
.src-max .src-dot      { background: #9B7BFF; }
.src-avito .src-dot    { background: #4ADE80; }
.src-insales .src-dot  { background: #FFB547; }
.src-retail .src-dot   { background: #A0A7B2; }

/* ---- chat column ---- */
.chat {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--bg);
}

.chat-head {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
  flex: 0 0 auto;
}
.chat-head-main { min-width: 0; flex: 1 1 auto; }
.chat-head-name {
  font-family: var(--font-display);
  font-size: 14px; font-weight: 600; letter-spacing: .01em;
  display: flex; align-items: center; gap: 8px;
}
.chat-head-sub {
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px; color: var(--fg-3); margin-top: 2px;
}
.chat-head-actions { display: flex; align-items: center; gap: 6px; }

.presence {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--amber);
  padding: 3px 7px; border-radius: 4px;
  background: rgba(255,181,71,.09);
  border: 1px solid rgba(255,181,71,.2);
}
.presence .pulse {
  width: 5px; height: 5px; border-radius: 50%; background: var(--amber);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

.chat-body {
  flex: 1 1 auto; overflow-y: auto; min-height: 0;
  padding: 18px 16px 8px;
  display: flex; flex-direction: column; gap: 2px;
}

.day-sep {
  align-self: center;
  margin: 14px 0 10px;
  padding: 3px 10px;
  border-radius: 99px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-family: var(--font-display);
  font-size: 10px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--fg-4);
}

.msg { display: flex; gap: 9px; max-width: 76%; margin-bottom: 8px; }
.msg.in  { align-self: flex-start; }
.msg.out { align-self: flex-end; flex-direction: row-reverse; }

.msg-bubble {
  padding: 8px 11px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.42;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.in .msg-bubble {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.msg.out .msg-bubble {
  background: #E9EBEE;
  color: #0A0B0D;
  border-bottom-right-radius: 4px;
}
.msg-foot {
  display: flex; align-items: center; gap: 6px;
  margin-top: 3px;
  font-family: var(--font-mono); font-size: 10px;
  color: var(--fg-4);
}
.msg.out .msg-foot { justify-content: flex-end; }
.msg-author { font-family: var(--font-display); font-size: 10.5px; color: var(--fg-3); letter-spacing: .02em; }
.msg-state { display: inline-flex; align-items: center; gap: 3px; }
.msg-state.read { color: var(--blue); }
.msg-state.unknown { color: var(--fg-4); }

.msg-note {
  align-self: center;
  max-width: 82%;
  margin: 6px 0 10px;
  padding: 7px 11px;
  border-radius: var(--r-sm);
  background: rgba(255,181,71,.06);
  border: 1px dashed rgba(255,181,71,.28);
  font-size: 12px; color: #E8C48A;
}
.msg-note .note-label {
  display: block;
  font-family: var(--font-display);
  font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase;
  color: rgba(255,181,71,.75); margin-bottom: 3px;
}

.chat-compose {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  background: var(--bg-1);
  padding: 10px 12px 12px;
}
.compose-mode {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.mode-toggle {
  display: flex; padding: 2px; gap: 2px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-sm);
}
.mode-toggle button {
  padding: 4px 10px; border-radius: 4px;
  font-family: var(--font-display); font-size: 11px; letter-spacing: .03em;
  color: var(--fg-3);
}
.mode-toggle button.is-active { background: var(--bg-4); color: var(--fg); }
.mode-toggle button.is-active.note-mode { background: rgba(255,181,71,.16); color: var(--amber); }

.compose-row { display: flex; gap: 8px; align-items: flex-end; }
.compose-row .textarea { min-height: 40px; max-height: 140px; }
.compose-hint { font-size: 11px; color: var(--fg-4); margin-top: 6px; }

/* ---- client card ---- */
.card-col {
  display: flex; flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--bg-1);
  overflow-y: auto;
}
.card-sec { padding: 13px 14px; border-bottom: 1px solid var(--line); }
.card-sec:last-child { border-bottom: none; }
.card-sec-title {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-family: var(--font-display);
  font-size: 10px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--fg-4);
  margin-bottom: 9px;
}
.card-id { display: flex; align-items: center; gap: 10px; }
.card-id-name { font-family: var(--font-display); font-size: 14px; font-weight: 600; }
.card-id-sub { font-size: 11.5px; color: var(--fg-3); margin-top: 1px; }

.kv { display: flex; flex-direction: column; gap: 7px; }
.kv-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 12px; }
.kv-k { color: var(--fg-3); flex: 0 0 auto; }
.kv-v { color: var(--fg); text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv-v.mono { font-size: 11.5px; }

.mini-order {
  display: block; width: 100%; text-align: left;
  padding: 8px 9px; margin-bottom: 6px;
  border-radius: var(--r-sm);
  background: var(--bg-2);
  border: 1px solid var(--line);
  transition: border-color .14s, background .14s;
}
.mini-order:hover { border-color: var(--line-3); background: var(--bg-3); }
.mini-order-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mini-order-num { font-family: var(--font-mono); font-size: 11px; color: var(--fg-2); }
.mini-order-title { font-size: 12px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-order-sum { font-family: var(--font-mono); font-size: 11.5px; color: var(--fg-2); margin-top: 3px; }

.note-item {
  padding: 7px 9px; margin-bottom: 6px;
  border-radius: var(--r-sm);
  background: rgba(255,181,71,.05);
  border-left: 2px solid rgba(255,181,71,.4);
  font-size: 12px; color: var(--fg-2);
}
.note-item .note-meta { font-family: var(--font-mono); font-size: 10px; color: var(--fg-4); margin-top: 3px; }

/* ============================ orders =========================== */

.page { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.page-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
  flex: 0 0 auto;
}
.page-bar .select { height: 29px; font-size: 12px; width: auto; min-width: 118px; }
.page-bar .input { height: 29px; font-size: 12px; width: 200px; }
.page-bar-spacer { flex: 1 1 auto; }

.page-body { flex: 1 1 auto; overflow-y: auto; min-height: 0; }

.table { width: 100%; border-collapse: collapse; }
.table thead th {
  position: sticky; top: 0; z-index: 2;
  text-align: left;
  padding: 9px 12px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line-2);
  font-family: var(--font-display);
  font-size: 10px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase;
  color: var(--fg-4);
  white-space: nowrap;
}
.table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  vertical-align: middle;
}
.table tbody tr { cursor: pointer; transition: background .12s; }
.table tbody tr:hover { background: rgba(255,255,255,.03); }
.table .num { font-family: var(--font-mono); font-size: 11.5px; color: var(--fg-2); white-space: nowrap; }
.table .money { font-family: var(--font-mono); font-size: 12px; text-align: right; white-space: nowrap; }
.table .money.due { color: var(--amber); }
.table .money.paid { color: var(--green); }
.table .cell-main { font-weight: 500; }
.table .cell-sub { font-size: 11px; color: var(--fg-3); margin-top: 1px; }
.row-overdue td { background: rgba(255,92,92,.045); }
.row-overdue:hover td { background: rgba(255,92,92,.075); }

/* ============================ tasks ============================ */

.task-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
  padding: 14px 16px;
}
.task-card {
  display: flex; flex-direction: column; gap: 9px;
  padding: 12px 13px;
  border-radius: var(--r);
  background: var(--bg-1);
  border: 1px solid var(--line);
  transition: border-color .14s, background .14s;
  cursor: pointer;
}
.task-card:hover { border-color: var(--line-3); background: var(--bg-2); }
.task-card.is-done { opacity: .55; }
.task-card.is-overdue { border-color: rgba(255,92,92,.3); }
.task-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.task-title { font-size: 13px; font-weight: 500; line-height: 1.35; }
.task-card.is-done .task-title { text-decoration: line-through; }
.task-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 11px; color: var(--fg-3); }
.task-links { display: flex; gap: 5px; flex-wrap: wrap; }
.prio { display: inline-flex; align-items: center; gap: 4px; font-family: var(--font-display); font-size: 10px; letter-spacing: .05em; text-transform: uppercase; }
.prio-high { color: var(--red); }
.prio-med  { color: var(--amber); }
.prio-low  { color: var(--fg-3); }

/* ============================ search =========================== */

.search-wrap { max-width: 860px; margin: 0 auto; padding: 22px 20px 40px; width: 100%; }
.search-hero { margin-bottom: 18px; }
.search-input {
  width: 100%; height: 46px;
  padding: 0 16px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  font-size: 15px;
  outline: none;
}
.search-input:focus { border-color: var(--line-3); background: var(--bg-3); }
.search-hint { font-size: 11.5px; color: var(--fg-4); margin-top: 8px; }
.search-group { margin-top: 22px; }
.search-group-title {
  font-family: var(--font-display);
  font-size: 10px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--fg-4); margin-bottom: 8px;
}
.search-hit {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg-1);
  margin-bottom: 6px;
  cursor: pointer;
  transition: border-color .14s, background .14s;
}
.search-hit:hover { border-color: var(--line-3); background: var(--bg-2); }
.search-hit-main { min-width: 0; flex: 1 1 auto; }
.search-hit-title { font-size: 13px; font-weight: 500; }
.search-hit-sub { font-size: 11.5px; color: var(--fg-3); margin-top: 1px; }

/* ============================ admin =========================== */

.admin-wrap { padding: 16px; overflow-y: auto; }
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 9px;
  margin-bottom: 16px;
}
.kpi {
  padding: 13px 14px;
  border-radius: var(--r);
  background: var(--bg-1);
  border: 1px solid var(--line);
}
.kpi-label {
  font-family: var(--font-display);
  font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--fg-4);
}
.kpi-value {
  font-family: var(--font-display);
  font-size: 25px; font-weight: 600; letter-spacing: -.01em;
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}
.kpi-value small { font-size: 13px; font-weight: 400; color: var(--fg-3); margin-left: 3px; }
.kpi-foot { font-size: 11px; color: var(--fg-3); margin-top: 3px; }
.kpi.alert { border-color: rgba(255,92,92,.28); background: rgba(255,92,92,.045); }
.kpi.alert .kpi-value { color: var(--red); }

.panel {
  border-radius: var(--r);
  background: var(--bg-1);
  border: 1px solid var(--line);
  margin-bottom: 12px;
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}
.panel-title {
  font-family: var(--font-display);
  font-size: 12px; font-weight: 600; letter-spacing: .04em;
}
.panel-body { padding: 12px 14px; }
.panel-body.flush { padding: 0; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.bar-label { width: 132px; flex: 0 0 auto; font-size: 12px; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1 1 auto; height: 6px; border-radius: 99px; background: rgba(255,255,255,.055); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: var(--fg-2); transition: width .5s cubic-bezier(.2,.8,.2,1); }
.bar-fill.accent { background: var(--white); }
.bar-val { width: 62px; flex: 0 0 auto; text-align: right; font-family: var(--font-mono); font-size: 11px; color: var(--fg-2); }

.sla-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px; align-items: center;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.sla-row:last-child { border-bottom: none; }
.sla-row.breach { background: rgba(255,92,92,.05); }
.sla-time { font-family: var(--font-mono); font-size: 11.5px; }
.sla-time.ok { color: var(--green); }
.sla-time.warn { color: var(--amber); }
.sla-time.bad { color: var(--red); }

.excl-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.excl-row:last-child { border-bottom: none; }
.excl-main { flex: 1 1 auto; min-width: 0; }
.excl-val { font-family: var(--font-mono); font-size: 11.5px; color: var(--fg-2); }
.excl-sub { font-size: 11px; color: var(--fg-4); margin-top: 1px; }

.switch {
  position: relative; width: 34px; height: 19px; flex: 0 0 auto;
  border-radius: 99px; background: var(--bg-4); border: 1px solid var(--line-2);
  transition: background .16s, border-color .16s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--fg-3);
  transition: transform .16s, background .16s;
}
.switch.on { background: rgba(74,222,128,.2); border-color: rgba(74,222,128,.4); }
.switch.on::after { transform: translateX(15px); background: var(--green); }

/* ============================ modal ============================ */

.modal-root { position: fixed; inset: 0; z-index: 200; pointer-events: none; }
.modal-root.is-open { pointer-events: auto; }

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(4,5,7,.72);
  backdrop-filter: blur(3px);
  opacity: 0; transition: opacity .18s;
}
.modal-root.is-open .modal-backdrop { opacity: 1; }

.modal {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%) scale(.97);
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  display: flex; flex-direction: column;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  box-shadow: 0 24px 70px rgba(0,0,0,.6);
  opacity: 0; transition: opacity .18s, transform .18s;
}
.modal-root.is-open .modal { opacity: 1; transform: translate(-50%,-50%) scale(1); }
.modal.wide { width: min(820px, calc(100vw - 32px)); }

.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.modal-title { font-family: var(--font-display); font-size: 14px; font-weight: 600; letter-spacing: .02em; }
.modal-body { padding: 16px; overflow-y: auto; flex: 1 1 auto; }
.modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-sec {
  grid-column: 1 / -1;
  font-family: var(--font-display);
  font-size: 10px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--fg-4);
  padding-top: 6px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}
.form-sec:first-child { border-top: none; padding-top: 0; margin-top: 0; }

.calc-box {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 13px;
  border-radius: var(--r-sm);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
}
.calc-label { font-family: var(--font-display); font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--fg-3); }
.calc-value { font-family: var(--font-display); font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.calc-value.due { color: var(--amber); }
.calc-value.zero { color: var(--green); }

/* ============================ toast ============================ */

.toast-root {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: 7px; align-items: center;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 14px;
  border-radius: var(--r-sm);
  background: var(--bg-4);
  border: 1px solid var(--line-3);
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  font-size: 12.5px;
  animation: toastIn .22s cubic-bezier(.2,.8,.2,1);
  max-width: min(460px, calc(100vw - 32px));
}
.toast.err { border-color: rgba(255,92,92,.4); background: #2A1618; }
.toast.ok  { border-color: rgba(74,222,128,.35); background: #14251C; }
.toast .t-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-2); flex: 0 0 auto; }
.toast.err .t-dot { background: var(--red); }
.toast.ok .t-dot { background: var(--green); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* =========================== responsive ======================== */

/* ============================ login ============================ */

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(255,255,255,.045), transparent 70%),
    var(--bg);
}

.login-card {
  width: min(420px, 100%);
  padding: 26px 24px 22px;
  border-radius: var(--r-lg);
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  box-shadow: 0 30px 80px rgba(0,0,0,.55);
}

.login-brand {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: .28em;
  color: var(--fg-4);
  margin-bottom: 14px;
}

.login-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: .01em;
}

.login-sub {
  font-size: 12.5px;
  color: var(--fg-3);
  margin-top: 6px;
  margin-bottom: 18px;
  line-height: 1.45;
}

.login-list { display: flex; flex-direction: column; gap: 6px; }

.login-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 11px;
  text-align: left;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg-2);
  transition: border-color .14s, background .14s;
}
.login-item:hover { border-color: var(--line-3); background: var(--bg-3); }

.login-item-main { display: flex; flex-direction: column; min-width: 0; }
.login-item-name { font-family: var(--font-display); font-size: 13px; font-weight: 500; }
.login-item-sub { font-size: 11px; color: var(--fg-3); margin-top: 1px; }
.login-empty { font-size: 12px; color: var(--fg-3); padding: 12px 0; }

/* =========================== responsive ======================== */

@media (max-width: 1280px) {
  .dlg-layout { grid-template-columns: 300px minmax(0,1fr) 280px; }
}

@media (max-width: 1080px) {
  .dlg-layout { grid-template-columns: 300px minmax(0,1fr); }
  .card-col { display: none; }
  .dlg-layout.show-card { grid-template-columns: minmax(0,1fr); }
  .dlg-layout.show-card .dlg-list,
  .dlg-layout.show-card .chat { display: none; }
  .dlg-layout.show-card .card-col { display: flex; }
}

@media (max-width: 760px) {
  :root { --rail-w: 54px; --topbar-h: 52px; }
  .app { grid-template-columns: var(--rail-w) 1fr; }
  .rail-btn { width: 40px; height: 40px; }
  .topbar { padding: 0 12px; }
  .topbar-sub { display: none; }
  .store-switch button { padding: 5px 8px; font-size: 10.5px; }

  .dlg-layout { grid-template-columns: minmax(0,1fr); }
  .dlg-layout .chat { display: none; }
  .dlg-layout.mobile-chat .dlg-list { display: none; }
  .dlg-layout.mobile-chat .chat { display: flex; }
  .card-col { display: none !important; }

  .form-grid { grid-template-columns: 1fr; }
  .table thead { display: none; }
  .table tbody tr { display: block; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .table tbody td { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border: none; }
  .table tbody td::before {
    content: attr(data-label);
    font-family: var(--font-display); font-size: 10px; letter-spacing: .07em;
    text-transform: uppercase; color: var(--fg-4);
  }
  .task-grid { grid-template-columns: 1fr; padding: 12px; }
  .admin-wrap { padding: 12px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.login-bitrix { text-decoration: none; color: inherit; }
