/* --- SDUI widget design tokens -------------------------------------------
 * pkg/ui_htmx serves the widget stylesheet (assets/nhc-form-widgets.css, the
 * verbatim shared rules for the date/time picker, its calendar grid and the
 * rich text editor) in the NHC design-system token vocabulary. The portal
 * theme speaks --portal-*, so it declares that vocabulary for the widgets
 * here rather than forking the shared stylesheet. Same mapping this file's
 * header documents for the hand-ported rules below, so both halves of the
 * form surface read the same colours.
 * Declared on the widgets (not on :root) so a portal page that also embeds a
 * design-system surface does not have its global tokens shadowed. */
.nhc-form,
.nhc-datetime,
.nhc-calendar,
.nhc-richtext {
  --text-high: var(--portal-text);
  --text-med: var(--portal-muted);
  --text-low: var(--portal-subtle);
  --highlight: var(--portal-accent);
  --ring: var(--portal-accent);
  --border: var(--portal-border);
  --bg-level-1: var(--portal-surface);
  --bg-level-2: var(--portal-surface-alt);
  --bg-level-3: var(--portal-bg-raised, var(--portal-surface-alt));
  --ds-z-popover: 40;
  --ds-z-editor-tools: 45;
  --ds-z-selection: 35;
}

/* Shared portal form controls: pkg/ui_htmx form surfaces and pkg/forms CMS forms. */
.nhc-surface { border: 1px solid var(--portal-border); border-radius: 1rem; background: var(--portal-surface); }
.nhc-surface__header { padding: .875rem 1rem; border-bottom: 1px solid var(--portal-border); font-size: .75rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--portal-muted); }
.nhc-surface__body { padding: 1rem; }

.nhc-form { display: flex; flex-direction: column; gap: .875rem; }
.nhc-form__fields { display: flex; flex-direction: column; gap: .875rem; min-height: 0; }
.nhc-form__field { display: flex; flex-direction: column; gap: .375rem; }
.nhc-form__image { display: flex; flex-direction: column; gap: .5rem; }
.nhc-form__control-row { display: flex; align-items: center; gap: .5rem; }
/* The input yields width and an inline action keeps its full label; on a
   narrow dialog the action wraps below the image link instead of clipping. */
.nhc-form__image .nhc-form__control-row { flex-wrap: wrap; }
.nhc-form__control-row > input { flex: 1 1 10rem; min-width: 0; }
.nhc-form__control-row > .nhc-form__inline-action { flex: 0 0 auto; }
.nhc-form__label { font-size: .675rem; font-weight: 500; letter-spacing: .1em; text-transform: uppercase; color: var(--portal-subtle); }

.nhc-form input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), .nhc-form textarea, .nhc-form select {
  box-sizing: border-box; width: 100%; min-width: 0; border: 1px solid var(--portal-border); border-radius: .75rem;
  background: var(--portal-surface-alt); color: var(--portal-text); padding: .65rem .85rem; font-size: .9rem;
}
.nhc-form textarea { min-height: 7.5rem; resize: vertical; }
.nhc-form label[data-form-field]:not([hidden]) { display: flex; flex-direction: column; gap: .375rem; font-size: .9375rem; }
.nhc-form label:has(> input:is([type="checkbox"], [type="radio"])):not([hidden]) {
  display: grid; grid-template-columns: 1.125rem minmax(0, 1fr); align-items: start; gap: .5rem .625rem;
  line-height: 1.5; cursor: pointer;
}
.nhc-form input:is([type="checkbox"], [type="radio"]) {
  appearance: auto; box-sizing: border-box; flex: 0 0 auto; width: 1.125rem; height: 1.125rem;
  min-width: 0; margin: .15rem 0 0; padding: 0; accent-color: var(--portal-accent);
}
.nhc-form label:has(> input:is([type="checkbox"], [type="radio"])) [data-form-field-error] { grid-column: 2; }
.nhc-form [data-form-field-error] { color: var(--portal-text); font-size: .875rem; font-weight: 600; }
.nhc-form input:focus, .nhc-form textarea:focus, .nhc-form select:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--portal-accent) 45%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--portal-accent) 25%, transparent);
}

.nhc-form__actions { display: flex; gap: .625rem; padding-top: .25rem; }
.nhc-form__actions button, .nhc-form > button[data-submit-action] {
  box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; max-width: 100%; min-height: 44px;
  border-radius: .75rem; border: 1px solid var(--portal-border); padding: .625rem 1rem; font-size: .72rem;
  line-height: 1.15; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; overflow: hidden;
  text-align: center; text-overflow: ellipsis; white-space: nowrap;
}
.nhc-form__actions button[type="submit"], .nhc-form > button[data-submit-action="primary"] { background: var(--portal-accent); color: var(--portal-accent-ink); border-color: transparent; cursor: pointer; }
.nhc-form > button[data-submit-action] { align-self: flex-start; padding: .75rem 1.5rem; font-size: .9375rem; letter-spacing: 0; text-transform: none; white-space: normal; }
.nhc-form > button[data-submit-action]:disabled { opacity: .65; cursor: wait; }
.nhc-form__actions button[type="button"] { background: transparent; color: var(--portal-muted); }

.nhc-form__inline-action {
  box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; max-width: 100%;
  min-height: 2.45rem; border-radius: .75rem; border: 1px solid var(--portal-border); padding: .65rem .9rem;
  font-size: .67rem; line-height: 1.15; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  overflow: hidden; text-align: center; text-overflow: ellipsis; white-space: nowrap;
  background: color-mix(in srgb, var(--portal-bg-raised, var(--portal-surface-alt)) 85%, transparent);
  color: var(--portal-text);
}
.nhc-form__clear {
  width: 2.2rem; min-width: 2.2rem; height: 2.2rem; border-radius: .75rem; border: 1px solid var(--portal-border);
  background: color-mix(in srgb, var(--portal-bg-raised, var(--portal-surface-alt)) 80%, transparent);
  color: var(--portal-muted); display: inline-flex; align-items: center; justify-content: center; font-size: 1rem; line-height: 1;
}
.nhc-form__clear:hover, .nhc-form__inline-action:hover {
  border-color: color-mix(in srgb, var(--portal-accent) 45%, var(--portal-border));
  color: var(--portal-text);
}

.nhc-source-panel { display: flex; flex-direction: column; gap: .45rem; }
.nhc-source-panel__controls { align-items: stretch; }
.nhc-source-panel__action { flex: 0 0 auto; width: min(100%, 14.75rem); min-width: 13.5rem; padding-inline: 1.1rem; }
.nhc-source-panel__status {
  display: none; align-items: center; gap: .45rem; min-height: 1.15rem; font-size: .72rem; font-weight: 700;
  letter-spacing: .02em; color: var(--portal-muted);
}
.nhc-source-panel__status[data-state="fresh"] { color: color-mix(in srgb, var(--portal-accent) 75%, white); }
.nhc-source-panel__status[data-state="stale"] { color: #facc15; }
.nhc-source-panel__status[data-state="error"] { color: #fca5a5; }
.nhc-source-panel__status[data-state="loading"]::before {
  content: ""; width: .9rem; height: .9rem; border-radius: 999px;
  border: 2px solid color-mix(in srgb, var(--portal-subtle) 50%, transparent);
  border-top-color: var(--portal-accent); animation: nhc-source-spin .8s linear infinite;
}
@keyframes nhc-source-spin { to { transform: rotate(360deg); } }

/* Country/category grid-select widget. Ported for legacy-CSS-range
 * completeness; no current NHC markup emits these classes (see file
 * header note). Kept dormant, not wired to a fake selector. */
.nhc-grid-select { position: relative; }
.nhc-grid-select__trigger {
  width: 100%; min-height: 2.45rem; border: 1px solid var(--portal-border); border-radius: .75rem;
  background: var(--portal-surface-alt); color: var(--portal-text); padding: .6rem .8rem; text-align: left; font-size: .9rem;
}
.nhc-grid-select__panel {
  position: relative; z-index: 20; margin-top: .45rem; border: 1px solid var(--portal-border); border-radius: .75rem;
  background: var(--portal-surface); padding: .5rem;
}
.nhc-grid-select__search {
  width: 100%; border: 1px solid var(--portal-border); border-radius: .6rem; background: var(--portal-surface-alt);
  color: var(--portal-text); padding: .45rem .65rem; margin-bottom: .45rem; font-size: .82rem;
}
.nhc-grid-select__list { max-height: 14rem; overflow: auto; border: 1px solid color-mix(in srgb, var(--portal-border) 65%, transparent); border-radius: .6rem; }
.nhc-grid-select__row {
  width: 100%; display: flex; align-items: center; justify-content: flex-start; background: transparent;
  color: var(--portal-text); border: 0; border-bottom: 1px solid color-mix(in srgb, var(--portal-border) 55%, transparent);
  padding: .45rem .6rem; font-size: .82rem; text-align: left;
}
.nhc-grid-select__row:last-child { border-bottom: 0; }
.nhc-grid-select__row:hover { background: color-mix(in srgb, var(--portal-accent) 16%, transparent); }

@media (max-width: 640px) {
  .nhc-source-panel__controls { flex-direction: column; align-items: stretch; }
  .nhc-source-panel__action { width: 100%; min-width: 0; }
}
