/* ===========================================================================
   Hisobchi AI — the assistant console.

   The same markup and the same element ids serve two places: the floating
   panel on every marketing page, and the full /chat page. chat.js is written
   once and drives both, so the two must never render at the same time.

   The thread is set as a ledger: each message is an entry with a marker in the
   margin, figures monospaced, and a hairline under every posting.
   ========================================================================= */

/* ============================================================ the fab ==== */

.chatfab {
  position: fixed; right: clamp(16px, 3vw, 30px); bottom: clamp(16px, 3vw, 30px);
  z-index: 80;
  width: 58px; height: 58px; padding: 0;
  border: 0; border-radius: 50%; cursor: pointer;
  background: var(--turq); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(10,37,48,.18), 0 16px 34px -12px rgba(10,115,111,.8);
  transition: transform .28s var(--ease), background .28s var(--ease);
}
.chatfab:hover { transform: translateY(-3px) scale(1.03); background: var(--turq-d); }
.chatfab svg { width: 26px; height: 26px; grid-area: 1/1; transition: opacity .22s var(--ease), transform .3s var(--ease); }
.chatfab__close { opacity: 0; transform: rotate(-90deg); }
.chatfab.is-open .chatfab__icon { opacity: 0; transform: rotate(90deg); }
.chatfab.is-open .chatfab__close { opacity: 1; transform: none; }

/* One slow pulse. It marks the assistant as live without demanding attention
   the way a bouncing badge would. */
.chatfab__ping {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid var(--turq);
  animation: ping 2.8s var(--ease) infinite;
}
.chatfab.is-open .chatfab__ping { display: none; }
@keyframes ping {
  0%   { transform: scale(1);    opacity: .7; }
  70%  { transform: scale(1.55); opacity: 0; }
  100% { transform: scale(1.55); opacity: 0; }
}

/* ========================================================== the panel ==== */

.chatpanel {
  position: fixed; right: clamp(16px, 3vw, 30px); bottom: calc(clamp(16px, 3vw, 30px) + 70px);
  z-index: 79;
  width: min(408px, calc(100vw - 32px));
  max-height: min(640px, calc(100vh - 130px));
  display: flex; flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: 0 4px 12px rgba(10,37,48,.1), 0 34px 70px -24px rgba(10,37,48,.4);
  overflow: hidden;
  animation: panel-in .3s var(--ease);
}
.chatpanel[hidden] { display: none; }

@keyframes panel-in {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .chatpanel { animation: none; } }

.chatpanel__head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 14px 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-2);
  flex: none;
}
.chatpanel__avatar {
  width: 34px; height: 34px; flex: none;
  border-radius: 9px; background: var(--ink); color: var(--turq);
  display: grid; place-items: center;
}
.chatpanel__avatar svg { width: 19px; height: 19px; }

.chatpanel__id { display: grid; gap: 2px; line-height: 1.25; }
.chatpanel__id b { font-family: var(--display); font-size: .96rem; font-weight: 600; letter-spacing: -.015em; }
.chatpanel__id span {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: .62rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-3);
}
.chatpanel__id i { width: 6px; height: 6px; border-radius: 50%; background: var(--turq); }

.chatpanel__x {
  margin-left: auto; width: 32px; height: 32px; flex: none;
  border: 0; background: none; cursor: pointer; color: var(--ink-3);
  border-radius: 8px; display: grid; place-items: center;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.chatpanel__x:hover { background: var(--line-2); color: var(--ink); }
.chatpanel__x svg { width: 17px; height: 17px; }

.chatpanel__body { flex: 1; min-height: 0; display: flex; }

.chatpanel__reset {
  border: 0; background: none; cursor: pointer;
  /* Padding out to a 40px hit area, pulled back by an equal negative margin so
     the label still sits where the layout expects it. A 14px-tall tap target
     is a miss on a phone. */
  padding: 13px 6px; margin: -13px -6px;
  font-family: var(--mono); font-size: .66rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-3);
  transition: color .18s var(--ease);
}
.chatpanel__reset:hover { color: var(--turq-d); }

/* ============================================================= thread ==== */

.thread {
  flex: 1; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 16px 8px;
  display: flex; flex-direction: column; gap: 4px;
  scrollbar-width: thin;
}
.thread::-webkit-scrollbar { width: 8px; }
.thread::-webkit-scrollbar-thumb { background: var(--line); border-radius: 100px; }

/* Each message is a ledger entry: marker in the margin, body beside it, a
   hairline underneath. */
.msg {
  display: grid; grid-template-columns: auto 1fr; gap: 11px;
  padding: 12px 0; border-bottom: 1px solid var(--line-2);
  animation: msg-in .34s var(--ease);
}
.msg:last-child { border-bottom: 0; }
@keyframes msg-in {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .msg { animation: none; } }

.msg__who {
  font-family: var(--mono); font-size: .58rem; font-weight: 600;
  letter-spacing: .08em; line-height: 1.9;
  width: 3.2ch; text-align: right; color: var(--ink-3);
  flex: none;
}
.msg--ai   .msg__who { color: var(--turq-d); }
.msg--error .msg__who { color: #B3261E; }

.msg__body { font-size: .93rem; line-height: 1.62; min-width: 0; }
.msg__body p { margin: 0 0 .7em; }
.msg__body p:last-child { margin-bottom: 0; }
.msg__body ul { margin: .3em 0 .7em; padding-left: 1.15em; }
.msg__body li { margin-bottom: .3em; }
.msg__body strong {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-weight: 700; font-size: .93em; color: var(--ink);
}
.msg__body code {
  font-family: var(--mono); font-size: .86em;
  background: var(--line-2); border-radius: 4px; padding: 1px 5px;
}
.msg__body a { color: var(--turq-d); }

.msg--op .msg__body { color: var(--ink); font-weight: 500; }
.msg--ai .msg__body { color: var(--ink-2); }
.msg--error .msg__body { color: #B3261E; }
.msg--intro .msg__body { color: var(--ink-2); }

.msg__meta {
  display: block; margin-top: 6px;
  font-family: var(--mono); font-size: .58rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-3);
}

/* A block cursor while the answer types itself in. */
.msg__body.is-typing > :last-child::after {
  content: ''; display: inline-block; vertical-align: -2px;
  width: .5em; height: 1em; margin-left: 2px;
  background: var(--turq); animation: caret .9s steps(2) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

.dots { display: inline-flex; gap: 4px; padding: 5px 0; }
.dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3);
  animation: dot 1.3s var(--ease) infinite;
}
.dots span:nth-child(2) { animation-delay: .16s; }
.dots span:nth-child(3) { animation-delay: .32s; }
@keyframes dot {
  0%, 60%, 100% { opacity: .28; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-4px); }
}

/* =============================================================== chips === */

.chips { display: grid; gap: 8px; padding: 6px 0 10px; }

.chip {
  display: grid; gap: 3px; text-align: left;
  padding: 12px 14px; cursor: pointer;
  background: var(--paper); color: inherit;
  border: 1px solid var(--line); border-radius: var(--r);
  transition: border-color .2s var(--ease), background .2s var(--ease), transform .2s var(--ease);
}
.chip:hover { border-color: var(--turq); background: var(--turq-wash); transform: translateX(3px); }
.chip b { font-size: .89rem; font-weight: 600; color: var(--ink); }
.chip span { font-size: .79rem; color: var(--ink-3); line-height: 1.45; }

/* ============================================================ composer === */

.composer {
  flex: none; padding: 12px 16px 14px;
  border-top: 1px solid var(--line);
  background: var(--paper-2);
}

.composer__form {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--r);
  padding: 7px 7px 7px 13px;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.composer__form:focus-within {
  border-color: var(--turq);
  box-shadow: 0 0 0 3px var(--turq-wash);
}

.composer__form textarea {
  flex: 1; min-width: 0;
  border: 0; outline: 0; resize: none; background: none;
  font-family: var(--body); font-size: .93rem; line-height: 1.5;
  color: var(--ink); padding: 7px 0; max-height: 160px;
}
.composer__form textarea::placeholder { color: var(--ink-3); }

.composer__actions { display: flex; align-items: center; gap: 6px; flex: none; }

.icon-btn {
  width: 42px; height: 42px; flex: none;
  display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--line); border-radius: 100px;
  background: var(--paper); color: var(--ink-2);
  transition: color .2s var(--ease), border-color .2s var(--ease), background .2s var(--ease);
}
.icon-btn:hover { color: var(--turq-d); border-color: var(--turq); }
.icon-btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn.is-recording {
  background: #B3261E; border-color: #B3261E; color: #fff;
  animation: rec 1.2s ease-in-out infinite;
}
@keyframes rec { 50% { box-shadow: 0 0 0 6px rgba(179,38,30,.18); } }

#send:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.composer__status {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 9px; min-height: 16px;
}
.composer__status .mono {
  font-size: .64rem; line-height: 1.4; color: var(--ink-3);
  flex: 1; min-width: 0;
}
.composer__status .is-live  { color: var(--turq-d); }
.composer__status .is-alert { color: #B3261E; }

/* ============================================================== langs ==== */

.langs { display: flex; gap: 5px; margin-top: 10px; }
.lang {
  flex: 1;
  padding: 10px 6px; min-height: 40px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 100px;
  background: var(--paper); color: var(--ink-3);
  font-family: var(--body); font-size: .75rem; font-weight: 500;
  transition: color .2s var(--ease), border-color .2s var(--ease), background .2s var(--ease);
}
.lang:hover { color: var(--ink); border-color: var(--ink-3); }
.lang.is-active {
  background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600;
}

/* ====================================================== the /chat page === */
/* The same components, given a page to breathe in: a two-column console with
   the thread on the right and what the assistant does — and does not do — on
   the left, where it stays visible while you type. */

/* The assistant gets its own ground. The rest of the site is porcelain; this
   is a dark workspace with the console sitting on it like a lit window, so
   that opening the chat feels like stepping into the tool rather than reading
   another page of the brochure. */
.console {
  position: relative; isolation: isolate; overflow: hidden;
  padding: clamp(26px, 4vw, 44px) 0 clamp(48px, 6vw, 76px);
  background: linear-gradient(180deg, #0A2530 0%, #0D3140 55%, #09222C 100%);
  color: rgba(255,255,255,.75);
}

/* A working grid, and a slow bloom of the brand colours over it. */
.console::before {
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(255,255,255,.055) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,.055) 1px, transparent 1px);
  background-size: 48px 48px;
  -webkit-mask-image: radial-gradient(130% 90% at 50% 0%, #000 25%, transparent 80%);
          mask-image: radial-gradient(130% 90% at 50% 0%, #000 25%, transparent 80%);
}
.console::after {
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(46% 40% at 12% 8%, hsl(176 78% 46% / .22), transparent 68%),
    radial-gradient(44% 42% at 88% 78%, hsl(223 66% 56% / .20), transparent 68%);
}

/* Everything in the aside has to flip for the dark ground. The console shell
   itself stays white — the conversation is the one thing that must read like
   a document, not like a terminal. */
.console h1 { color: #fff; }
.console .eyebrow { color: var(--turq); }
.console .eyebrow::before { background: var(--turq); }

.console__grid {
  display: grid;
  grid-template-columns: minmax(0, 320px) minmax(0, 1fr);
  gap: clamp(22px, 3.4vw, 44px);
  align-items: start;
}

.console__aside { position: sticky; top: 96px; display: grid; gap: 26px; }
.console__aside h1 { font-size: clamp(1.7rem, 3vw, 2.3rem); margin-bottom: 12px; }
.console__aside p { font-size: .95rem; color: rgba(255,255,255,.68); }

.console__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.console__list li {
  display: grid; grid-template-columns: auto 1fr; gap: 12px;
  padding: 12px 0; border-top: 1px solid rgba(255,255,255,.13);
  font-size: .9rem; color: rgba(255,255,255,.72);
}
.console__list li:last-child { border-bottom: 1px solid rgba(255,255,255,.13); }
.console__list b {
  font-family: var(--mono); font-size: .66rem; font-weight: 600;
  /* A lighter turquoise than the brand token: #0E9A94 on this ground measures
     3.97:1, under the 4.5 minimum for body text. */
  letter-spacing: .06em; color: hsl(176 62% 62%); padding-top: .25em;
  min-width: 6.5ch;
}

.console__limit {
  background: rgba(224,145,58,.13);
  border: 1px solid rgba(224,145,58,.26);
  border-radius: var(--r); padding: 18px 20px;
  font-size: .87rem; color: #F2DCB6; line-height: 1.6;
}
.console__limit b { display: block; font-family: var(--body); margin-bottom: 5px; color: #FFF1DA; }

/* The console shell reuses the panel's internals, so chat.js needs no branch
   for which surface it is running on. */
.console__shell {
  display: flex; flex-direction: column;
  height: min(74vh, 700px);
  background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.console__shell .chatpanel__head { border-radius: 0; }
.console__shell .thread { padding: 20px 22px 10px; }
.console__shell .composer { padding: 14px 22px 18px; }
.console__shell .chips { grid-template-columns: 1fr 1fr; }

@media (max-width: 940px) {
  .console__grid { grid-template-columns: 1fr; }
  .console__aside { position: static; }
  .console__shell { height: min(78vh, 620px); }
  .console__shell .chips { grid-template-columns: 1fr; }
}

/* On a phone the floating panel is effectively a sheet — anything smaller is
   unusable for reading a tax answer. */
@media (max-width: 560px) {
  .chatpanel {
    right: 8px; left: 8px; bottom: 8px;
    width: auto;
    max-height: min(86vh, calc(100vh - 16px));
  }
  .chatfab { right: 16px; bottom: 16px; }
  body.chat-open { overflow: hidden; }
  body.chat-open .chatfab { opacity: 0; pointer-events: none; }
}
