/* ============================================================
   Reaction ERP — the UI library's own controls (js/components/ui/).
   ------------------------------------------------------------
   Only .ui-* selectors, only tokens from theme.css. Everything a control
   borrows from the app (.pill, .alert, .progress, .tabs, .form-section,
   .tl-item, .pcard-*, .al-pager, .gt-*, .sdd-*, .chip, .form-file-strip)
   is painted by theme.css / layout.css and left alone here, so skin.css
   (which keys on those class names) and responsive.css still apply.

   Two house rules run through every control:
   - the Thai line-box rule (theme.css:181-191): a control states its
     line-height and min-height, so it is the same height in both languages;
   - the z-index scale (theme.css:95-104): anything that floats takes its
     layer from a --z-* token, never a number of its own.
   ============================================================ */

/* ---------- Icons ---------- */
.ui-icon { display: inline-block; vertical-align: -3px; flex: none; }

/* ---------- Avatar ---------- */
.ui-avatar {
  --ui-av: 36px;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: var(--ui-av); height: var(--ui-av); border-radius: 50%;
  color: #fff; font-weight: 700; font-size: calc(var(--ui-av) * .38); letter-spacing: .01em;
  background-size: cover; background-position: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}
.ui-avatar.square { border-radius: calc(var(--ui-av) * .3); }

/* ---------- Alert ---------- */
.ui-alert .alert { position: relative; }
.ui-alert .alert > div { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ui-alert-title { font-weight: 700; }
.ui-alert-x { position: absolute; top: 6px; right: 6px; color: inherit; opacity: .7; }
.ui-alert-x:hover { opacity: 1; }
.ui-alert .alert:has(.ui-alert-x) { padding-right: 40px; }

/* ---------- Spinner ---------- */
.ui-spinner {
  --ui-sp: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--ui-sp); height: var(--ui-sp); flex: none;
}
.ui-spinner.inline { vertical-align: middle; }
.ui-spinner-ring {
  display: block; width: 100%; height: 100%; border-radius: 50%;
  border: calc(var(--ui-sp) / 7) solid color-mix(in srgb, currentColor 18%, transparent);
  border-top-color: currentColor;
  animation: ui-spin .8s linear infinite;
}
.btn .ui-spinner { color: #fff; }
.btn.secondary .ui-spinner, .btn.ghost .ui-spinner { color: var(--c-main); }
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* ---------- Progress & ring ---------- */
.ui-progress { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.ui-progress-head { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; line-height: 16px; }
.ui-progress-label { color: var(--text-dim); font-weight: 600; }
.ui-progress-val { color: var(--heading); font-weight: 700; }
.ui-ring { --ui-ring: 64px; position: relative; display: inline-grid; place-items: center; width: var(--ui-ring); height: var(--ui-ring); }
.ui-ring svg { position: absolute; inset: 0; }
.ui-ring-track { stroke: var(--surface-3); }
.ui-ring-fill { stroke: var(--c-main); transition: stroke-dashoffset .5s cubic-bezier(.25, .8, .3, 1); }
.ui-ring.green .ui-ring-fill { stroke: var(--c-green); }
.ui-ring.orange .ui-ring-fill { stroke: var(--c-orange); }
.ui-ring.red .ui-ring-fill { stroke: var(--c-red); }
.ui-ring-val { position: relative; font-weight: 800; font-size: calc(var(--ui-ring) * .22); color: var(--heading); line-height: 1; }

/* ---------- Switch ---------- */
.ui-switch-row { display: inline-flex; align-items: center; gap: 9px; min-height: 24px; }
.ui-switch {
  position: relative; width: 38px; height: 22px; flex: none; padding: 0;
  border: none; border-radius: 999px; cursor: pointer;
  background: var(--border-strong);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .12);
  transition: background .15s;
}
.ui-switch-knob {
  position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
  transition: transform .15s;
}
.ui-switch.on, .ui-switch[aria-checked="true"] { background: linear-gradient(180deg, var(--c-main), var(--c-main-deep)); }
.ui-switch[aria-checked="true"] .ui-switch-knob { transform: translateX(16px); }
.ui-switch:disabled { opacity: .5; cursor: not-allowed; }
.ui-switch:focus-visible { outline: 2px solid var(--c-main); outline-offset: 2px; }
.ui-switch-label { display: flex; flex-direction: column; font-size: 13px; line-height: 16px; cursor: pointer; }
.ui-switch-hint { font-size: 11.5px; color: var(--text-dim); line-height: 16px; }
.ui-switch-state { font-size: 12px; line-height: 16px; min-width: 2.5em; }

/* ---------- Rating ---------- */
.ui-rating { --ui-star: 20px; display: inline-flex; align-items: center; gap: 2px; }
.ui-star {
  position: relative; display: inline-grid; place-items: center; padding: 0;
  width: calc(var(--ui-star) + 4px); height: calc(var(--ui-star) + 4px);
  border: none; background: none; border-radius: 6px; cursor: pointer; color: var(--star-off);
}
.ui-rating.readonly .ui-star { cursor: default; }
.ui-star .ui-star-off { fill: currentColor; stroke: currentColor; }
.ui-star-fill { position: absolute; left: 2px; top: 2px; height: var(--ui-star); width: 0; overflow: hidden; color: var(--c-accent); }
.ui-star-fill .ui-star-on { fill: currentColor; stroke: currentColor; filter: drop-shadow(0 1px 2px rgba(246, 192, 42, .45)); }
.ui-star:hover, .ui-star:focus-visible { background: rgba(0, 112, 192, .08); }
.ui-star:focus-visible { outline: 2px solid var(--c-main); outline-offset: 1px; }
.ui-rating-tx { margin-left: 6px; font-size: 12px; line-height: 16px; min-width: 2.2em; font-variant-numeric: tabular-nums; }

/* ---------- Divider ---------- */
.ui-divider { display: flex; align-items: center; gap: 12px; margin: 14px 0; color: var(--text-dim); font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.ui-divider::before, .ui-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.ui-divider:empty::after { display: none; }
.ui-divider-tx { line-height: 16px; }
.ui-divider.vertical { flex-direction: column; align-self: stretch; width: 1px; margin: 0 12px; }
.ui-divider.vertical::before, .ui-divider.vertical::after { width: 1px; height: auto; flex: 1; }

/* ---------- Textfield ---------- */
.ui-tf-wrap { position: relative; }
.ui-tf-error { font-size: 11.5px; color: var(--danger-fg); line-height: 16px; }

/* ---------- Tabs ---------- */
.ui-tabs .tabs { margin-bottom: 12px; }
.ui-tab-panel { min-height: 24px; }

/* ---------- Stepper ---------- */
.ui-stepper {
  display: flex; max-width: 100%; list-style: none; margin: 0; padding: 0; gap: 0;
  counter-reset: ui-step; overflow-x: auto; scrollbar-width: none;
}
.ui-stepper::-webkit-scrollbar { display: none; }
.ui-step { position: relative; flex: 1 1 0; min-width: 96px; display: flex; }
.ui-step-btn {
  display: flex; flex-direction: column; align-items: center; gap: 7px; width: 100%;
  padding: 4px 6px; border: none; background: none; font-family: inherit; color: inherit;
  text-align: center; cursor: default; border-radius: 10px;
}
button.ui-step-btn { cursor: pointer; }
button.ui-step-btn:hover { background: rgba(0, 112, 192, .06); }
button.ui-step-btn:focus-visible { outline: 2px solid var(--c-main); outline-offset: 2px; }
.ui-step-disc {
  position: relative; z-index: 1; display: grid; place-items: center; flex: none;
  width: 28px; height: 28px; border-radius: 50%; font-size: 12.5px; font-weight: 700;
  background: var(--surface); color: var(--text-dim);
  box-shadow: inset 0 0 0 1.5px var(--border-strong);
}
.ui-step-disc svg { width: 15px; height: 15px; }
/* the line between discs: drawn from each step to the next, behind the disc */
.ui-step:not(:last-child)::after {
  content: ''; position: absolute; top: 17px; left: calc(50% + 16px); right: calc(-50% + 16px);
  height: 1.5px; background: var(--border-strong);
}
.ui-step.step-done::after { background: var(--c-main); }
.ui-step.step-done .ui-step-disc { background: var(--c-main); color: #fff; box-shadow: none; }
.ui-step.step-now .ui-step-disc {
  color: var(--c-main); background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--c-main), 0 0 0 4px rgba(0, 112, 192, .14);
}
.ui-step-tx { display: flex; flex-direction: column; gap: 1px; font-size: 12px; line-height: 16px; min-width: 0; max-width: 100%; }
.ui-step-tx b { font-weight: 600; color: var(--text-dim); overflow-wrap: anywhere; }
.ui-step.step-now .ui-step-tx b { color: var(--heading); font-weight: 700; }
.ui-step.step-done .ui-step-tx b { color: var(--text); }
.ui-step-sub { font-size: 11px; color: var(--text-dim); }

/* ---------- Timeline ---------- */
.ui-timeline { list-style: none; margin: 0; padding: 0; }

/* ---------- Profile card (inline) ---------- */
.ui-profile {
  display: inline-block; width: 300px; max-width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.ui-profile.compact { width: auto; padding: 10px 12px; }
.ui-profile .pcard-av {
  flex: none; width: 64px; height: 64px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 22px; background-size: cover; background-position: center;
}
.ui-profile .pcard-av.party { background: linear-gradient(135deg, #f59e0b, #ef4444); border-radius: 16px; }
.ui-profile .pcard-av.has-photo { color: transparent; }

/* ---------- Filter bar ---------- */
.ui-filter { display: flex; flex-direction: column; gap: 4px; }
.ui-filter-row { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; }
.ui-filter-facet { display: flex; flex-direction: column; gap: 4px; min-width: 150px; flex: 1 1 150px; max-width: 240px; }
.ui-filter-label { font-size: 12px; font-weight: 600; color: var(--text-dim); line-height: 16px; }
.ui-filter-chips:empty { display: none; }
.ui-filter-chips .chip b { font-weight: 700; }
.ui-filter-chips .chip { line-height: 16px; }
.ui-filter-clear { align-self: center; }

/* ---------- Pagination ---------- */
.ui-pagination-host .tbl-top:empty { display: none; }

/* ---------- Datagrid ---------- */
.ui-datagrid-bar { justify-content: space-between; margin-bottom: 10px; }
.ui-datagrid-search { position: relative; display: flex; align-items: center; flex: 1 1 220px; max-width: 360px; }
.ui-datagrid-search .ui-icon { position: absolute; left: 10px; color: var(--text-dim); pointer-events: none; }
.ui-datagrid-search .input { padding-left: 32px; }
.ui-datagrid-size:empty { display: none; }

/* ---------- Autocomplete ---------- */
.ui-hl { background: rgba(246, 192, 42, .35); color: inherit; border-radius: 3px; padding: 0 1px; }
[data-theme="dark"] .ui-hl { background: rgba(246, 192, 42, .28); }
.sdd-item.hl .ui-hl, .sdd-item:hover .ui-hl { background: rgba(246, 192, 42, .5); }
.ui-ac-wait { font-style: italic; }

/* ---------- File upload ---------- */
.ui-fileupload { display: flex; flex-direction: column; gap: 0; }
.ui-fu-strip:focus-visible { outline: 2px solid var(--c-main); outline-offset: 2px; }
.ui-fu-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.ui-files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ui-files:empty { display: none; }
.ui-file {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.ui-file-thumb {
  width: 44px; height: 44px; flex: none; border-radius: 8px; overflow: hidden;
  display: grid; place-items: center; background: var(--surface-3); color: var(--text-dim);
}
.ui-file-thumb img, .ui-file-thumb .fc-doc-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ui-file-thumb svg { width: 20px; height: 20px; }
.ui-file-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ui-file-name { font-weight: 600; font-size: 13px; line-height: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-file-meta { font-size: 11.5px; line-height: 16px; }
.ui-file-err { color: var(--danger-fg); }
.ui-file .progress { height: 5px; margin-top: 2px; }
.ui-file .progress-fill { display: block; height: 100%; }
.ui-file.failed { border-color: rgba(240, 90, 90, .35); }

/* ---------- Signature pad ---------- */
.ui-sigpad { display: flex; flex-direction: column; gap: 8px; }
.ui-sigpad-paper {
  position: relative; width: 100%; max-width: 560px; height: 180px;
  background: #fff; border: 1.5px dashed var(--border-strong); border-radius: 10px; overflow: hidden;
  /* paper is paper in both themes — the ink must read as it will on the printed page */
  box-shadow: inset 0 0 0 1px rgba(28, 39, 51, .04);
}
.ui-sigpad-canvas { display: block; touch-action: none; cursor: crosshair; }
.ui-sigpad-canvas:focus-visible { outline: 2px solid var(--c-main); outline-offset: -2px; }
.ui-sigpad-line { position: absolute; left: 24px; right: 24px; bottom: 34px; height: 1px; background: #c9d2dd; pointer-events: none; }
.ui-sigpad-hint { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); font-size: 12px; line-height: 16px; color: #8a97a8; pointer-events: none; }
.ui-sigpad-hint[hidden] { display: none; }
.ui-sigpad-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.ui-sigpad-note { margin: -4px 0 10px; font-size: 12.5px; }

/* ---------- Gantt ---------- */
.ui-gantt { display: flex; flex-direction: column; gap: 10px; min-width: 0; max-width: 100%; }
.ui-gantt .sched-scroll { max-width: 100%; }
.ui-gantt-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.ui-gantt .gt-wrap { grid-template-rows: auto auto; }
.ui-gantt .gt-corner span { line-height: 16px; }
.ui-gantt .empty { padding: 30px 10px; }

/* ---------- The demo page (#/ui-kit) ---------- */
.ui-kit { display: flex; flex-direction: column; gap: 14px; }
.ui-kit-bar { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; }
.ui-kit-bar .spacer { flex: 1; }
.ui-kit-nav { display: flex; flex-wrap: wrap; gap: 6px; }
.ui-kit-nav a { font-size: 12px; line-height: 16px; padding: 4px 9px; border-radius: 999px; background: var(--surface-3); color: var(--text); text-decoration: none; }
.ui-kit-nav a:hover { background: var(--surface-3-hover); color: var(--c-main); }
.ui-kit-sec > h2 { scroll-margin-top: 70px; }
.ui-kit-sec .ui-kit-kind { margin-left: auto; }
.ui-kit-import {
  display: block; margin: 0 0 12px; padding: 7px 10px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-family: var(--font-mono); font-size: 12px; line-height: 16px; color: var(--text-dim);
  overflow-x: auto; white-space: pre;
}
.ui-kit-note { font-size: 12.5px; color: var(--text-dim); margin: -4px 0 12px; line-height: 1.5; }
.ui-kit-demo { display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: center; min-width: 0; }
.ui-kit-demo.stack { flex-direction: column; align-items: stretch; }
/* A wrapped COLUMN flex container takes the max-content width of its children
   (the gantt's day scale, four stepper cells), and so overflowed its section on
   a phone while its children's own scrollers never engaged. Stacked demos do
   not wrap, and are never wider than the section. */
.ui-kit-demo.stack { flex-wrap: nowrap; min-width: 0; max-width: 100%; }
.ui-kit-demo.stack > * { min-width: 0; max-width: 100%; }
.ui-kit-demo > .wide { flex: 1 1 100%; min-width: 0; }
.ui-kit-demo .ui-kit-cell { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ui-kit-demo .ui-kit-cell > .muted { font-size: 11.5px; line-height: 16px; }
.ui-kit-icons { display: flex; flex-wrap: wrap; gap: 6px; }
.ui-kit-icon { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); font-size: 11.5px; line-height: 16px; }
.ui-kit-icon code { font-family: var(--font-mono); color: var(--text-dim); }
.ui-kit-out { font-size: 12.5px; line-height: 16px; color: var(--text-dim); min-height: 16px; }
.ui-kit-out b { color: var(--heading); }
@media (max-width: 680px) {
  .ui-kit-demo { gap: 12px; }
  .ui-profile { width: 100%; }
}
