@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@400;500;600;700&family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap");

/* Factorium components — every value comes from tokens.css */
body { margin: 0; font-family: var(--font-sans); font-size: 16px; line-height: 26px; background: var(--surface); color: var(--ink); -webkit-font-smoothing: antialiased; }
.fx-mono { font-family: var(--font-mono); font-size: 14px; font-weight: 500; letter-spacing: 0; }
.fx-muted { color: var(--ink-muted); }
.fx-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.fx-icon { flex: none; display: inline-block; vertical-align: middle; }
:where(.fx-btn, .fx-input, .fx-check-input, .fx-tab, .fx-side-item, .fx-alert-close):focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* preview helpers */
.fx-row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; padding: var(--space-4); }
.fx-stack { display: grid; gap: var(--space-4); padding: var(--space-4); }
.fx-grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--space-4); padding: var(--space-4); }

/* Button */
.fx-btn { font: inherit; font-size: 15px; line-height: 24px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); height: 38px; padding: 0 var(--space-4); border-radius: var(--radius-md); border: 1px solid var(--line-strong); background: var(--surface-raised); color: var(--ink); cursor: pointer; white-space: nowrap; transition: background-color .12s ease, border-color .12s ease; }
.fx-btn:hover { background: var(--surface-sunken); }
.fx-btn-sm { height: 30px; padding: 0 var(--space-3); font-size: 14px; }
.fx-btn-block { width: 100%; }
.fx-btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.fx-btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.fx-btn-danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.fx-btn-danger:hover { filter: brightness(0.92); background: var(--danger); }
.fx-btn-ghost { background: transparent; border-color: transparent; color: var(--brand); }
.fx-btn-ghost:hover { background: var(--brand-soft); }
.fx-btn:disabled { cursor: not-allowed; background: var(--surface-sunken); border-color: var(--line); color: var(--ink-disabled); filter: none; }
.fx-btn-ghost:disabled { background: transparent; border-color: transparent; }
.fx-spinner { width: 14px; height: 14px; border-radius: var(--radius-pill); border: 2px solid currentColor; border-right-color: transparent; animation: fx-spin .7s linear infinite; }
@keyframes fx-spin { to { transform: rotate(360deg); } }

/* Fields */
.fx-field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.fx-label { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--ink); }
.fx-req { color: var(--danger); }
.fx-input { font: inherit; font-size: 16px; line-height: 26px; width: 100%; box-sizing: border-box; height: 40px; padding: 0 var(--space-3); border-radius: var(--radius-md); border: 1px solid var(--line-strong); background: var(--surface-raised); color: var(--ink); }
.fx-input::placeholder { color: var(--ink-muted); }
.fx-input:hover { border-color: var(--ink-muted); }
.fx-input:focus-visible { outline-offset: 0; border-color: var(--focus); }
.fx-input[readonly] { background: var(--surface-sunken); border-color: var(--line); }
.fx-input:disabled { background: var(--surface-sunken); color: var(--ink-disabled); border-color: var(--line); cursor: not-allowed; }
.fx-textarea { height: auto; padding: var(--space-2) var(--space-3); resize: vertical; }
.fx-field.has-error .fx-input { border-color: var(--danger); }
.fx-hint { margin: 0; font-size: 14px; line-height: 22px; color: var(--ink-muted); display: flex; gap: var(--space-1); align-items: center; }
.fx-hint-error { color: var(--danger); }
.fx-input-wrap, .fx-select-wrap { position: relative; }
.fx-input-icon { position: absolute; left: var(--space-3); top: 12px; color: var(--ink-muted); pointer-events: none; }
.fx-input-has-icon { padding-left: 36px; }
.fx-select { appearance: none; -webkit-appearance: none; padding-right: 36px; cursor: pointer; }
.fx-select-caret { position: absolute; right: var(--space-3); top: 12px; color: var(--ink-muted); pointer-events: none; }

/* Checkbox */
.fx-check { display: inline-flex; gap: var(--space-2); align-items: flex-start; cursor: pointer; position: relative; }
.fx-check-input { position: absolute; opacity: 0; width: 20px; height: 20px; margin: 2px 0 0; cursor: pointer; }
.fx-check-box { flex: none; width: 18px; height: 18px; margin-top: 3px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface-raised); display: grid; place-items: center; color: transparent; }
.fx-check-input:checked + .fx-check-box { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.fx-check-input:focus-visible + .fx-check-box { outline: 2px solid var(--focus); outline-offset: 2px; }
.fx-check-text { display: grid; }
.fx-check-label { font-size: 16px; line-height: 26px; color: var(--ink); }
.fx-check-desc { font-size: 14px; line-height: 22px; color: var(--ink-muted); }
.fx-check.is-disabled { cursor: not-allowed; }
.fx-check.is-disabled .fx-check-label { color: var(--ink-disabled); }
.fx-check.is-disabled .fx-check-box { background: var(--surface-sunken); border-color: var(--line); }

/* StatusBadge */
.fx-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; line-height: 21px; font-weight: 500; padding: 1px var(--space-2); border-radius: var(--radius-sm); white-space: nowrap; }
.fx-badge-dot { width: 6px; height: 6px; border-radius: var(--radius-pill); background: currentColor; }
.fx-badge-brand { background: var(--brand-soft); color: var(--brand); }
.fx-badge-warning { background: var(--warning-soft); color: var(--warning); }
.fx-badge-success { background: var(--success-soft); color: var(--success); }
.fx-badge-danger { background: var(--danger-soft); color: var(--danger); }
.fx-badge-hold { background: var(--hold-soft); color: var(--hold); }
.fx-badge-neutral { background: var(--neutral-soft); color: var(--ink-muted); }
.fx-badge-neutral .fx-badge-dot { background: transparent; border: 1.5px solid currentColor; width: 4px; height: 4px; }
.fx-badge-danger .fx-badge-dot { border-radius: 1px; transform: rotate(45deg); }

/* Alert */
.fx-alert { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); border: 1px solid transparent; }
.fx-alert-icon { margin-top: 2px; }
.fx-alert-body { flex: 1; min-width: 0; }
.fx-alert-title { margin: 0; font-size: 16px; line-height: 26px; font-weight: 600; }
.fx-alert-text { font-size: 15px; line-height: 24px; color: var(--ink); }
.fx-alert-action { flex: none; align-self: center; }
.fx-alert-close { flex: none; border: 0; background: transparent; color: var(--ink-muted); cursor: pointer; padding: var(--space-1); border-radius: var(--radius-sm); }
.fx-alert-info { background: var(--brand-soft); border-color: var(--brand-muted); }
.fx-alert-info .fx-alert-icon, .fx-alert-info .fx-alert-title { color: var(--brand); }
.fx-alert-success { background: var(--success-soft); }
.fx-alert-success .fx-alert-icon, .fx-alert-success .fx-alert-title { color: var(--success); }
.fx-alert-warning { background: var(--warning-soft); }
.fx-alert-warning .fx-alert-icon, .fx-alert-warning .fx-alert-title { color: var(--warning); }
.fx-alert-danger { background: var(--danger-soft); }
.fx-alert-danger .fx-alert-icon, .fx-alert-danger .fx-alert-title { color: var(--danger); }

/* Card */
.fx-card { background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); min-width: 0; }
.fx-card-head { display: flex; gap: var(--space-4); align-items: flex-start; justify-content: space-between; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--line); }
.fx-card-title { margin: 0; font-size: 17px; line-height: 24px; font-weight: 600; }
.fx-card-sub { margin: 2px 0 0; font-size: 14px; line-height: 22px; color: var(--ink-muted); }
.fx-card-actions { display: flex; gap: var(--space-2); flex: none; }
.fx-card-body { padding: var(--space-5); }
.fx-card-flush .fx-card-body { padding: 0; }
.fx-card-foot { padding: var(--space-3) var(--space-5); border-top: 1px solid var(--line); display: flex; gap: var(--space-2); justify-content: flex-end; }

/* Definition list used inside cards */
.fx-dl { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-5); margin: 0; font-size: 15px; line-height: 24px; }
.fx-dl dt { color: var(--ink-muted); }
.fx-dl dd { margin: 0; color: var(--ink); }

/* StatCard */
.fx-stat { background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5); box-shadow: var(--shadow-1); }
.fx-stat p { margin: 0; }
.fx-stat-label { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--ink-muted); display: flex; gap: var(--space-2); align-items: center; }
.fx-stat-value { font-family: var(--font-mono); font-size: 28px; line-height: 36px; font-weight: 500; color: var(--ink); margin-top: var(--space-2) !important; font-variant-numeric: tabular-nums; }
.fx-stat-unit { font-family: var(--font-sans); font-size: 15px; font-weight: 400; color: var(--ink-muted); margin-left: var(--space-1); }
.fx-stat-delta { font-size: 14px; line-height: 22px; font-weight: 500; margin-top: var(--space-1) !important; }
.fx-stat-hint { font-size: 13px; line-height: 21px; color: var(--ink-muted); margin-top: var(--space-1) !important; }
.fx-tone-success { color: var(--success); }
.fx-tone-danger { color: var(--danger); }
.fx-tone-warning { color: var(--warning); }
.fx-tone-neutral { color: var(--ink-muted); }

/* DataTable */
.fx-table-wrap { background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: auto; box-shadow: var(--shadow-1); }
.fx-table { width: 100%; border-collapse: collapse; font-size: 15px; line-height: 24px; }
.fx-table th { position: sticky; top: 0; background: var(--surface-sunken); color: var(--ink-muted); font-size: 14px; line-height: 22px; font-weight: 500; padding: 10px var(--space-4); border-bottom: 1px solid var(--line); white-space: nowrap; text-align: left; }
.fx-table td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); color: var(--ink); vertical-align: middle; }
.fx-table td.fx-muted { color: var(--ink-muted); }
.fx-table td.fx-mono { white-space: nowrap; }
.fx-table tbody tr:last-child td { border-bottom: 0; }
.fx-table-dense td { padding: 6px var(--space-4); }
.fx-table tr.is-clickable { cursor: pointer; }
.fx-table tr.is-clickable:hover td { background: var(--surface-sunken); }
.fx-table tr.is-selected td { background: var(--brand-soft); }
.fx-table-empty { text-align: center !important; color: var(--ink-muted) !important; padding: var(--space-6) !important; }
.fx-table-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-4); border-top: 1px solid var(--line); font-size: 14px; color: var(--ink-muted); }

/* Tabs */
.fx-tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--line); overflow-x: auto; }
.fx-tab { font: inherit; font-size: 15px; line-height: 24px; font-weight: 500; background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 10px var(--space-3); color: var(--ink-muted); cursor: pointer; display: inline-flex; gap: var(--space-2); align-items: center; white-space: nowrap; border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.fx-tab:hover { color: var(--ink); background: var(--surface-sunken); }
.fx-tab.is-active { color: var(--brand); border-bottom-color: var(--brand); }
.fx-tab-count { font-family: var(--font-mono); font-size: 13px; line-height: 21px; padding: 0 6px; border-radius: var(--radius-sm); background: var(--neutral-soft); color: var(--ink-muted); }
.fx-tab.is-active .fx-tab-count { background: var(--brand-soft); color: var(--brand); }

/* SidebarNav */
.fx-side { width: 248px; box-sizing: border-box; background: var(--sidebar); color: var(--on-sidebar); display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-4) var(--space-3); min-height: 100%; }
.fx-side-brand { display: grid; padding: var(--space-2) var(--space-3) var(--space-3); border-bottom: 1px solid rgba(255,255,255,0.12); }
.fx-side-name { font-size: 19px; line-height: 26px; font-weight: 700; letter-spacing: 0.01em; }
.fx-side-org { font-size: 13px; line-height: 21px; color: var(--on-sidebar-muted); }
.fx-side-title { margin: 0 0 var(--space-1); padding: 0 var(--space-3); font-size: 13px; line-height: 21px; font-weight: 500; color: var(--on-sidebar-muted); }
.fx-side ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.fx-side-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); color: var(--on-sidebar); text-decoration: none; font-size: 15px; line-height: 24px; }
.fx-side-item .fx-icon { color: var(--on-sidebar-muted); }
.fx-side-item:hover { background: rgba(255,255,255,0.08); }
.fx-side-item.is-active { background: var(--sidebar-active); font-weight: 500; }
.fx-side-item.is-active .fx-icon { color: var(--on-sidebar); }
.fx-side-item:focus-visible { outline-color: var(--on-sidebar); }
.fx-side-count { margin-left: auto; font-family: var(--font-mono); font-size: 13px; line-height: 21px; padding: 0 6px; border-radius: var(--radius-sm); background: rgba(255,255,255,0.14); }
.fx-side-user { margin-top: auto; display: flex; gap: var(--space-3); align-items: center; padding: var(--space-3); border-top: 1px solid rgba(255,255,255,0.12); }
.fx-side-avatar { width: 32px; height: 32px; border-radius: var(--radius-pill); background: var(--sidebar-active); display: grid; place-items: center; font-weight: 600; }
.fx-side-uname { display: block; font-size: 15px; line-height: 24px; font-weight: 500; }
.fx-side-role { display: block; font-size: 13px; line-height: 21px; color: var(--on-sidebar-muted); }
