/* =========================================================
   KOMETA component classes — single source of truth for
   interactive elements and floating surfaces.

   Rules:
   - Templates style buttons/tabs/panels ONLY through these
     classes; layout utilities (width, margin, flex) may be
     added on top, identity utilities (colors, padding,
     radius, states) may not.
   - A deliberate deviation requires an inline
     `design-exception:` comment next to the element.
   ========================================================= */

/* ---- kometa theme tokens (component-scope) ----
   Brand palette and elevation primitives live in the :root
   block of kometa.css (--k-*). Tokens here name component
   decisions so a future theme can override them wholesale. */
:root {
  --btn-height: 44px;
  --btn-radius: 999px;
  --btn-pad-x: 20px;
  --btn-font: 14px;
  --btn-weight: 500;
  --btn-tracking: 0;

  --grad-primary: linear-gradient(180deg, #2F73F6, #1F55D9);
  --grad-primary-hover: linear-gradient(180deg, #1F55D9, #153A8A);
  --btn-primary-border: rgba(37, 99, 235, .86);
  --btn-outline-border: rgba(37, 99, 235, .26);
  --shadow-btn-outline: 0 10px 24px rgba(8, 15, 23, .045);
  --shadow-btn-primary-hover: 0 18px 40px rgba(37, 99, 235, .28), inset 0 1px 0 rgba(255, 255, 255, .20);

  --danger: #EF4444;
  --danger-hover: #DC2626;

  --tab-radius: 14px;
  --grad-active: linear-gradient(180deg, #2563EB, #1D4ED8);
  --seg-height: 46px;

  --modal-radius: 30px;
  --modal-shadow: 0 34px 110px rgba(8, 15, 23, .34);
  --modal-backdrop: rgba(8, 15, 23, .54);

  --stripe: linear-gradient(90deg, #2563EB, #2563EB 58%, #FF7A1A 58%, #FF7A1A 72%, transparent 72%);

  /* Shared page shell: every top-level surface (header card, content
     wrappers, footer) is centered and capped at the same width. */
  --content-max: 1188px;
  --content-gutter: 28px;

  --surface-radius: 20px;
  --surface-border: rgba(18, 27, 38, .08);
  --shadow-pop: 0 18px 46px rgba(8, 15, 23, .16);
}

@media (max-width: 1024px) {
  :root { --content-gutter: 18px; }
}

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: 108px;
  min-height: var(--btn-height);
  padding: 0 var(--btn-pad-x);
  border: 1px solid transparent;
  border-radius: var(--btn-radius);
  font-size: var(--btn-font);
  font-weight: var(--btn-weight);
  letter-spacing: var(--btn-tracking);
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .16s ease, border-color .16s ease,
              color .16s ease, box-shadow .16s ease;
}
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .25);
}
.btn:disabled,
.btn[disabled],
.btn.is-disabled {
  opacity: .52;
  filter: grayscale(.2);
  box-shadow: none;
  pointer-events: none;
}

/* Validation-failed state, toggled from JS via .is-invalid (never utilities). */
.btn.is-invalid {
  background: #fff;
  color: var(--danger);
  border-color: var(--danger);
  box-shadow: none;
}

.btn-primary {
  background: var(--grad-primary);
  color: #fff;
  border-color: var(--btn-primary-border);
  box-shadow: 0 18px 34px rgba(37, 99, 235, .24), inset 0 1px 0 rgba(255, 255, 255, .28);
}
.btn-primary:hover {
  background: var(--grad-primary-hover);
  box-shadow: var(--shadow-btn-primary-hover);
}
.btn-primary svg { color: #fff; }

.btn-outline {
  background: #fff;
  color: var(--k-blue);
  border-color: var(--btn-outline-border);
  box-shadow: var(--shadow-btn-outline);
}
.btn-outline:hover {
  background: var(--k-blue);
  border-color: var(--k-blue);
  color: #fff;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }

/* Plain icon button (modal ×, table row actions). */
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--k-text-mid);
  cursor: pointer;
  transition: color .16s ease, background-color .16s ease;
}
.btn-ghost:hover { color: var(--k-ink); }
.btn-ghost:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .25);
}

.btn-sm {
  min-height: 36px;
  padding: 0 14px;
  font-size: 13px;
}

.btn-lg {
  min-height: 52px;
  padding: 0 26px;
  font-size: 15px;
}

/* ---------------- Tabs ---------------- */

/* Frosted tray that groups a tab row. */
.tab-tray {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 18px;
  background: rgba(255, 255, 255, .92);
  border: 1px solid rgba(18, 27, 38, .08);
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: var(--tab-radius);
  background: transparent;
  color: #536174;
  font-size: 13px;
  font-weight: 820;
  letter-spacing: -.025em;
  cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease,
              color .16s ease, box-shadow .16s ease;
}
.tab svg { width: 22px; height: 22px; color: currentColor; }
.tab span { font-size: 13px; font-weight: 820; }
.tab:hover {
  background: #EDF1F7;
  color: var(--k-blue);
  border-color: rgba(37, 99, 235, .22);
}
.tab.is-active,
.tab.is-active:hover {
  color: #fff;
  background: var(--grad-active);
  border-color: rgba(37, 99, 235, .18);
  box-shadow: 0 9px 18px rgba(37, 99, 235, .24);
}
.tab.is-active:focus-visible { outline: 0; box-shadow: 0 9px 18px rgba(37, 99, 235, .24); }

/* Segmented control (joined pill group: glossary source, topics). */
.seg-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--seg-height);
  padding: 0 20px;
  border: 1px solid rgba(15, 44, 52, .10);
  background: rgba(255, 255, 255, .78);
  color: var(--k-text-mid);
  font-size: var(--btn-font);
  font-weight: var(--btn-weight);
  border-radius: 0;
  cursor: pointer;
  transition: background-color .16s ease, color .16s ease, border-color .16s ease;
}
.seg-tab:first-child { border-radius: 999px 0 0 999px; }
.seg-tab:last-child { border-radius: 0 999px 999px 0; }
/* Standalone segment (e.g. JS-built topic chips laid out with gaps). */
.seg-tab.seg-tab--pill { border-radius: 999px; }
.seg-tab:hover { color: var(--k-blue); }
.seg-tab.is-active,
.seg-tab.selected {
  background: var(--grad-active);
  color: #fff;
  border-color: var(--btn-primary-border);
  box-shadow: 0 14px 30px rgba(37, 99, 235, .18);
}

/* ---------------- Floating surfaces ---------------- */

/* Full-screen dimmed backdrop hosting a modal panel. */
.modal-overlay {
  z-index: 100;
  background: var(--modal-backdrop);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.modal-panel {
  position: relative;
  width: 100%;
  margin-left: 1rem;
  margin-right: 1rem;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  border-radius: var(--modal-radius);
  border: 1px solid rgba(255, 255, 255, .52);
  background: #fff;
  box-shadow: var(--modal-shadow);
}
.modal-panel--md { max-width: 690px; }
.modal-panel--lg { max-width: 800px; }
/* Narrow dialog for content that doesn't need the two-column width (e.g. the
   add-glossary upload step without language selectors). */
.modal-panel--compact { max-width: 520px; }
/* Full-screen dialog (e.g. the long glossary guide): fills the viewport and
   scrolls internally. */
.modal-panel--full {
  width: 100%;
  max-width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  border-radius: 0;
}

/* Small anchored dropdown/popover card. */
.popover {
  background: rgba(255, 255, 255, .98);
  border: 1px solid rgba(15, 44, 52, .10);
  border-radius: 22px;
  box-shadow: 0 24px 70px rgba(11, 15, 23, .14);
  padding: 8px;
}

/* Dark hover tooltip bubble; positioning stays on the element. */
.tooltip-bubble {
  background: var(--k-ink-2);
  color: #fff;
  font-size: 11px;
  line-height: 1.45;
  border-radius: 10px;
  padding: 10px 14px;
}
.tooltip-bubble--danger { background: var(--danger); }
/* 45°-rotated square peeking from under the bubble; position on the element. */
.tooltip-arrow {
  width: 12px;
  height: 12px;
  background: var(--k-ink-2);
  transform: rotate(45deg);
}
.tooltip-bubble--danger + .tooltip-arrow,
.tooltip-bubble--danger .tooltip-arrow { background: var(--danger); }

/* Row inside a .popover (menu option). */
.popover-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background-color .16s ease, color .16s ease;
}
.popover-item:hover { background: rgba(37, 99, 235, .06); color: var(--k-blue); }

/* Auth/registration card (login, register, password flows). */
.auth-card {
  display: flex;
  flex-direction: column;
  position: relative;
  width: min(100%, 430px);
  padding: 34px;
  border-radius: 26px;
  border: 1px solid rgba(18, 27, 38, .08);
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 24px 70px rgba(8, 15, 23, .10);
}

/* Brand stripe pinned to the top edge of a primary content card. */
.brand-stripe { position: relative; }
.brand-stripe::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 5px;
  background: var(--stripe);
  pointer-events: none;
}

/* Centered page shell: the same width system as the header card — capped
   at --content-max, centered, with --content-gutter breathing room. Every
   page's top-level wrapper uses this. */
.content-shell {
  position: relative;
  z-index: 1;
  width: min(100%, var(--content-max));
  margin-left: auto;
  margin-right: auto;
}

/* Adaptive panel: hugs its content when sparse, grows with content, but
   never beyond the visible viewport — past the cap it scrolls internally.
   --panel-viewport-offset ≈ fixed chrome above/below the panel (header,
   title, tabs, action row); override it where the surroundings differ. */
.panel-fit {
  min-height: 0;
  max-height: max(420px, calc(100dvh - var(--panel-viewport-offset, 430px)));
  overflow-y: auto;
  /* No overscroll-behavior here: when the page keeps residual overflow
     (offset drift, extra chrome), `contain` would trap the wheel inside the
     panel and the page could never be scrolled from over it. */
  /* When the cap is active the panel is the only scrollable surface on the
     page — overlay scrollbars hide until scrolled, so keep the thumb
     visible as the affordance that there is more content below. */
  scrollbar-width: thin;
  scrollbar-color: rgba(15, 44, 52, .28) transparent;
}
.panel-fit::-webkit-scrollbar { width: 8px; }
.panel-fit::-webkit-scrollbar-track { background: transparent; }
.panel-fit::-webkit-scrollbar-thumb {
  background: rgba(15, 44, 52, .28);
  border-radius: 999px;
}
/* Below this the page scrolls as a whole; an inner cap would leave a
   cramped double-scroll area. The height threshold is the panel floor
   (420px — one full card row plus the cue of the next) plus the largest
   chrome offset (620px, the document-translate wizard): above it the cap
   always yields ≥ the floor, below it internal scroll gets too small to
   be discoverable or useful. */
@media (max-width: 900px), (max-height: 1040px) {
  .panel-fit {
    max-height: none;
    overflow-y: visible;
  }
}

/* Animated indicator for long-running states (translation in progress).
   Applied together with a status text; spins until the state class is
   swapped for a terminal one. */
.status-processing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.status-processing::before {
  content: "";
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid rgba(37, 99, 235, .25);
  border-top-color: var(--k-blue);
  animation: status-spin .8s linear infinite;
}
@keyframes status-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .status-processing::before { animation-duration: 2.4s; }
}

/* Generic content card for pages without a bespoke card treatment. */
.panel {
  background: #fff;
  border: 1px solid var(--surface-border);
  border-radius: var(--surface-radius);
  box-shadow: var(--k-shadow-lg);
}

/* ---------------- Scenario cards ---------------- */
/* Single-choice "prescription" cards for the translation-scenario step:
   a responsive grid of vertical card buttons (icon, title, divider,
   description) with a round check in the top-right corner. Selection is
   the semantic `selected` class + aria-pressed, set from JS. */

.scenario-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
}
@media (max-width: 980px) {
  .scenario-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .scenario-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 470px) {
  .scenario-grid { grid-template-columns: 1fr; }
}

.scenario-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  min-height: 170px;
  padding: 14px 10px 10px;
  text-align: center;
  background: var(--k-white);
  border: 1px solid var(--k-mist);
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(18, 24, 38, .07);
  cursor: pointer;
  transition: border-color var(--k-transition), box-shadow var(--k-transition),
              transform var(--k-transition);
}
.scenario-card:hover {
  border-color: rgba(37, 99, 235, .48);
  box-shadow: 0 12px 26px rgba(18, 24, 38, .12);
  transform: translateY(-3px);
}
.scenario-card:focus-visible {
  outline: 3px solid rgba(37, 99, 235, .22);
  outline-offset: 2px;
}
.scenario-card.selected {
  border-color: var(--k-blue);
  box-shadow: 0 10px 26px rgba(37, 99, 235, .17), inset 0 0 0 1px var(--k-blue);
}
/* Orange marker bar centered on the top edge of the selected card. */
.scenario-card.selected::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 58px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--k-orange);
}

.scenario-card__check {
  position: absolute;
  top: 14px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--k-white);
  border: 1.5px solid var(--k-mist);
  color: transparent;
  transition: background var(--k-transition), border-color var(--k-transition),
              color var(--k-transition);
}
.scenario-card.selected .scenario-card__check {
  background: var(--k-blue);
  border-color: var(--k-blue);
  color: #fff;
}
.scenario-card__check svg { display: block; }

.scenario-card__icon {
  width: 34px;
  height: 34px;
  margin: 5px 0;
  object-fit: contain;
}

.scenario-card__title {
  min-height: 28px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--k-ink);
}

.scenario-card__divider {
  flex-shrink: 0;
  width: 34px;
  height: 2px;
  border-radius: 1px;
  background: var(--k-mist);
}
.scenario-card.selected .scenario-card__divider { background: var(--k-orange); }

.scenario-card__desc {
  font-size: 11px;
  font-weight: 400;
  line-height: 1.3;
  color: var(--k-ink-2);
  opacity: .78;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .scenario-card,
  .scenario-card__check { transition: none; }
  .scenario-card:hover { transform: none; }
}
