/* Asistent (views/assistant.js, docs/SPEC_AI_ASSISTANT.md §3): header button, editor strip tile and
   the panel — a side panel on wide screens, a bottom sheet on phones. Colours only from app.css tokens
   (light and dark themes). Prefix: .as- */

/* ---------- Header button ---------- */
.sh-assistant { display: flex; align-items: center; margin-left: auto; }
.sh-assistant:empty { display: none; }
.as-btn { position: relative; }
.as-btn-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.as-btn-count[hidden] { display: none; }
.as-btn.has-warn .as-btn-count { background: var(--warning-soft); color: var(--warning-text); }
.as-btn.has-new .as-btn-count { background: var(--accent); color: var(--accent-contrast); }
.as-btn.has-new::after {
  content: "";
  position: absolute;
  top: -3px;
  right: -3px;
  width: 9px;
  height: 9px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
}
.as-btn.is-running .as-btn-icon { animation: as-pulse 1.4s ease-in-out infinite; }
@keyframes as-pulse { 50% { opacity: 0.35; } }

/* ---------- Editor strip tile ("Kontrola: 3 upozornenia") ---------- */
.as-strip-slot { display: flex; flex: none; min-width: 0; }
.as-strip-slot:empty { display: none; }
.as-tile {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 190px;
  padding: 6px 10px;
  border: 0;
  border-left: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
.as-tile[hidden] { display: none; }
.as-tile:hover { background: var(--surface-2); }
.as-tile:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.as-tile-icon { flex: none; color: var(--good); }
.as-tile.is-warn .as-tile-icon { color: var(--warning); }
.as-tile-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.as-tile-label { color: var(--text-2); font-size: 11.5px; }
.as-tile-value { font-weight: 650; overflow-wrap: anywhere; }
.as-tile.is-warn .as-tile-value { color: var(--warning-text); }
.as-tile-chevron { flex: none; color: var(--link); }

/* ---------- Panel: side panel (wide screens) ---------- */
.modal-backdrop.as-backdrop { align-items: stretch; justify-content: flex-end; padding: 0; overflow: hidden; }
.modal.as-panel {
  width: 100%;
  max-width: 480px;
  height: 100%;
  max-height: none;
  border-width: 0 0 0 1px;
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  animation: as-slide-in 0.2s ease-out;
}
.as-panel .modal-body { padding: 0 20px 20px; overscroll-behavior: contain; }
@keyframes as-slide-in { from { transform: translateX(32px); opacity: 0.6; } to { transform: none; opacity: 1; } }

/* Phones: a bottom sheet with a grab handle. */
@media (max-width: 720px) {
  .modal-backdrop.as-backdrop { align-items: flex-end; justify-content: center; }
  .modal.as-panel {
    max-width: none;
    /* A fixed height: switching tabs / a running review must not move the tabs (only .modal-body scrolls). */
    height: calc(100vh - 24px);
    max-height: calc(100vh - 24px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    border-width: 1px 0 0;
    border-radius: 16px 16px 0 0;
    animation: as-sheet-in 0.2s ease-out;
  }
  .modal.as-panel::before { content: ""; flex: none; width: 36px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--border-strong); }
  .as-panel .modal-header { padding: 8px 12px 2px 16px; }
  .as-panel .modal-body { padding: 0 16px 16px; }
}
@supports (height: 100dvh) {
  @media (max-width: 720px) {
    .modal.as-panel { height: calc(100dvh - 24px); max-height: calc(100dvh - 24px); }
  }
}
@keyframes as-sheet-in { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .modal.as-panel, .as-btn.is-running .as-btn-icon { animation: none; }
}

/* ---------- Panel content ---------- */
.as-root { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.as-tabs { position: sticky; top: 0; z-index: 2; margin: 0 -4px; padding-top: 4px; background: var(--surface); }
.as-tabs .tab { flex: 1 1 0; justify-content: center; min-height: 44px; }
.as-tabs .tab-count:empty { display: none; }
.as-pane { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.as-pane[hidden] { display: none; }
.as-head { margin: 0; font-size: 15px; font-weight: 650; }
.as-note { margin: 0; font-size: 13px; color: var(--text-2); }
.as-note[hidden] { display: none; }
.as-loading { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13.5px; color: var(--text-2); }
.as-empty { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 20px 8px; text-align: center; }
.as-empty[hidden] { display: none; }
.as-empty-icon { color: var(--good); }
.as-empty-title { margin: 4px 0 0; font-weight: 650; }
.as-empty-text { margin: 0; font-size: 13px; color: var(--text-2); line-height: 1.5; }
.as-group { display: flex; flex-direction: column; gap: 8px; }
.as-group[hidden] { display: none; }
.as-group-title { margin: 4px 0 0; font-size: 12.5px; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; color: var(--text-2); }
.as-list { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.as-card {
  --as-tone: var(--link);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--as-tone);
  border-radius: var(--radius);
  background: var(--surface);
}
.as-card--important { --as-tone: var(--critical); }
.as-card--warning { --as-tone: var(--warning); }
.as-card.is-dismissed { --as-tone: var(--border-strong); background: var(--surface-2); }
.as-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; font-size: 12.5px; color: var(--text-2); }
.as-card-kind { font-weight: 600; }
.as-card-where { min-width: 0; overflow-wrap: anywhere; }
.as-card-title { margin: 0; font-size: 15px; font-weight: 650; line-height: 1.35; overflow-wrap: anywhere; }
.as-card-text { margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--text-2); overflow-wrap: anywhere; }
.as-vals { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; font-size: 13.5px; }
.as-val { display: inline-flex; align-items: baseline; gap: 5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.as-val-k { font-size: 12px; color: var(--text-2); }
.as-val--new b { color: var(--good-text); }
.as-arrow { color: var(--text-2); }
.as-val-note { flex-basis: 100%; font-size: 12px; color: var(--text-2); }
.as-meta, .as-source { margin: 0; font-size: 12.5px; color: var(--text-2); overflow-wrap: anywhere; }
.as-sources { display: flex; flex-direction: column; gap: 2px; font-size: 13px; min-width: 0; }
.as-sources-k { font-size: 12px; color: var(--text-2); }
.as-sources ul { margin: 0; padding-left: 18px; }
.as-sources li { overflow-wrap: anywhere; }
.as-sources a, .as-source a { color: var(--link); }
.as-card-actions { display: flex; flex-wrap: wrap; gap: 6px 8px; margin-top: 2px; }
.as-card-actions .btn { flex: 0 1 auto; }

.as-dismissed, .as-history { min-width: 0; }
.as-dismissed[hidden], .as-history[hidden] { display: none; }
.as-dismissed > .as-list { margin-top: 8px; }
.as-more {
  display: flex;
  align-items: center;
  min-height: 40px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--link);
  cursor: pointer;
}

/* AI tab */
.as-avail:empty, .as-message:empty { display: none; }
.as-message { display: flex; flex-direction: column; gap: 8px; }
.as-controls { display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.as-controls[hidden] { display: none; }
.as-controls-row { display: flex; flex-wrap: wrap; gap: 8px; }
.as-focus { flex: 1 1 160px; display: flex; }
.as-focus .segmented-item { flex: 1 1 0; justify-content: center; }
.as-start { flex: 1 1 180px; }
.as-limits { margin: 0; font-size: 12.5px; color: var(--text-2); }
.as-limits[hidden] { display: none; }
.as-progress {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 10px;
  align-items: start;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--accent-soft);
}
.as-progress[hidden] { display: none; }
.as-progress-spin { margin-top: 2px; }
.as-progress-body { min-width: 0; }
.as-progress-title { margin: 0; font-weight: 650; }
.as-progress-hint, .as-progress-time { margin: 2px 0 0; font-size: 12.5px; color: var(--text-2); }
.as-progress .as-stop { grid-column: 1 / -1; justify-self: start; }
.as-result { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.as-result[hidden] { display: none; }
.as-result-head { display: flex; flex-direction: column; gap: 4px; }
.as-result-title { margin: 0; font-size: 15px; font-weight: 650; }
.as-summary p { margin: 0 0 6px; font-size: 14px; line-height: 1.55; overflow-wrap: anywhere; }
.as-summary:empty { display: none; }
.as-history-list { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.as-history-items { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.as-history-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.as-history-item:hover:not(:disabled) { background: var(--surface-2); }
.as-history-item.is-active { border-color: var(--accent); }
.as-history-item:disabled { cursor: default; opacity: 0.7; }
.as-history-date { font-size: 13.5px; font-weight: 600; }
.as-history-meta { font-size: 12px; color: var(--text-2); overflow-wrap: anywhere; }
.as-disclaimer { display: flex; align-items: flex-start; gap: 6px; margin: 4px 0 0; font-size: 12px; line-height: 1.5; color: var(--text-2); }
.as-disclaimer .icon { flex: none; margin-top: 2px; }

/* Technical cause of a failed AI review (server debug mode): collapsed, wraps on a phone. */
.as-error-cause { margin-top: 4px; font-size: 12.5px; color: var(--text-2); }
.as-error-cause summary { cursor: pointer; font-weight: 600; }
.as-error-cause code {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- Touch / phones: 40 px tap targets ---------- */
@media (pointer: coarse), (max-width: 720px) {
  .as-error-cause summary { padding: 10px 0; }
  .as-panel .btn-sm, .as-btn.btn-sm { min-height: 40px; }
  .as-panel .as-start { min-height: 44px; }
  .as-sources li { padding: 2px 0; }
  .as-card-actions .btn { flex: 1 1 auto; }
  .as-tile { min-height: 40px; }
  .as-focus .segmented-item { min-height: 40px; }
}

/* Narrow layout of the editor strip: the tile becomes a full-width row under the scrolling KPIs. */
@media (max-width: 899px) {
  .ed-strip.as-strip-has-tile { flex-wrap: wrap; }
  .ed-strip.as-strip-has-tile .ed-strip-tiles { flex: 1 1 100%; }
  .ed-strip.as-strip-has-tile .as-strip-slot { flex: 1 1 100%; }
  .as-tile { flex: 1 1 auto; max-width: none; border-left: 0; border-top: 1px solid var(--border); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
  .as-tile-text { flex-direction: row; flex-wrap: wrap; gap: 0 4px; flex: 1 1 auto; align-items: baseline; }
  .as-tile-label { font-size: 12.5px; }
}

@media print {
  .sh-assistant, .as-strip-slot { display: none !important; }
}
