/* =========================================================================
   Дарима — витрина. Госстиль: синий/золото, Lora + Golos Text (self-hosted).
   ========================================================================= */

:root{
  --blue:#003DA5; --gold:#F2C200; --gold-deep:#B8860B; --blue-deep:#062C63;
  --blue-mid:#2E6CB8; --paper:#F5F6F8; --card:#FFFFFF; --ink:#14243B;
  --muted:#5B6B80; --line:#DCE3ED; --ok:#1C7B4D; --alert:#B23A2E;
  --user-bubble:#EAF0FA;
  --serif:'Lora',Georgia,'Times New Roman',serif;
  --sans:'Golos Text','Helvetica Neue',Arial,sans-serif;
  --shadow-card: 0 1px 2px rgba(6,44,99,.05), 0 8px 24px -12px rgba(6,44,99,.18);
  --header-h: 84px;
  --tabbar-h: 60px;
}

*{box-sizing:border-box; margin:0; padding:0;}
/* атрибут hidden обязан побеждать любые классовые display: (иначе .badge{display:inline-block}
   и подобные правила той же специфичности переигрывают [hidden] по порядку каскада) */
[hidden]{display:none !important;}
html,body{height:100%;}
body{
  background:var(--paper);
  color:var(--ink);
  font-family:var(--sans);
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
  overflow:hidden;
  overflow-x:hidden; /* дублируем явно: страница не скроллится вбок ни при каких условиях */
}

/* защита от «раздувания» grid/flex-контейнеров чужим intrinsic-min-width
   (частый источник горизонтального переполнения на мобильных) */
.grid, .col, .card, .msg, .msg-bubble{min-width:0;}

h1,h2,h3{font-family:var(--serif); color:var(--blue-deep); font-weight:600;}

.kicker{
  font-size:11px; font-weight:700; letter-spacing:.18em; text-transform:uppercase;
  color:var(--blue-mid); margin-bottom:8px;
}

button{font-family:var(--sans); cursor:pointer;}

/* ===== card primitive ===== */
.card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:16px;
  box-shadow:var(--shadow-card);
  padding:20px 22px;
}

/* =========================================================================
   Гейт доступа
   ========================================================================= */
.gate{
  position:fixed; inset:0; z-index:1000;
  background:linear-gradient(160deg, var(--blue-deep) 0%, #0a2f6b 45%, var(--blue) 100%);
  display:flex; align-items:center; justify-content:center;
  padding:24px;
}
.gate[hidden]{display:none;}
.gate-card{
  background:var(--card);
  border-radius:20px;
  padding:40px 36px;
  width:100%; max-width:380px;
  box-shadow:0 24px 60px -20px rgba(0,0,0,.5);
  text-align:left;
}
.gate-card h2{font-size:22px; margin-bottom:8px;}
.gate-hint{color:var(--muted); font-size:14px; margin-bottom:22px; line-height:1.5;}
#gate-form{display:flex; gap:10px;}
#gate-code{
  flex:1; min-width:0;
  border:1px solid var(--line); border-radius:10px;
  padding:12px 14px; font-size:16px; font-family:var(--sans);
  color:var(--ink); background:var(--paper);
}
#gate-code:focus{outline:2px solid var(--blue-mid); outline-offset:1px;}
#gate-submit{
  border:none; border-radius:10px; padding:12px 18px;
  background:var(--blue); color:#fff; font-weight:600; font-size:15px;
  transition:background .15s ease;
}
#gate-submit:hover{background:var(--blue-deep);}
.gate-error{
  margin-top:14px; color:var(--alert); font-size:13px; font-weight:600;
}

/* =========================================================================
   Шапка
   ========================================================================= */
.app-shell{display:flex; flex-direction:column; height:100vh;}

.app-header{
  height:var(--header-h);
  flex:0 0 auto;
  display:flex; align-items:center; justify-content:space-between;
  gap:24px;
  padding:0 28px;
  background:var(--card);
  border-bottom:1px solid var(--line);
}
.header-left h1{font-size:22px; line-height:1.15;}
.header-right{display:flex; flex-direction:column; align-items:flex-end; gap:6px;}

.line-indicator{
  display:flex; align-items:center; gap:8px;
  font-size:13px; font-weight:600; color:var(--ink);
}
.line-dot{
  width:9px; height:9px; border-radius:50%;
  background:var(--muted);
  box-shadow:0 0 0 0 rgba(28,123,77,.5);
}
.line-indicator[data-state="free"] .line-dot{
  background:var(--ok);
  animation:dot-pulse 2.2s ease-in-out infinite;
}
.line-indicator[data-state="busy"] .line-dot{background:var(--gold-deep);}
.line-indicator[data-state="full"] .line-dot{background:var(--alert);}
@keyframes dot-pulse{
  0%,100%{box-shadow:0 0 0 0 rgba(28,123,77,.35);}
  50%{box-shadow:0 0 0 5px rgba(28,123,77,0);}
}
.disclaimer{font-size:11.5px; color:var(--muted); text-align:right; max-width:280px; line-height:1.4;}

/* =========================================================================
   Сетка колонок
   ========================================================================= */
.grid{
  flex:1 1 auto;
  min-height:0;
  display:grid;
  grid-template-columns: 380px 1fr 360px;
  gap:20px;
  padding:20px 20px 0;
  overflow:hidden;
}

.col{
  min-height:0;
  overflow-y:auto;
  display:flex; flex-direction:column; gap:16px;
  padding-bottom:20px;
  scrollbar-width:thin;
}
.col::-webkit-scrollbar{width:8px;}
.col::-webkit-scrollbar-thumb{background:var(--line); border-radius:8px;}

/* =========================================================================
   Колонка 1 — Звонок
   ========================================================================= */
.orb-card{display:flex; flex-direction:column; align-items:center; text-align:center; gap:10px;}
.orb-wrap{width:220px; height:220px; display:flex; align-items:center; justify-content:center;}
#orb-canvas{width:220px; height:220px;}

.call-status{font-size:15px; font-weight:600; color:var(--ink); min-height:20px;}
.call-timer{
  font-family:var(--serif); font-variant-numeric:tabular-nums;
  font-size:26px; color:var(--blue-deep); letter-spacing:.02em;
}
.call-btn{
  margin-top:6px;
  width:100%;
  border:none; border-radius:12px;
  padding:14px 20px;
  font-size:15px; font-weight:700;
  background:var(--blue); color:#fff;
  transition:background .15s ease, transform .1s ease;
}
.call-btn:hover{background:var(--blue-deep);}
.call-btn:active{transform:scale(.98);}
.call-btn.active{background:var(--alert);}
.call-btn.active:hover{background:#8f2c22;}
.call-btn:disabled{opacity:.55; cursor:not-allowed;}

.transcript-card{flex:1; display:flex; flex-direction:column; min-height:220px;}
.transcript{
  flex:1; overflow-y:auto; margin-top:4px;
  display:flex; flex-direction:column; gap:10px;
  padding-right:2px;
}

.msg{display:flex; gap:8px; max-width:92%;}
.msg-bot{align-self:flex-start;}
.msg-user{align-self:flex-end; flex-direction:row-reverse;}
.msg-system{align-self:center; max-width:100%;}

.msg-avatar{
  flex:0 0 auto; width:26px; height:26px; border-radius:50%;
  background:var(--blue); color:#fff;
  display:flex; align-items:center; justify-content:center;
  font-family:var(--serif); font-weight:600; font-size:13px;
}
.msg-bubble{
  border-radius:14px; padding:9px 13px; font-size:14px; line-height:1.45;
  overflow-wrap:break-word;
}
.msg-bot .msg-bubble{background:var(--card); border:1px solid var(--line); color:var(--ink); border-top-left-radius:4px;}
.msg-user .msg-bubble{background:var(--user-bubble); color:var(--ink); border-top-right-radius:4px;}
.msg-system{
  font-size:12px; color:var(--blue-mid); font-weight:700;
  background:rgba(46,108,184,.08); border-radius:999px; padding:5px 12px;
  text-align:center;
}
.msg.interim .msg-bubble{opacity:.6; font-style:italic;}
.msg.filler .msg-bubble{opacity:.5; font-style:italic; background:transparent; border-color:transparent; padding-left:0;}
.msg.filler{gap:0;}
.msg.filler .msg-avatar{display:none;}

/* =========================================================================
   Колонка 2 — Дарима понимает
   ========================================================================= */
.timeline{
  list-style:none;
  display:flex; align-items:flex-start; justify-content:space-between;
  gap:4px;
}
.timeline-step{
  flex:1;
  display:flex; flex-direction:column; align-items:center; gap:8px;
  text-align:center; position:relative;
}
.timeline-step::before{
  content:"";
  position:absolute; top:6px; left:-50%; width:100%; height:2px;
  background:var(--line); z-index:0;
}
.timeline-step:first-child::before{display:none;}
.tl-dot{
  width:14px; height:14px; border-radius:50%;
  background:var(--card); border:2px solid var(--line);
  position:relative; z-index:1;
  transition:background .3s ease, border-color .3s ease, box-shadow .3s ease;
}
.tl-label{font-size:11px; color:var(--muted); font-weight:600; line-height:1.3;}
.timeline-step.done .tl-dot{background:var(--gold); border-color:var(--gold-deep); box-shadow:0 0 0 3px rgba(242,194,0,.2);}
.timeline-step.done .tl-label{color:var(--ink);}
.timeline-step.active .tl-dot{background:var(--gold); border-color:var(--gold-deep); box-shadow:0 0 0 4px rgba(242,194,0,.28); animation:tl-pulse 1.6s ease-in-out infinite;}
.timeline-step.active .tl-label{color:var(--blue-deep);}
@keyframes tl-pulse{
  0%,100%{box-shadow:0 0 0 4px rgba(242,194,0,.28);}
  50%{box-shadow:0 0 0 7px rgba(242,194,0,.12);}
}

.card-obrashcheniya{position:relative;}
.card-badges{display:flex; gap:8px; margin-bottom:10px; flex-wrap:wrap;}
.badge{
  display:inline-block; font-size:11px; font-weight:700; letter-spacing:.03em;
  border-radius:999px; padding:5px 12px;
  background:#EEF1F5; color:var(--muted);
}
.badge-urgency[data-level="normal"]{background:#EEF1F5; color:var(--muted);}
.badge-urgency[data-level="elevated"]{background:#FBEEC7; color:#8a6d24;}
.badge-urgency[data-level="urgent"]{background:#F6DEDC; color:var(--alert);}
.badge-suicide{background:#F6DEDC; color:var(--alert);}
.urgency-source{margin:-2px 0 10px; font-size:11.5px; color:var(--muted);}
.card-placeholder{
  margin-top:4px; padding:18px 14px; border:1px dashed var(--line); border-radius:8px;
  font-size:13.5px; line-height:1.45; text-align:center; color:var(--muted);
}
.field-badge{
  display:inline-block; margin-left:6px; padding:1px 7px; border-radius:999px;
  font-size:10.5px; font-weight:700; letter-spacing:.02em; vertical-align:1px;
  background:#FBEEC7; color:#8a6d24;
}

.card-fields{display:flex; flex-direction:column; margin-top:4px;}
.field-row{
  display:flex; justify-content:space-between; gap:14px;
  padding:9px 0; border-bottom:1px dashed var(--line);
  font-size:13.5px; border-radius:4px;
  transition:background-color 1.2s ease;
}
.field-row:last-child{border-bottom:none;}
.field-label{color:var(--muted); flex:0 0 auto;}
.field-value{
  font-weight:600; text-align:right; color:var(--ink);
  max-width:58%;
  opacity:1;
  overflow-wrap:break-word;
  transition:opacity .4s ease;
}
.field-value.empty{color:var(--line); font-weight:400;}
.field-row.flash{background-color:rgba(242,194,0,.25);}
.field-value.fade-in{animation:field-fade-in .4s ease;}
@keyframes field-fade-in{
  from{opacity:0; transform:translateY(-2px);}
  to{opacity:1; transform:translateY(0);}
}

.response-time{margin-top:12px; font-size:11.5px; color:var(--muted);}

/* =========================================================================
   Колонка 3 — Результат
   ========================================================================= */
.stats-row{display:grid; grid-template-columns:repeat(3,1fr); gap:12px;}
.stat-tile{
  background:var(--card); border:1px solid var(--line); border-radius:14px;
  padding:14px 10px; text-align:center; box-shadow:var(--shadow-card);
}
.stat-value{font-family:var(--serif); font-size:32px; color:var(--blue-deep); font-weight:600; line-height:1;}
.stat-value.hot{color:var(--gold-deep);}
.stat-label{margin-top:6px; font-size:11px; color:var(--muted); font-weight:600;}

.registry-card{flex:1; display:flex; flex-direction:column; min-height:200px;}
.registry-list{display:flex; flex-direction:column; margin-top:6px; overflow-y:auto; min-height:0;}
.registry-empty{color:var(--muted); font-size:13px; padding:12px 0;}
.registry-empty[hidden]{display:none;}
.registry-rows{display:flex; flex-direction:column; gap:8px;}
.reg-row{
  display:flex; align-items:center; gap:10px;
  border:1px solid var(--line); border-radius:10px;
  padding:9px 11px; font-size:12.5px;
  transition:box-shadow .3s ease, border-color .3s ease;
}
.reg-row.fresh{
  border-color:var(--gold-deep);
  box-shadow:0 0 0 2px rgba(242,194,0,.35);
  animation:reg-fade 3s ease forwards;
}
@keyframes reg-fade{
  0%{box-shadow:0 0 0 2px rgba(242,194,0,.5);}
  85%{box-shadow:0 0 0 2px rgba(242,194,0,.35);}
  100%{box-shadow:0 0 0 0 rgba(242,194,0,0); border-color:var(--line);}
}
.reg-num{font-family:'Golos Text',monospace; font-variant-numeric:tabular-nums; font-weight:700; color:var(--blue-deep); flex:0 0 auto;}
.reg-cat{color:var(--ink); flex:1 1 auto; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
.reg-deadline{color:var(--muted); font-size:11.5px; flex:0 0 auto; text-align:right;}

.letter-card{position:relative; overflow:visible;}
.letter-stamp{
  position:absolute; top:-14px; right:18px;
  transform:rotate(-3deg);
  background:var(--card);
  border:2px solid var(--gold-deep);
  color:var(--gold-deep);
  font-weight:800; font-size:12px; letter-spacing:.06em;
  padding:6px 12px; border-radius:6px;
  box-shadow:0 4px 10px -4px rgba(0,0,0,.25);
}
.letter-to{font-weight:700; margin:6px 0 8px; color:var(--blue-deep); font-size:14px;}
.letter-text{
  white-space:pre-wrap; overflow-wrap:break-word; font-size:13.5px; line-height:1.6; color:var(--ink);
  max-height:calc(12 * 1.6em + 4px);
  overflow:hidden;
  position:relative;
}
.letter-text.expanded{max-height:none;}
.letter-expand{
  margin-top:10px; border:1px solid var(--line); background:transparent;
  color:var(--blue-mid); font-weight:600; font-size:12.5px;
  border-radius:8px; padding:7px 12px;
}
.letter-expand:hover{background:var(--paper);}

/* =========================================================================
   Футер / таббар
   ========================================================================= */
.app-footer{
  flex:0 0 auto; text-align:center; padding:8px;
  font-size:11px; color:var(--muted);
}
.tabbar{display:none;}

/* =========================================================================
   Мобайл (<1100px)
   ========================================================================= */
@media (max-width: 1099.98px){
  body{overflow-x:hidden; overflow-y:auto;}
  .app-shell{height:auto; min-height:100vh;}
  .app-header{
    height:auto; flex-wrap:wrap; align-items:flex-start;
    padding:14px 16px; gap:10px;
  }
  .header-left h1{font-size:18px;}
  .header-right{align-items:flex-start;}
  .disclaimer{text-align:left; max-width:none;}

  .grid{
    grid-template-columns:1fr;
    padding:14px 14px calc(var(--tabbar-h) + 14px);
    overflow:visible;
    gap:14px;
  }
  .col{
    overflow-y:visible;
    display:none;
    padding-bottom:0;
  }
  .col.tab-active{display:flex;}

  .tabbar{
    display:flex;
    position:fixed; left:0; right:0; bottom:0; z-index:100;
    height:var(--tabbar-h);
    background:var(--card);
    border-top:1px solid var(--line);
    box-shadow:0 -6px 18px -10px rgba(6,44,99,.25);
  }
  .tab-btn{
    flex:1; border:none; background:transparent;
    font-family:var(--sans); font-size:12.5px; font-weight:600;
    color:var(--muted);
    display:flex; align-items:center; justify-content:center;
    position:relative;
  }
  .tab-btn.active{color:var(--blue);}
  .tab-btn.active::before{
    content:""; position:absolute; top:0; left:22%; right:22%; height:2px;
    background:var(--gold);
  }
  .app-footer{padding-bottom:calc(var(--tabbar-h) + 10px);}
}

/* wide phones vs small phones: modest tightening */
@media (max-width: 420px){
  .stats-row{gap:8px;}
  .stat-value{font-size:26px;}
  .call-timer{font-size:22px;}
}

/* =========================================================================
   Pre-flight «Проверка связи» — панель в orb-card до начала звонка
   ========================================================================= */
.preflight{
  margin-top:14px; padding:16px;
  border:1px solid var(--line); border-radius:12px;
  background:var(--paper); text-align:left; width:100%;
}
.pf-step{font-size:15px; font-weight:600; color:var(--blue-deep); line-height:1.4;}
.pf-mic-label{font-size:12px; color:var(--muted); margin-top:6px;}
.pf-meter{margin-top:10px; height:10px; border-radius:6px; background:var(--line); overflow:hidden;}
.pf-meter-fill{
  height:100%; width:0; border-radius:6px;
  background:linear-gradient(90deg, var(--blue-mid), var(--ok));
  transition:width .12s linear;
}
.pf-hint{
  margin-top:10px; padding:10px 12px; border-radius:10px;
  background:#F6DEDC; color:var(--alert);
  font-size:13px; line-height:1.45; font-weight:600;
}
.pf-mic-select{
  margin-top:10px; width:100%; padding:9px 10px;
  border:1px solid var(--line); border-radius:10px;
  font-family:var(--sans); font-size:14px; background:var(--card); color:var(--ink);
}
.pf-actions{margin-top:12px; display:flex; gap:10px; align-items:center; flex-wrap:wrap;}
.call-btn.pf-start{width:auto; padding:10px 18px; font-size:14px;}
.pf-retry{
  padding:10px 16px; border:1px solid var(--blue-mid); border-radius:10px;
  background:var(--card); color:var(--blue); font-weight:600; font-size:14px;
}
.pf-retry:hover{background:var(--user-bubble);}
.pf-skip{
  margin-left:auto; background:none; border:none;
  color:var(--muted); font-size:12px; text-decoration:underline;
}
.pf-skip:hover{color:var(--ink);}
