/* Reusable components: navigation, buttons, forms, chips, tabs, tables, charts, dialogs, toasts, chat. */

/* ===================== Header: floating pill ===================== */

.site-header {
  position: fixed;
  top: calc(var(--frame) + 8px);
  left: 0; right: 0;
  z-index: var(--z-header);
  padding-inline: calc(var(--frame) + 8px);
  pointer-events: none;
  view-transition-name: site-header;
}
.nav-pill {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: 1480px;
  min-height: 72px;
  margin-inline: auto;
  padding: 10px 10px 10px 14px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow), 0 0 0 1px var(--line);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  transition: box-shadow var(--dur) var(--ease), min-height var(--dur) var(--ease), padding var(--dur) var(--ease);
}
.site-header.is-scrolled .nav-pill { min-height: 64px; padding-block: 6px; box-shadow: var(--shadow-lg), 0 0 0 1px var(--line); }

/* The brand never shrinks on wide screens; app.js collapses the links into the menu button instead. */
.brand { display: flex; align-items: center; gap: 12px; flex: none; color: var(--ink) !important; text-decoration: none; }
.brand__logo { width: 50px; height: 48px; flex: none; object-fit: contain; }
.brand__text { display: flex; flex-direction: column; line-height: 1.2; }
.brand__name { font-weight: 800; font-size: 1rem; letter-spacing: -0.015em; white-space: nowrap; }
.brand__place { margin-top: 2px; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.01em; color: var(--muted); white-space: nowrap; }

.primary-nav { margin-inline: auto; }
.primary-nav__list { display: flex; align-items: center; gap: 2px; }
.nav-link {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 9px 12px;
  border: 0; border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text);
  font-size: var(--text-sm); font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-link:hover, .nav-item.is-open > .nav-link { background: var(--surface-2); }
.nav-link[aria-current='page'], .nav-link.is-current { background: var(--sun); color: var(--navy-950); }
.primary-nav__portal { box-shadow: inset 0 0 0 1px var(--line-strong); }
.nav-home { display: none; }

/* Sub-menus */
.nav-item { position: relative; }
.nav-item__chev { opacity: 0.6; transition: transform var(--dur) var(--ease); }
.nav-item.is-open .nav-item__chev { transform: rotate(180deg); }
.nav-menu {
  position: absolute; top: calc(100% + 14px); left: -8px;
  z-index: var(--z-popover);
  display: grid; gap: 2px;
  width: 310px;
  padding: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--line);
  opacity: 0; visibility: hidden; transform: translateY(6px);
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur) var(--ease-out), visibility var(--dur-fast);
}
/* A hover bridge over the gap between the button and the menu. */
.nav-menu::before { content: ''; position: absolute; left: 0; right: 0; top: -16px; height: 16px; }
.nav-item:nth-last-child(-n + 3) .nav-menu { left: auto; right: -8px; }
.nav-item.is-open .nav-menu { opacity: 1; visibility: visible; transform: none; }
@media (hover: hover) {
  :root:not(.nav-fit) .nav-item:not(.is-picked):hover .nav-menu { opacity: 1; visibility: visible; transform: none; }
  :root:not(.nav-fit) .nav-item:hover > .nav-link:not(.is-current) { background: var(--surface-2); }
  :root:not(.nav-fit) .nav-item:not(.is-picked):hover .nav-item__chev { transform: rotate(180deg); }
}
.nav-menu__link {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink) !important; text-decoration: none;
  transition: background var(--dur-fast) var(--ease);
}
.nav-menu__link:hover, .nav-menu__link:focus-visible { background: var(--surface-2); }
.nav-menu__link > span:last-child { display: grid; gap: 1px; min-width: 0; line-height: 1.3; }
.nav-menu__link strong { font-size: var(--text-sm); font-weight: 700; }
.nav-menu__link small { font-size: var(--text-xs); color: var(--muted); }
.nav-menu__icon { display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 11px; background: var(--surface-2); color: var(--navy-900); transition: background var(--dur-fast) var(--ease); }
.nav-menu__link:hover .nav-menu__icon { background: var(--sun-soft); }
.nav-menu__icon--accent { background: var(--sun); color: var(--navy-950); }
:root[data-theme='dark'] .nav-menu__icon { color: var(--sun); }
:root[data-theme='dark'] .nav-menu__link:hover .nav-menu__icon { background: var(--accent-soft); }
:root[data-theme='dark'] .nav-menu__icon--accent { background: var(--sun); color: var(--navy-950); }

.nav-tools { display: flex; align-items: center; gap: var(--space-2); flex: none; }
.nav-call { display: inline-flex; align-items: center; gap: 10px; padding-right: 8px; color: var(--ink) !important; text-decoration: none; }
.nav-call__icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--sun); color: var(--navy-950); }
.nav-call__text { display: flex; flex-direction: column; line-height: 1.2; }
.nav-call__text small { font-size: 11px; color: var(--muted); font-weight: 500; }
.nav-call__text strong { font-size: var(--text-sm); white-space: nowrap; }
:root.nav-no-call .nav-call { display: none; }

.nav-tools .nav-toggle { display: none; }
.nav-toggle__close { display: none !important; }
:root.nav-open .nav-toggle__open { display: none !important; }
:root.nav-open .nav-toggle__close { display: inline-flex !important; }

/* Collapsed navigation: app.js adds .nav-fit to <html> whenever the links do not fit on one line
 * (narrow windows, larger text, Hindi or Punjabi labels). */
:root.nav-fit .nav-tools .nav-toggle { display: inline-grid; }
/* The pill's backdrop-filter makes it the containing block, so the folded menu hangs from the pill. */
.nav-pill { position: relative; }
:root.nav-fit .primary-nav {
  position: absolute;
  top: calc(100% + 10px); left: 0; right: 0;
  padding: var(--space-3);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--line), 0 0 0 100vmax rgba(8, 10, 36, 0.35);
  opacity: 0; transform: translateY(-8px); visibility: hidden;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease), visibility var(--dur);
  max-height: calc(100vh - 130px); overflow-y: auto; overscroll-behavior: contain;
}
:root.nav-fit.nav-open .primary-nav { opacity: 1; transform: none; visibility: visible; }
:root.nav-fit .primary-nav__list { flex-direction: column; align-items: stretch; gap: 2px; }
:root.nav-fit .nav-home { display: block; }
:root.nav-fit .nav-link { width: 100%; justify-content: space-between; font-size: var(--text-lg); padding: 12px 16px; }
:root.nav-fit .primary-nav__portal { justify-content: flex-start; margin-top: var(--space-2); }
/* Folded menu: sub-menus open in place, like an accordion. */
:root.nav-fit .nav-menu {
  position: static; width: auto; padding: 2px 0 var(--space-2) var(--space-3);
  box-shadow: none; background: transparent;
  display: none; opacity: 1; visibility: visible; transform: none;
}
:root.nav-fit .nav-menu::before { display: none; }
:root.nav-fit .nav-item.is-open .nav-menu { display: grid; }
:root.nav-fit .brand { margin-right: auto; }
:root.nav-measuring .site-header * { transition: none !important; }

@media (max-width: 560px) {
  .nav-tools .nav-tools__apply { display: none; }
  /* The name may wrap here, but never narrower than its longest word, so app.js still sees overflow. */
  .brand { flex: 0 1 auto; gap: 10px; }
  .brand__logo { width: 42px; height: 40px; }
  .brand__name { font-size: 0.85rem; white-space: normal; max-width: 15ch; }
  .brand__place { display: none; }
  .nav-pill { min-height: 62px; gap: var(--space-2); padding: 8px 8px 8px 12px; }
}

/* Display options popover (language, theme, text size, contrast, motion) */
.popover-wrap { position: relative; }
.popover {
  position: absolute; right: 0; top: calc(100% + 12px);
  z-index: var(--z-popover);
  width: 280px;
  padding: var(--space-4);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--line);
  display: grid; gap: var(--space-3);
}
.popover__label { margin: 0; font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: var(--radius-pill); padding: 4px; }
.segmented button { border: 0; background: transparent; height: 34px; padding: 0 8px; border-radius: var(--radius-pill); font-weight: 600; font-size: var(--text-sm); }
.segmented button:hover { background: var(--surface); }
.segmented button[aria-pressed='true'] { background: var(--navy-900); color: #fff; }
.segmented button[lang='hi'] { font-family: 'Noto Sans Devanagari', sans-serif; }
.segmented button[lang='pa'] { font-family: 'Noto Sans Gurmukhi', sans-serif; }
:root[data-theme='dark'] .segmented button[aria-pressed='true'] { background: var(--sun); color: var(--navy-950); }

.theme-switch { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border: 0; border-radius: var(--radius-pill); background: var(--surface-2); }
.theme-switch__opt { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; border-radius: var(--radius-pill); font-size: var(--text-sm); font-weight: 600; }
:root:not([data-theme='dark']) .theme-switch__opt--light,
:root[data-theme='dark'] .theme-switch__opt--dark { background: var(--surface); box-shadow: var(--shadow-sm); }

/* ===================== Buttons ===================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 48px; padding: 0 var(--space-5);
  border: 0; border-radius: var(--radius-pill);
  font-weight: 700; font-size: var(--text-sm); line-height: 1.2;
  text-decoration: none; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn--primary, .btn--dark { background: var(--primary); color: var(--on-primary) !important; }
.btn--primary:hover, .btn--dark:hover { background: var(--primary-hover); }
.btn--dark { background: var(--navy-950); color: #fff !important; }
.btn--dark:hover { background: var(--navy-800); }
:root[data-theme='dark'] .btn--dark { background: var(--surface-3); }
.btn--sun { background: var(--sun); color: var(--navy-950) !important; }
.btn--sun:hover { background: #ffdf6e; }
.btn--secondary { background: var(--surface); color: var(--ink) !important; box-shadow: inset 0 0 0 1px var(--line-strong); }
.btn--secondary:hover { background: var(--surface-2); }
.btn--ghost { background: transparent; color: var(--ink) !important; }
.btn--ghost:hover { background: var(--surface-2); }
.btn--glass { background: rgba(255, 255, 255, 0.14); color: #fff !important; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3); backdrop-filter: blur(8px); }
.btn--glass:hover { background: rgba(255, 255, 255, 0.22); }
.btn--danger { background: var(--bad); color: #fff !important; }
.btn--sm { min-height: 38px; padding: 0 var(--space-4); font-size: var(--text-sm); }
.btn--block { width: 100%; }

/* Pill button with a round arrow badge on the right, as in the reference design. */
.btn--arrow { padding-right: 6px; gap: var(--space-3); }
.btn__arrow {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 50%;
  transition: transform var(--dur) var(--ease);
}
.btn--sun .btn__arrow { background: var(--navy-950); color: var(--sun); }
.btn--dark .btn__arrow, .btn--primary .btn__arrow { background: var(--sun); color: var(--navy-950); }
.btn--arrow:hover .btn__arrow { transform: rotate(45deg); }
.btn--sm.btn--arrow .btn__arrow { width: 28px; height: 28px; }

.link-underline {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 0; border: 0; background: none;
  font-weight: 700; font-size: var(--text-sm);
  color: inherit; text-decoration: underline; text-underline-offset: 0.3em; text-decoration-thickness: 1.5px;
}
.link-underline:hover { text-decoration-thickness: 2.5px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--ink);
  transition: background var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn--soft { background: var(--surface-2); }
.icon-btn--soft:hover { background: var(--surface-3); }
.icon-btn--sm { width: 34px; height: 34px; }
.icon-btn--primary { background: var(--navy-900); color: #fff; }
.icon-btn--primary:hover { background: var(--navy-800); }
:root[data-theme='dark'] .icon-btn--primary { background: var(--sun); color: var(--navy-950); }
.icon-btn--danger { color: var(--bad); }
.icon-btn--danger:hover { background: var(--bad-soft); }

.round-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: var(--surface); color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.round-btn:hover:not(:disabled) { transform: translateY(-1px); }
.round-btn:disabled { opacity: 0.35; cursor: default; }
.round-btn--dark { background: var(--navy-900); color: #fff; box-shadow: none; }
:root[data-theme='dark'] .round-btn--dark { background: var(--sun); color: var(--navy-950); }
.carousel-nav { display: flex; gap: var(--space-2); flex: none; }

.text-link {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: var(--space-3);
  font-weight: 700; font-size: var(--text-sm);
  text-decoration: none; background: none; border: 0; padding: 0;
  color: var(--ink);
}
.text-link span { text-decoration: underline; text-underline-offset: 0.3em; text-decoration-thickness: 1.5px; }
.text-link--sm { margin: 0 0 0 var(--space-2); font-size: var(--text-xs); }

.pill-link {
  display: inline-flex; align-items: center; gap: var(--space-3);
  padding: 5px 5px 5px 16px;
  border-radius: var(--radius-pill);
  background: #fff; color: var(--navy-950) !important;
  font-weight: 700; font-size: var(--text-sm); text-decoration: none;
}
.pill-link__arrow { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--navy-950); color: var(--sun); transition: transform var(--dur) var(--ease); }
.pill-link:hover .pill-link__arrow { transform: rotate(45deg); }

/* ===================== Switch ===================== */

.switch { display: flex; align-items: center; gap: var(--space-3); cursor: pointer; font-size: var(--text-sm); font-weight: 500; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track { position: relative; flex: none; width: 42px; height: 24px; border-radius: var(--radius-pill); background: var(--surface-3); transition: background var(--dur-fast) var(--ease); }
.switch__track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--dur-fast) var(--ease); }
.switch input:checked + .switch__track { background: var(--navy-700); }
.switch input:checked + .switch__track::after { transform: translateX(18px); background: var(--sun); }
.switch input:focus-visible + .switch__track { outline: 3px solid var(--focus); outline-offset: 2px; }
.switch--field { align-self: end; min-height: 48px; }

/* ===================== Chips, tags, badges, notes ===================== */

.chip-group { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 38px; padding: 0 var(--space-4);
  border: 0; border-radius: var(--radius-pill);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  font-size: var(--text-sm); font-weight: 600; text-align: left;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed='true'] { background: var(--navy-900); color: #fff; box-shadow: none; }
:root[data-theme='dark'] .chip[aria-pressed='true'] { background: var(--sun); color: var(--navy-950); }
.chip--sm { min-height: 32px; padding: 4px 14px; font-size: var(--text-xs); line-height: 1.3; }

.tag-list { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.tag-list li { padding: 6px 14px; border-radius: var(--radius-pill); background: var(--surface); font-size: var(--text-sm); font-weight: 500; box-shadow: inset 0 0 0 1px var(--line); }
.tag-list--accent li { background: var(--sun-soft); color: var(--navy-900); box-shadow: none; }
:root[data-theme='dark'] .tag-list--accent li { background: var(--accent-soft); color: var(--sun); }

.bullet-list li { position: relative; padding-left: 1.4rem; margin-bottom: var(--space-2); }
.bullet-list li::before { content: ''; position: absolute; left: 0; top: 0.7em; width: 10px; height: 2px; background: var(--logo-teal); }
.plain-list li { margin-bottom: var(--space-2); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--text);
  font-family: var(--font-body); font-size: 11px; font-weight: 700; line-height: 1.7;
  vertical-align: middle; white-space: nowrap;
}
.badge--good { background: var(--sun-soft); color: var(--navy-800); }
:root[data-theme='dark'] .badge--good { background: var(--accent-soft); color: var(--sun); }
.badge--warn { background: var(--peach); color: var(--peach-ink); }
.badge--muted { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line-strong); }
.count-badge { margin-left: auto; min-width: 22px; height: 22px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--peach); color: var(--peach-ink); font-size: var(--text-xs); font-weight: 800; display: inline-grid; place-items: center; }

.note { display: flex; gap: var(--space-3); align-items: flex-start; margin-top: var(--space-5); padding: var(--space-4) var(--space-5); border-radius: var(--radius); background: var(--sun-soft); color: var(--navy-950); font-size: var(--text-sm); }
.note a { color: inherit; }
.note > [data-icon], .note > svg { margin-top: 2px; }
.note--warn { background: var(--peach); color: var(--text); }
.note--good { background: var(--good-soft); color: var(--text); }
:root[data-theme='dark'] .note { background: var(--accent-soft); color: var(--text); }

.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--sun-soft); color: var(--navy-900);
  font-family: var(--font-body); font-size: var(--text-xs); font-weight: 800;
}
:root[data-theme='dark'] .avatar { background: var(--accent-soft); color: var(--sun); }
.avatar--lg { width: 58px; height: 58px; font-size: var(--text-md); }
.avatar--sm { width: 28px; height: 28px; font-size: 10px; }
.avatar--ring { box-shadow: 0 0 0 3px var(--navy-900); }
.avatar-stack { display: flex; }
.avatar-stack .avatar + .avatar { margin-left: -8px; }
.avatar-stack .avatar { width: 34px; height: 34px; font-size: 10px; }
.avatar--more { background: var(--sun); color: var(--navy-950); }

.empty { display: grid; justify-items: center; gap: var(--space-2); padding: var(--space-7) var(--space-4); color: var(--muted); text-align: center; }

/* ===================== Photo cards ===================== */

.photo-card { position: relative; overflow: hidden; border-radius: var(--radius-lg); background: var(--surface-3); aspect-ratio: 4 / 3; }
.photo-card img { width: 100%; height: 100%; object-fit: cover; transition: transform 1.2s var(--ease-out); }
.photo-card:hover img { transform: scale(1.04); }
.photo-card--tall { aspect-ratio: 4 / 5; margin-top: var(--space-5); }
.photo-card--wide { aspect-ratio: 16 / 9; margin-top: var(--space-5); }

/* ===================== Forms ===================== */

.panel {
  padding: clamp(1.25rem, 1rem + 1vw, 2rem);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--line);
}
.panel__title { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-4); font-size: var(--text-lg); }

.form-grid { display: grid; gap: var(--space-4); margin-bottom: var(--space-5); }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } .field--full { grid-column: 1 / -1; } }
.field { display: grid; gap: 6px; margin-bottom: var(--space-4); }
.form-grid .field { margin-bottom: 0; }
.field label { font-size: var(--text-sm); font-weight: 700; }
.field--inline { margin: 0; }
.field__hint { margin: 0; font-size: var(--text-xs); color: var(--muted); }
.field__error { display: flex; align-items: center; gap: 6px; margin: 0; font-size: var(--text-sm); color: var(--bad); }
.field__error:empty { display: none; }

input[type='text'], input[type='email'], input[type='tel'], input[type='number'], input[type='password'], input[type='search'], input[type='date'], input:not([type]), select, textarea {
  width: 100%; min-height: 48px; padding: 10px 16px;
  border: 0; border-radius: var(--radius-sm);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--text);
  transition: box-shadow var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
input:hover, select:hover, textarea:hover { box-shadow: inset 0 0 0 1px var(--line-strong); }
textarea { resize: vertical; min-height: 120px; }
select { appearance: none; padding-right: 40px; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 20px) 52%, calc(100% - 15px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; background: var(--surface); box-shadow: inset 0 0 0 2px var(--logo-teal); }
:root[data-theme='dark'] input:focus-visible, :root[data-theme='dark'] select:focus-visible, :root[data-theme='dark'] textarea:focus-visible { box-shadow: inset 0 0 0 2px var(--sun); }
[aria-invalid='true'] { box-shadow: inset 0 0 0 2px var(--bad) !important; }
input[type='range'] { width: 100%; accent-color: var(--logo-teal); }
input[type='checkbox'], input[type='radio'] { accent-color: var(--logo-teal); }
.select-sm { min-height: 36px; padding: 4px 34px 4px 14px; font-size: var(--text-sm); width: auto; border-radius: var(--radius-pill); }

.input-with-btn { position: relative; }
.input-with-btn input { padding-right: 50px; }
.input-with-btn .icon-btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
.form-error { display: flex; gap: 6px; align-items: center; min-height: 1.5em; color: var(--bad); font-size: var(--text-sm); }

.check { display: flex; align-items: flex-start; gap: var(--space-3); cursor: pointer; padding: var(--space-3) 0; }
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check__box { display: grid; place-items: center; flex: none; width: 24px; height: 24px; margin-top: 1px; border-radius: 8px; box-shadow: inset 0 0 0 1.5px var(--line-strong); background: var(--surface); color: transparent; transition: background var(--dur-fast) var(--ease); }
.check input:checked + .check__box { background: var(--sun); color: var(--navy-950); box-shadow: none; }
.check input:focus-visible + .check__box { outline: 3px solid var(--focus); outline-offset: 2px; }
.check input:checked ~ span:last-child { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line-strong); }

.progress { display: inline-block; width: 140px; height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; vertical-align: middle; margin-right: var(--space-3); }
.progress span { display: block; height: 100%; width: var(--p, 0%); background: var(--sun-600); border-radius: 4px; transition: width var(--dur) var(--ease); }

.disclosure { margin-top: var(--space-6); }
.disclosure summary { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; font-weight: 700; padding: var(--space-2) 0; }
.disclosure[open] summary { margin-bottom: var(--space-4); }

/* ===================== Tabs ===================== */

.tablist { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-5); }
.tab {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: 42px; padding: 0 var(--space-4);
  border: 0; border-radius: var(--radius-pill);
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--line-strong);
  font-weight: 700; font-size: var(--text-sm);
}
.tab:hover { background: var(--surface-2); }
.tab[aria-selected='true'] { background: var(--navy-900); color: #fff; box-shadow: none; }
:root[data-theme='dark'] .tab[aria-selected='true'] { background: var(--sun); color: var(--navy-950); }
.tablist--lg .tab { min-height: 50px; padding: 0 var(--space-5); }

/* ===================== Tables ===================== */

.table-wrap { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table th, .data-table td { padding: 14px 18px; text-align: left; vertical-align: top; }
.data-table thead th { background: var(--surface-2); font-weight: 700; font-size: var(--text-xs); letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.data-table tbody tr + tr th, .data-table tbody tr + tr td { border-top: 1px solid var(--line); }
.data-table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
.data-table tbody th { font-weight: 700; }
.data-table tfoot td { background: var(--surface-2); font-size: var(--text-xs); color: var(--muted); }
.data-table--dense th, .data-table--dense td { padding: 10px 14px; }
.cell-wrap { min-width: 220px; }

/* ===================== Charts ===================== */

.chart-card { padding: var(--space-5); background: var(--surface); border-radius: var(--radius-lg); box-shadow: 0 0 0 1px var(--line); min-width: 0; }
.chart-card figcaption { margin-bottom: var(--space-3); font-weight: 700; font-size: var(--text-sm); color: var(--muted); }
.chart-card__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
.chart { width: 100%; min-width: 0; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 4; }
.chart-tick, .chart-label { fill: var(--muted); font-size: 11px; font-family: var(--font-body); font-weight: 500; }
.chart-value { fill: var(--text); font-size: 11px; font-weight: 700; font-family: var(--font-body); }
.chart-line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart-point { stroke: var(--surface); stroke-width: 2; }
.chart-track { stroke: var(--surface-3); }
.chart-center { fill: var(--ink); font-family: var(--font-display); font-size: 30px; font-weight: 700; }
.chart-center-sub { fill: var(--muted); font-size: 12px; font-family: var(--font-body); }
.chart-c1 { fill: var(--chart-1); stroke: var(--chart-1); background: var(--chart-1); }
.chart-c2 { fill: var(--chart-2); stroke: var(--chart-2); background: var(--chart-2); }
.chart-c3 { fill: var(--chart-3); stroke: var(--chart-3); background: var(--chart-3); }
.chart-c4 { fill: var(--chart-4); stroke: var(--chart-4); background: var(--chart-4); }
.chart-c5 { fill: var(--chart-5); stroke: var(--chart-5); background: var(--chart-5); }
.chart-c6 { fill: var(--chart-6); stroke: var(--chart-6); background: var(--chart-6); }
.chart-line.chart-c1, .chart-line.chart-c2, .chart-line.chart-c3, .chart-line.chart-c4, .chart-line.chart-c5, .chart-line.chart-c6 { fill: none; }
.chart-seg { fill: none !important; }
.chart-bar { stroke: none; }
.chart-legend { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin-top: var(--space-3); font-size: var(--text-xs); color: var(--muted); font-weight: 600; }
.chart-legend li { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend--stack { flex-direction: column; gap: var(--space-2); margin: 0; font-size: var(--text-sm); }
.chart-legend--stack strong { margin-left: auto; padding-left: var(--space-4); color: var(--text); }
.chart-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.chart-doughnut { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-5); }
.chart-doughnut svg { width: 150px; height: 150px; flex: none; }
.chart-doughnut .chart-legend { flex: 1; min-width: 140px; }

/* Slim column chart (dashboard style): navy bars, one highlighted sun-yellow bar with a tooltip. */
.columns-chart { position: relative; }
.columns-chart .col-bar { fill: var(--navy-950); }
:root[data-theme='dark'] .columns-chart .col-bar { fill: var(--muted); }
:root[data-theme='dark'] .columns-chart .col-bar.is-hi { fill: var(--sun); }
.columns-chart .col-bar.is-hi { fill: var(--sun-600); }
.col-tip rect { fill: var(--navy-950); }
.col-tip text { fill: #fff; font-family: var(--font-body); font-size: 11px; font-weight: 600; }
:root[data-theme='dark'] .col-tip rect { fill: var(--sun); }
:root[data-theme='dark'] .col-tip text { fill: var(--navy-950); }

.ring { display: block; }
.ring__track { stroke: var(--surface-3); }
.ring__value { stroke: var(--sun-600); stroke-linecap: round; transition: stroke-dashoffset 900ms var(--ease-out); }
.ring--low .ring__value { stroke: var(--peach-ink); }

.chart--enter .chart-bar, .chart--enter .col-bar { transform-box: fill-box; transform-origin: bottom; animation: bar-grow var(--dur-slow) var(--ease-out) both; animation-delay: calc(var(--i, 0) * 50ms); }
.chart--enter .chart-line { stroke-dasharray: 1; stroke-dashoffset: 1; animation: line-draw 900ms var(--ease) forwards; }
.chart--enter .chart-point { animation: fade-in var(--dur) var(--ease) both; animation-delay: calc(400ms + var(--i, 0) * 60ms); }
.chart--enter .chart-seg { animation: fade-in var(--dur-slow) var(--ease) both; animation-delay: calc(var(--i, 0) * 120ms); }
@keyframes bar-grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes line-draw { to { stroke-dashoffset: 0; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ===================== Dialogs ===================== */

.modal { width: min(580px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 0; border-radius: var(--radius-lg); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.modal--wide { width: min(780px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(8, 10, 36, 0.55); backdrop-filter: blur(3px); }
.modal[open] { display: flex; flex-direction: column; animation: modal-in var(--dur) var(--ease-out); }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-5) var(--space-5) var(--space-3); }
.modal__title { font-size: var(--text-xl); }
.modal__scroll { flex: 0 1 auto; }
.modal__body { padding: 0 var(--space-5) var(--space-4); overflow-y: auto; }
.modal__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-5); background: var(--surface-2); }
.modal .form-grid { margin-bottom: 0; }
.ai-test { display: flex; align-items: center; gap: 6px; min-height: 1.5em; margin: var(--space-3) 0 0; font-size: var(--text-sm); }
.ai-test.is-good { color: var(--good); }
.ai-test.is-bad { color: var(--bad); }

/* ===================== Toasts ===================== */

.toasts { position: fixed; left: 50%; bottom: var(--space-5); transform: translateX(-50%); z-index: var(--z-toast); display: grid; gap: var(--space-2); width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius); background: var(--navy-950); color: #fff; box-shadow: var(--shadow-lg); font-size: var(--text-sm); font-weight: 500; opacity: 0; transform: translateY(8px); transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease); }
.toast.is-in { opacity: 1; transform: none; }
.toast.is-out { opacity: 0; transform: translateY(8px); }
.toast svg { color: var(--sun); }
.toast--error svg { color: #ff8a80; }
.toast--warning svg { color: #f0b85a; }

/* ===================== KIS Buddy ===================== */

.chat-launcher {
  position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: var(--z-chat);
  display: inline-flex; align-items: center; gap: var(--space-3);
  min-height: 56px; padding: 6px var(--space-5) 6px 6px;
  border: 0; border-radius: var(--radius-pill);
  background: var(--navy-950); color: #fff;
  font-weight: 700; font-size: var(--text-sm);
  box-shadow: var(--shadow-lg);
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
  view-transition-name: chat-launcher;
}
.chat-launcher__icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--sun); color: var(--navy-950); }
.chat-launcher:hover { transform: translateY(-2px); }
:root.chat-open .chat-launcher, :root.nav-open .chat-launcher { opacity: 0; pointer-events: none; transform: translateY(8px); }
@media (max-width: 560px) {
  .chat-launcher { right: var(--space-4); bottom: var(--space-4); padding: 6px; }
  .chat-launcher__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

.chat {
  position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: var(--z-chat);
  display: flex; flex-direction: column;
  width: min(410px, calc(100vw - 32px)); height: min(640px, calc(100vh - 120px));
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--line);
  overflow: hidden;
  animation: chat-in var(--dur) var(--ease-out);
}
@keyframes chat-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }
@media (max-width: 560px) { .chat { inset: auto 0 0 0; width: 100%; height: min(88vh, 100% - 40px); border-radius: var(--radius-lg) var(--radius-lg) 0 0; } }
.chat__head { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4); background: var(--navy-950); color: #fff; }
.chat__head .icon-btn { color: #fff; }
.chat__head .icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.chat__avatar { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--sun); color: var(--navy-950); }
.chat__heading { flex: 1; min-width: 0; display: grid; gap: 2px; justify-items: start; }
.chat__title { font-size: var(--text-lg); color: #fff; }
.status-chip { display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px 1px 7px; border: 0; border-radius: var(--radius-pill); background: rgba(255, 255, 255, 0.12); color: #c8cce8; font-size: 11px; font-weight: 700; }
.status-chip.is-online { background: var(--sun); color: var(--navy-950); }
.chat__scroll { flex: 1 1 auto; }
.chat__log { flex: 1; overflow-y: auto; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); background: var(--bg); }
.msg { display: flex; gap: var(--space-2); max-width: 92%; }
.msg--user { align-self: flex-end; }
.msg__avatar { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--sun); color: var(--navy-950); margin-top: 2px; }
.msg__bubble { padding: var(--space-3) var(--space-4); border-radius: 18px; background: var(--surface); box-shadow: 0 0 0 1px var(--line); font-size: var(--text-sm); line-height: 1.55; overflow-wrap: anywhere; }
.msg--user .msg__bubble { background: var(--navy-900); color: #fff; box-shadow: none; border-bottom-right-radius: 6px; }
.msg--user .msg__bubble a { color: var(--sun); }
.msg--bot .msg__bubble { border-top-left-radius: 6px; }
.msg__bubble ul, .msg__bubble ol { margin: var(--space-2) 0; padding-left: 1.1rem; }
.msg__bubble li { list-style: disc; margin-bottom: 4px; }
.msg__bubble ol li { list-style: decimal; }
.msg__bubble p { margin-bottom: var(--space-2); }
.msg__meta { display: flex; align-items: center; gap: 4px; margin: var(--space-2) 0 0 !important; font-size: 11px; color: var(--muted); }
.typing { display: inline-flex; align-items: center; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: typing 1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing { 0%, 80%, 100% { opacity: 0.25; transform: none; } 40% { opacity: 1; transform: translateY(-3px); } }
.chat__suggestions { display: flex; gap: var(--space-2); padding: var(--space-2) var(--space-4); overflow-x: auto; background: var(--bg); scrollbar-width: none; }
.chat__suggestions:empty { display: none; }
.chat__suggestions .chip { flex: none; }
.chat__form { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3); background: var(--surface); box-shadow: 0 -1px 0 var(--line); }
.chat__form input { flex: 1; min-height: 44px; border-radius: var(--radius-pill); padding: 8px 18px; }
[data-chat-mic].is-listening { background: var(--bad-soft); color: var(--bad); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }

/* ===================== Lightbox ===================== */

.lightbox { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: var(--space-5); border: 0; background: rgba(7, 9, 30, 0.94); color: #fff; }
.lightbox[open] { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--space-3); }
.lightbox::backdrop { background: transparent; }
.lightbox .icon-btn { color: #fff; background: rgba(255, 255, 255, 0.1); }
.lightbox .icon-btn:hover { background: rgba(255, 255, 255, 0.2); }
.lightbox__close { position: absolute; top: var(--space-4); right: var(--space-4); }
.lightbox__figure { display: grid; gap: var(--space-3); justify-items: center; min-width: 0; }
.lightbox__media { width: min(100%, 1100px); aspect-ratio: 3 / 2; max-height: 80vh; border-radius: var(--radius-lg); overflow: hidden; background: transparent; }
.lightbox__media img { width: 100%; height: 100%; object-fit: contain; }
.lightbox figcaption { font-size: var(--text-sm); color: #d8dbef; }

/* ===================== Media ===================== */

.media { position: relative; display: block; aspect-ratio: 4 / 3; overflow: hidden; border-radius: var(--radius); background: var(--surface-3); }
.media--wide { aspect-ratio: 16 / 9; }
.media img { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: cover; }
.media-placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: var(--surface-3); }
.media.has-image .media-placeholder { display: none; }

/* ===================== Scroll areas (no scrollbars) ===================== */

/* Faded edges show there is more to scroll to; set by KIS.ui.scrollAreas in js/ui.js. */
[data-scroll-axis='x'][data-more='end'] { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent); }
[data-scroll-axis='x'][data-more='start'] { -webkit-mask-image: linear-gradient(90deg, transparent, #000 36px); mask-image: linear-gradient(90deg, transparent, #000 36px); }
[data-scroll-axis='x'][data-more='both'] { -webkit-mask-image: linear-gradient(90deg, transparent, #000 36px, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(90deg, transparent, #000 36px, #000 calc(100% - 36px), transparent); }
[data-scroll-axis='y'][data-more='end'] { -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(180deg, #000 calc(100% - 32px), transparent); }
[data-scroll-axis='y'][data-more='start'] { -webkit-mask-image: linear-gradient(180deg, transparent, #000 32px); mask-image: linear-gradient(180deg, transparent, #000 32px); }
[data-scroll-axis='y'][data-more='both'] { -webkit-mask-image: linear-gradient(180deg, transparent, #000 32px, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(180deg, transparent, #000 32px, #000 calc(100% - 32px), transparent); }

/* Arrow buttons above a horizontal area */
.scroll-bar { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin: 0 0 var(--space-2); }
.scroll-bar[hidden] { display: none; }
.scroll-bar__hint { display: inline-flex; align-items: center; gap: 6px; margin-right: auto; font-size: var(--text-xs); font-weight: 600; color: var(--muted); }
.scroll-bar__btn, .scroll-area__btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: 50%; background: var(--surface); color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  transition: background var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.scroll-bar__btn:hover:not(:disabled), .scroll-area__btn:hover { background: var(--sun); color: var(--navy-950); box-shadow: none; }
.scroll-bar__btn:disabled { opacity: 0.35; cursor: default; }

/* Up and down buttons floating inside a vertical area */
.scroll-area { position: relative; display: flex; flex-direction: column; min-height: 0; }
.scroll-area > :first-child { flex: 1 1 auto; min-height: 0; }
.scroll-area__btn { position: absolute; right: 12px; z-index: 2; background: var(--navy-900); color: #fff; box-shadow: var(--shadow-sm); opacity: 0; pointer-events: none; transform: scale(0.8); }
.scroll-area__btn--up { top: 10px; }
.scroll-area__btn--down { bottom: 10px; }
.scroll-area.can-up .scroll-area__btn--up, .scroll-area.can-down .scroll-area__btn--down { opacity: 1; pointer-events: auto; transform: none; }
:root[data-theme='dark'] .scroll-area__btn { background: var(--sun); color: var(--navy-950); }

.chat-launcher__icon { overflow: hidden; background: #fff; }
.chat-launcher__icon img, .chat__avatar img { width: 100%; height: 100%; object-fit: contain; }
.chat__avatar { overflow: hidden; background: #fff; }
.msg__avatar { overflow: hidden; background: #fff; }
.msg__avatar img { width: 100%; height: 100%; object-fit: contain; }
