/* ==========================================================================
   Vergari UI — first-party component layer (Phase B of the owned-UI plan).

   The native elements that replaced the third-party web components are
   styled here: .btn (buttons/links), .badge, .callout, .divider, .dlg and
   .drawer (native <dialog>), [data-tip] tooltips, and .container-page.
   Form fields reuse the storefront .field system in custom.css.

   Loaded between tw.css and custom.css, so page-specific rules in custom.css
   keep the last word. All values are our own; the tone palette derives from
   the hand-authored brand ramps this project already used as theme overrides.
   ========================================================================== */

:root {
  /* Semantic tones (light theme) */
  --tone-brand:   #957328;
  --tone-neutral: #4f5550;
  --tone-success: #416130;
  --tone-warning: #874d00;
  --tone-danger:  #a72528;
  --tone-ink:     #ffffff;      /* text on a solid tone fill */

  --ui-radius:      0.55rem;
  --ui-radius-card: 0.9rem;
  --ui-font: 'Inter', sans-serif;

  /* First-party font tokens (replace the old vendor font variables) */
  --font-body:     'Inter', sans-serif;
  --font-longform: 'Aleo', serif;
  --font-code:     'Geist Mono', monospace;

  /* Soft borders derived from the tones (used by inline panel borders) */
  --tone-brand-border:   color-mix(in srgb, var(--tone-brand) 45%, transparent);
  --tone-success-border: color-mix(in srgb, var(--tone-success) 45%, transparent);
  --tone-warning-border: color-mix(in srgb, var(--tone-warning) 45%, transparent);
  --tone-danger-border:  color-mix(in srgb, var(--tone-danger) 45%, transparent);
}

html.theme-dark {
  --tone-brand:   #ceaa62;
  --tone-neutral: #a4aba6;
  --tone-success: #93b782;
  --tone-warning: #e6a149;
  --tone-danger:  #ef6a63;
  --tone-ink:     #14170f;
}

/* --------------------------------------------------------------------------
   Page container (replaces the old vendor container utility)
   -------------------------------------------------------------------------- */
.container-page {
  width: 100%;
  max-width: 85rem;
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2rem);
}

/* --------------------------------------------------------------------------
   Buttons — markup: class="btn btn-solid|btn-outline|btn-ghost|btn-soft
   [btn-brand|btn-success|btn-warning|btn-danger] [btn-sm|btn-lg]"
   Tone defaults to neutral; appearance defaults need an explicit class.
   -------------------------------------------------------------------------- */
.btn {
  --tone: var(--tone-neutral);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  font-family: var(--ui-font);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
  padding: 0.55em 1.15em;
  border: 1px solid transparent;
  border-radius: var(--ui-radius);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease,
              border-color 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--brand-gold, #cfa13f) 75%, transparent);
  outline-offset: 2px;
}

.btn-brand   { --tone: var(--tone-brand); }
.btn-success { --tone: var(--tone-success); }
.btn-warning { --tone: var(--tone-warning); }
.btn-danger  { --tone: var(--tone-danger); }
/* legacy hook kept from the WA era: recolors any button it sits on */
.action-danger { --tone: var(--tone-danger); }

.btn-solid { background: var(--tone); color: var(--tone-ink); }
.btn-solid:hover { background: color-mix(in srgb, var(--tone) 86%, var(--tone-ink)); }

.btn-outline {
  background: transparent;
  color: var(--tone);
  border-color: color-mix(in srgb, var(--tone) 55%, transparent);
}
.btn-outline:hover { background: color-mix(in srgb, var(--tone) 12%, transparent); }

.btn-ghost { background: transparent; color: var(--tone); }
.btn-ghost:hover { background: color-mix(in srgb, var(--tone) 10%, transparent); }

.btn-soft {
  background: color-mix(in srgb, var(--tone) 14%, transparent);
  color: var(--tone);
}
.btn-soft:hover { background: color-mix(in srgb, var(--tone) 22%, transparent); }

/* Bare icon button (the old variant="text"): inherits the surrounding color */
.btn-text {
  background: none; border: none; padding: 0;
  color: inherit; cursor: pointer; font: inherit;
}
.btn-text:hover { opacity: 0.75; }

.btn-sm { font-size: 0.78rem; padding: 0.42em 0.85em; }
.btn-lg { font-size: 1.02rem; padding: 0.7em 1.5em; letter-spacing: 0.04em; }

/* --------------------------------------------------------------------------
   Badges — outlined pill, the shape the order-status labels always had.
   Tone classes are emitted from Python (shop/order_flow.py status metas).
   -------------------------------------------------------------------------- */
.badge {
  --tone: var(--tone-neutral);
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  font-family: var(--ui-font);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1;
  padding: 0.38em 0.75em;
  border-radius: 999px;
  color: var(--tone);
  border: 1px solid color-mix(in srgb, var(--tone) 50%, transparent);
  background: color-mix(in srgb, var(--tone) 9%, transparent);
  white-space: nowrap;
}
.badge .vi { width: 1.1em; height: 1.1em; vertical-align: -0.15em; }
.badge-brand   { --tone: var(--tone-brand); }
.badge-neutral { --tone: var(--tone-neutral); }
.badge-success { --tone: var(--tone-success); }
.badge-warning { --tone: var(--tone-warning); }
.badge-danger  { --tone: var(--tone-danger); }

/* --------------------------------------------------------------------------
   Callouts — tinted note boxes (form errors, hints, empty states)
   -------------------------------------------------------------------------- */
.callout {
  --tone: var(--tone-neutral);
  display: flex;
  align-items: flex-start;
  gap: 0.65em;
  padding: 0.9rem 1.1rem;
  border-radius: var(--ui-radius);
  border-inline-start: 3px solid var(--tone);
  background: color-mix(in srgb, var(--tone) 9%, transparent);
  color: var(--theme-text-primary, inherit);
  font-size: 0.92rem;
  line-height: 1.45;
}
.callout > .vi:first-child { color: var(--tone); flex: none; margin-top: 0.14em; }
.callout--sm { padding: 0.6rem 0.85rem; font-size: 0.85rem; }
.callout-brand   { --tone: var(--tone-brand); }
.callout-neutral { --tone: var(--tone-neutral); }
.callout-success { --tone: var(--tone-success); }
.callout-warning { --tone: var(--tone-warning); }
.callout-danger  { --tone: var(--tone-danger); }

/* --------------------------------------------------------------------------
   Divider
   -------------------------------------------------------------------------- */
hr.divider {
  border: 0;
  border-top: 1px solid var(--theme-border-subtle, color-mix(in srgb, currentColor 15%, transparent));
  margin: 0.75rem 0;
}

/* --------------------------------------------------------------------------
   Dialogs — native <dialog>, opened via [data-dialog-open] (core/js/dialogs.js)
   -------------------------------------------------------------------------- */
dialog.dlg {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(34rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 4rem);
  margin: auto;
  overflow: visible;
}
dialog.dlg::backdrop {
  background: rgb(10 12 10 / 0.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.dlg__card {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 4rem);
  background: var(--theme-bg, #fff);
  color: var(--theme-text-primary, inherit);
  border: 1px solid var(--theme-border-subtle, transparent);
  border-radius: var(--ui-radius-card);
  box-shadow: 0 24px 60px -18px rgb(0 0 0 / 0.45);
}
.dlg__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.3rem 0.4rem;
}
.dlg__title {
  margin: 0;
  font-family: var(--ui-font);
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}
.dlg__x {
  background: none; border: none; padding: 0.3rem; margin: -0.3rem;
  color: var(--theme-text-muted, inherit); cursor: pointer;
  border-radius: 0.4rem; line-height: 0; flex: none;
}
.dlg__x:hover { color: var(--theme-text-primary, inherit); }
.dlg__body { padding: 0.6rem 1.3rem 1.2rem; overflow-y: auto; }
.dlg__body > :first-child { margin-top: 0; }
.dlg__foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 0 1.3rem 1.2rem;
}
/* Forms placed directly inside the body keep the footer buttons aligned */
.dlg__body .dlg__foot { padding: 0.9rem 0 0; }

dialog.dlg[open] { animation: dlg-in 0.18s ease-out; }
dialog.dlg[open]::backdrop { animation: dlg-fade 0.18s ease-out; }
@keyframes dlg-in   { from { opacity: 0; transform: translateY(8px) scale(0.985); } }
@keyframes dlg-fade { from { opacity: 0; } }

/* Lock page scroll while any modal is up */
body:has(dialog[open]) { overflow: hidden; }

/* --------------------------------------------------------------------------
   Drawer — the mobile nav, as an edge-docked <dialog>
   -------------------------------------------------------------------------- */
dialog.drawer {
  border: 0;
  padding: 0;
  margin: 0 0 0 auto;              /* dock to the inline end */
  width: min(300px, 85vw);
  height: 100dvh;
  max-height: 100dvh;
  background: var(--theme-bg, #fff);
  color: var(--theme-text-primary, inherit);
  border-left: 1px solid var(--theme-border-subtle, transparent);
  box-shadow: -18px 0 48px -20px rgb(0 0 0 / 0.5);
  overflow-y: auto;
}
dialog.drawer::backdrop {
  background: rgb(10 12 10 / 0.45);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
dialog.drawer[open] { animation: drawer-in 0.22s ease-out; }
@keyframes drawer-in { from { transform: translateX(100%); } }
.drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0.25rem 1.25rem;
}
.drawer__title {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--theme-text-muted, inherit);
}

@media (prefers-reduced-motion: reduce) {
  dialog.dlg[open], dialog.dlg[open]::backdrop, dialog.drawer[open] { animation: none; }
}

/* --------------------------------------------------------------------------
   Tooltips — [data-tip] content is shown in a floating .tip-bubble appended
   to <body> by dialogs.js. A pure-CSS ::after can't escape ancestors with
   overflow (the rounded order/product tables clip it); the fixed-position
   bubble always can.
   -------------------------------------------------------------------------- */
.tip-bubble {
  position: fixed;
  z-index: 200;
  max-width: 16rem;
  padding: 0.4rem 0.6rem;
  border-radius: 0.45rem;
  background: var(--theme-text-primary, #1c211d);
  color: var(--theme-bg, #fff);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.tip-bubble.is-on { opacity: 1; transform: translateY(0); }

/* --------------------------------------------------------------------------
   Native form controls — checkbox/radio tick color (the old WA
   form-control-activated-color), and textarea/select in .field blocks
   -------------------------------------------------------------------------- */
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand-gold, #cfa13f); }

.field textarea,
.field select {
  font: inherit;
  color: var(--theme-text-primary, inherit);
  background: var(--theme-surface-sunken, transparent);
  border: 1px solid var(--theme-border-subtle, currentColor);
  border-radius: var(--ui-radius);
  padding: 0.55rem 0.75rem;
}
.field textarea:focus,
.field select:focus { outline: none; border-color: var(--brand-gold, #cfa13f); }

/* Input with a leading icon (e.g. the manage-console search box) */
.input-icon { position: relative; display: flex; align-items: center; }
.input-icon > .vi {
  position: absolute; left: 0.65rem;
  color: var(--theme-text-muted, currentColor);
  pointer-events: none;
}
.input-icon > input {
  width: 100%;
  padding: 0.45rem 0.75rem 0.45rem 2.2rem;
  font: inherit; font-size: 0.85rem;
  color: var(--theme-text-primary, inherit);
  background: var(--theme-surface-sunken, transparent);
  border: 1px solid var(--theme-border-subtle, currentColor);
  border-radius: var(--ui-radius);
}
.input-icon > input:focus { outline: none; border-color: var(--brand-gold, #cfa13f); }
