/* SkyChat — спокойный профессиональный кокпит. Golos Text + тил-акцент. */
:root {
  --paper:    #F4F3EF;
  --surface:  #FFFFFF;
  --surface-2:#FBFAF7;
  --ink:      #1B1D1E;
  --ink-soft: #4C4F52;
  --muted:    #8C8F93;
  --faint:    #B6B8BB;
  --line:     #E7E4DD;
  --line-2:   #EFEDE7;
  --accent:   #0F7A66;
  --accent-d: #0B5E4F;
  --accent-soft:#E3F2EE;
  --amber:    #C8861B;
  --out-bg:   #0F7A66;
  --out-ink:  #F2FBF8;
  --in-bg:    #FFFFFF;
  --danger:   #BE3A36;
  --wa:  #25D366;  --tg: #2AABEE;  --max: #7C5CFF;  --other:#9AA0A6;
  --r:  14px;  --r-sm: 10px;
  --shadow: 0 1px 2px rgba(20,22,24,.04), 0 8px 24px -12px rgba(20,22,24,.18);
  --shadow-pop: 0 12px 40px -12px rgba(20,22,24,.28);
  --font: "Golos Text", -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  overflow: hidden;
}
button, input, textarea { font-family: inherit; }
::selection { background: var(--accent-soft); }

/* Layout: 3 колонки */
.app {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 0px;
  height: 100vh;
  transition: grid-template-columns .28s cubic-bezier(.4,0,.2,1);
}
.app.has-panel { grid-template-columns: 320px minmax(0,1fr) 320px; }

/* ---------- RAIL (диалоги) ---------- */
.rail {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.rail__top { padding: 16px 16px 8px; border-bottom: 1px solid var(--line-2); }
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 800; font-size: 17px; letter-spacing: -.02em; margin-bottom: 14px;
}
.brand__mark {
  color: var(--accent); font-size: 20px;
  transform: translateY(-1px);
}
.rail__search input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: var(--surface-2); color: var(--ink);
  font-size: 13px; outline: none; transition: border-color .15s, background .15s;
}
.rail__search input:focus { border-color: var(--accent); background: #fff; }
.filters { display: flex; gap: 6px; margin-top: 12px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  padding: 5px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 500;
  cursor: pointer; transition: all .15s;
}
.chip:hover { border-color: var(--faint); }
.chip.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }

.dialogs { overflow-y: auto; flex: 1; padding: 6px 8px 16px; min-height: 0; }
.dialogs::-webkit-scrollbar, .messages::-webkit-scrollbar, .panel__body::-webkit-scrollbar { width: 9px; }
.dialogs::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb, .panel__body::-webkit-scrollbar-thumb {
  background: #E1DED7; border-radius: 9px; border: 3px solid var(--surface);
}

.d-item {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 11px;
  align-items: center; padding: 10px 10px; border-radius: var(--r-sm);
  cursor: pointer; position: relative; transition: background .13s;
}
.d-item:hover { background: var(--surface-2); }
.d-item.is-active { background: var(--accent-soft); }
.d-item.is-active::before {
  content: ""; position: absolute; left: -8px; top: 8px; bottom: 8px; width: 3px;
  background: var(--accent); border-radius: 0 3px 3px 0;
}
.d-ava {
  width: 44px; height: 44px; border-radius: 13px; object-fit: cover;
  background: var(--line-2); display: grid; place-items: center;
  font-weight: 700; color: var(--ink-soft); font-size: 15px; position: relative;
  overflow: hidden;
}
.d-ava .ch {
  position: absolute; right: -2px; bottom: -2px; width: 14px; height: 14px;
  border-radius: 50%; border: 2.5px solid var(--surface);
}
.d-main { min-width: 0; }
.d-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-prev { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.d-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.d-time { color: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.d-badge {
  min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center; line-height: 1;
}

/* ---------- THREAD (переписка) ---------- */
.thread { background: var(--paper); display: flex; flex-direction: column; min-width: 0; position: relative; }
.thread__empty {
  margin: auto; text-align: center; color: var(--muted); padding: 40px;
}
.empty-art {
  font-size: 56px; color: var(--line); margin-bottom: 10px;
  animation: floaty 4s ease-in-out infinite;
}
@keyframes floaty { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-7px)} }
.thread__empty h2 { font-size: 18px; color: var(--ink-soft); margin: 0 0 6px; font-weight: 700; }
.thread__empty p { margin: 0; font-size: 13.5px; line-height: 1.6; }

.thread__live { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.thread__head {
  display: flex; align-items: center; gap: 12px; padding: 13px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(20,22,24,.02);
}
.th-ava { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: var(--line-2); font-weight: 700; color: var(--ink-soft); position: relative; overflow: visible; }
.th-ava .ch { position: absolute; right: -3px; bottom: -3px; width: 13px; height: 13px; border-radius: 50%; border: 2.5px solid var(--surface); }
.th-name { font-weight: 700; font-size: 14.5px; }
.th-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.th-actions { margin-left: auto; display: flex; gap: 7px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-soft); cursor: pointer; font-size: 14px;
  display: grid; place-items: center; transition: all .14s;
}
.icon-btn:hover { border-color: var(--faint); color: var(--ink); background: var(--surface-2); }
.icon-btn.is-toggled { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-d); }

.messages {
  flex: 1; overflow-y: auto; padding: 22px 24px; min-height: 0;
  display: flex; flex-direction: column; gap: 3px;
  background:
    radial-gradient(circle at 1px 1px, rgba(20,22,24,.025) 1px, transparent 0) 0 0 / 22px 22px;
}
.day-sep { align-self: center; margin: 14px 0 8px; padding: 4px 12px; border-radius: 999px;
  background: rgba(255,255,255,.7); border: 1px solid var(--line-2); color: var(--muted);
  font-size: 11.5px; font-weight: 500; backdrop-filter: blur(4px); }
.msg { max-width: 70%; display: flex; flex-direction: column; }
.msg.in  { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble {
  padding: 9px 13px; border-radius: 15px; font-size: 13.5px; line-height: 1.45;
  word-wrap: break-word; white-space: pre-wrap; position: relative;
}
.msg.in .bubble {
  background: var(--in-bg); border: 1px solid var(--line); color: var(--ink);
  border-bottom-left-radius: 5px; box-shadow: var(--shadow);
}
.msg.out .bubble {
  background: var(--out-bg); color: var(--out-ink);
  border-bottom-right-radius: 5px;
}
.msg + .msg.in, .msg + .msg.out { margin-top: 8px; }
.msg-time { font-size: 10.5px; color: var(--faint); margin: 3px 4px 0; font-variant-numeric: tabular-nums; }
.msg.out .msg-time { color: var(--muted); }
.msg-author { font-size: 11px; font-weight: 600; color: var(--accent-d); margin: 0 0 3px 4px; }

.composer { padding: 12px 16px 16px; background: var(--surface); border-top: 1px solid var(--line); }
.composer__tpls { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tpl-chip {
  border: 1px dashed var(--line); background: var(--surface-2); color: var(--ink-soft);
  padding: 5px 11px; border-radius: 999px; font-size: 12px; cursor: pointer; transition: all .14s;
}
.tpl-chip:hover { border-style: solid; border-color: var(--accent); color: var(--accent-d); background: #fff; }
.composer__row { display: flex; gap: 10px; align-items: flex-end; }
#input {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 13px;
  padding: 11px 14px; font-size: 13.5px; line-height: 1.4; max-height: 140px; outline: none;
  background: var(--surface-2); transition: border-color .15s, background .15s;
}
#input:focus { border-color: var(--accent); background: #fff; }
.send {
  width: 42px; height: 42px; border-radius: 12px; border: none; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 16px; display: grid; place-items: center;
  transition: transform .12s, background .15s; flex-shrink: 0;
}
.send:hover { background: var(--accent-d); }
.send:active { transform: scale(.92); }
.send:disabled { background: var(--faint); cursor: default; }

/* ---------- PANEL (контекст клиента) ---------- */
.panel { background: var(--surface); border-left: 1px solid var(--line); overflow: hidden; }
.panel__body { padding: 18px 16px; overflow-y: auto; height: 100%; }
.p-sec { margin-bottom: 20px; }
.p-sec h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
  margin: 0 0 10px; font-weight: 700; }
.p-card { border: 1px solid var(--line); border-radius: var(--r); padding: 13px; background: var(--surface-2); }
.p-client-name { font-weight: 700; font-size: 15px; }
.p-client-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.deal-row { display: flex; justify-content: space-between; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line-2); }
.deal-row:last-child { border-bottom: none; }
.deal-row b { font-weight: 600; font-size: 13px; }
.deal-stage { font-size: 11px; color: var(--accent-d); background: var(--accent-soft);
  padding: 2px 8px; border-radius: 6px; display: inline-block; margin-top: 3px; }
.deal-sum { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tags { display: flex; flex-wrap: wrap; gap: 7px; }
.tag {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  padding: 5px 12px; border-radius: 999px; font-size: 12.5px; cursor: pointer; transition: all .14s;
}
.tag:hover { border-color: var(--faint); }
.tag.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.act-row { display: flex; flex-direction: column; gap: 8px; }
.act { width: 100%; padding: 10px 13px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 13px; font-weight: 500; cursor: pointer;
  text-align: left; transition: all .14s; }
.act:hover { background: var(--surface-2); border-color: var(--faint); }
.act.danger { color: var(--danger); border-color: #E7CFCE; }
.act.danger:hover { background: #FBF1F0; }
.act-transfer { display: flex; gap: 8px; }
.act-transfer select { flex: 1; padding: 9px 10px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); font-size: 12.5px; }
.muted-note { color: var(--muted); font-size: 12.5px; line-height: 1.5; }

/* ---------- skeletons / boot ---------- */
.skeleton-list { padding: 6px; }
.sk-row { height: 62px; border-radius: var(--r-sm); margin-bottom: 4px;
  background: linear-gradient(100deg, var(--line-2) 30%, #F6F4EF 50%, var(--line-2) 70%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.boot { position: fixed; inset: 0; background: var(--paper); display: grid; place-items: center;
  z-index: 50; transition: opacity .4s; }
.boot__mark { font-size: 40px; color: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.boot__txt { color: var(--muted); margin-top: 10px; font-size: 13px; }
@keyframes pulse { 0%,100%{opacity:.4; transform:scale(.95)} 50%{opacity:1; transform:scale(1.05)} }
.app[data-state="ready"] .boot { opacity: 0; pointer-events: none; }
.app[data-state="error"] .boot { opacity: 1; }

.fade-in { animation: fadeIn .3s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* адаптив: на узком прячем правую панель оверлеем */
@media (max-width: 1100px) {
  .app.has-panel { grid-template-columns: 300px minmax(0,1fr) 300px; }
}
@media (max-width: 860px) {
  .app, .app.has-panel { grid-template-columns: 1fr; }
  .rail { display: var(--rail-display, flex); }
}
