/**
 * THEO shared UI components.
 * Requirement baseline: COM-01, COM-02, COM-05, COM-06, COM-08, COM-12,
 * COM-18, COM-19, COM-20, COM-22, COM-24.
 */

:root {
  --color-surface: #f6f6f6;
  --color-success: #287a4d;
  --color-success-bg: #edf7f1;
  --color-warning: #9b6a0a;
  --color-warning-bg: #fff8e8;
  --color-caution: #a84a16;
  --color-caution-bg: #fff2ea;
  --color-danger: #b42318;
  --color-danger-bg: #fff0ef;
  --color-focus: #111111;
  --shadow-low: 0 12px 36px rgba(17, 17, 17, .08);
  --shadow-high: 0 28px 80px rgba(17, 17, 17, .2);
  --control-height: 52px;
  --touch-target: 44px;
  --type-caption: 14px;
  --type-small: 14px;
  --type-ui: 16px;
  --type-body: 16px;
  --type-h3: clamp(20px, 1.7vw, 22px);
  --type-h2: clamp(32px, 2.5vw, 40px);
  --type-h1: clamp(40px, 4vw, 56px);
}

body.modal-open { overflow: hidden; }

body:not(.home) .site-header {
  color: var(--color-ink);
  background: #fff;
  box-shadow: 0 10px 32px rgba(17, 17, 17, .06);
}
body:not(.home) .site-header::after,
body:not(.home) .utility-bar { border-color: rgba(17, 17, 17, .1); }
body:not(.home) .site-header::after { background: rgba(17, 17, 17, .1); }
body:not(.home) .utility-bar__note { color: var(--color-neutral); }
body:not(.home) .utility-nav__icon [data-theo-header-cart-count] {
  border-color: var(--color-ink);
  color: var(--color-white);
  background: var(--color-ink);
}
body:not(.home) .utility-nav a:hover,
body:not(.home) .utility-nav button:hover { background: rgba(17, 17, 17, .05); }

@media (max-width: 980px) {
  body:not(.home).menu-open .site-header {
    color: var(--color-ink);
    background: var(--color-white);
    box-shadow: none;
  }
  body:not(.home).menu-open .site-header::after { background: var(--color-line); }
}

.button--primary {
  color: var(--color-white);
  background: var(--color-deep);
}
.button--primary:hover { background: var(--color-deep-2); }
.button--secondary {
  border-color: var(--color-deep);
  color: var(--color-deep);
  background: transparent;
}
.button--secondary:hover { color: var(--color-white); background: var(--color-deep); }
.button--danger {
  border-color: var(--color-danger);
  color: var(--color-danger-text, #9a2424);
  background: transparent;
}
.button--danger:hover { color: var(--color-white); background: var(--color-danger); }
.button:disabled,
.button[aria-disabled="true"] {
  border-color: var(--color-line);
  color: #8b8b8b;
  background: #f6f6f6;
  cursor: not-allowed;
  transform: none;
}
.button.is-loading { position: relative; color: transparent; pointer-events: none; }
.button.is-loading::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  color: var(--color-white);
  animation: theo-spin .7s linear infinite;
}
@keyframes theo-spin { to { transform: rotate(360deg); } }

.theo-page-hero {
  padding: calc(var(--header-height) + var(--space-10)) 0 var(--space-8);
  border-bottom: 1px solid var(--color-line);
  background: var(--color-warm);
}
.theo-page-hero .eyebrow { margin-bottom: var(--space-2); }
.theo-page-hero h1 {
  max-width: 18ch;
  margin-bottom: var(--space-3);
  font-size: var(--type-h1);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -.035em;
}
.theo-page-hero p:last-child { max-width: 66ch; margin-bottom: 0; color: var(--color-neutral); }

.theo-ui-section { padding: var(--space-10) 0; border-bottom: 1px solid var(--color-line); }
.theo-ui-section:nth-child(even) { background: var(--color-warm); }
.theo-ui-heading { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 480px); gap: var(--space-6); align-items: end; margin-bottom: var(--space-6); }
.theo-ui-heading h2 { margin: 0; font-size: var(--type-h2); line-height: 1.3; }
.theo-ui-heading p { margin: 0; color: var(--color-neutral); }
.theo-ui-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3); }
.theo-ui-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.theo-ui-stack { display: grid; gap: var(--space-3); }
.theo-ui-inline { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.theo-ui-label { margin: 0 0 var(--space-2); color: var(--color-deep); font-size: var(--type-caption); font-weight: 600; letter-spacing: .12em; text-transform: uppercase; }

.theo-swatch {
  min-height: 168px;
  padding: var(--space-3);
  border: 1px solid var(--color-line);
  background: var(--swatch, var(--color-white));
}
.theo-swatch--dark { color: var(--color-white); border-color: transparent; }
.theo-swatch strong, .theo-swatch span { display: block; }
.theo-swatch span { margin-top: var(--space-6); font-size: var(--type-small); }

.theo-card {
  min-width: 0;
  padding: var(--space-4);
  border: 1px solid var(--color-line);
  background: var(--color-white);
}
.theo-card h3 { margin-bottom: var(--space-2); font-size: var(--type-h3); line-height: 1.4; }
.theo-card p { margin-bottom: 0; color: var(--color-neutral); }
.theo-card--interactive { transition: border-color var(--motion), box-shadow var(--motion), transform var(--motion); }
.theo-card--interactive:hover,
.theo-card--interactive:focus-within { border-color: var(--color-deep); box-shadow: var(--shadow-low); transform: translateY(-3px); }

.theo-field { display: grid; gap: 7px; }
.theo-field > label,
.theo-field > legend { color: var(--color-ink); font-size: var(--type-small); font-weight: 600; }
.theo-field input:not([type="checkbox"]):not([type="radio"]),
.theo-field select,
.theo-field textarea {
  width: 100%;
  min-height: var(--control-height);
  padding: 12px 14px;
  border: 1px solid #a3a3a3;
  border-radius: 0;
  color: var(--color-ink);
  background: var(--color-white);
  outline: 0;
  transition: border-color var(--motion), box-shadow var(--motion), background var(--motion);
}
.theo-field select:not([multiple]) {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 52px;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right var(--select-arrow-inset) center;
  background-size: var(--select-arrow-size) var(--select-arrow-size);
}
.theo-field textarea { min-height: 132px; resize: vertical; }
.theo-field input:focus,
.theo-field select:focus,
.theo-field textarea:focus { border-color: var(--color-focus); box-shadow: 0 0 0 3px rgba(17, 17, 17, .18); }
.theo-field input:disabled,
.theo-field select:disabled,
.theo-field textarea:disabled { color: #777; background: #f6f6f6; cursor: not-allowed; }
.theo-field__help,
.theo-field__error { margin: 0; font-size: var(--type-caption); line-height: 1.5; }
.theo-field__help { color: var(--color-neutral); }
.theo-field__error { color: var(--color-danger-text, #9a2424); font-weight: 600; }
.theo-field.is-error input,
.theo-field.is-error select,
.theo-field.is-error textarea { border-color: var(--color-danger); }

.theo-check {
  display: flex;
  min-height: var(--touch-target);
  align-items: flex-start;
  gap: 10px;
  color: var(--color-ink);
  cursor: pointer;
  font-size: var(--type-ui);
}
.theo-check input {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  margin: 2px 0 0;
  accent-color: var(--color-deep);
}
.theo-check small { display: block; margin-top: 3px; color: var(--color-neutral); font-size: var(--type-caption); }

.theo-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 4px 9px;
  border: 1px solid currentColor;
  color: var(--color-deep);
  background: var(--color-white);
  font-size: var(--type-caption);
  font-weight: 600;
  line-height: 1;
}
.theo-badge--success { color: var(--color-success); background: var(--color-success-bg); }
.theo-badge--warning { color: var(--color-warning-text, #775600); background: var(--color-warning-bg); }
.theo-badge--caution { color: var(--color-caution); background: var(--color-caution-bg); }
.theo-badge--danger { color: var(--color-danger-text, #9a2424); background: var(--color-danger-bg); }
.theo-badge--neutral { color: var(--color-neutral); background: #f6f6f6; }

.theo-alert {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  padding: var(--space-3);
  border: 1px solid var(--color-line);
  border-left: 4px solid var(--color-deep);
  background: var(--color-white);
}
.theo-alert::before { content: "i"; display: grid; width: 24px; height: 24px; place-items: center; border: 1px solid currentColor; border-radius: 50%; font-size: 14px; font-weight: 600; }
.theo-alert strong { display: block; margin-bottom: 4px; }
.theo-alert p { margin: 0; color: var(--color-neutral); font-size: var(--type-small); }
.theo-alert--success { border-left-color: var(--color-success); color: var(--color-success); background: var(--color-success-bg); }
.theo-alert--warning { border-left-color: var(--color-warning); color: var(--color-warning-text, #775600); background: var(--color-warning-bg); }
.theo-alert--danger { border-left-color: var(--color-danger); color: var(--color-danger-text, #9a2424); background: var(--color-danger-bg); }
.theo-alert--success p,
.theo-alert--warning p,
.theo-alert--danger p { color: var(--color-ink); }

.theo-progress { display: grid; gap: 8px; }
.theo-progress__meta { display: flex; justify-content: space-between; gap: var(--space-2); font-size: var(--type-small); }
.theo-progress__track { height: 8px; overflow: hidden; background: var(--color-line); }
.theo-progress__bar { width: var(--progress, 0%); height: 100%; background: var(--color-deep); transition: width var(--motion); }

.theo-skeleton { position: relative; overflow: hidden; min-height: 18px; background: #ebebeb; }
.theo-skeleton::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .68), transparent); transform: translateX(-100%); animation: theo-skeleton 1.4s infinite; }
.theo-skeleton--media { min-height: 220px; }
@keyframes theo-skeleton { to { transform: translateX(100%); } }

.theo-accordion { border-top: 1px solid var(--color-line); }
.theo-accordion details { border-bottom: 1px solid var(--color-line); }
.theo-accordion summary { display: flex; min-height: 72px; align-items: center; justify-content: space-between; gap: var(--space-3); cursor: pointer; list-style: none; font-size: 17px; font-weight: 600; }
.theo-accordion summary::-webkit-details-marker { display: none; }
.theo-accordion summary::after { content: "+"; color: var(--color-deep); font-size: 24px; font-weight: 400; transition: transform var(--motion); }
.theo-accordion details[open] summary::after { transform: rotate(45deg); }
.theo-accordion__body { max-width: 68ch; padding: 0 var(--space-6) var(--space-3) 0; color: var(--color-neutral); }
.theo-accordion__body p:last-child { margin-bottom: 0; }

.theo-modal[hidden] { display: none; }
.theo-modal { position: fixed; z-index: 400; inset: 0; display: grid; place-items: center; padding: var(--space-3); }
.theo-modal__backdrop { position: absolute; inset: 0; background: rgba(8, 13, 18, .72); backdrop-filter: blur(4px); }
.theo-modal__dialog,
.theo-modal__panel { position: relative; z-index: 1; width: min(100%, 620px); max-height: min(760px, calc(100svh - 48px)); overflow-y: auto; padding: var(--space-4); background: var(--color-white); box-shadow: var(--shadow-high); }
.theo-modal__header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.theo-modal__header h2 { margin: 0; font-size: 24px; line-height: 1.35; }
.theo-modal__close { display: grid; width: var(--touch-target); height: var(--touch-target); flex: 0 0 auto; place-items: center; margin: -8px -8px 0 0; border: 0; background: transparent; cursor: pointer; font-size: 26px; }
.theo-modal__body { color: var(--color-neutral); }
.theo-modal__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; margin-top: var(--space-4); }

.theo-exception {
  display: grid;
  min-height: 320px;
  place-items: center;
  padding: var(--space-6);
  border: 1px solid var(--color-line);
  background: var(--color-warm);
  text-align: center;
}
.theo-exception > div { max-width: 580px; }
.theo-exception__code { display: block; margin-bottom: var(--space-2); color: var(--color-deep); font-size: var(--type-caption); font-weight: 600; letter-spacing: .16em; }
.theo-exception h3 { margin-bottom: var(--space-2); font-size: 24px; }
.theo-exception p { color: var(--color-neutral); }

@media (max-width: 980px) {
  .theo-ui-heading { grid-template-columns: 1fr; gap: var(--space-2); }
  .theo-ui-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .theo-page-hero { padding: calc(var(--header-height) + var(--space-8)) 0 var(--space-6); }
  .theo-ui-section { padding: var(--space-8) 0; }
  .theo-ui-grid,
  .theo-ui-grid--2 { grid-template-columns: 1fr; }
  .theo-card { padding: var(--space-3); }
  .theo-ui-inline { align-items: stretch; flex-direction: column; }
  .theo-ui-inline .button { width: 100%; }
  .theo-alert { padding: var(--space-2); }
  .theo-accordion__body { padding-right: 0; }
  .theo-modal { padding: var(--space-2); }
  .theo-modal__dialog { max-height: calc(100svh - 32px); padding: var(--space-3); }
  .theo-modal__actions { align-items: stretch; flex-direction: column-reverse; }
  .theo-modal__actions .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .theo-skeleton::after { animation: none; }
  .button.is-loading::after { animation-duration: 1.4s; }
}
.theo-journal-filters { display:flex; gap:12px; flex-wrap:wrap; margin:0 0 32px; }
.theo-journal-filters a[aria-current="page"] { background:#111111; color:white; border-color:#111111; }
.theo-password-reset { width:min(100%, 560px); margin:48px auto; padding:32px; border:1px solid #dedede; background:#fff; }
.theo-password-reset h1 { font-size:clamp(24px, 3vw, 32px); margin:8px 0 20px; }
.theo-password-reset form { display:grid; gap:24px; margin:28px 0; }
.theo-password-reset .field { display:grid; gap:8px; }
.theo-password-reset input[type="text"] { min-height:48px; width:100%; padding:12px 16px; }
@media(max-width:600px) { .theo-password-reset { padding:24px 16px; margin:24px auto; } body:has(input:focus, textarea:focus, select:focus) .site-actions { visibility:hidden; pointer-events:none; } }
.utility-nav a,.utility-nav button,.theo-order-support nav a,.theo-information-links a,.theo-journal-filters a { min-height:44px; display:inline-flex; align-items:center; }
.footer-grid nav a,.footer-grid nav button,.footer-bottom a { min-height:44px; display:flex; align-items:center; }
