/* ==========================================================================
   ==== Task 10B: Pitaj pravilnik (AI chat) + floating "Pitaj" button ====
   js/views/pitaj.js, js/components/chat*.js, the .nz-askfab in index.html.
   Editorial, not a chat app: questions read like headings in a ledger,
   answers like prose with citation chips; one red accent (the send button).
   ========================================================================== */

/* ── Layout ───────────────────────────────────────────────────────────── */
.nz-ask {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 32px;
}
.nz-ask__head {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.nz-ask__head .nz-lead {
  margin: 0;
}
.nz-ask__main {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
  max-width: 780px;
}

@media (min-width: 1100px) {
  .nz-ask {
    grid-template-columns: minmax(0, 1fr) 300px;
    column-gap: 64px;
    row-gap: 40px;
  }
  .nz-ask__head {
    grid-column: 1 / -1;
  }
  .nz-ask__main {
    grid-column: 1;
  }
  .nz-ask__aside {
    grid-column: 2;
    grid-row: 2;
    align-self: start;
    position: sticky;
    top: 84px;
  }
}

/* ── Aside: how it answers ────────────────────────────────────────────── */
.nz-ask__aside {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
}
.nz-ask__rules {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.nz-ask__rules li {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--paper-dim);
}
.nz-ask__rules i {
  padding-top: 3px;
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
}
.nz-ask__corpus {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
}
.nz-ask__contact {
  margin: 0;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-dim);
}
.nz-ask__contact a,
.nz-ask__off a {
  color: var(--paper);
  text-decoration-color: var(--rule);
  overflow-wrap: anywhere;
}
.nz-ask__contact a:hover,
.nz-ask__off a:hover {
  color: var(--red-text);
  text-decoration-color: currentColor;
}

/* ── Starter questions ────────────────────────────────────────────────── */
.nz-ask__starters {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.nz-ask__starterlist {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--rule);
}
.nz-ask__starter {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 14px 4px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  color: var(--paper);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur-hover) ease, color var(--dur-hover) ease;
}
.nz-ask__starteridx {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.nz-ask__startertext {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.4;
  text-wrap: pretty;
}
.nz-ask__starterarrow {
  font-family: system-ui, sans-serif;
  color: var(--text-dim);
  transition: transform var(--dur-chip) var(--ease-out), color var(--dur-hover) ease;
}
.nz-ask__starter:hover:not(:disabled) {
  background: var(--red-soft);
}
.nz-ask__starter:hover:not(:disabled) .nz-ask__starterarrow {
  color: var(--red-text);
  transform: translateX(3px);
}
.nz-ask__starter:focus-visible {
  outline-offset: -2px;
}
.nz-ask__starter:disabled {
  cursor: default;
  color: var(--text-dim);
}

/* ── Conversation ─────────────────────────────────────────────────────── */
.nz-ask__log {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nz-ask__loghead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule);
}
.nz-ask__turns {
  display: flex;
  flex-direction: column;
}

.nz-turn {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px 0 28px;
  border-bottom: 1px solid var(--rule);
  scroll-margin-top: 76px;
  animation: nz-turn-in var(--dur-view) var(--ease-out) backwards;
}
@keyframes nz-turn-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}
.nz-turn__q {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: baseline;
  gap: 12px;
}
.nz-turn__idx {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.nz-turn__qtext {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(19px, 2vw, 23px);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.015em;
  color: var(--paper);
  overflow-wrap: anywhere;
  white-space: pre-line;
  text-wrap: pretty;
}
.nz-turn__a {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  margin-left: 52px; /* idx column + gap: answers hang under the question */
}
.nz-turn__label {
  display: flex;
  align-items: center;
  gap: 8px;
}
.nz-turn__ai {
  padding: 1px 6px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-code);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

/* Thinking: three dots + elapsed seconds */
.nz-turn__thinking {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-size: 15px;
  color: var(--paper-dim);
}
.nz-turn__thinking[hidden] {
  display: none;
}
.nz-turn__elapsed {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.nz-turn__slow {
  flex-basis: 100%;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-dim);
}
.nz-dots {
  display: inline-flex;
  gap: 4px;
}
.nz-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--red);
  animation: nz-dot 1.1s ease-in-out infinite;
}
.nz-dots i:nth-child(2) {
  animation-delay: 0.15s;
}
.nz-dots i:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes nz-dot {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* Answer prose */
.nz-answer {
  max-width: 68ch;
  font-size: 16px;
  line-height: 1.62;
  overflow-wrap: break-word;
}
.nz-answer[hidden] {
  display: none;
}
.nz-answer .nz-cite {
  margin-inline: 2px;
}
.nz-answer__h {
  font-weight: 700;
  color: var(--paper);
}
.nz-answer a {
  overflow-wrap: anywhere;
}
/* Streaming caret after the last block */
.nz-answer.is-streaming > :last-child::after {
  content: '';
  display: inline-block;
  width: 0.5em;
  height: 1.05em;
  margin-left: 3px;
  vertical-align: -0.15em;
  background: var(--red);
  animation: nz-caret 1s steps(2, jump-none) infinite;
}
.nz-answer.is-streaming > ul:last-child::after,
.nz-answer.is-streaming > ol:last-child::after {
  display: none;
}
.nz-answer.is-streaming > ul:last-child > li:last-child::after,
.nz-answer.is-streaming > ol:last-child > li:last-child::after {
  content: '';
  display: inline-block;
  width: 0.5em;
  height: 1.05em;
  margin-left: 3px;
  vertical-align: -0.15em;
  background: var(--red);
  animation: nz-caret 1s steps(2, jump-none) infinite;
}
@keyframes nz-caret {
  50% {
    opacity: 0;
  }
}

.nz-answer__sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding-top: 12px;
  border-top: 1px dashed var(--rule);
}
.nz-answer__sources .nz-kicker i {
  margin-right: 2px;
}
.nz-turn__sources:empty,
.nz-turn__error:empty {
  display: none;
}

.nz-turn__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}
.nz-turn__foot[hidden] {
  display: none;
}
.nz-turn__foot .nz-btn--quiet {
  padding-inline: 0;
  margin-right: 4px;
}
.nz-turn__model {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

/* ── Unavailable notice ───────────────────────────────────────────────── */
.nz-ask__off[hidden] {
  display: none;
}
.nz-ask__off .nz-callout__body p {
  margin: 0;
}
.nz-ask__off .nz-callout__body p:not([hidden]) ~ p {
  margin-top: 0.5em;
}

/* ── Composer ─────────────────────────────────────────────────────────── */
.nz-ask__composer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
  padding: 14px 0 16px;
  background: linear-gradient(180deg, transparent, var(--ink) 18px);
}
.nz-ask__box {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 8px 8px 8px 16px;
  border: 1.5px solid var(--rule);
  background: var(--panel);
  transition: border-color var(--dur-hover) ease;
}
.nz-ask__box:hover {
  border-color: var(--paper-dim);
}
.nz-ask__box:focus-within {
  border-color: var(--focus);
}
.nz-ask__input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  max-height: 220px;
  margin: 0;
  padding: 11px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 16px; /* ≥ 16px: iOS does not zoom on focus */
  line-height: 1.4;
  resize: none;
  overflow-y: auto;
  -webkit-appearance: none;
  appearance: none;
}
.nz-ask__input:focus {
  outline: none;
}
.nz-ask__input::placeholder {
  color: var(--text-dim);
  opacity: 0.9;
}
.nz-ask__input:disabled {
  cursor: not-allowed;
}
.nz-ask__send {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  height: 44px;
  padding: 0 16px;
  border: 1.5px solid var(--red-fill);
  border-radius: 0;
  background: var(--red-fill);
  color: var(--on-red);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur-hover) ease, border-color var(--dur-hover) ease, color var(--dur-hover) ease;
}
.nz-ask__send:hover {
  border-color: var(--red-deep);
  background: var(--red-deep);
}
.nz-ask__send:disabled {
  border-color: var(--rule);
  background: transparent;
  color: var(--text-dim);
  cursor: default;
}
.nz-ask__send.is-stop {
  border-color: var(--paper);
  background: transparent;
  color: var(--paper);
}
.nz-ask__send.is-stop:hover {
  background: var(--paper);
  color: var(--ink);
}
.nz-ask__send i {
  font-size: 13px;
}
.nz-ask__meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.nz-ask__disclaimer {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-dim);
}
.nz-ask__disclaimer i {
  font-size: 11px;
}
.nz-ask__count {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.nz-ask__count:empty {
  display: none;
}

/* ── Floating "Pitaj" button (all other views) ────────────────────────── */
.nz-askfab {
  position: fixed;
  right: max(24px, env(safe-area-inset-right, 0px));
  bottom: max(24px, env(safe-area-inset-bottom, 0px));
  z-index: 50; /* above content, below the tab bar (60) and modals (100) */
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 46px;
  padding: 0 18px 0 16px;
  border: 1.5px solid var(--red-fill);
  border-radius: var(--radius-pill);
  background: var(--red-fill);
  color: var(--on-red);
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
  box-shadow: 0 10px 28px rgba(20, 16, 14, 0.38);
  -webkit-tap-highlight-color: transparent;
  animation: nz-fab-in var(--dur-panel) var(--ease-panel) backwards;
  transition: background-color var(--dur-hover) ease, border-color var(--dur-hover) ease,
    transform var(--dur-chip) var(--ease-out), opacity var(--dur-chip) ease;
}
.nz-askfab[hidden] {
  display: none;
}
/* Tucked away while the reader scrolls down (js/app.js), so it never sits
   on top of the text being read; back on scroll up, at the page end and on
   keyboard focus. */
.nz-askfab.is-tucked:not(:focus-visible) {
  opacity: 0;
  pointer-events: none;
  transform: translateY(calc(100% + 32px));
}
/* At the end of the page the footer leaves room for it (desktop). */
body:has(.nz-askfab:not([hidden])) .nz-footer {
  padding-bottom: 80px;
}
/* The "na vrh" button (Pravila, Radionica) shares the corner: it stacks
   above the floating button instead of hiding behind it. */
body:has(.nz-askfab:not([hidden])) .nz-totop {
  bottom: calc(max(24px, env(safe-area-inset-bottom, 0px)) + 46px + 12px);
  right: max(24px, env(safe-area-inset-right, 0px));
}
body:has(.nz-askfab:not([hidden])):has(.nz-totop) .nz-footer {
  padding-bottom: 140px;
}
.nz-askfab:hover {
  border-color: var(--red-deep);
  background: var(--red-deep);
  color: var(--on-red);
  transform: translateY(-1px);
}
.nz-askfab:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
.nz-askfab i {
  font-size: 15px;
}
@keyframes nz-fab-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

@media (max-width: 819.98px) {
  .nz-ask {
    gap: 24px;
  }
  .nz-turn__a {
    margin-left: 0;
  }
  .nz-turn__q {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 8px;
  }
  .nz-ask__starter {
    grid-template-columns: 32px minmax(0, 1fr) auto;
    gap: 10px;
  }
  .nz-ask__composer {
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: 10px;
  }
  .nz-ask__box {
    padding-left: 12px;
  }
  .nz-ask__sendlabel {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .nz-ask__send {
    padding: 0;
    width: 44px;
  }
  .nz-turn__foot .nz-btn {
    min-height: var(--tap);
  }
  .nz-ask__loghead .nz-btn {
    min-height: var(--tap);
  }
  .nz-askfab {
    right: max(16px, env(safe-area-inset-right, 0px));
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 14px);
    min-height: var(--tap);
    padding: 0 16px 0 14px;
  }
  /* Room under the footer so the floating button never covers its last line
     (overrides the desktop 80px above). */
  body:has(.nz-askfab:not([hidden])) .nz-footer {
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 64px);
  }
  body:has(.nz-askfab:not([hidden])) .nz-totop {
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 14px + var(--tap) + 10px);
    right: max(16px, env(safe-area-inset-right, 0px));
  }
  body:has(.nz-askfab:not([hidden])):has(.nz-totop) .nz-footer {
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 14px + 2 * var(--tap) + 24px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .nz-turn,
  .nz-askfab {
    animation: none;
  }
  .nz-dots i {
    animation: none;
    opacity: 0.7;
  }
  .nz-answer.is-streaming > :last-child::after,
  .nz-answer.is-streaming > ul:last-child > li:last-child::after,
  .nz-answer.is-streaming > ol:last-child > li:last-child::after {
    animation: none;
  }
  .nz-ask__starterarrow,
  .nz-askfab {
    transition: none;
  }
}

@media print {
  .nz-askfab,
  .nz-ask__composer,
  .nz-ask__starters,
  .nz-turn__foot {
    display: none !important;
  }
}
