/* FIBERBLAZE IMAT: ONE layout and table style for every module. Loaded LAST, so these sizes win over the older per-page ones.
   Only spacing, widths and alignment live here: the colours are the redesign tokens (resources/css/filament/app/tokens.css).

   Sizes (Compact = default):    gutter 16 · gap 12 · card pad 12 · cell 4 x 10 · row 32 · table text 13 · header 11/600 UPPERCASE · controls 32
   Comfortable (per user):       gap 16 · card pad 18 · cell 11 x 10 · row 44 · table text 14 · controls 36
   Default: the person's own choice, else Comfortable for Management / Field Technician, else Compact (AdminPanelProvider::density()).
   The density is the user's own setting (users.ui_density): the top-bar switch and My account both write it,
   the page carries it as html[data-density] and the classes imat-density-compact / imat-density-comfortable on <html> and <body>.

   Column types (custom tables get them from public/js/imat-layout.js, Filament columns from the imat* column macros):
     imat-col-short  IDs, dates, status words, province, source  -> centred, never wraps
     imat-col-num    numbers, %, durations, counts               -> right, never wraps, same-width digits
     imat-col-status pills / badges                              -> centred, never wraps
     imat-col-action buttons / links at the row end              -> centred, never wraps
     imat-col-long   names, addresses, notes                     -> left, wraps, at least 150px */

:root {
    --imat-gutter: 16px; --imat-gap: 12px; --imat-pad: 12px;
    --imat-cell-y: 4px; --imat-cell-x: 10px; --imat-row: var(--imat-row-compact, 32px);
    --imat-fs: var(--imat-fs-compact, 13px); --imat-fs-h: 11px; --imat-ctl: var(--imat-ctl-compact, 32px); --imat-max: 1840px;
    --imat-card: var(--imat-surface, #fff); --imat-head-bg: var(--imat-head, #F3F5F9); --imat-hair: var(--imat-divider, #EEF0F5); --imat-line: var(--imat-border, #E6E9F0);
    --imat-hover: var(--imat-row-hover, #F3F6FD);
    --fv-row: var(--imat-row);
}
html[data-density="comfortable"], html.imat-density-comfortable, body.imat-density-comfortable {
    --imat-gap: 16px; --imat-pad: 18px; --imat-cell-y: 11px; --imat-row: var(--imat-row-comfortable, 44px); --fv-row: var(--imat-row);
    --imat-fs: var(--imat-fs-comfortable, 14px); --imat-ctl: var(--imat-ctl-comfortable, 36px);
}

/* ============ 1. page shell: equal gutters, full width, centred above 1920px ============ */
.fv-bar2, .fv-body, .fv-incs, .fv-chips-row { padding-left: var(--imat-gutter); padding-right: var(--imat-gutter); }
.fv-top { padding-left: var(--imat-gutter); }
.fv-body { gap: var(--imat-gap); padding-top: var(--imat-gap); padding-bottom: var(--imat-gutter); box-sizing: border-box; }
.fv-bar2 + .fv-body, .fv-incs + .fv-body, .fv-chips-row + .fv-body { padding-top: 0; }
.fv-body.fv-grid2 { gap: var(--imat-gap); }
.fv-flow > * + * { margin-top: 0; }
.fv-flow .m-card, .fv-flow .ln-g2 { margin-bottom: var(--imat-gap); }
.fv-card, .m-card, .fi-section, .fi-ta-ctn, .ssa-card { max-width: 100%; box-sizing: border-box; }
.fv-body > .fv-card { width: 100%; }
.fv-body.fv-split > .fv-card, .fv-body.fv-grid2 > .fv-card { width: auto; }
.fv-ph { padding: 8px var(--imat-pad); gap: 8px; min-height: 40px; box-sizing: border-box; }
.fv-foot, .fv-more { padding-left: var(--imat-pad); padding-right: var(--imat-pad); }
/* Filament pages that are not in the compact shell (Settings resources, My account) */
.fi-main { padding-left: var(--imat-gutter) !important; padding-right: var(--imat-gutter) !important; box-sizing: border-box; }
body:has(:is(.fv-page, .fv-settings)) .fi-main { padding-left: 0 !important; padding-right: 0 !important; }
body:has(.fv-settings) .fi-page-header-main-ctn { padding-left: var(--imat-gutter) !important; padding-right: var(--imat-gutter) !important; }
.fi-page-main, .fi-page-content { row-gap: var(--imat-gap); }
html { overflow-x: clip; }   /* the page never scrolls sideways: wide tables scroll inside their own card */

@media (min-width: 1921px) {
    .fv-page:not(.fv-map) :is(.fv-bar2, .fv-body, .fv-incs, .fv-chips-row) { padding-left: max(var(--imat-gutter), calc((100% - var(--imat-max)) / 2)); padding-right: max(var(--imat-gutter), calc((100% - var(--imat-max)) / 2)); }
    body:not(:has(.fv-page)) .fi-main { max-width: var(--imat-max) !important; margin-left: auto; margin-right: auto; }
    body:has(.fv-settings) .fi-page-header-main-ctn { padding-left: max(var(--imat-gutter), calc((100% - var(--imat-max)) / 2)) !important; padding-right: max(var(--imat-gutter), calc((100% - var(--imat-max)) / 2)) !important; }
}

/* ============ 2. tables: one look for every table class ============ */
:is(.fv-tbl, .m-table, .ln-mt, .cw-t, .cp table, .fi-ta-table) { width: 100%; table-layout: auto; font-variant-numeric: tabular-nums; }
:is(.fv-tbl, .m-table, .ln-mt, .cw-t, .cp table) :is(th, td) { padding: var(--imat-cell-y) var(--imat-cell-x); vertical-align: middle; box-sizing: border-box; }
:is(.fv-tbl, .m-table, .ln-mt, .cw-t, .cp table) td { font-size: var(--imat-fs); height: var(--imat-row); line-height: 1.35; border-bottom: 1px solid var(--imat-hair); }
:is(.fv-tbl, .m-table, .ln-mt, .cw-t, .cp table) th { font-size: var(--imat-fs-h); font-weight: 600; height: var(--imat-row); line-height: 1.2; white-space: nowrap; border-bottom: 1px solid var(--imat-line); }
:is(.fv-tbl, .m-table, .ln-mt, .cw-t, .cp table) :is(th, td):first-child { padding-left: var(--imat-pad); }
:is(.fv-tbl, .m-table, .ln-mt, .cw-t, .cp table) :is(th, td):last-child { padding-right: var(--imat-pad); }
table.fv-tbl > tbody > tr > td { padding-top: 0; padding-bottom: 0; }          /* one-line rows keep exactly the row height (32 / 44) */
table.fv-tbl > tbody > tr > td:is(.imat-col-long, .pl-note) { padding-top: var(--imat-cell-y); padding-bottom: var(--imat-cell-y); }
/* no zebra stripes, a light hover tint, hairline dividers */
.ln-mt tbody tr:nth-child(odd), .cw-t tbody tr:nth-child(odd) { background: transparent; }
:is(.fv-tbl, .m-table, .ln-mt, .cw-t) tbody tr:hover > td { background: var(--imat-hover); }
.m-table tbody tr:hover, .fv-tbl tr.click:hover { background: transparent; }
.fv-tbl tr.sel > td { background: var(--imat-tint, #EAF0FF) !important; }
.fv-tbl tr.pl-row-full > td, .ws-row-likely > td, tr.click.cur-c > td { background-clip: padding-box; }

/* ---- column types ---- */
:is(th, td).imat-col-short, :is(th, td).imat-col-num, :is(th, td).imat-col-status, :is(th, td).imat-col-action { text-align: center; white-space: nowrap; }
:is(th, td).imat-col-num { font-variant-numeric: tabular-nums; text-align: right; }   /* numbers on the right (redesign) */
td.imat-col-long { text-align: left; white-space: normal; min-width: 150px; max-width: 420px; overflow-wrap: anywhere; word-break: normal; }
th.imat-col-long { text-align: left; }
td.imat-col-long .imat-clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
td.imat-col-action { width: 1%; }
/* the narrow details panel of a split view (Live network, Offline, PON capacity, Weak signal): a little tighter so its 7 columns fit */
.fv-detail { --imat-cell-x: 8px; }
.fv-detail td.imat-col-long { min-width: 120px; }
:is(.fv-tbl, .m-table) td select { max-width: 240px; text-overflow: ellipsis; }   /* a long option list never widens its column */
td.imat-col-action > :is(div, span):only-child { justify-content: center; }
/* the old "numbers on the right / actions on the right" rules: numbers on the right, actions centred */
.fv-tbl :is(th, td).n { text-align: right; }
.fv-tbl :is(th, td).act { text-align: center; }
.fv-tbl :is(th, td).n.imat-col-long, .fv-tbl :is(th, td).act.imat-col-long { text-align: left; }
/* pills: one height, vertically centred in the row */
:is(.fv-tbl, .m-table, .ln-mt, .cw-t, .fi-ta-table) :is(.fv-pill, .pc-pill, .fi-badge) { vertical-align: middle; height: 22px; box-sizing: border-box; }
.fv-tbl td > .fv-btn, .fv-tbl td > a.fv-btn { vertical-align: middle; }

/* ---- a table always fits its card: it scrolls inside the card, never the page ---- */
:is(.fv-card, .m-card, .ssa-card, .fv-flow, .cp-b, .cw-body):has(> table) { overflow-x: auto; }
.m-table-wrap, .ssa-tblwrap, .cw-scroll, .ln-mscroll, .fv-scroll { overflow-x: auto; max-width: 100%; }
/* the header stays put where the table already scrolls up and down */
:is(.fv-scroll, .m-table-wrap, .cw-scroll, .ln-mscroll) > table thead th { position: sticky; top: 0; z-index: 2; background: var(--imat-head-bg); }
.fv-tbl th { background: var(--imat-head-bg); }

/* ============ 3. Filament tables (Settings: Users, Activity log, OLTs, NAP boxes ...) ============ */
.fi-ta-ctn { overflow: hidden; }
.fi-ta-content-ctn, .fi-ta-content { overflow-x: auto; max-width: 100%; }
.fi-ta-header-cell { padding: var(--imat-cell-y) var(--imat-cell-x) !important; height: var(--imat-row); font-size: var(--imat-fs-h) !important; font-weight: 600 !important; }
.fi-ta-header-cell-label { white-space: normal; line-height: 1.15; }   /* a long label ("PON port (frame/slot/port)") may take two lines; the values never wrap */
.fi-ta-cell { padding: var(--imat-cell-y) var(--imat-cell-x) !important; height: var(--imat-row); vertical-align: middle; font-size: var(--imat-fs); }
.fi-ta-cell > :is(div, a, span) { min-height: 0; }
.fi-ta-cell:first-child, .fi-ta-header-cell:first-child { padding-left: var(--imat-pad) !important; }
.fi-ta-cell:last-child, .fi-ta-header-cell:last-child { padding-right: var(--imat-pad) !important; }
.fi-ta-cell :is(.fi-ta-text, .fi-ta-col, .fi-ta-icon, .fi-ta-image, .fi-ta-color, .fi-ta-checkbox, .fi-ta-toggle, .fi-ta-select, .fi-ta-text-input) { padding: 0 !important; }   /* Filament pads the inner wrapper too: the cell alone sets the spacing */
.fi-ta-actions-header-cell, .fi-ta-cell:has(> .fi-ta-actions) { text-align: center; white-space: nowrap; width: 1%; }
.fi-ta-cell > .fi-ta-actions { justify-content: center; flex-wrap: nowrap; }
.fi-ta-cell.imat-col-action :is(a, button, .fi-ta-text-item) { white-space: nowrap; }
.fi-ta-row:hover { background: var(--imat-hover) !important; }
.fi-ta-cell.imat-col-short .fi-ta-text, .fi-ta-cell.imat-col-num .fi-ta-text, .fi-ta-cell.imat-col-status .fi-ta-text,
.fi-ta-cell.imat-col-short .fi-ta-text-item, .fi-ta-cell.imat-col-num .fi-ta-text-item, .fi-ta-cell.imat-col-short .fi-ta-text-item-label, .fi-ta-cell.imat-col-num .fi-ta-text-item-label { white-space: nowrap !important; }
.fi-ta-cell.imat-col-long .fi-ta-text, .fi-ta-cell.imat-col-long .fi-ta-text-item-label { white-space: normal; }
.fi-ta-cell.imat-col-long { min-width: 150px; }
.fi-ta-header-cell.imat-col-num, .fi-ta-header-cell.imat-col-num .fi-ta-header-cell-label { white-space: normal; line-height: 1.15; }
/* a Filament table wider than its card scrolls inside it with the first column held in place */
.fi-ta-content :is(.fi-ta-header-cell, .fi-ta-cell):first-child { position: sticky; left: 0; z-index: 1; background: var(--imat-card); }
.fi-ta-content .fi-ta-row:hover > .fi-ta-cell:first-child { background: var(--imat-hover); }
.fi-ta-content .fi-ta-header-cell:first-child { background: var(--imat-head-bg); z-index: 2; }
@media (min-width: 1024px) and (max-width: 1439px) {
    body:has(.fv-settings) .fi-page-sub-navigation-sidebar-ctn { flex-basis: 184px; width: 184px; }
}
.fi-ta-header-ctn, .fi-ta-header-toolbar { padding: 8px var(--imat-pad) !important; gap: 8px; }
.fi-pagination { padding: 8px var(--imat-pad); column-gap: 8px; row-gap: 8px; align-items: center; }
.fi-ta-empty-state { padding: 32px var(--imat-pad); text-align: center; }

/* ============ 4. toolbars: one line, one control height, 8px gaps, lined up with the table edges ============ */
.fv-bar2 { gap: 8px; min-height: 0; padding-top: 8px; padding-bottom: 8px; align-items: center; flex-wrap: wrap; white-space: normal; overflow: visible; row-gap: 8px; }   /* wraps neatly instead of hiding controls off the right edge */
.fv-bar2 > * { white-space: nowrap; }
.fv-bar2 > *, .fv-top .fv-actions > * { flex-shrink: 0; }
:is(.fv-bar2, .ssa-bar, .pc-bar) :is(.fv-btn, .fv-inp, select, input:not([type=checkbox]):not([type=radio]), .fv-seg, .fv-tab) { height: var(--imat-ctl); box-sizing: border-box; }
.fv-tab { display: inline-flex; align-items: center; }
.fv-seg button { display: inline-flex; align-items: center; }
.ssa-bar, .pc-bar { gap: 8px; }
/* paging and "showing X of Y" in one row */
.fv-more, .ln-mpg, .cw-pager, .fv-pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.fv-more { justify-content: center; }
.ln-mpg { padding: 8px var(--imat-pad); justify-content: flex-end; }
/* the Export panel keeps its own position and z-index (fibervu-ui.css); only its inner spacing follows */
.px-pop { padding: var(--imat-pad); }

/* ============ 5. tiles, side-by-side cards, forms, modals, empty states ============ */
:is(.ws-tiles, .ssa-tiles, .ln-totals, .m-cards-4, .m-cards-6, .pc-kpis) { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--imat-gap); align-items: stretch; }
:is(.ws-tile, .ssa-tile, .pc-k, .m-stat, .ln-total) { height: 100%; box-sizing: border-box; text-align: center; align-items: center; justify-content: center; }
.pc-kpis { padding-left: var(--imat-gutter); padding-right: var(--imat-gutter); }
.fv-stats { gap: 8px; } .fv-stats > div { text-align: center; }
:is(.m-two, .ssa-grid, .ln-g2) { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--imat-gap); }
.ssa-card.wide { grid-column: 1 / -1; }
.ssa { gap: var(--imat-gap); padding: var(--imat-gap) var(--imat-gutter); }
.ssa-card, .m-card { padding: var(--imat-pad); }
.m-card:has(> .m-table-wrap, > table) { padding: 0; }
.m-card > .m-table-wrap, .m-card > table { margin: 0; }
/* forms: labels above, 36px fields, buttons on the right */
.fv-pop-box label, .px-pop label.px-lbl { display: flex; flex-direction: column; gap: 4px; }
.fv-form :is(input:not([type=checkbox]):not([type=radio]), select), .fi-fo-field .fi-input-wrp { min-height: 36px; }
.fv-form-actions, .fi-form-actions, .fi-modal-footer-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
/* modals: centred */
.fi-modal:not(.fi-modal-slide-over):not(.fi-no-database) .fi-modal-window-ctn { align-items: center; justify-content: center; }
.lc-modal { align-items: center; justify-content: center; }
/* empty and loading states */
.fv-empty, .ssa-empty, .cw-msg, .m-empty, .fi-ta-empty-state, .fv-loading { text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 32px var(--imat-pad); }
td.fv-empty, td .fv-empty, td.m-empty { display: table-cell; }

/* ============ 6. narrow screens ============ */
/* a table wider than its card scrolls inside the card with the first column held in place (the background is a weak :where so row colours still win) */
:is(.fv-scroll, .m-table-wrap, .ssa-tblwrap, .cw-scroll, .ln-mscroll, .fv-card, .m-card, .ssa-card) > :is(.fv-tbl, .m-table, .ln-mt, .cw-t) :is(th, td):first-child { position: sticky; left: 0; z-index: 1; }
:is(.fv-scroll, .m-table-wrap, .ssa-tblwrap, .cw-scroll, .ln-mscroll, .fv-card, .m-card, .ssa-card) > :is(.fv-tbl, .m-table, .ln-mt, .cw-t) th:first-child { z-index: 3; }
:where(.fv-tbl, .m-table, .ln-mt, .cw-t) :where(td:first-child) { background: var(--imat-card); }
:where(.fv-tbl, .m-table, .ln-mt, .cw-t) :where(tr:hover > td:first-child) { background: var(--imat-hover); }
/* number headers may take two lines ("Ports over limit") so narrow panels still fit; the numbers below never wrap */
:is(.fv-tbl, .m-table) th.imat-col-num { white-space: normal; line-height: 1.15; }
@media (max-width: 1024px) {
    .fv-bar2 { flex-wrap: wrap; white-space: normal; overflow-x: visible; row-gap: 8px; }
    td.imat-col-long { min-width: 150px; max-width: 280px; }
}
@media (max-width: 767px) {
    :root { --imat-gutter: 12px; }
    /* phones: the toolbar stacks into two even columns; search boxes and the Export button take a whole line */
    .fv-bar2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
    .fv-bar2 > * { width: 100% !important; max-width: none; min-width: 0; margin-left: 0 !important; }
    .fv-bar2 > :is(input:not([type=checkbox]):not([type=radio]), .fv-seg, .px-wrap, .fv-sp, .fv-actions, div) { grid-column: 1 / -1; }
    .fv-bar2 > .px-wrap { position: static; padding-left: 0; background: none; }
    .fv-bar2 > .px-wrap .px-btn { width: 100%; justify-content: center; }
    .fv-bar2 .fv-tab { justify-content: center; }
    :is(.ws-tiles, .ssa-tiles, .ln-totals, .m-cards-4, .m-cards-6, .pc-kpis) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    :is(.m-two, .ssa-grid, .ln-g2, .fv-grid2) { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 359px) {
    :is(.ws-tiles, .ssa-tiles, .ln-totals, .m-cards-4, .m-cards-6, .pc-kpis) { grid-template-columns: minmax(0, 1fr); }
}

/* /field/* web views: 44px touch targets */
.imat-field :is(a, button, input:not([type=checkbox]):not([type=radio]), select, .fv-btn) { min-height: 44px; }
