/* Shared building blocks for feature pages (kit.ui) and the page header (kit.header). Loaded in every design, before the
   design's theme.css. Everything is drawn from CML OS's own variables (--bg --panel --line --fg --muted --faint --accent
   --bad --hover --r --font), so a page looks native in any design. A design can tune these too:
     --x-card-r  card corners          --x-card-pad  card padding        --x-gap   space between blocks
     --x-h2      drawer title (font)   --x-h3        card title (font)   --x-num   tile numbers (font)
     --x-mono    figures in tables     --x-good      "up" colour         --x-drawer-w  drawer width */

:root { --x-good: var(--good, #2F855A); }  /* CML OS's own green (lighter in dark); designs may set their own */

/* page header (kit.header): the title with its one line under it */
.kit-head { display: grid; min-width: 0; margin: 0 auto 0 0; }
.kit-head h1 { margin: 0; }
.kit-line { margin: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.bar .x-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.x-page { display: grid; gap: var(--x-gap, 20px); align-content: start; min-width: 0; }
.x-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: var(--x-gap, 20px); align-items: start; }
.x-muted { color: var(--muted); }
.x-a { color: var(--accent); font-weight: 500; text-decoration: none; }  /* a link to another page or sheet */
.x-a:hover { text-decoration: underline; }
.x-none { margin: 0; padding: 14px 0; color: var(--faint); }

.x-card { min-width: 0; padding: var(--x-card-pad, 16px 18px); border: 1px solid var(--line); border-radius: var(--x-card-r, calc(var(--r) + 4px)); background: var(--panel); }
.x-card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.x-card-h h3 { margin: 0; min-width: 0; font: var(--x-h3, 600 15px/1.3 var(--font)); }
.x-card-h .x-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.x-card-f { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.x-card > .x-tablewrap { margin: 0 -4px; }

.x-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border: 1px solid var(--line); border-radius: var(--x-card-r, calc(var(--r) + 4px)); background: var(--panel); overflow: hidden; }
.x-tile { display: grid; gap: 2px; align-content: start; padding: 14px 18px; border-left: 1px solid var(--line); min-width: 0; }
.x-tile:first-child { border-left: 0; }
.x-tile b { font: var(--x-num, 600 24px/1.15 var(--font)); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.x-tile span { color: var(--muted); font-size: 13px; }
.x-tile small { color: var(--faint); font-size: 12.5px; }
@media (max-width: 760px) { .x-tile b { font-size: 24px; } }  /* two tiles side by side on a phone: big numbers stay whole */
.x-tile .up { color: var(--x-good, #2F855A); }
.x-tile .down, .x-tile .bad { color: var(--bad); }

.x-tablewrap { overflow-x: auto; }
.x-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.x-table th { padding: 8px 10px; border-bottom: 1px solid var(--line); color: var(--faint); font-size: 12.5px; font-weight: 600; text-align: left; white-space: nowrap; }
.x-table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.x-table tr:last-child td { border-bottom: 0; }
.x-table .num { text-align: right; white-space: nowrap; }
.x-table td.num { font-family: var(--x-mono, inherit); }
.x-table tr[data-i] { cursor: pointer; }
.x-table tr[data-i]:hover td, .x-table tr[data-i]:focus-visible td { background: var(--hover); }
.x-table tr[data-i]:focus-visible { outline: none; }

.x-tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.x-tab { flex: none; margin-bottom: -1px; padding: 9px 12px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font-weight: 600; cursor: pointer; }
.x-tab:hover { color: var(--fg); }
.x-tab.on { border-bottom-color: var(--accent); color: var(--fg); }
.x-tab em { margin-left: 6px; color: var(--faint); font-style: normal; font-weight: 500; }

.x-field { display: grid; gap: 6px; min-width: 0; }
.x-field > span { color: var(--muted); font-size: 13px; font-weight: 500; }
.x-field small { color: var(--faint); font-size: 12.5px; }
.x-field input:not([type=checkbox]):not([type=radio]), .x-field select, .x-field textarea {
  width: 100%; min-width: 0; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--panel); color: var(--fg); font: inherit; }
.x-field input:not([type=checkbox]):not([type=radio]), .x-field select { height: 36px; }
.x-field textarea { padding: 8px 10px; resize: vertical; }
.x-check { display: flex; align-items: center; gap: 8px; }
.x-check > span { color: var(--fg); font-size: inherit; }
.x-check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.x-form { display: grid; gap: 14px; }

.x-empty { display: grid; justify-items: center; gap: 8px; padding: 44px 20px; color: var(--muted); text-align: center; }
.x-empty h3 { margin: 0; color: var(--fg); font: var(--x-h3, 600 15px/1.3 var(--font)); }
.x-empty p { margin: 0; max-width: 48ch; }
.x-empty .btn { margin-top: 6px; }

.x-kv { display: grid; grid-template-columns: minmax(90px, 140px) 1fr; gap: 8px 16px; margin: 0; }
.x-kv dt { color: var(--muted); }
.x-kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.x-drawer { position: fixed; inset: 0 0 0 auto; width: min(var(--x-drawer-w, 520px), 100vw); height: 100%; max-width: 100vw; max-height: none; margin: 0; padding: 0;
  border: 0; border-left: 1px solid var(--line); background: var(--bg); color: var(--fg); box-shadow: -8px 0 30px rgba(0, 0, 0, .12); }
.x-drawer::backdrop { background: rgba(0, 0, 0, .18); }
.x-drawer[open] { display: flex; flex-direction: column; }
.x-drawer header { display: flex; align-items: center; gap: 8px; flex: none; min-height: 56px; padding: 10px 12px 10px 20px; border-bottom: 1px solid var(--line); }
.x-drawer header h2 { flex: 1; min-width: 0; margin: 0; font: var(--x-h2, 600 17px/1.3 var(--font)); }
.x-drawer-body { flex: 1; min-height: 0; overflow-y: auto; padding: 18px 20px 24px; display: grid; gap: var(--x-gap, 20px); align-content: start; }
@media (prefers-reduced-motion: no-preference) { .x-drawer[open] { animation: x-in .18s ease-out; } @keyframes x-in { from { transform: translateX(24px); opacity: 0; } } }

/* extra tabs on CML OS pages (kit.addTab): while one is open, the page's own content steps aside for it */
#app.kit-tab-on > :not(.bar):not(.kit-pane) { display: none !important; }

/* CML OS's stretched charts (preserveAspectRatio="none"): labels and dots keep their real shape (--kx from kit.js) */
:root:not([data-skin="0"]) .lk-chart svg[preserveAspectRatio="none"] text { transform-box: fill-box; transform-origin: left center; transform: scale(var(--kx, 1), 1); }
:root:not([data-skin="0"]) .lk-chart svg[preserveAspectRatio="none"] text[text-anchor="middle"] { transform-origin: center; }
:root:not([data-skin="0"]) .lk-chart svg[preserveAspectRatio="none"] text[text-anchor="end"] { transform-origin: right center; }
:root:not([data-skin="0"]) .lk-chart svg[preserveAspectRatio="none"] circle { transform-box: fill-box; transform-origin: center; transform: scale(var(--kx, 1), 1); }
:root:not([data-skin="0"]) .lk-chart circle[cx="-10"] { visibility: hidden; }  /* the hover dot's parking spot, off the chart */

/* toast with Undo and a link (kit.ui.toast(msg, { undo, href })) */
.x-toast { position: fixed; z-index: 60; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: var(--x-card-r, 12px); background: var(--fg); color: var(--bg); font-size: 13.5px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); }
.x-toast span { min-width: 0; }
.x-toast button, .x-toast a { flex: none; padding: 0; border: 0; background: none; color: inherit; font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* Twit-Fleet status: a soft pastel pill like the Open button, text centred (Jack 25 Nov). Beats the skins' generic select rules (ui.css loads before theme.css). */
:root[data-skin] select.tf-st[data-st] { --c: #8a9099; box-sizing: border-box; width: 124px; max-width: 100%; height: 28px; margin: 0; padding: 0 10px; border: 1px solid color-mix(in srgb, var(--c) 30%, transparent); border-radius: 999px; background: color-mix(in srgb, var(--c) 14%, transparent); color: color-mix(in srgb, var(--c) 70%, var(--fg, #111)); font-size: 12.5px; font-weight: 500; text-align: center; text-align-last: center; -webkit-appearance: none; appearance: none; cursor: pointer; }
:root[data-skin] select.tf-st[data-st]:hover { border-color: color-mix(in srgb, var(--c) 55%, transparent); }
:root[data-skin] select.tf-st[data-st]:focus-visible { border-color: color-mix(in srgb, var(--c) 55%, transparent); outline: 2px solid color-mix(in srgb, var(--c) 40%, transparent); outline-offset: 2px; }
:root[data-skin] select.tf-st[data-st] option { color: #111; background: #fff; text-align: left; }
:root[data-skin] select.tf-st[data-st="ok"] { --c: #2f9e5b; }
:root[data-skin] select.tf-st[data-st="prog"] { --c: #3b74d9; }
:root[data-skin] select.tf-st[data-st="bad"] { --c: #d64545; }
