/**
 * Portable UI primitives. Depend only on tokens.css (--st-*).
 * Prefix st- = design-system kit name, not Storybook.
 * Copy with tokens.css — no catalog / app overrides required.
 */

/* —— Nav —— */
.st-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--st-space-4);
  min-height: var(--st-nav-h);
  padding: 0 var(--st-space-5);
  background: var(--st-bg);
  border-bottom: 1px solid var(--st-border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.st-nav__brand {
  font-weight: 800;
  letter-spacing: 0.03em;
  color: var(--st-text);
  text-decoration: none;
  flex-shrink: 0;
}

.st-nav__brand:hover {
  text-decoration: none;
}

.st-nav__brand span {
  color: var(--st-accent);
}

.st-nav__logo {
  display: block;
  height: 40px;
  width: auto;
}

.st-nav__right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--st-space-4);
  margin-left: auto;
  flex-wrap: wrap;
}

.st-nav__links {
  display: flex;
  gap: var(--st-space-4);
  flex-wrap: wrap;
}

.st-nav__links a {
  color: var(--st-nav-link);
  font-weight: 600;
  font-size: 0.875rem;
  text-decoration: none;
}

.st-nav__links a:hover,
.st-nav__links a.is-active {
  color: var(--st-nav-link-active);
}

.st-nav__user {
  display: flex;
  align-items: center;
  gap: var(--st-space-3);
  color: var(--st-muted);
  font-size: 0.8125rem;
  padding-left: var(--st-space-4);
  border-left: 1px solid var(--st-border);
}

/* —— Layout —— */
.st-wrap {
  max-width: var(--st-max);
  margin: 0 auto;
  padding: var(--st-space-4) var(--st-space-4) var(--st-space-5);
}

.st-wrap--fluid {
  max-width: none;
  width: 100%;
  padding-left: var(--st-space-4);
  padding-right: var(--st-space-4);
}

.st-split {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: var(--st-space-4);
  align-items: start;
}

.st-split--wide-form {
  grid-template-columns: minmax(380px, 1fr) minmax(0, 1.15fr);
}

.st-split__preview {
  position: sticky;
  top: calc(var(--st-nav-h) + var(--st-space-3));
  align-self: start;
  min-height: 0;
}

@media (max-width: 960px) {
  .st-split,
  .st-split--wide-form {
    grid-template-columns: 1fr;
  }
  .st-split__preview {
    position: static;
  }
}

.st-section {
  margin-bottom: var(--st-space-3);
  padding-bottom: 0;
  border-bottom: none;
}

.st-section__title {
  margin: 0 0 2px;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--st-muted);
}

.st-section__hint {
  margin: 0 0 var(--st-space-2);
  font-size: 0.75rem;
  color: var(--st-muted);
}

.st-section__hint--inline {
  display: inline;
  margin-left: var(--st-space-2);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

/* —— Accordion (details) —— */
.st-acc {
  margin-bottom: 0;
  border: none;
  background: transparent;
}

.st-acc + .st-acc {
  border-top: 1px solid var(--st-border);
  margin-top: var(--st-space-2);
  padding-top: var(--st-space-2);
}

.st-acc__summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  cursor: pointer;
  list-style: none;
  padding: 6px 0;
  color: var(--st-text);
  font-size: 0.8125rem;
  font-weight: 700;
  user-select: none;
}

.st-acc__summary::-webkit-details-marker {
  display: none;
}

.st-acc__summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid var(--st-muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  flex-shrink: 0;
  align-self: center;
  transition: transform 0.12s ease;
}

.st-acc[open] > .st-acc__summary::before {
  transform: rotate(90deg);
}

.st-acc__hint {
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--st-muted);
}

.st-acc__body {
  padding: 0 0 var(--st-space-2) 14px;
}

.st-hr {
  border: 0;
  border-top: 1px solid var(--st-border);
  margin: var(--st-space-3) 0;
}

.st-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--st-space-2);
  align-items: center;
}

.st-row--stretch > * {
  flex: 1;
  min-width: 140px;
}

.st-sticky-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: var(--st-space-2);
  padding: var(--st-space-3) 0;
  position: sticky;
  bottom: 0;
  background: var(--st-bg);
  border-top: 1px solid var(--st-border);
  margin-top: var(--st-space-3);
  z-index: 5;
}

.st-icon {
  display: inline-block;
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.st-drop {
  position: relative;
}

.st-drop__menu {
  display: none;
  position: absolute;
  right: 0;
  bottom: calc(100% + 4px);
  min-width: 168px;
  padding: 4px;
  background: var(--st-surface);
  border: 1px solid var(--st-border);
  border-radius: var(--st-radius);
  box-shadow: var(--st-shadow);
  z-index: 30;
}

.st-drop.is-open .st-drop__menu {
  display: flex;
  flex-direction: column;
}

.st-drop__item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--st-radius-sm);
  background: transparent;
  color: var(--st-text);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.st-drop__item:hover:not(:disabled) {
  background: var(--st-table-hover);
}

.st-drop__item:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* —— Buttons —— */
.st-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--st-space-2);
  font: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  line-height: 1.2;
  padding: 8px 14px;
  border-radius: var(--st-radius);
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--st-surface);
  color: var(--st-text);
  text-decoration: none;
  width: auto;
}

.st-btn:hover {
  text-decoration: none;
}

.st-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.st-btn--primary {
  background: var(--st-accent);
  border-color: var(--st-accent);
  color: #fff;
}

.st-btn--primary:hover:not(:disabled) {
  background: var(--st-accent-hover);
  border-color: var(--st-accent-hover);
}

.st-btn--ghost {
  background: transparent;
  border-color: var(--st-border);
  color: var(--st-text);
}

.st-btn--ghost:hover:not(:disabled) {
  background: var(--st-table-hover);
}

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

.st-btn--sm {
  padding: 5px 10px;
  font-size: 0.8125rem;
}

.st-btn--block {
  display: flex;
  width: 100%;
}

/* —— Fields —— */
.st-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: var(--st-space-2);
}

.st-field__label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--st-muted);
}

.st-field__hint {
  font-size: 0.6875rem;
  color: var(--st-muted);
}

.st-input,
.st-select,
.st-textarea {
  font: inherit;
  font-size: 0.8125rem;
  color: var(--st-text);
  background: var(--st-input-bg);
  border: 1px solid var(--st-border);
  border-radius: var(--st-radius-sm);
  padding: 6px 8px;
  width: 100%;
}

.st-input:focus,
.st-select:focus,
.st-textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--st-accent) 35%, transparent);
  outline-offset: 1px;
  border-color: var(--st-accent);
}

.st-textarea {
  min-height: 72px;
  font-family: var(--st-font-mono);
  font-size: 0.75rem;
  resize: vertical;
}

.st-textarea--tall {
  min-height: 140px;
}

.st-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235c6b7a' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}

.st-select--lg {
  padding: 10px 32px 10px 12px;
  font-size: 0.875rem;
  font-weight: 600;
  min-height: 40px;
  background-position: right 12px center;
}

/* —— Select + detail panel (long option lists) —— */
.st-select-detail {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px 16px;
}

.st-select-detail > .st-field {
  margin-bottom: 0;
  flex: 1 1 180px;
  min-width: 160px;
  max-width: 280px;
}

.st-select-detail__panel {
  flex: 1 1 220px;
  min-width: 180px;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
}

.st-select-detail__title {
  margin: 0 0 4px;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--st-text);
  letter-spacing: 0.01em;
}

.st-select-detail__lead {
  margin: 0 0 8px;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--st-muted);
}

.st-select-detail__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.st-select-detail__list li {
  position: relative;
  padding-left: 1.1em;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--st-text);
}

.st-select-detail__list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.45em;
  width: 0.4em;
  height: 0.4em;
  border-radius: 50%;
  background: var(--st-accent);
}

.st-select-detail__panel--empty {
  color: var(--st-muted);
  font-size: 0.75rem;
  padding-top: 1.4rem;
}

/* —— Segmented radio —— */
.st-seg {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1px solid var(--st-border);
  border-radius: var(--st-radius);
  overflow: hidden;
  background: var(--st-surface);
}

.st-seg__item {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--st-muted);
  cursor: pointer;
  border-right: 1px solid var(--st-border);
  background: transparent;
  user-select: none;
}

.st-seg__item:last-child {
  border-right: none;
}

.st-seg__item:hover {
  color: var(--st-text);
  background: var(--st-table-hover);
}

.st-seg__item:has(input:checked) {
  color: #fff;
  background: var(--st-accent);
}

.st-seg__item input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.st-seg__desc {
  font-weight: 400;
  font-size: 0.6875rem;
  opacity: 0.85;
}

/* —— Radio list —— */
.st-radio-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.st-radio {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  padding: 2px 0;
  border: none;
  background: none;
}

.st-radio input {
  appearance: none;
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  flex-shrink: 0;
  border: 1.5px solid var(--st-border);
  border-radius: 50%;
  background: var(--st-input-bg);
  cursor: pointer;
}

.st-radio input:checked {
  border-color: var(--st-accent);
  box-shadow: inset 0 0 0 4px var(--st-accent);
  background: var(--st-surface);
}

.st-radio__text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.st-radio__label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--st-text);
}

.st-radio__hint {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--st-muted);
}

/* —— Checkbox (plain: box + label, no chip/border) —— */
.st-opt-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.st-opt-list--wrap {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px 18px;
}

.st-opt {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  cursor: pointer;
  padding: 0;
  border: none;
  background: none;
  color: var(--st-text);
  font-size: 0.8125rem;
  user-select: none;
}

.st-opt input {
  appearance: none;
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  flex-shrink: 0;
  border: 1.5px solid color-mix(in srgb, var(--st-muted) 55%, var(--st-border));
  border-radius: 3px;
  background: var(--st-input-bg);
  cursor: pointer;
}

.st-opt input:hover {
  border-color: var(--st-accent);
}

.st-opt input:checked {
  background: var(--st-accent);
  border-color: var(--st-accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round' d='M3.5 8.5l3 3 6-6'/%3E%3C/svg%3E");
  background-size: 12px 12px;
  background-position: center;
  background-repeat: no-repeat;
}

.st-opt input:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--st-accent) 40%, transparent);
  outline-offset: 2px;
}

.st-opt__text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.st-opt__label {
  font-weight: 600;
  line-height: 1.3;
}

.st-opt__hint {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--st-muted);
  line-height: 1.3;
}

/* —— Table —— */
.st-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.st-table th,
.st-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--st-border);
  vertical-align: middle;
}

.st-table th {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--st-muted);
}

.st-table tbody tr:hover {
  background: var(--st-table-hover);
}

.st-table__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--st-space-2);
  justify-content: flex-end;
  white-space: nowrap;
}

.st-swatch {
  display: inline-block;
  width: 48px;
  height: 12px;
  border-radius: 2px;
  vertical-align: middle;
  border: 1px solid var(--st-border);
}

/* —— Alerts —— */
.st-alert {
  padding: var(--st-space-3);
  border-radius: var(--st-radius);
  font-size: 0.875rem;
  margin-bottom: var(--st-space-3);
}

.st-alert--error {
  color: var(--st-danger);
  background: var(--st-danger-bg);
}

.st-alert--ok {
  color: var(--st-ok);
  background: var(--st-ok-bg);
}

/* —— Preview frame —— */
.st-preview {
  width: 100%;
  height: calc(100vh - var(--st-nav-h) - 72px);
  min-height: 420px;
  border: 1px solid var(--st-border);
  border-radius: var(--st-radius-sm);
  background: #fff;
}

.st-preview--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--st-muted);
  font-size: 0.8125rem;
  background: var(--st-surface);
}

.st-preview--loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--st-muted);
  font-size: 0.8125rem;
  background: var(--st-surface);
}

.st-preview__spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--st-border);
  border-top-color: var(--st-accent);
  border-radius: 50%;
  animation: st-spin 0.8s linear infinite;
}

@keyframes st-spin {
  to {
    transform: rotate(360deg);
  }
}

.st-muted {
  color: var(--st-muted);
}

/* Split auth login (brand left, form right) — matches Scheduler / Policy Manager */
.auth-layout {
  display: flex;
  width: 100%;
  min-height: 100vh;
  height: 100vh;
  margin: 0;
  color: var(--st-text);
  font-family: var(--st-font, inherit);
  background: var(--st-bg);
}

.auth-brand-panel {
  position: relative;
  flex: 1;
  background: var(--st-bg);
  border-right: 1px solid var(--st-border);
  display: flex;
  flex-direction: column;
  padding: 64px 80px;
  overflow: hidden;
}

.auth-brand-panel::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 10%;
  width: 16rem;
  height: 16rem;
  transform: translateX(-50%);
  background-image: url("/images/brand/crop/background-mark-01-arc.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  opacity: 0.28;
  pointer-events: none;
}

.auth-brand-panel .logo,
.auth-brand-panel .brand-content {
  position: relative;
  z-index: 1;
}

.auth-brand-panel .logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-brand-panel .logo img {
  height: 40px;
  width: auto;
  display: block;
}

.auth-brand-panel .brand-content {
  margin-top: auto;
  margin-bottom: 14vh;
}

.auth-brand-panel .hero-text {
  font-size: 48px;
  font-weight: 700;
  line-height: 1.1;
  margin: 0 0 24px;
  letter-spacing: -1.5px;
  max-width: 520px;
}

.auth-brand-panel .sub-text {
  font-size: 18px;
  color: var(--st-muted);
  line-height: 1.6;
  margin: 0;
  max-width: 420px;
}

.auth-form-panel {
  flex: 1;
  background: var(--st-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px 96px;
}

.auth-marks {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 32px;
}

.auth-marks img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.login-form {
  width: min(480px, 100%);
  display: flex;
  flex-direction: column;
}

.login-form .form-header {
  margin-bottom: 40px;
}

.login-form .form-header h2 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -1px;
  margin: 0;
}

.login-form .form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 24px;
}

.login-form .form-group label {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
}

.login-form input[type="text"],
.login-form input[type="password"] {
  width: 100%;
  height: 36px;
  border: 1px solid var(--st-border);
  border-radius: 6px;
  padding: 0 12px;
  font: inherit;
  font-size: 14px;
  color: var(--st-text);
  background: var(--st-surface);
  box-sizing: border-box;
}

.login-form input[type="text"]:focus,
.login-form input[type="password"]:focus {
  outline: none;
  border-color: var(--st-accent);
  box-shadow: 0 0 0 1px var(--st-accent);
}

.login-form button[type="submit"] {
  width: 100%;
  height: 36px;
  background: var(--st-accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 8px;
}

.login-form button[type="submit"]:hover {
  filter: brightness(0.95);
}

.login-form .form-footer {
  margin-top: 32px;
  text-align: center;
  font-size: 14px;
  color: var(--st-muted);
}

.login-form .flash {
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 16px;
  background: #fef2f2;
  color: var(--st-danger, #b91c1c);
  font-size: 14px;
}

.rv-account-embed {
  display: block;
  width: 100%;
  height: 80px;
  margin: 0 0 16px;
  border: 0;
  border-radius: 12px;
  overflow: hidden;
  background: #17233a;
  color-scheme: none;
}

.auth-local-rule {
  width: 100%;
  margin: 8px 0 16px;
  border: 0;
  border-top: 1px solid var(--st-border);
}

.auth-local-toggle {
  display: block;
  width: 100%;
  margin: 0 0 24px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--st-muted);
  font-family: inherit;
  font-size: 14px;
  text-align: center;
  cursor: pointer;
}

.auth-local-toggle:hover {
  color: var(--st-text);
}

.auth-local {
  margin: 0;
  padding: 0;
  border: 0;
  min-inline-size: 0;
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition:
    grid-template-rows 0.26s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.22s ease;
}

.auth-local__inner {
  overflow: hidden;
  min-height: 0;
}

.auth-local--open {
  grid-template-rows: 1fr;
  opacity: 1;
}

@media (max-width: 900px) {
  .auth-layout {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  .auth-brand-panel {
    padding: 32px 24px;
    border-right: 0;
    border-bottom: 1px solid var(--st-border);
  }

  .auth-brand-panel .brand-content {
    margin-bottom: 24px;
  }

  .auth-brand-panel .hero-text {
    font-size: 32px;
    letter-spacing: -1px;
  }

  .login-form {
    width: 100%;
    max-width: 480px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .auth-local {
    transition: none;
  }
}

.st-page-list {
  display: flex;
  flex-direction: column;
  gap: var(--st-space-3);
}

.st-page-item {
  border: 1px solid var(--st-border);
  border-radius: var(--st-radius-sm);
  padding: var(--st-space-2);
  background: var(--st-surface);
}

@media print {
  .st-nav,
  .st-sticky-actions,
  .no-print {
    display: none !important;
  }
}

@media (max-width: 720px) {
  .st-nav__user {
    border-left: none;
    padding-left: 0;
  }
}
