/* ============================================================
   CryptoCashPoint CRM — оформление
   Вся палитра вынесена в переменные. Чтобы поменять тему —
   правим только блоки :root (тёмная) и [data-theme="light"].
   ============================================================ */

:root {
  /* Бренд */
  --brand: #7c3aed;
  --brand-600: #6d28d9;
  --brand-700: #5b21b6;
  --brand-soft: rgba(124, 58, 237, 0.15);

  /* Тёмная тема (основная) */
  --bg: #0f0d17;
  --bg-elev: #171423;
  --panel: #1c1830;
  --panel-2: #241f3a;
  --border: #2e2747;
  --text: #ece9f5;
  --text-dim: #a39fb8;
  --text-mute: #6f6a85;

  --bubble-client: #241f3a;
  --bubble-client-border: transparent;
  --bubble-op: #6d28d9;
  --bubble-op-text: #ffffff;

  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --badge: #ef4444;

  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
  --radius: 14px;
  --radius-sm: 10px;
}

[data-theme="light"] {
  --bg: #f4f2fb;
  --bg-elev: #ffffff;
  --panel: #ffffff;
  --panel-2: #f6f4fc;
  --border: #e6e1f3;
  --text: #1c172b;
  --text-dim: #5f5876;
  --text-mute: #9b95ad;

  --bubble-client: #ffffff;
  --bubble-client-border: #d9d2ee;
  --bubble-op: #7c3aed;
  --bubble-op-text: #ffffff;

  --shadow: 0 8px 30px rgba(80, 50, 160, 0.10);
  --shadow-sm: 0 2px 10px rgba(80, 50, 160, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-mute); }
::-webkit-scrollbar-track { background: transparent; }

.hidden { display: none !important; }

/* ===================== LOGIN ===================== */
#login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(900px 500px at 80% -10%, var(--brand-soft), transparent),
    var(--bg);
}
.login-card {
  width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 20px; font-weight: 700; margin-bottom: 4px;
}
.login-logo .dot {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), var(--brand-700));
  display: grid; place-items: center; color: #fff; font-size: 16px;
}
.login-sub { color: var(--text-dim); margin: 0 0 22px; font-size: 13px; }
.login-card label { display: block; font-size: 12px; color: var(--text-dim); margin: 14px 0 6px; }
.login-card input {
  width: 100%; padding: 11px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
}
.login-card input:focus { outline: none; border-color: var(--brand); }
.login-card button {
  width: 100%; margin-top: 22px; padding: 12px;
  border: none; border-radius: var(--radius-sm);
  background: var(--brand); color: #fff; font-weight: 600; font-size: 14px;
}
.login-card button:hover { background: var(--brand-600); }
.login-error { color: var(--danger); font-size: 12px; margin-top: 12px; min-height: 16px; }

/* ===================== LAYOUT ===================== */
#app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; gap: 16px;
  padding: 0 18px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.topbar .logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.topbar .logo .dot {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--brand-700));
  display: grid; place-items: center; color: #fff;
}
.topbar .spacer { flex: 1; }
.topbar .op-name { color: var(--text-dim); font-size: 13px; }
.icon-btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; font-size: 16px;
}
.icon-btn:hover { border-color: var(--brand); }
.text-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text-dim);
  padding: 7px 12px; border-radius: 9px; font-size: 13px;
}
.text-btn:hover { color: var(--text); border-color: var(--brand); }

.main { flex: 1; display: grid; grid-template-columns: 320px 1fr 320px; min-height: 0; }

/* ===================== LEFT: deals list ===================== */
.left {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--bg-elev); border-right: 1px solid var(--border);
}
.left .head { padding: 16px 16px 10px; }
.left .head h2 { margin: 0 0 12px; font-size: 17px; }
.tabs { display: flex; gap: 4px; background: var(--panel-2); padding: 4px; border-radius: 10px; }
.tabs button {
  flex: 1; border: none; background: transparent; color: var(--text-dim);
  padding: 7px 2px; border-radius: 7px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.tabs button[data-status="blocked"] { flex: 0 0 32px; font-size: 13px; }
.tabs button.active { background: var(--brand); color: #fff; }
.search { padding: 10px 16px; }
.search input {
  width: 100%; padding: 9px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 13px;
}
.search input:focus { outline: none; border-color: var(--brand); }

.deal-list { flex: 1; overflow-y: auto; padding: 4px 8px 16px; }
.deal-item {
  display: flex; gap: 11px; align-items: center;
  padding: 10px; border-radius: 11px; cursor: pointer; position: relative;
}
.deal-item:hover { background: var(--panel-2); }
.deal-item.active { background: var(--brand-soft); }
.avatar {
  width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 16px;
}
.deal-item .mid { flex: 1; min-width: 0; }
.deal-item .row1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.deal-item .name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deal-item .time { color: var(--text-mute); font-size: 11px; flex-shrink: 0; }
.deal-item .preview { color: var(--text-dim); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.badge {
  background: var(--badge); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px;
  display: grid; place-items: center; margin-top: 4px;
}
.empty-hint { color: var(--text-mute); text-align: center; padding: 40px 20px; font-size: 13px; }

/* ===================== CENTER: chat ===================== */
.center { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.chat-head {
  height: 60px; flex-shrink: 0; display: flex; align-items: center; gap: 12px;
  padding: 0 18px; border-bottom: 1px solid var(--border); background: var(--bg-elev);
}
.chat-head .who { flex: 1; min-width: 0; }
.chat-head .who .n { font-weight: 600; }
.chat-head .who .meta { color: var(--text-mute); font-size: 12px; margin-top: 1px; }
.chat-head .status-pill {
  font-size: 11px; padding: 3px 9px; border-radius: 20px; font-weight: 600;
  background: var(--panel-2); color: var(--text-dim);
}

.messages { flex: 1; overflow-y: auto; padding: 22px 22px 8px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 68%; padding: 9px 13px; border-radius: 15px; font-size: 13.5px; line-height: 1.4; word-wrap: break-word; }
.msg .t { display: block; font-size: 10.5px; margin-top: 4px; opacity: 0.65; }
.msg.client { align-self: flex-start; background: var(--bubble-client); color: var(--text); border-bottom-left-radius: 5px; border: 1px solid var(--bubble-client-border); box-shadow: var(--shadow-sm); }
.msg.operator { align-self: flex-end; background: var(--bubble-op); color: var(--bubble-op-text); border-bottom-right-radius: 5px; }
.day-sep { align-self: center; font-size: 11px; color: var(--text-mute); background: var(--panel-2); padding: 3px 12px; border-radius: 12px; margin: 8px 0; }
.msg-img { display: block; max-width: 240px; max-height: 280px; border-radius: 10px; margin-bottom: 4px; cursor: zoom-in; }

/* ===================== ОТЧЁТ ===================== */
#report {
  position: fixed; inset: 0; z-index: 150;
  background: var(--bg); display: flex; flex-direction: column;
}
.report-head {
  height: 60px; flex-shrink: 0; display: flex; align-items: center; gap: 14px;
  padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--bg-elev);
}
.report-head h2 { margin: 0; font-size: 18px; }
.report-head .spacer { flex: 1; }
.report-total { color: var(--text-dim); font-size: 13px; }
.report-body { flex: 1; overflow-y: auto; padding: 18px 20px 40px; }
.report-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-table th {
  text-align: left; padding: 10px 12px; color: var(--text-dim); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg);
}
.report-table td { padding: 11px 12px; border-bottom: 1px solid var(--border); }
.report-table tbody tr:hover { background: var(--panel-2); }
.report-table .num { font-variant-numeric: tabular-nums; }
.report-table .money { font-weight: 600; }
.report-table .reward { color: var(--ok); font-weight: 600; }
.report-more-wrap { display: flex; justify-content: center; margin-top: 18px; }
.report-empty { color: var(--text-mute); text-align: center; padding: 40px; }

/* Просмотрщик фото (lightbox) */
#lightbox {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.88);
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out;
}
#lightbox img {
  max-width: 94vw; max-height: 92vh;
  border-radius: 8px; background: #fff;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.6);
}
#lightbox-close {
  position: absolute; top: 18px; right: 24px;
  color: #fff; font-size: 30px; line-height: 1; cursor: pointer;
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 50%; background: rgba(255, 255, 255, 0.12);
}
#lightbox-close:hover { background: rgba(255, 255, 255, 0.25); }
.msg-file {
  display: inline-flex; align-items: center; gap: 6px; margin-bottom: 4px;
  padding: 8px 11px; border-radius: 10px; background: rgba(0,0,0,0.15);
  color: inherit; text-decoration: none; font-size: 13px; max-width: 100%;
}
.msg.operator .msg-file { background: rgba(255,255,255,0.18); }
.msg-file:hover { text-decoration: underline; }
/* плееры прямо в сообщении: голосовые и видео-кружки */
.msg-audio { display: block; width: 260px; max-width: 100%; margin-bottom: 4px; }
.msg-video { display: block; max-width: 240px; max-height: 280px; border-radius: 10px; margin-bottom: 4px; background: #000; }

.composer {
  flex-shrink: 0; border-top: 1px solid var(--border); padding: 12px 16px;
  display: flex; gap: 9px; align-items: flex-end; background: var(--bg-elev);
}
.composer textarea {
  flex: 1; resize: none; max-height: 120px; min-height: 42px;
  padding: 11px 13px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 13.5px; line-height: 1.4;
}
.composer textarea:focus { outline: none; border-color: var(--brand); }
.send-btn {
  width: 42px; height: 42px; border-radius: 12px; border: none;
  background: var(--brand); color: #fff; font-size: 18px; flex-shrink: 0;
}
.send-btn:hover { background: var(--brand-600); }
.send-btn:disabled { opacity: 0.5; cursor: default; }

.no-chat { flex: 1; display: grid; place-items: center; color: var(--text-mute); text-align: center; }
.no-chat .big { font-size: 40px; margin-bottom: 10px; }

/* ===================== RIGHT: deal + templates ===================== */
.right { display: flex; flex-direction: column; min-height: 0; background: var(--bg-elev); border-left: 1px solid var(--border); }

/* переключатель Сделка / Шаблоны */
.right-tabs {
  display: flex; gap: 6px; flex-shrink: 0;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.right-tabs button {
  flex: 1; padding: 9px 6px; border-radius: 9px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text-dim);
}
.right-tabs button:hover { border-color: var(--brand); color: var(--text); }
.right-tabs button.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.right-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.right-pane.hidden { display: none !important; }
.right .section { padding: 16px; border-bottom: 1px solid var(--border); }
.right .section h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); }

/* Client card (collapsible) */
.client-card .cc-head { display: flex; align-items: center; gap: 11px; cursor: pointer; user-select: none; }
.client-card .cc-head .avatar { width: 38px; height: 38px; border-radius: 11px; font-size: 15px; flex-shrink: 0; }
.client-card .cc-head .cc-who { flex: 1; min-width: 0; }
.client-card .cc-name { font-weight: 600; font-size: 14px; }
.client-card .cc-id { color: var(--text-mute); font-size: 11.5px; margin-top: 1px; }
.cc-toggle {
  background: none; border: none; color: var(--text-dim); font-size: 12px;
  width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0; transition: transform 0.15s;
}
.cc-toggle:hover { background: var(--panel-2); color: var(--text); }
.cc-body { display: none; margin-top: 12px; }
.client-card.open .cc-body { display: block; }
.cc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cc-stat { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.cc-stat .v { font-weight: 700; font-size: 15px; }
.cc-stat .k { color: var(--text-dim); font-size: 11px; margin-top: 1px; }
.cc-meta { margin-top: 10px; font-size: 12px; color: var(--text-dim); line-height: 1.7; }
.cc-meta b { color: var(--text); font-weight: 600; }
.cc-banned { color: var(--danger); font-weight: 600; }

.field { margin-bottom: 11px; }
.field .lbl { font-size: 12px; color: var(--text-dim); margin-bottom: 5px; display: block; }
.field-row { display: flex; gap: 8px; }
.field-row input {
  flex: 1; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 13px;
}
.field-row input:focus { outline: none; border-color: var(--brand); }
.field-row button {
  padding: 0 14px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-weight: 600;
}
.field-row button:hover { border-color: var(--brand); }

.pct-row { display: flex; gap: 8px; margin: 6px 0 14px; }
.pct-row button {
  flex: 1; padding: 9px 0; border-radius: 9px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-weight: 700;
}
.pct-row button.sel { background: var(--brand); color: #fff; border-color: var(--brand); }
.pct-row button:hover { border-color: var(--brand); }

.deal-actions { display: flex; gap: 9px; }
.btn-lg { flex: 1; padding: 12px; border-radius: 11px; border: none; font-weight: 700; font-size: 13.5px; color: #fff; }
.btn-ok { background: var(--ok); }
.btn-ok:hover { filter: brightness(1.07); }
.btn-cancel { background: var(--danger); }
.btn-cancel:hover { filter: brightness(1.07); }

.deal-summary { font-size: 12.5px; color: var(--text-dim); margin-top: 10px; line-height: 1.7; }
.deal-summary b { color: var(--text); }

/* Templates */
.tpl-section { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-bottom: 0; }
.tpl-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.tpl-head h3 { margin: 0; }
.mini-btn {
  background: var(--brand-soft); border: 1px solid var(--brand); color: var(--brand);
  padding: 5px 10px; border-radius: 8px; font-size: 12px; font-weight: 600;
}
[data-theme="light"] .mini-btn { color: var(--brand-700); }
.mini-btn:hover { background: var(--brand); color: #fff; }
.tpl-item { position: relative; }
.tpl-actions { position: absolute; top: 6px; right: 8px; display: none; gap: 4px; }
.tpl-item:hover .tpl-actions { display: flex; }
.tpl-edit, .tpl-del {
  width: 20px; height: 20px; display: grid; place-items: center;
  border-radius: 5px; color: var(--text-mute); font-size: 12px;
}
.tpl-edit:hover { background: var(--brand); color: #fff; }
.tpl-del:hover { background: var(--danger); color: #fff; }
.tpl-search { margin-bottom: 10px; }
.tpl-search input {
  width: 100%; padding: 8px 11px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 12.5px;
}
.tpl-search input:focus { outline: none; border-color: var(--brand); }
.tpl-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 7px; padding-bottom: 16px; }
.tpl-item {
  text-align: left; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
}
.tpl-item:hover { border-color: var(--brand); background: var(--panel); }
.tpl-item .tt { font-weight: 600; font-size: 12.5px; display: flex; justify-content: space-between; }
.tpl-item .tt .cat { color: var(--text-mute); font-weight: 500; font-size: 11px; }
.tpl-item .bb { color: var(--text-dim); font-size: 11.5px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===================== TOASTS / MODAL ===================== */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: center; }
.toast {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px;
  animation: toastin 0.18s ease;
}
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--danger); }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: grid; place-items: center; z-index: 90;
}
.modal {
  width: 440px; max-width: 92vw; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 14px; }
.modal pre { white-space: pre-wrap; word-wrap: break-word; background: var(--panel-2); padding: 12px; border-radius: 10px; max-height: 50vh; overflow: auto; font-size: 12.5px; color: var(--text-dim); }
.modal .actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 16px; }
.modal label { display: block; font-size: 12px; color: var(--text-dim); margin: 12px 0 6px; }
.modal input, .modal textarea {
  width: 100%; padding: 10px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 13px;
}
.modal input:focus, .modal textarea:focus { outline: none; border-color: var(--brand); }
.modal textarea { resize: vertical; min-height: 90px; line-height: 1.4; }
.btn-primary {
  background: var(--brand); border: 1px solid var(--brand); color: #fff;
  padding: 8px 16px; border-radius: 9px; font-weight: 600; font-size: 13px;
}
.btn-primary:hover { background: var(--brand-600); }
