/* WrapServicer v2 — shared portal chrome
 * Mobile-first shell layout layered on top of tailwind.css / brand.css.
 * No @tailwind directives here — this file extends, never duplicates.
 *
 * Token sources:
 *   var(--ws-*)            brand.css custom properties
 *   env(safe-area-inset-*) device safe-area (iOS notch / home indicator)
 *
 * BEM structure:
 *   .app-shell              Root shell viewport wrapper
 *   .app-shell__sidebar     Off-canvas on mobile, fixed rail on desktop
 *   .app-shell__frame       Right column (topbar + scrollable main)
 *   .app-shell__topbar      Sticky header strip
 *   .app-shell__main        Scrollable content area below the topbar
 */

/* ═══════════════════════════════════════════════════════════════════════════
   ROOT SHELL
   ═══════════════════════════════════════════════════════════════════════════ */

.app-shell {
  display: flex;
  flex-direction: column;       /* mobile: stacks vertically */
  height: 100dvh;               /* dynamic viewport height — avoids mobile bar jump */
  overflow: hidden;
  background-color: var(--ws-ink-50, #F8FAFC);
}

/* ═══════════════════════════════════════════════════════════════════════════
   SIDEBAR
   Hidden / off-canvas on mobile; the sidebar component controls its own
   visibility via fixed positioning and JS toggle. This wrapper handles
   the left safe-area inset and collapses to 0 in-flow height on mobile.
   ═══════════════════════════════════════════════════════════════════════════ */

.app-shell__sidebar {
  flex-shrink: 0;
  overflow: hidden;
  /* Left notch / camera-island clearance */
  padding-left: env(safe-area-inset-left, 0px);
}

/* ═══════════════════════════════════════════════════════════════════════════
   FRAME (right column — topbar + scrollable content)
   ═══════════════════════════════════════════════════════════════════════════ */

.app-shell__frame {
  display: flex;
  flex-direction: column;
  flex: 1 1 0%;
  min-width: 0;                 /* prevent flex blowout on long content */
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOPBAR
   Sticky within the frame. Right safe-area inset keeps controls clear of
   camera islands on landscape iPad / notched phones.
   ═══════════════════════════════════════════════════════════════════════════ */

.app-shell__topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  flex-shrink: 0;
  padding-right: env(safe-area-inset-right, 0px);
}

/* ═══════════════════════════════════════════════════════════════════════════
   MAIN (scrollable content region below the topbar)
   ═══════════════════════════════════════════════════════════════════════════ */

.app-shell__main {
  flex: 1 1 0%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* iOS home indicator clearance */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ═══════════════════════════════════════════════════════════════════════════
   FOCUS VISIBLE — shell chrome interactive targets
   ═══════════════════════════════════════════════════════════════════════════ */

.app-shell :focus-visible {
  outline: 2px solid var(--ws-brand-600, #4F46E5);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   DESKTOP — sidebar and frame sit side-by-side
   ═══════════════════════════════════════════════════════════════════════════ */

@media (min-width: 1024px) {
  .app-shell {
    flex-direction: row;        /* sidebar on left, frame on right */
  }

  .app-shell__sidebar {
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .app-shell,
  .app-shell__sidebar,
  .app-shell__frame,
  .app-shell__topbar,
  .app-shell__main {
    transition: none !important;
    animation: none !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   PRINT — hide chrome, reveal content only
   ═══════════════════════════════════════════════════════════════════════════ */

@media print {
  .app-shell {
    display: block;
    height: auto;
    overflow: visible;
  }

  .app-shell__sidebar,
  .app-shell__topbar {
    display: none;
  }

  .app-shell__frame {
    display: block;
  }

  .app-shell__main {
    overflow: visible;
    padding-bottom: 0;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   DEFERRED PAINT — below-the-fold content
   Tells the browser it can skip layout/paint until the element is near the
   viewport. The intrinsic-size hint prevents scroll-jump when content loads.
   ═══════════════════════════════════════════════════════════════════════════ */

.defer-paint {
  content-visibility: auto;
  contain-intrinsic-size: 1px 800px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   FORM PRIMITIVES (chunk 057.1)
   Opt-in BEM-style classes for consistent form rendering across portal,
   admin, and operator UIs. Layered on top of brand.css design tokens.
   All classes are additive — existing forms (ui-form-field*, .field, etc.)
   are untouched.
   ═══════════════════════════════════════════════════════════════════════════ */

/* Vertical field stack: label on top, control below, optional hint/error after */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 1rem;
}

/* Small-caps label above an input */
.form-label {
  font-family: var(--ws-font-sans, var(--font-sans, 'Inter', system-ui, sans-serif));
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ws-ink-600, var(--ink-600, #475569));
  line-height: 1.25;
}

/* Shared control surface (inputs, selects, textareas) */
.form-input,
.form-select,
.form-textarea {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-family: var(--ws-font-sans, var(--font-sans, 'Inter', system-ui, sans-serif));
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--ws-ink-900, var(--ink-900, #0F172A));
  background-color: var(--surface, #FFFFFF);
  border: 1px solid var(--border, var(--ws-ink-200, #E2E8F0));
  border-radius: var(--ws-radius-sm, var(--radius-md, 0.375rem));
  transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
  appearance: none;
  -webkit-appearance: none;
}

.form-textarea {
  min-height: 5.5rem;
  resize: vertical;
  line-height: 1.5;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--ws-ink-400, var(--ink-400, #94A3B8));
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: 2px solid var(--ws-brand-600, var(--brand-600, #4F46E5));
  outline-offset: 2px;
  border-color: var(--ws-brand-600, var(--brand-600, #4F46E5));
}

/* Disabled state */
.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
  background-color: var(--ws-ink-50, #F8FAFC);
  color: var(--ws-ink-400, #94A3B8);
  cursor: not-allowed;
}

/* Inline error message under the field */
.form-error {
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--money-red-500, var(--ws-money-out, #EF4444));
  margin-top: 0.25rem;
}

/* Inline help / hint text under the field */
.form-hint {
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--ws-ink-500, var(--ink-500, #64748B));
  margin-top: 0.25rem;
}

/* Horizontal layout variant: label sits beside the control on >= 640px */
.form-group--inline {
  flex-direction: column;
  align-items: stretch;
}

@media (min-width: 640px) {
  .form-group--inline {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
  }

  .form-group--inline > .form-label {
    flex: 0 0 auto;
    min-width: 8rem;
    margin-bottom: 0;
  }

  .form-group--inline > .form-input,
  .form-group--inline > .form-select,
  .form-group--inline > .form-textarea {
    flex: 1 1 auto;
  }
}

/* Sizing variants */
.form-group--sm .form-input,
.form-group--sm .form-select,
.form-group--sm .form-textarea {
  padding: 0.3125rem 0.5rem;
  font-size: 0.8125rem;
}

.form-group--sm .form-label {
  font-size: 0.6875rem;
}

.form-group--lg .form-input,
.form-group--lg .form-select,
.form-group--lg .form-textarea {
  padding: 0.6875rem 0.875rem;
  font-size: 1rem;
}

.form-group--lg .form-label {
  font-size: 0.8125rem;
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE FORM + CONTAINER FIXES
   Mobile (< 640px): force form controls to full width; inline groups collapse
   to a vertical stack; layout containers get consistent horizontal padding.
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
  .form-group--inline {
    flex-direction: column;
    align-items: stretch;
  }

  .form-group--inline > .form-label {
    margin-bottom: 0.25rem;
    min-width: 0;
  }

  .form-input,
  .form-select,
  .form-textarea {
    width: 100%;
  }

  .container {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}
