/* =============================================================================
   Base — reset, typography, layout shell, Tom Select integration, overlays,
   utility classes. Theme-agnostic: every color here comes from tokens.css.
   ============================================================================= */

/* ── Smooth Theme Transitions ── */
html { transition: background-color 0.3s ease; }
html, body, .shell, .sidebar, .topbar, .content, .stat-card, .widget-card, 
.btn, .form-control, .form-select, .modal-content, .offcanvas, .data-area, 
.page-title-row, .cmd-bar, .page-bar, .tab-bar, .status-bar { 
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease; 
}


/* =============================================================================
   2. MAIN — Reset, Base Typography, Layout Shell
   ============================================================================= */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Scrollbars ──
   Applied to everything rather than opted into per component. The previous
   approach listed each scrollable container by name, which meant any new
   page, any inline overflow:auto and every vendor widget kept the browser
   default - white bars over the dark theme. Colours come from tokens, so
   the light/dark swap is automatic.

   :root also sets color-scheme, which covers the surfaces these rules
   cannot reach: Firefox uses scrollbar-color above, and anything rendered
   by the browser itself (form controls, iframes) follows the scheme. ── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); border-radius: 4px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border: 2px solid var(--scrollbar-track); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }
::-webkit-scrollbar-corner { background: var(--scrollbar-track); }

/* ── Keyboard focus ring (accessibility) ──
   :focus-visible fires only for keyboard navigation, never on mouse
   clicks, so this adds a clear ring for keyboard users without changing
   anything for mouse users. --color-secondary is the same blue in both
   themes, visible on light cards and on the dark surfaces alike. */
:focus-visible {
  outline: 2px solid var(--color-secondary);
  outline-offset: 1px;
}
/* Bootstrap sets its own box-shadow focus styles on inputs - keep the
   ring off elements that already show an obvious focus state. */
.form-control:focus-visible,
.form-select:focus-visible {
  outline: none;
}

html, body { 
  height: 100%; 
  font-family: var(--font-family); 
  font-size: var(--font-size-base); 
  line-height: var(--line-height); 
  color: var(--color-text-primary); 
  overflow: hidden; 
  -webkit-font-smoothing: antialiased; 
}

body { 
  font-size: var(--font-size-base) !important; 
  line-height: var(--line-height) !important; 
}

h1, h2, h3, h4, h5, h6 { 
  margin-top: 0; 
  margin-bottom: 0; 
  font-family: var(--font-family); 
}

/* ── Core Components Reset ── */
.card { border-radius: var(--radius-sm); }
.btn:focus, .btn:focus-visible { box-shadow: var(--focus-ring); outline: none; }
.form-control:focus, .form-select:focus, .ts-wrapper.focus .ts-control {
  border-color: rgba(var(--color-primary-rgb), .55);
  box-shadow: var(--focus-ring);
}
.form-control-sm, .form-select-sm { font-size: var(--font-size-md); }

/* ── Tom Select System Integration (replaces select2) ──
   The vendor tom-select.bootstrap5 css supplies structure; these rules
   pull it onto the app's tokens and density. The original <select>
   carries form-select form-select-sm select2 - Tom Select copies those
   classes onto its .ts-wrapper, so sizing hooks off the wrapper. */
.ts-wrapper.form-select,
.ts-wrapper.form-select.form-select-sm {
  padding: 0;
  border: 0;
  background-image: none;
}
.ts-wrapper .ts-control {
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-sm);
  background-color: var(--color-bg-white);
  color: var(--color-text-primary);
  font-size: var(--font-size-md);
  min-height: 26px;
  padding: 2px var(--space-6);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}
.ts-wrapper .ts-control input {
  color: var(--color-text-primary);
  font-size: inherit;
}
/* Single-select must stay a one-line, fixed-height control: the vendor
   bootstrap5 theme gives the search input a large min-width that wraps
   it onto a second line once an item is selected, ballooning the box.
   With an item present the input only needs to exist for focus/typing -
   collapse it. */
.ts-wrapper.single .ts-control {
  flex-wrap: nowrap;
  align-items: center;
}
.ts-wrapper.single .ts-control > .item {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.ts-wrapper.single.has-items .ts-control > input {
  flex: 0 0 4px;
  min-width: 4px;
  width: 4px;
}
/* Multi-select inside an input-group (command-bar filters): same one-line,
   fixed-height box as a single select - chips sit in a row and clip, the
   search input collapses once something is picked (it still takes focus
   and typing), so the bar never grows a second line over the page.
   ตัวกรองสาเหตุ NCR เลือกหลายรายการ 2026-11-18 */
.input-group > .ts-wrapper.multi .ts-control {
  flex-wrap: nowrap;
  align-items: center;
  overflow: hidden;
  height: 26px;
}
.input-group > .ts-wrapper.multi .ts-control > .item {
  white-space: nowrap;
  flex: 0 0 auto;
  margin: 0 3px 0 0;
  padding: 0 4px;
  line-height: 18px;
  font-size: var(--font-size-sm);
}
.input-group > .ts-wrapper.multi.has-items .ts-control > input {
  flex: 1 0 4px;
  min-width: 4px;
  width: 4px;
}
.input-group > .ts-wrapper.multi.has-items .ts-control > input::placeholder { color: transparent; }
.ts-wrapper .ts-control .clear-button {
  position: static;
  margin-left: auto;
  padding-left: var(--space-3);
  flex-shrink: 0;
}
/* Inside a Bootstrap .input-group (command-bar filters: icon box +
   select) the wrapper must fuse with the icon addon the way the raw
   select would: Bootstrap's corner-trimming rules hit the wrapper (a
   direct child) but the visible border lives on the inner .ts-control,
   so trim/stretch that instead - otherwise the control keeps rounded
   corners against the icon box and its height drifts from the addon's. */
.input-group > .ts-wrapper {
  flex: 1 1 auto;
  width: 1%;
  min-width: 0;
  display: flex;
  align-items: stretch;
}
.input-group > .ts-wrapper .ts-control {
  width: 100%;
  height: 100%;
  min-height: 0;
}
.input-group > .ts-wrapper:not(:first-child) .ts-control {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.input-group > .ts-wrapper:not(:last-child) .ts-control {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.ts-wrapper .ts-control input::placeholder { color: var(--color-text-muted); }
.ts-wrapper.focus .ts-control {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 0.15rem rgba(16, 42, 67, 0.08);
}
.ts-wrapper .clear-button { color: var(--color-text-muted); }
.ts-dropdown {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--elevation-2);
  background: var(--color-bg-white);
  color: var(--color-text-primary);
  font-size: var(--font-size-md);
  z-index: 1065;
}
.ts-dropdown .option { padding: var(--space-3) var(--space-6); }
.ts-dropdown .active {
  background: var(--color-row-hover);
  color: var(--color-text-primary);
}
.ts-dropdown .option.selected { background: var(--color-row-selected); }
.ts-dropdown-content { max-height: 260px; }

/* ── Shell Layout Structure ── */
.shell { display: flex; flex-direction: column; height: 100vh; width: 100vw; }
/* The workspace is a card on a frame (UI_UX_RULES §10.6): 6px of frame
   around it, the sidebar stays flush. */
.body { display: flex; flex: 1; overflow: hidden; background: var(--color-bg-frame); }
.content { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--color-bg-app); margin: 6px; border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--elevation-1); }
#page-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.flex-g1 { flex: 1; }
.min-w-0 { min-width: 0; }

/* ── Color Utility Classes ── */
.text-muted { color: var(--color-text-muted) !important; }
.text-primary { color: var(--color-text-primary) !important; }
.text-secondary { color: var(--color-text-secondary) !important; }
.text-warning { color: var(--color-status-pending-fg) !important; }
.text-danger { color: var(--color-status-inactive-fg) !important; }
.text-sky { color: var(--color-text-sky) !important; }
.text-blue { color: var(--color-text-blue) !important; }

/* ── Light Badge Backgrounds (code/status pills on detail-page summary cards) ── */
.bg-light-primary { background-color: rgba(16, 42, 67, 0.1); }
.bg-success-light { background-color: rgba(25, 135, 84, 0.1); }
.bg-danger-light { background-color: rgba(220, 53, 69, 0.1); }
.bg-info-light { background-color: rgba(13, 202, 240, 0.12); }
.bg-warning-light { background-color: rgba(255, 193, 7, 0.15); }
.bg-secondary-light { background-color: rgba(108, 117, 125, 0.12); }

/* ── Text Alignment ── */
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mono { font-family: var(--font-mono); font-size: var(--font-size-md); }
.hidden { display: none !important; }


/* =============================================================================
   3. OVERLAYS & POPUPS — Modals, Offcanvas, SweetAlert, Toasts
   ============================================================================= */

.offcanvas { font-family: var(--font-family); font-size: var(--font-size-base); }

.modal .modal-content { border-radius: var(--radius-sm); font-family: var(--font-family); font-size: var(--font-size-base); }
.modal .modal-header { font-size: var(--font-size-title); font-weight: 600; padding: var(--space-6); }
.modal .modal-body { padding: var(--space-6); font-size: var(--font-size-lg); }
.modal .modal-footer { padding: var(--space-5) var(--space-6); }

/* ── Wachi UI Custom Alerts / Toasts ── */
.wachi-swal-popup { font-size: 14px; border-radius: .375rem; }
.wachi-swal-title { font-weight: 600; font-size: 1rem; }
.wachi-swal-html { margin-top: .25rem; }

.wachi-toast-popup { 
  font-size: 0.9375rem; 
  border-radius: .375rem; 
  padding: .5rem .75rem; 
  background: var(--bs-body-bg, #ffffff); 
  color: var(--bs-body-color, #212529); 
  box-shadow: 0 .25rem .5rem rgba(0,0,0,.08); 
  border: 1px solid rgba(0,0,0,.06); 
  min-width: 220px; 
  display: flex; 
  align-items: center; 
}
.wachi-toast-title { font-weight: 600; font-size: .95rem; margin: 0; }

/* ── Fullscreen Offcanvas Layout View ── */
.offcanvas.offcanvas-full { 
  width: 100vw; 
  max-width: none; 
  height: 100vh; 
  top: 0; right: 0; left: 0; bottom: 0; 
  visibility: hidden; 
  transform: translateX(100%); 
  transition: transform .3s ease-in-out, visibility .2s; 
  --bs-offcanvas-width: 100vw; 
}
.offcanvas.offcanvas-full.show { visibility: visible; transform: none; }
.offcanvas.offcanvas-full .offcanvas-content { height: 100%; overflow: auto; }


/* =============================================================================
   4. UTILITIES — Elevation, Animation Effects
   ============================================================================= */

.elev-1 { box-shadow: var(--elevation-1); }
.elev-2 { box-shadow: var(--elevation-2); }
.elev-3 { box-shadow: var(--elevation-3); }
.surface-sheen { background-image: var(--surface-sheen); }














/* AgGrid vendor styles live in vendor-aggrid.css; these are the custom select-footer controls */
.ag-select-footer {
  padding: 0.5rem;
  background: var(--color-bg-header);
  border-top: 1px solid var(--color-border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--color-text-muted);
}
.ag-select-clear {
  color: var(--color-primary);
  cursor: pointer;
  text-decoration: none;
}
.ag-select-clear:hover {
  text-decoration: underline;
}
