/*
 * RS-TH12 — Auth, Error & System States Audit
 * Shared production layer for authentication, HTTP errors, maintenance,
 * offline/network feedback, bootstrap loading and session-expiry surfaces.
 */
:root {
  --th12-bg: #f4f7f4;
  --th12-surface: #ffffff;
  --th12-surface-2: #edf5f0;
  --th12-text: #15251d;
  --th12-muted: #53665c;
  --th12-line: #cbd9d1;
  --th12-primary: #176b49;
  --th12-primary-strong: #0f5137;
  --th12-danger: #a22637;
  --th12-warning: #8b5b08;
  --th12-info: #185b78;
  --th12-shadow: 0 24px 70px rgba(25, 56, 41, .16);
  --th12-radius: 24px;
}

html[data-theme="dark"] {
  --th12-bg: #07110d;
  --th12-surface: #0d1e17;
  --th12-surface-2: #122a20;
  --th12-text: #eef8f2;
  --th12-muted: #b8c9c0;
  --th12-line: #315246;
  --th12-primary: #55d49d;
  --th12-primary-strong: #83e8b8;
  --th12-danger: #ff8d9b;
  --th12-warning: #f6c96d;
  --th12-info: #78c9ed;
  --th12-shadow: 0 28px 84px rgba(0, 0, 0, .42);
}

.herb-bootstrap-state {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--th12-bg) 92%, transparent);
  backdrop-filter: blur(8px);
  transition: opacity .18s ease, visibility .18s ease;
}

.herb-bootstrap-state[hidden],
.herb-bootstrap-state.is-ready {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.herb-bootstrap-state__card {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: min(340px, calc(100vw - 48px));
  padding: 18px 20px;
  border: 1px solid var(--th12-line);
  border-radius: 18px;
  background: var(--th12-surface);
  color: var(--th12-text);
  box-shadow: var(--th12-shadow);
}

.herb-bootstrap-state__spinner {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border: 3px solid color-mix(in srgb, var(--th12-primary) 24%, transparent);
  border-top-color: var(--th12-primary);
  border-radius: 50%;
  animation: th12-spin .8s linear infinite;
}

.herb-bootstrap-state__title {
  display: block;
  font-weight: 800;
  line-height: 1.35;
}

.herb-bootstrap-state__desc {
  display: block;
  margin-top: 2px;
  color: var(--th12-muted);
  font-size: .875rem;
}

.herb-network-banner {
  position: fixed;
  z-index: 2147482500;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  width: min(680px, calc(100vw - 24px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--th12-warning) 52%, var(--th12-line));
  border-radius: 16px;
  background: color-mix(in srgb, var(--th12-surface) 94%, var(--th12-warning) 6%);
  color: var(--th12-text);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .2);
}

.herb-network-banner[hidden] { display: none; }
.herb-network-banner__content { min-width: 0; }
.herb-network-banner__title { display: block; font-weight: 800; }
.herb-network-banner__message { display: block; color: var(--th12-muted); font-size: .875rem; }
.herb-network-banner__actions { display: flex; gap: 8px; flex: 0 0 auto; }

.herb-system-action,
.system-state-btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--th12-line);
  border-radius: 12px;
  background: var(--th12-surface);
  color: var(--th12-text);
  font: inherit;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
  transition: border-color .16s ease, background-color .16s ease, color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.herb-system-action:hover,
.system-state-btn:hover { border-color: var(--th12-primary); color: var(--th12-primary-strong); }
.herb-system-action:focus-visible,
.system-state-btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--th12-primary) 36%, transparent); outline-offset: 2px; }
.system-state-btn--primary { border-color: var(--th12-primary); background: var(--th12-primary); color: #fff; }
html[data-theme="dark"] .system-state-btn--primary { color: #062116; }
.system-state-btn--danger {
  border-color: #841d2d;
  background-color: #841d2d;
  background-image: linear-gradient(135deg, #a1283b 0%, #841d2d 100%);
  color: #fff;
  box-shadow: 0 10px 24px rgba(132, 29, 45, .2);
}
.system-state-btn--danger:hover {
  border-color: #6f1725;
  background-color: #6f1725;
  background-image: linear-gradient(135deg, #8f2133 0%, #6f1725 100%);
  color: #fff;
  box-shadow: 0 12px 28px rgba(111, 23, 37, .26);
  transform: translateY(-1px);
}
.system-state-btn--danger:focus-visible {
  outline-color: rgba(161, 40, 59, .38);
}
html[data-theme="dark"] .system-state-btn--danger {
  border-color: #d85a6d;
  background-color: #8d2639;
  background-image: linear-gradient(135deg, #a93448 0%, #8d2639 100%);
  color: #fff;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .28);
}
html[data-theme="dark"] .system-state-btn--danger:hover {
  border-color: #ef7586;
  background-color: #9d2c41;
  background-image: linear-gradient(135deg, #bd3d53 0%, #9d2c41 100%);
  color: #fff;
}
.system-state-btn[disabled], .system-state-btn[aria-disabled="true"] { opacity: .68; cursor: wait; transform: none; box-shadow: none; }


/* RS-TH12.1 logout confirmation hierarchy. */
body[data-system-state="logout-confirmation"] .system-state-lead strong {
  color: var(--th12-text);
  font-weight: 850;
}
body[data-system-state="logout-confirmation"] .system-state-actions .system-state-btn--danger {
  min-width: 164px;
}
body[data-system-state="logout-confirmation"] .system-state-actions .system-state-btn:not(.system-state-btn--danger) {
  background: var(--th12-surface-2);
}

.herb-system-dialog {
  position: fixed;
  inset: 0;
  z-index: 2147482600;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 12, 8, .66);
  backdrop-filter: blur(7px);
}

.herb-system-dialog[hidden] { display: none; }
.herb-system-dialog__panel {
  width: min(520px, 100%);
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid var(--th12-line);
  border-radius: var(--th12-radius);
  background: var(--th12-surface);
  color: var(--th12-text);
  box-shadow: var(--th12-shadow);
}
.herb-system-dialog__eyebrow { color: var(--th12-danger); font-weight: 800; letter-spacing: .02em; }
.herb-system-dialog__title { margin: 8px 0 10px; font-size: clamp(1.4rem, 4vw, 2rem); font-weight: 850; }
.herb-system-dialog__message { margin: 0; color: var(--th12-muted); line-height: 1.75; }
.herb-system-dialog__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }

.system-state-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(18px, 4vw, 48px);
  background:
    radial-gradient(circle at 8% 8%, color-mix(in srgb, var(--th12-primary) 14%, transparent), transparent 32%),
    radial-gradient(circle at 92% 92%, color-mix(in srgb, var(--th12-warning) 10%, transparent), transparent 34%),
    var(--th12-bg);
  color: var(--th12-text);
}

.system-state-card {
  width: min(100%, 980px);
  overflow: hidden;
  border: 1px solid var(--th12-line);
  border-radius: var(--th12-radius);
  background: var(--th12-surface);
  box-shadow: var(--th12-shadow);
}

.system-state-grid { display: grid; grid-template-columns: minmax(260px, .8fr) minmax(360px, 1.2fr); }
.system-state-aside {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  justify-content: space-between;
  gap: 40px;
  padding: clamp(28px, 5vw, 54px);
  background: linear-gradient(145deg, #0f5137, #176b49 58%, #227c58);
  color: #fff;
}
.system-state-code { font-size: clamp(3.5rem, 11vw, 7.5rem); font-weight: 900; line-height: .9; letter-spacing: -.06em; }
.system-state-badge { display: inline-flex; width: fit-content; padding: 7px 11px; border: 1px solid rgba(255,255,255,.42); border-radius: 999px; background: rgba(255,255,255,.12); font-size: .78rem; font-weight: 800; }
.system-state-brand { font-weight: 850; }
.system-state-aside p { margin: 8px 0 0; color: rgba(255,255,255,.86); line-height: 1.7; }
.system-state-main { position: relative; padding: clamp(28px, 5vw, 58px); }
.system-state-theme { position: absolute; top: 18px; right: 18px; min-width: 44px; min-height: 44px; border: 1px solid var(--th12-line); border-radius: 12px; background: var(--th12-surface-2); color: var(--th12-text); }
.system-state-title { margin: 12px 54px 10px 0; font-size: clamp(1.65rem, 4vw, 2.65rem); font-weight: 900; letter-spacing: -.025em; }
.system-state-lead { max-width: 700px; margin: 0; color: var(--th12-muted); line-height: 1.8; }
.system-state-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 26px; }
.system-state-help { margin-top: 20px; padding: 14px 16px; border: 1px solid var(--th12-line); border-radius: 14px; background: var(--th12-surface-2); color: var(--th12-muted); line-height: 1.65; }
.system-state-meta { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; margin-top: 24px; }
.system-state-meta__item { min-width: 0; padding: 12px 14px; border: 1px solid var(--th12-line); border-radius: 13px; background: var(--th12-surface-2); }
.system-state-meta__label { color: var(--th12-muted); font-size: .78rem; font-weight: 750; }
.system-state-meta__value { margin-top: 4px; overflow-wrap: anywhere; font-weight: 750; }

.system-state-form { margin-top: 26px; }
.system-state-field { margin-bottom: 18px; }
.system-state-label { display: block; margin-bottom: 7px; font-weight: 800; }
.system-state-required { color: var(--th12-danger); }
.system-state-input {
  width: 100%;
  min-height: 48px;
  padding: 10px 13px;
  border: 1px solid var(--th12-line);
  border-radius: 12px;
  background: var(--th12-surface);
  color: var(--th12-text);
  font: inherit;
}
.system-state-input::placeholder { color: var(--th12-muted); opacity: 1; }
.system-state-input:focus { border-color: var(--th12-primary); outline: 3px solid color-mix(in srgb, var(--th12-primary) 24%, transparent); }
.system-state-hint { margin-top: 7px; color: var(--th12-muted); font-size: .875rem; line-height: 1.55; }
.system-state-alert { margin: 18px 0; padding: 13px 15px; border: 1px solid var(--th12-line); border-left-width: 5px; border-radius: 12px; background: var(--th12-surface-2); line-height: 1.65; }
.system-state-alert--danger { border-left-color: var(--th12-danger); }
.system-state-alert--warning { border-left-color: var(--th12-warning); }
.system-state-alert--success { border-left-color: var(--th12-primary); }
.system-state-alert--info { border-left-color: var(--th12-info); }
.system-state-debug { max-height: 300px; overflow: auto; margin-top: 18px; padding: 14px; border-radius: 12px; background: #07110d; color: #d8f5e6; font-size: .78rem; white-space: pre-wrap; }

/* Existing auth and error pages join the same state language without being rebuilt. */
.theme-scope-auth .login-state-notice { margin-bottom: 16px; }
.theme-scope-auth .login-card,
.theme-scope-auth .login-showcase { border-color: var(--th12-line); }
.theme-scope-auth .login-card__title,
.theme-scope-auth .form-label { color: var(--th12-text); }
.theme-scope-auth .login-first-run { margin-top: 16px; }
.theme-scope-auth [data-system-submit].is-submitting { opacity: .76; cursor: wait; }

.theme-scope-error .error-shell { background: var(--th12-bg); }
.theme-scope-error .error-card { border: 1px solid var(--th12-line); box-shadow: var(--th12-shadow); }
.theme-scope-error .error-panel { background: var(--th12-surface); color: var(--th12-text); }
.theme-scope-error .error-sub,
.theme-scope-error .error-help { color: var(--th12-muted); }
.theme-scope-error .error-meta-item { border-color: var(--th12-line); background: var(--th12-surface-2); }
.theme-scope-error .error-meta-item .value { overflow-wrap: anywhere; }
.theme-scope-error .error-request-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.theme-scope-error .error-btn { min-height: 44px; }

@media (max-width: 767.98px) {
  .system-state-shell { align-items: start; padding: 12px; }
  .system-state-grid { grid-template-columns: 1fr; }
  .system-state-aside { min-height: auto; gap: 20px; padding: 24px; }
  .system-state-code { font-size: 3.2rem; }
  .system-state-main { padding: 24px; }
  .system-state-meta { grid-template-columns: 1fr; }
  .system-state-actions, .herb-system-dialog__actions { flex-direction: column; }
  .system-state-btn, .herb-system-action { width: 100%; }
  .herb-network-banner { align-items: stretch; flex-direction: column; }
  .herb-network-banner__actions { width: 100%; }
  .herb-network-banner__actions > * { flex: 1 1 0; }
}

@media (prefers-reduced-motion: reduce) {
  .herb-bootstrap-state, .herb-bootstrap-state__spinner { transition: none; animation: none; }
}

@media (forced-colors: active) {
  .herb-bootstrap-state__card,
  .herb-network-banner,
  .herb-system-dialog__panel,
  .system-state-card,
  .system-state-input,
  .system-state-btn { border: 2px solid CanvasText; }
  .system-state-btn:focus-visible, .herb-system-action:focus-visible { outline: 3px solid Highlight; }
}

@media print {
  .herb-bootstrap-state,
  .herb-network-banner,
  .herb-system-dialog,
  .system-state-theme { display: none !important; }
  .system-state-shell { min-height: auto; padding: 0; background: #fff !important; color: #000 !important; }
  .system-state-card { border: 1px solid #777; box-shadow: none; }
  .system-state-aside { background: #fff !important; color: #000 !important; border-bottom: 1px solid #777; }
  .system-state-aside p, .system-state-lead, .system-state-help { color: #222 !important; }
}

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