/* MTJ Foundation ERP web UI: plain CSS on Fluent 2 design tokens (css/tokens.css).
   The Fluent web components read the same variables, so our components and theirs share one theme.
   Layers keep specificity predictable: reset < base < layout < components < pages < utilities. */
@layer reset, base, layout, components, pages, utilities;

/* ---------------------------------------------------------------- reset */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; height: 100%; }
  h1, h2, h3, p, figure { margin: 0; }
  button, input, select, textarea { font: inherit; color: inherit; }
  table { border-collapse: collapse; }
  img, svg { display: block; }
}

/* ---------------------------------------------------------------- base */
@layer base {
  :root { --tl-topbar-h: 40px; --tl-nav-w: 248px; --tl-nav-w-collapsed: 48px; --tl-topbar-bg: #1b1b1f; }
  :root[data-theme="dark"] { --tl-topbar-bg: #0b0b0d; }
  body {
    font-family: var(--fontFamilyBase);
    font-size: var(--fontSizeBase300);
    line-height: var(--lineHeightBase300);
    color: var(--colorNeutralForeground1);
    background: var(--colorNeutralBackground1);
    -webkit-font-smoothing: antialiased;
  }
  a { color: var(--colorBrandForegroundLink); text-decoration: none; }
  a:hover { color: var(--colorBrandForegroundLinkHover); text-decoration: underline; }
  :focus-visible { outline: 2px solid var(--colorStrokeFocus2); outline-offset: 1px; }
  .icon { width: 20px; height: 20px; flex: none; fill: currentColor; }
  .icon-16 { width: 16px; height: 16px; }
  .icon-24 { width: 24px; height: 24px; }
  /* Hide web components until defined, to avoid a flash of unstyled markup */
  fluent-dialog:not(:defined), fluent-drawer:not(:defined), fluent-menu:not(:defined) { display: none; }
}

/* ---------------------------------------------------------------- layout: Azure-portal style shell */
@layer layout {
  .tl-topbar {
    position: sticky; top: 0; z-index: 20; height: var(--tl-topbar-h);
    display: flex; align-items: center; gap: 4px; padding: 0 8px 0 0;
    background: var(--tl-topbar-bg); color: #fff;
  }
  .tl-topbar .tb-btn {
    width: 40px; height: var(--tl-topbar-h); display: grid; place-items: center;
    background: none; border: 0; color: #fff; cursor: pointer;
  }
  .tl-topbar .tb-btn:hover { background: rgba(255,255,255,.12); }
  .tl-brand { display: flex; align-items: center; gap: 8px; padding: 0 12px 0 4px; color: #fff; font-weight: 600; white-space: nowrap; }
  .tl-brand:hover { color: #fff; text-decoration: none; }
  .tl-brand .mark { display: grid; place-items: center; min-width: 24px; padding: 0 4px; height: 24px; border-radius: 4px; background: var(--colorBrandBackground); font-size: 11px; font-weight: 700; }
  .tl-brand .env { font-weight: 400; opacity: .7; font-size: var(--fontSizeBase200); }
  .tl-search { position: relative; flex: 1; max-width: 560px; margin: 0 auto; }
  .tl-search input {
    width: 100%; height: 28px; padding: 0 10px 0 32px; border-radius: var(--borderRadiusMedium);
    border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: #fff;
  }
  .tl-search input::placeholder { color: rgba(255,255,255,.7); }
  .tl-search input:focus { outline: none; background: #fff; color: var(--colorNeutralForeground1); }
  .tl-search input:focus::placeholder { color: var(--colorNeutralForeground3); }
  .tl-search > .icon { position: absolute; left: 8px; top: 4px; opacity: .8; pointer-events: none; }
  .tl-search-results {
    position: absolute; top: 32px; left: 0; right: 0; z-index: 30; display: none;
    background: var(--colorNeutralBackground1); color: var(--colorNeutralForeground1);
    border-radius: var(--borderRadiusMedium); box-shadow: var(--shadow16); padding: 4px 0; max-height: 360px; overflow: auto;
  }
  .tl-search-results.open { display: block; }
  .tl-search-results a { display: flex; gap: 10px; align-items: center; padding: 8px 12px; color: inherit; }
  .tl-search-results a:hover, .tl-search-results a.active { background: var(--colorNeutralBackground1Hover); text-decoration: none; }
  .tl-search-results .group { padding: 6px 12px 2px; font-size: var(--fontSizeBase100); color: var(--colorNeutralForeground3); text-transform: uppercase; letter-spacing: .5px; }
  .tl-avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--colorBrandBackground2); color: var(--colorBrandForeground2); font-size: 12px; font-weight: 600; }

  .tl-shell { display: grid; grid-template-columns: var(--tl-nav-w) 1fr; height: calc(100vh - var(--tl-topbar-h)); }
  :root.nav-collapsed .tl-shell { grid-template-columns: var(--tl-nav-w-collapsed) 1fr; }
  .tl-main { overflow: auto; padding: 0 24px 40px; background: var(--colorNeutralBackground1); }
  .tl-main:focus { outline: none; }

  /* Left navigation */
  .tl-nav { overflow: auto; background: var(--colorNeutralBackground2); border-right: 1px solid var(--colorNeutralStroke2); padding: 6px 0 16px; }
  .tl-nav a, .tl-nav summary {
    display: flex; align-items: center; gap: 12px; min-height: 36px; padding: 0 12px 0 14px;
    color: var(--colorNeutralForeground2); cursor: pointer; list-style: none; position: relative; user-select: none;
  }
  .tl-nav summary::-webkit-details-marker { display: none; }
  .tl-nav a:hover, .tl-nav summary:hover { background: var(--colorNeutralBackground2Hover); color: var(--colorNeutralForeground1); text-decoration: none; }
  .tl-nav a.active { background: var(--colorNeutralBackground2Selected); color: var(--colorNeutralForeground1); font-weight: 600; }
  .tl-nav a.active::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--colorBrandBackground); }
  .tl-nav .label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tl-nav .chev { transition: transform .15s; opacity: .7; }
  .tl-nav details[open] > summary .chev { transform: rotate(90deg); }
  .tl-nav details details summary, .tl-nav details a { padding-left: 46px; }
  .tl-nav details details a { padding-left: 62px; }
  .tl-nav .planned .label { opacity: .55; }
  .tl-nav .live { width: 7px; height: 7px; border-radius: 50%; background: var(--colorPaletteGreenBackground3); flex: none; }
  .tl-nav .divider { height: 1px; background: var(--colorNeutralStroke2); margin: 6px 12px; }
  .tl-nav .legend { font-size: var(--fontSizeBase100); color: var(--colorNeutralForeground3); padding: 12px 16px 0; display: flex; align-items: center; gap: 6px; }
  :root.nav-collapsed .tl-nav .label, :root.nav-collapsed .tl-nav .chev, :root.nav-collapsed .tl-nav .live,
  :root.nav-collapsed .tl-nav details > :not(summary), :root.nav-collapsed .tl-nav .legend { display: none; }
  :root.nav-collapsed .tl-nav a, :root.nav-collapsed .tl-nav summary { padding: 0 14px; }

  @media (max-width: 800px) {
    .tl-shell, :root.nav-collapsed .tl-shell { grid-template-columns: 1fr; }
    .tl-nav { position: fixed; top: var(--tl-topbar-h); bottom: 0; left: 0; width: var(--tl-nav-w); z-index: 15; box-shadow: var(--shadow16); display: none; }
    :root.nav-open .tl-nav { display: block; }
    .tl-main { padding: 0 12px 32px; }
    .tl-brand .env, .hide-sm { display: none !important; }
  }
}

/* ---------------------------------------------------------------- components */
@layer components {
  /* Page header, breadcrumb, command bar */
  .tl-breadcrumb { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: var(--fontSizeBase200); margin: 14px 0 6px; color: var(--colorNeutralForeground3); }
  .tl-breadcrumb .sep { opacity: .6; }
  .tl-page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
  .tl-page-icon { width: 40px; height: 40px; border-radius: var(--borderRadiusLarge); display: grid; place-items: center; background: var(--colorBrandBackground2); color: var(--colorBrandForeground1); }
  .tl-page-icon .icon { width: 24px; height: 24px; }
  .tl-page-header h1 { font-size: var(--fontSizeBase600); line-height: var(--lineHeightBase600); font-weight: var(--fontWeightSemibold); }
  .tl-page-header .subtitle { font-size: var(--fontSizeBase200); color: var(--colorNeutralForeground3); }
  .tl-page-header .header-extra { margin-left: auto; display: flex; gap: 8px; align-items: center; }

  .tl-cmdbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 4px 0; margin: 8px 0 16px; border-bottom: 1px solid var(--colorNeutralStroke2); }
  .cmd {
    display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 8px; border: 0; border-radius: var(--borderRadiusMedium);
    background: none; color: var(--colorNeutralForeground1); cursor: pointer; white-space: nowrap; font-size: var(--fontSizeBase300);
  }
  .cmd .icon { color: var(--colorBrandForeground1); }
  .cmd:hover { background: var(--colorSubtleBackgroundHover); color: var(--colorNeutralForeground1); text-decoration: none; }
  .cmd:disabled { opacity: .4; cursor: default; background: none; }
  .cmd.danger .icon { color: var(--colorPaletteRedForeground1); }
  .cmd-sep { width: 1px; height: 20px; background: var(--colorNeutralStroke2); margin: 0 6px; }
  .cmdbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
  .tl-cmdbar form, .tl-cmdbar fluent-menu { display: inline-flex; }
  .fieldset-reset { border: 0; padding: 0; margin: 0; min-width: 0; }

  /* Cards and sections */
  .card { background: var(--colorNeutralBackground1); border: 1px solid var(--colorNeutralStroke2); border-radius: var(--borderRadiusLarge); padding: 16px; }
  .card + .card { margin-top: 16px; }
  .card-title { display: flex; align-items: center; gap: 8px; font-size: var(--fontSizeBase400); font-weight: var(--fontWeightSemibold); margin-bottom: 12px; }
  .card-title .icon { color: var(--colorBrandForeground1); }
  .card-title .aside { margin-left: auto; font-size: var(--fontSizeBase200); font-weight: 400; color: var(--colorNeutralForeground3); }
  .section-label { font-size: var(--fontSizeBase200); font-weight: var(--fontWeightSemibold); color: var(--colorNeutralForeground3); text-transform: uppercase; letter-spacing: .4px; margin: 4px 0 8px; }

  /* Essentials (Azure resource overview) */
  .essentials { border-bottom: 1px solid var(--colorNeutralStroke2); padding-bottom: 12px; margin-bottom: 16px; }
  .essentials summary { cursor: pointer; font-weight: var(--fontWeightSemibold); display: flex; align-items: center; gap: 6px; list-style: none; margin-bottom: 8px; }
  .essentials summary::-webkit-details-marker { display: none; }
  .essentials[open] summary .chev { transform: rotate(90deg); }
  .essentials dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 32px; margin: 0; }
  .essentials dl > div { display: grid; grid-template-columns: 150px 1fr; gap: 8px; font-size: var(--fontSizeBase300); }
  .essentials dt { color: var(--colorNeutralForeground3); }
  .essentials dd { margin: 0; }
  @media (max-width: 900px) { .essentials dl { grid-template-columns: 1fr; } }

  /* Forms */
  .form-grid { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); align-items: start; }
  .form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  @media (max-width: 900px) { .form-grid.cols-4, .form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
  .span-2 { grid-column: span 2; }
  .span-all { grid-column: 1 / -1; }
  .field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
  .field > label, .field > .label { font-size: var(--fontSizeBase300); font-weight: var(--fontWeightSemibold); color: var(--colorNeutralForeground1); }
  .field > label.req::after { content: " *"; color: var(--colorPaletteRedForeground1); }
  .field .hint { font-size: var(--fontSizeBase200); color: var(--colorNeutralForeground3); }
  .input, .select, .textarea {
    width: 100%; min-height: 32px; padding: 4px 10px; border-radius: var(--borderRadiusMedium);
    border: 1px solid var(--colorNeutralStroke1); border-bottom-color: var(--colorNeutralStrokeAccessible);
    background: var(--colorNeutralBackground1); color: var(--colorNeutralForeground1);
  }
  .textarea { min-height: 64px; resize: vertical; }
  .input:hover, .select:hover, .textarea:hover { border-color: var(--colorNeutralStroke1Hover); border-bottom-color: var(--colorNeutralStrokeAccessibleHover); }
  .input:focus, .select:focus, .textarea:focus { outline: none; border-bottom: 2px solid var(--colorCompoundBrandStroke); padding-bottom: 3px; }
  .input[readonly], .input.computed { background: var(--colorNeutralBackground3); border-color: transparent; border-bottom-color: var(--colorNeutralStroke2); }
  .input.num { text-align: right; font-variant-numeric: tabular-nums; }
  .input-validation-error { border-color: var(--colorPaletteRedBorder2) !important; }
  .field-validation-error, .text-danger { font-size: var(--fontSizeBase200); color: var(--colorPaletteRedForeground1); }
  .check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; min-height: 32px; }
  .check input { width: 16px; height: 16px; accent-color: var(--colorBrandBackground); }
  .is-short .input { color: var(--colorPaletteRedForeground1); font-weight: 600; }

  /* Buttons */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 32px; padding: 0 12px;
    border-radius: var(--borderRadiusMedium); border: 1px solid var(--colorNeutralStroke1); background: var(--colorNeutralBackground1);
    color: var(--colorNeutralForeground1); font-weight: var(--fontWeightSemibold); cursor: pointer; white-space: nowrap;
  }
  .btn:hover { background: var(--colorNeutralBackground1Hover); border-color: var(--colorNeutralStroke1Hover); color: var(--colorNeutralForeground1); text-decoration: none; }
  .btn:disabled { opacity: .45; cursor: default; }
  .btn-primary { background: var(--colorBrandBackground); border-color: transparent; color: var(--colorNeutralForegroundOnBrand); }
  .btn-primary:hover { background: var(--colorBrandBackgroundHover); border-color: transparent; color: var(--colorNeutralForegroundOnBrand); }
  .btn-subtle { border-color: transparent; background: transparent; }
  .btn-danger { background: var(--colorPaletteRedBackground3); border-color: transparent; color: #fff; }
  .btn-danger:hover { background: var(--colorPaletteRedForeground1); color: #fff; }
  .btn-icon { min-width: 32px; padding: 0; border-color: transparent; background: transparent; }
  .btn-icon:hover { background: var(--colorSubtleBackgroundHover); border-color: transparent; }
  .btn-icon.danger { color: var(--colorPaletteRedForeground1); }
  .btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

  /* Filter pills (Azure list filters) */
  .filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; margin-bottom: 10px; }
  .filter-bar .field { width: 160px; }
  .filter-bar .field.wide { width: 220px; }
  .pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
  .pill {
    display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 4px 0 10px; border-radius: 12px;
    background: var(--colorNeutralBackground3); border: 1px solid var(--colorNeutralStroke2); font-size: var(--fontSizeBase200);
  }
  .pill b { font-weight: var(--fontWeightSemibold); }
  .pill a { display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; color: var(--colorNeutralForeground2); }
  .pill a:hover { background: var(--colorNeutralBackground3Hover); text-decoration: none; }
  .pill.static { padding-right: 10px; }

  /* Data grid */
  .grid-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: var(--fontSizeBase200); color: var(--colorNeutralForeground3); margin-bottom: 6px; }
  .grid-wrap { overflow: auto; border-top: 1px solid var(--colorNeutralStroke2); }
  .tl-grid { width: 100%; font-size: var(--fontSizeBase300); }
  .tl-grid th {
    position: sticky; top: 0; z-index: 1; background: var(--colorNeutralBackground1); text-align: left; white-space: nowrap;
    font-weight: var(--fontWeightSemibold); padding: 8px 12px; border-bottom: 1px solid var(--colorNeutralStroke1);
  }
  .tl-grid th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
  .tl-grid th a:hover { text-decoration: none; color: var(--colorBrandForeground1); }
  .tl-grid td { padding: 7px 12px; border-bottom: 1px solid var(--colorNeutralStroke2); vertical-align: middle; }
  .tl-grid tbody tr:hover td { background: var(--colorNeutralBackground1Hover); }
  .tl-grid tbody tr[data-href] { cursor: pointer; }
  .tl-grid .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .tl-grid .actions { white-space: nowrap; text-align: right; width: 1%; }
  .tl-grid .actions .btn-icon { min-height: 28px; min-width: 28px; }
  .tl-grid .actions form, .tl-grid .actions fluent-menu { display: inline-block; vertical-align: middle; }
  .tl-grid tfoot td { font-weight: var(--fontWeightSemibold); border-top: 1px solid var(--colorNeutralStroke1); border-bottom: 0; }
  .tl-grid .empty { text-align: center; padding: 32px; color: var(--colorNeutralForeground3); }
  .tl-grid .editing td { background: var(--colorBrandBackground2) !important; }
  .tags fluent-badge { margin-left: 6px; vertical-align: 1px; }
  .tl-pager { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; font-size: var(--fontSizeBase200); color: var(--colorNeutralForeground3); }
  .tl-pager .pages { display: flex; gap: 2px; }
  .tl-pager .pages a, .tl-pager .pages span { min-width: 30px; height: 30px; display: grid; place-items: center; border-radius: var(--borderRadiusMedium); color: var(--colorNeutralForeground1); padding: 0 6px; }
  .tl-pager .pages a:hover { background: var(--colorSubtleBackgroundHover); text-decoration: none; }
  .tl-pager .pages .current { background: var(--colorBrandBackground2); color: var(--colorBrandForeground1); font-weight: 600; }
  .tl-pager .pages .disabled { opacity: .35; }

  /* Type-ahead (own component, js/typeahead.js) */
  tl-typeahead { display: block; position: relative; }
  tl-typeahead .ta-list {
    position: absolute; z-index: 25; top: calc(100% + 2px); left: 0; right: 0; max-height: 280px; overflow: auto; display: none;
    background: var(--colorNeutralBackground1); border-radius: var(--borderRadiusMedium); box-shadow: var(--shadow16); padding: 4px 0; margin: 0; list-style: none;
  }
  tl-typeahead[open] .ta-list { display: block; }
  tl-typeahead .ta-list li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 12px; cursor: pointer; }
  tl-typeahead .ta-list li .hint { color: var(--colorNeutralForeground3); font-size: var(--fontSizeBase200); }
  tl-typeahead .ta-list li[aria-selected="true"], tl-typeahead .ta-list li:hover { background: var(--colorNeutralBackground1Hover); }
  tl-typeahead .ta-list .ta-empty { color: var(--colorNeutralForeground3); cursor: default; }

  /* KPI tiles and dashboard */
  .tiles { display: grid; gap: 16px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
  .tiles > .card, .editor-layout .card + .summary-panel { margin-top: 0; }
  .tile { grid-column: span 3; }
  .tile-6 { grid-column: span 6; } .tile-8 { grid-column: span 8; } .tile-4 { grid-column: span 4; } .tile-5 { grid-column: span 5; } .tile-7 { grid-column: span 7; } .tile-12 { grid-column: 1 / -1; }
  @media (max-width: 1100px) { .tile, .tile-4, .tile-5, .tile-6, .tile-7, .tile-8 { grid-column: span 6; } }
  @media (max-width: 700px) { .tile, .tile-4, .tile-5, .tile-6, .tile-7, .tile-8 { grid-column: 1 / -1; } }
  .kpi { display: flex; gap: 14px; align-items: center; height: 100%; }
  .kpi-icon { width: 44px; height: 44px; border-radius: var(--borderRadiusXLarge); display: grid; place-items: center; flex: none; }
  .kpi-icon .icon { width: 24px; height: 24px; }
  .kpi-icon.brand { background: var(--colorBrandBackground2); color: var(--colorBrandForeground1); }
  .kpi-icon.teal { background: var(--colorPaletteTealBackground2); color: var(--colorPaletteTealForeground2); }
  .kpi-icon.purple { background: var(--colorPaletteBerryBackground2); color: var(--colorPaletteBerryForeground2); }
  .kpi-icon.orange { background: var(--colorPaletteDarkOrangeBackground2); color: var(--colorPaletteDarkOrangeForeground2); }
  .kpi-label { font-size: var(--fontSizeBase200); color: var(--colorNeutralForeground3); }
  .kpi-value { font-size: var(--fontSizeBase600); line-height: var(--lineHeightBase600); font-weight: var(--fontWeightSemibold); font-variant-numeric: tabular-nums; }
  .kpi-sub { font-size: var(--fontSizeBase200); color: var(--colorNeutralForeground3); }
  .bar-chart { width: 100%; height: 230px; }
  .bar-chart .grid { stroke: var(--colorNeutralStroke2); }
  .bar-chart .axis { fill: var(--colorNeutralForeground3); font-size: 10px; font-family: var(--fontFamilyBase); }
  .bar-chart .bar { fill: var(--colorBrandBackground); opacity: .85; }
  .bar-chart .bar:hover { opacity: 1; }
  .bar-chart .bar.today { fill: var(--colorPaletteTealForeground2); }
  .rank { margin-bottom: 10px; }
  .rank-head { display: flex; justify-content: space-between; gap: 8px; font-size: var(--fontSizeBase300); }
  .rank-bar { height: 4px; border-radius: 2px; background: var(--colorNeutralBackground3); margin: 4px 0 2px; overflow: hidden; }
  .rank-bar span { display: block; height: 100%; background: var(--colorBrandBackground); border-radius: 2px; }
  .rank-sub { font-size: var(--fontSizeBase100); color: var(--colorNeutralForeground3); }
  .activity { list-style: none; margin: 0; padding: 0; }
  .activity li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--colorNeutralStroke2); }
  .activity li:last-child { border-bottom: 0; }
  .activity .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--colorNeutralStroke1); }
  .activity .dot.ok { background: var(--colorPaletteGreenBackground3); } .activity .dot.bad { background: var(--colorPaletteRedBackground3); } .activity .dot.info { background: var(--colorBrandBackground); }
  .activity .when { font-size: var(--fontSizeBase100); color: var(--colorNeutralForeground3); }
  .quick-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .quick-links a { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: var(--borderRadiusMedium); border: 1px solid var(--colorNeutralStroke2); color: var(--colorNeutralForeground1); }
  .quick-links a:hover { background: var(--colorNeutralBackground1Hover); text-decoration: none; }
  .quick-links .icon { color: var(--colorBrandForeground1); }

  /* Fluent dialog/drawer content helpers */
  fluent-drawer { --drawer-width: 560px; }
  .drawer-section { margin-bottom: 16px; }
  .drawer-actions { display: flex; gap: 8px; justify-content: flex-end; }

  /* Toasts (top-right, like Azure notifications) */
  .tl-toasts { position: fixed; top: calc(var(--tl-topbar-h) + 12px); right: 16px; z-index: 40; display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 32px)); }
  .toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--borderRadiusLarge); background: var(--colorNeutralBackground1); box-shadow: var(--shadow16); border-left: 4px solid var(--colorBrandBackground); animation: toast-in .2s ease-out; }
  .toast.success { border-left-color: var(--colorPaletteGreenBackground3); } .toast.success .icon { color: var(--colorPaletteGreenForeground1); }
  .toast.warning { border-left-color: var(--colorPaletteDarkOrangeBackground3); } .toast.warning .icon { color: var(--colorPaletteDarkOrangeForeground1); }
  .toast.error { border-left-color: var(--colorPaletteRedBackground3); } .toast.error .icon { color: var(--colorPaletteRedForeground1); }
  .toast .msg { flex: 1; }
  .toast .close { background: none; border: 0; cursor: pointer; color: var(--colorNeutralForeground3); padding: 0; }
  @keyframes toast-in { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }

  /* Report viewer */
  .viewer-frame { display: block; width: 100%; height: calc(100vh - 250px); min-height: 420px; border: 1px solid var(--colorNeutralStroke2); border-radius: var(--borderRadiusMedium); background: #dfe3e8; }
  .criteria { margin-bottom: 12px; }
  .criteria > summary { cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-weight: var(--fontWeightSemibold); list-style: none; margin-bottom: 10px; }
  .criteria > summary::-webkit-details-marker { display: none; }
  .criteria[open] > summary .chev { transform: rotate(90deg); }
  .empty-state { text-align: center; padding: 48px 16px; color: var(--colorNeutralForeground3); border: 1px dashed var(--colorNeutralStroke1); border-radius: var(--borderRadiusLarge); }
  .empty-state .icon { width: 40px; height: 40px; margin: 0 auto 8px; color: var(--colorNeutralForeground4); }
}

/* ---------------------------------------------------------------- pages */
@layer pages {
  /* Login */
  .login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--colorNeutralBackground2); }
  .login-card { width: 100%; max-width: 440px; background: var(--colorNeutralBackground1); border-radius: var(--borderRadiusXLarge); box-shadow: var(--shadow16); padding: 36px 40px 28px; }
  .login-card .brand { display: flex; align-items: center; gap: 10px; font-size: var(--fontSizeBase500); font-weight: var(--fontWeightSemibold); margin-bottom: 20px; }
  .login-card .brand .mark { min-width: 32px; padding: 0 6px; height: 32px; border-radius: 6px; display: grid; place-items: center; background: var(--colorBrandBackground); color: #fff; font-size: 13px; font-weight: 700; }
  .login-card h1 { font-size: var(--fontSizeBase600); font-weight: var(--fontWeightSemibold); margin-bottom: 4px; }
  .login-card .lead { color: var(--colorNeutralForeground3); margin-bottom: 20px; }
  .login-card form { display: flex; flex-direction: column; gap: 14px; }
  .login-card .btn-primary { width: 100%; min-height: 36px; margin-top: 6px; }
  .login-card details { margin-top: 18px; font-size: var(--fontSizeBase200); color: var(--colorNeutralForeground3); }
  .login-card details table { width: 100%; margin-top: 6px; }
  .login-card details td { padding: 3px 4px; border-bottom: 1px solid var(--colorNeutralStroke2); }
  .login-foot { margin-top: 16px; font-size: var(--fontSizeBase200); color: var(--colorNeutralForeground3); text-align: center; }

  /* Invoice editor */
  .editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
  @media (max-width: 1200px) { .editor-layout { grid-template-columns: 1fr; } }
  .summary-panel { position: sticky; top: 12px; }
  .summary-list { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: var(--fontSizeBase300); }
  .summary-list dt { color: var(--colorNeutralForeground3); }
  .summary-list dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
  .grand { display: flex; justify-content: space-between; align-items: baseline; margin: 12px 0 4px; padding: 10px 12px; border-radius: var(--borderRadiusMedium); background: var(--colorBrandBackground); color: var(--colorNeutralForegroundOnBrand); }
  .grand b { font-size: var(--fontSizeBase500); font-variant-numeric: tabular-nums; }
  .grand.alt { background: var(--colorNeutralBackground3); color: var(--colorNeutralForeground1); }
  .words { font-size: var(--fontSizeBase200); color: var(--colorNeutralForeground3); }
  .customer-facts { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: var(--fontSizeBase200); color: var(--colorNeutralForeground2); min-height: 20px; margin-top: 6px; }
  .customer-facts span { display: inline-flex; align-items: center; gap: 4px; }
  .line-editor { border-left: 3px solid var(--colorBrandBackground); }
  .line-totals { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 22px; margin-top: 12px; padding: 8px 12px; border-radius: var(--borderRadiusMedium); background: var(--colorNeutralBackground3); }
  .line-totals > div:not(.btn-row) { display: flex; flex-direction: column; }
  .line-totals label { font-size: var(--fontSizeBase100); color: var(--colorNeutralForeground3); text-transform: uppercase; }
  .line-totals output { font-weight: 600; font-variant-numeric: tabular-nums; }
  .line-totals .net output { color: var(--colorBrandForeground1); font-size: var(--fontSizeBase400); }
  .line-totals .btn-row { margin-left: auto; }
  .editor-fields { display: grid; gap: 10px 12px; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
  .editor-fields .product { grid-column: span 3; }
  @media (max-width: 700px) { .editor-fields .product { grid-column: 1 / -1; } }
}

/* ---------------------------------------------------------------- utilities */
@layer utilities {
  .muted { color: var(--colorNeutralForeground3); }
  .small { font-size: var(--fontSizeBase200); }
  .strong { font-weight: var(--fontWeightSemibold); }
  .nowrap { white-space: nowrap; }
  .text-right { text-align: right; }
  .num { font-variant-numeric: tabular-nums; }
  .hidden { display: none !important; }
  .mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mb-16 { margin-bottom: 16px; }
  .flex { display: flex; align-items: center; gap: 8px; }
  .spacer { flex: 1; }
  .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
}

@layer pages {
  /* Key/value list (coming-soon page, record facts) */
  .kv { display: grid; grid-template-columns: 140px 1fr; gap: var(--spacingVerticalS) var(--spacingHorizontalL); margin: 0; }
  .kv dt { color: var(--colorNeutralForeground3); }
  .kv dd { margin: 0; overflow-wrap: anywhere; }

  /* Tabs as links (server-rendered; each tab is its own URL) */
  .tl-tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--colorNeutralStroke2); margin: -8px 0 16px; }
  .tl-tabs a {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; color: var(--colorNeutralForeground2);
    border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: var(--fontWeightRegular);
  }
  .tl-tabs a .icon { width: 16px; height: 16px; color: var(--colorNeutralForeground3); }
  .tl-tabs a:hover { color: var(--colorNeutralForeground1); text-decoration: none; background: var(--colorSubtleBackgroundHover); }
  .tl-tabs a.active { color: var(--colorNeutralForeground1); font-weight: var(--fontWeightSemibold); border-bottom-color: var(--colorCompoundBrandStroke); }
  .tl-tabs a.active .icon { color: var(--colorBrandForeground1); }

  /* Command-bar picker (user / group) */
  .tl-cmdbar .picker { display: inline-flex; align-items: center; gap: 6px; margin-right: 4px; }
  .tl-cmdbar .picker .select { min-width: 300px; max-width: 420px; }

  /* Grant checklists (Security) */
  .access-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }
  .access-toolbar .field.wide { width: 280px; }
  .access-section { border: 1px solid var(--colorNeutralStroke2); border-radius: var(--borderRadiusLarge); margin-bottom: 12px; background: var(--colorNeutralBackground1); }
  .access-section__head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 12px; background: var(--colorNeutralBackground2); border-bottom: 1px solid var(--colorNeutralStroke2); border-radius: var(--borderRadiusLarge) var(--borderRadiusLarge) 0 0; }
  .access-list { list-style: none; margin: 0; padding: 4px 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 0 24px; }
  .access-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 34px; border-bottom: 1px solid var(--colorNeutralStroke3); }
  .access-list li[hidden], .access-section[hidden] { display: none; }
  .access-list .check { min-height: 30px; }
  .access-tags { display: inline-flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; align-items: center; }
  .save-bar {
    position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 10px 0; margin-top: 8px;
    background: var(--colorNeutralBackground2); border-top: 1px solid var(--colorNeutralStroke2);
  }
  .tl-grid tr.inactive td { color: var(--colorNeutralForeground3); }

  /* Edit forms */
  .form-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; align-items: start; max-width: 1200px; }
  .form-columns > .card + .card { margin-top: 0; }
  .narrow { max-width: 520px; }
  .hint-list { margin: 0; padding-left: 18px; font-size: var(--fontSizeBase200); color: var(--colorNeutralForeground3); }
  .hint { font-size: var(--fontSizeBase200); color: var(--colorNeutralForeground3); }

  /* Quick-entry form above a master list (legacy "name box + Insert / Update / Cancel") */
  .quick-entry { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; }
  .quick-entry .field.wide { flex: 1 1 280px; max-width: 420px; }
  .quick-entry .field:not(.wide) { width: 130px; }
  .quick-entry .check { min-height: 32px; }
  .quick-entry .span-all { flex-basis: 100%; margin: 0; }
  .quick-entry.editing { border-color: var(--colorBrandStroke1); background: var(--colorBrandBackground2); }

  /* Segmented links (All / Active / Inactive) */
  .seg { display: inline-flex; border: 1px solid var(--colorNeutralStroke1); border-radius: var(--borderRadiusMedium); overflow: hidden; }
  .seg a { padding: 5px 12px; color: var(--colorNeutralForeground1); border-right: 1px solid var(--colorNeutralStroke2); }
  .seg a:last-child { border-right: 0; }
  .seg a:hover { background: var(--colorSubtleBackgroundHover); text-decoration: none; }
  .seg a.active { background: var(--colorBrandBackground2); color: var(--colorBrandForeground1); font-weight: var(--fontWeightSemibold); }

  /* Holidays month calendar */
  .tl-cmdbar .picker input[type=month] { width: 170px; }
  .holiday-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, 1fr); gap: 16px; align-items: start; }
  .holiday-layout > .card + .card { margin-top: 0; }
  .holiday-layout .span-all { grid-column: 1 / -1; }
  @media (max-width: 1000px) { .holiday-layout { grid-template-columns: 1fr; } }
  .cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
  .cal__head { text-align: center; font-size: var(--fontSizeBase200); font-weight: var(--fontWeightSemibold); color: var(--colorNeutralForeground3); padding-bottom: 2px; }
  .cal__day {
    position: relative; display: flex; flex-direction: column; gap: 2px; min-height: 64px; padding: 6px 8px; cursor: pointer;
    border: 1px solid var(--colorNeutralStroke2); border-radius: var(--borderRadiusMedium); background: var(--colorNeutralBackground1);
  }
  .cal__day:hover { border-color: var(--colorNeutralStroke1Hover); background: var(--colorNeutralBackground1Hover); }
  .cal__day input { position: absolute; top: 6px; right: 6px; width: 16px; height: 16px; accent-color: var(--colorBrandBackground); }
  .cal__day:has(input:focus-visible) { outline: 2px solid var(--colorStrokeFocus2); outline-offset: 1px; }
  .cal__num { font-weight: var(--fontWeightSemibold); font-variant-numeric: tabular-nums; }
  .cal__note { font-size: var(--fontSizeBase100); color: var(--colorNeutralForeground3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .cal__day.is-sunday .cal__num { color: var(--colorPaletteRedForeground1); }
  .cal__day.is-today { box-shadow: inset 0 0 0 2px var(--colorCompoundBrandStroke); }
  .cal__day.is-holiday { background: var(--colorPaletteGreenBackground1); border-color: var(--colorPaletteGreenBorder1); }
  .cal__day.is-holiday .cal__note { color: var(--colorPaletteGreenForeground1); }

  /* Employee form */
  .employee-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); gap: 16px; align-items: start; }
  .employee-form > .card + .card { margin-top: 0; }
  .employee-form .field:has(.reveal) { position: relative; }
  .employee-form .reveal { position: absolute; right: 2px; top: 25px; min-height: 28px; padding: 0 8px; }

  /* Increments / openings grids with inputs */
  .tl-grid.increments .inc-cell { min-width: 110px; }
  .tl-grid.increments .inc-cell > span { display: block; line-height: 1.2; }
  .tl-grid.increments .inc-cell .input, .tl-grid.openings .input { min-height: 28px; padding: 2px 6px; margin: 2px 0; }
  .tl-grid.openings .input { width: 110px; }
  .tl-grid tr.has-increment td { background: var(--colorBrandBackground2); }
  .tl-grid.increments .emp-cell { min-width: 230px; }
  .tl-grid.increments .emp-cell fluent-badge { display: inline-flex; margin: 2px 4px 0 0; white-space: nowrap; }
  .input:disabled, .select:disabled { background: var(--colorNeutralBackgroundDisabled); color: var(--colorNeutralForegroundDisabled); border-color: var(--colorNeutralStrokeDisabled); cursor: not-allowed; }

  /* Branch report images */
  .image-slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
  .image-slot { display: flex; flex-direction: column; gap: 6px; }
  .image-slot .thumb { height: 96px; display: grid; place-items: center; border: 1px dashed var(--colorNeutralStroke1); border-radius: var(--borderRadiusMedium); background: var(--colorNeutralBackground3); overflow: hidden; }
  .image-slot .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
  .image-slot input[type=file].input { padding: 4px; font-size: var(--fontSizeBase200); }

  /* Slice 5: attendance and leaves */
  .seg-radio { min-height: 32px; }
  .seg-radio label { display: inline-flex; align-items: center; padding: 5px 14px; cursor: pointer; border-right: 1px solid var(--colorNeutralStroke2); }
  .seg-radio label:last-child { border-right: 0; }
  .seg-radio input { position: absolute; opacity: 0; width: 1px; height: 1px; }
  .seg-radio label:has(input:checked) { background: var(--colorBrandBackground2); color: var(--colorBrandForeground1); font-weight: var(--fontWeightSemibold); }
  .seg-radio label:has(input:focus-visible) { outline: 2px solid var(--colorStrokeFocus2); outline-offset: -2px; }
  fieldset.field { border: 0; padding: 0; margin: 0; min-width: 0; }
  fieldset.field legend { font-size: var(--fontSizeBase200); font-weight: var(--fontWeightSemibold); margin-bottom: 4px; padding: 0; }
  .tl-grid th.sel, .tl-grid td.sel { width: 36px; text-align: center; }
  .tl-grid td.sel input, .tl-grid th.sel input { width: 16px; height: 16px; accent-color: var(--colorBrandBackground); }
  .grid-meta .btn.danger:not(:disabled) { color: var(--colorPaletteRedForeground1); }
  .day-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; }
  .day-strip label { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 2px; cursor: pointer;
    border: 1px solid var(--colorNeutralStroke2); border-radius: var(--borderRadiusMedium); font-size: var(--fontSizeBase200); }
  .day-strip label .dow { color: var(--colorNeutralForeground3); font-size: var(--fontSizeBase100); }
  .day-strip label.is-sunday .num { color: var(--colorPaletteRedForeground1); }
  .day-strip label.is-holiday { border-color: var(--colorPaletteGreenBorder1); background: var(--colorPaletteGreenBackground1); }
  .day-strip label:has(input:not(:checked)) { opacity: .5; text-decoration: line-through; background: var(--colorNeutralBackground3); }
  .day-strip input { accent-color: var(--colorBrandBackground); }
  .tl-grid.generator .input { min-height: 28px; padding: 2px 6px; width: 110px; }
  .tl-grid.generator tr:has(input[data-include]:not(:checked)) td:not(.sel) { opacity: .5; }
  /* Leaves: D-096 decision cell (super administrator) */
  .tl-grid td.decide form { display: inline-flex; align-items: center; gap: 6px; margin-left: 8px; }
  .tl-grid td.decide .input { width: 160px; min-height: 28px; }
  .tl-grid td.decide .btn { min-height: 28px; }
  /* Salaries: the editable sheet */
  .tl-grid.salary th, .tl-grid.salary td { white-space: nowrap; }
  .tl-grid.salary .input { min-height: 28px; padding: 2px 6px; width: 84px; text-align: right; }
  .tl-grid.salary .input.remarks { width: 160px; text-align: left; }
  .tl-grid.salary td.calc { font-weight: 600; }
  .tl-grid.salary tfoot td { font-weight: 600; border-top: 2px solid var(--colorNeutralStroke1); }
  /* Unticked / locked rows are muted with colour, not opacity: frozen cells must stay opaque over the scrolled columns. */
  .tl-grid.salary tr:has(input[data-include]:not(:checked)) td:not(.sel) { color: var(--colorNeutralForeground4); }
  .tl-grid.salary tr:has(input[data-include]:not(:checked)) td .input { color: var(--colorNeutralForeground4); }
  /* Salary sheet: fits the window so both scrollbars stay in view; header, key columns, net pay and totals stay put. */
  .sheet-wrap { max-height: calc(100vh - 230px); min-height: 320px; overflow: auto; border: 1px solid var(--colorNeutralStroke2); border-radius: 6px; }
  .sheet-wrap:focus-visible { outline: 2px solid var(--colorBrandStroke1); }
  .tl-grid.salary { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; }
  .tl-grid.salary thead th { position: sticky; top: 0; z-index: 2; background: var(--colorNeutralBackground3); }
  .tl-grid.salary tfoot td { position: sticky; bottom: 0; z-index: 2; background: var(--colorNeutralBackground3); }
  .tl-grid.salary .stick { position: sticky; z-index: 1; background: var(--colorNeutralBackground1); }
  .tl-grid.salary thead .stick, .tl-grid.salary tfoot .stick { z-index: 3; background: var(--colorNeutralBackground3); }
  .tl-grid.salary .s1 { left: 0; width: 36px; min-width: 36px; }
  .tl-grid.salary .s2 { left: 36px; width: 56px; min-width: 56px; }
  .tl-grid.salary .s3 { left: 92px; width: 220px; min-width: 220px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; box-shadow: 2px 0 0 var(--colorNeutralStroke1); }
  .tl-grid.salary .stick-r { position: sticky; right: 0; z-index: 1; background: var(--colorNeutralBackground1); box-shadow: -2px 0 0 var(--colorNeutralStroke1); }
  .tl-grid.salary thead .stick-r, .tl-grid.salary tfoot .stick-r { z-index: 3; background: var(--colorNeutralBackground3); }
  .tl-grid.salary tbody tr:hover td.stick, .tl-grid.salary tbody tr:hover td.stick-r { background: var(--colorNeutralBackground1Hover); }
  .tl-grid.salary .grp-sum { background-image: linear-gradient(var(--colorBrandBackground2), var(--colorBrandBackground2)); }
  .tl-grid.salary .input:focus { outline: 2px solid var(--colorBrandStroke1); outline-offset: -1px; }
  .sheet-wrap.hide-pay [data-g="pay"], .sheet-wrap.hide-days [data-g="days"], .sheet-wrap.hide-earn [data-g="earn"],
  .sheet-wrap.hide-ded [data-g="ded"], .sheet-wrap.hide-remarks [data-g="remarks"] { display: none; }
  .tl-grid.salary tr.find-hidden { display: none; }
  .sheet-tools { flex-wrap: wrap; }
  .sheet-toggles { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
  .sheet-toggles .chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border: 1px solid var(--colorNeutralStroke1); border-radius: 999px; cursor: pointer; color: var(--colorNeutralForeground2); }
  .sheet-toggles .chip:has(input:not(:checked)) { color: var(--colorNeutralForeground3); border-style: dashed; }
  .sheet-find { width: 180px; min-height: 28px; }
  /* Slice 8: System Configuration */
  .inline-flex { display: inline-flex; align-items: center; }
  .gap-8 { gap: 8px; }
  .color-swatch { display: inline-block; width: 28px; height: 28px; border-radius: 4px; border: 1px solid var(--colorNeutralStroke1); }

  /* Leave balance panel (D-141): Leaves screen, employee preview */
  .leave-balance { max-width: 760px; }
  .leave-balance .tl-grid td, .leave-balance .tl-grid th { padding-block: 4px; }
  .leave-balance tr.over td { background: var(--colorPaletteRedBackground1); }
  .neg { color: var(--colorPaletteRedForeground1); }
  .mb-8 { margin-bottom: 8px; }
  .policy-grid .input, .policy-grid .select { min-width: 0; }
  .policy-grid td.num .input { width: 6.5rem; text-align: right; }
  ul.plain { margin: 0; padding-left: 1.1em; }
}

