:root {
  --bg: #f5f6f8; --panel: #ffffff; --text: #1c2230; --muted: #667085; --border: #e3e6eb;
  --accent: #3b6cf6; --accent-text: #ffffff; --danger: #d92d20; --success: #12805c; --warn: #b54708;
  --sidebar: #141a26; --sidebar-text: #c9d1e0; --sidebar-active: #273149; --row-hover: #f2f5fb;
  --input: #ffffff; --code: #f0f2f5;
  color-scheme: light;
}
/* Dark colours: when the computer prefers dark (Auto), or when someone picks Dark (data-theme on <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f131b; --panel: #171c27; --text: #e4e8f0; --muted: #98a2b3; --border: #2a3142;
    --accent: #5b85ff; --sidebar: #0b0f16; --sidebar-active: #1f2738; --row-hover: #1d2432;
    --input: #121722; --code: #1f2533;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #0f131b; --panel: #171c27; --text: #e4e8f0; --muted: #98a2b3; --border: #2a3142;
    --accent: #5b85ff; --sidebar: #0b0f16; --sidebar-active: #1f2738; --row-hover: #1d2432;
    --input: #121722; --code: #1f2533;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* a class with its own display (e.g. .check) mustn't un-hide it */
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: var(--code); border-radius: 4px; }
code { padding: 1px 5px; }
pre { padding: 10px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--sidebar); color: var(--sidebar-text); padding: 16px 10px; flex-shrink: 0; display: flex; flex-direction: column; }
/* Stays in view while the page scrolls (scrolls itself if the window is short). */
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; align-self: flex-start; }
.sidebar > * { flex-shrink: 0; } /* a long menu scrolls; nothing in it gets squashed */
.sidebar .brand { font-weight: 700; font-size: 16px; color: #fff; padding: 4px 10px 16px; }
.sidebar nav a { display: block; color: var(--sidebar-text); padding: 7px 10px; border-radius: 6px; margin-bottom: 2px; }
.sidebar nav a:hover { background: var(--sidebar-active); text-decoration: none; }
.sidebar nav a.active { background: var(--sidebar-active); color: #fff; }
.sidebar .section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6b7690; padding: 14px 10px 4px; }
.sidebar .me { margin-top: auto; padding: 10px; font-size: 12px; border-top: 1px solid #263046; }
.sidebar .me button { background: none; border: 0; color: var(--sidebar-text); padding: 0; cursor: pointer; font: inherit; text-decoration: underline; }
main { flex: 1; padding: 24px 28px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: var(--row-hover); }
.table-wrap { overflow-x: auto; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; border: 1px solid transparent; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.bar { height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
.bar > span { display: block; height: 100%; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs .count { font-size: 11px; background: var(--code); border-radius: 999px; padding: 0 6px; margin-left: 4px; }

form.inline { display: inline; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--input); color: var(--text); font: inherit;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 16px; }
.field { margin-bottom: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: normal; color: var(--text); font-size: 14px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters > * { width: auto; }
.filters input[type=search] { width: auto; flex: 1 1 260px; min-width: 220px; max-width: 420px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.ms { width: 100%; justify-content: center; padding: 10px; font-weight: 600; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--border); background: var(--panel); }
.flash.success { border-color: var(--success); color: var(--success); }
.flash.error { border-color: var(--danger); color: var(--danger); }
.secret-box { border: 2px dashed var(--warn); border-radius: 8px; padding: 12px; margin-bottom: 18px; background: var(--panel); }
.secret-box code { font-size: 14px; word-break: break-all; display: block; padding: 8px; margin: 6px 0; user-select: all; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login h1 { margin-bottom: 4px; }
.divider { text-align: center; color: var(--muted); font-size: 12px; margin: 16px 0; }
.pagination { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }
.history-item { border-left: 3px solid var(--border); padding: 4px 0 8px 12px; margin-bottom: 6px; }
.history-item .chg { font-size: 12px; }
.bulkbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.bulkbar select { width: auto; }

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; position: static; height: auto; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .sidebar .section { display: none; }
  main { padding: 16px; }
}

/* Help page */
.help-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.help-toc { position: sticky; top: 16px; font-size: 13px; max-height: calc(100vh - 32px); overflow: auto; }
.help-toc a { display: block; padding: 3px 0; color: var(--muted); }
.help-toc a.sub { padding-left: 12px; }
.help-toc a:hover { color: var(--text); }
.help section { scroll-margin-top: 16px; }
.help h2 { font-size: 19px; margin: 8px 0 10px; }
.help h3 { text-transform: none; letter-spacing: 0; color: var(--text); font-size: 15px; margin: 18px 0 6px; }
.help p, .help li { max-width: 820px; }
.help ol li, .help ul li { margin-bottom: 4px; }
.help table { margin: 8px 0 12px; max-width: 900px; }
.code { position: relative; }
.code pre { margin: 6px 0 12px; padding-right: 64px; }
.code button { position: absolute; top: 6px; right: 6px; font-size: 11px; padding: 2px 8px; }
.note { border-left: 3px solid var(--accent); padding: 6px 12px; background: var(--panel); margin: 10px 0; max-width: 820px; }
@media (max-width: 900px) { .help-layout { grid-template-columns: 1fr; } .help-toc { position: static; max-height: none; } }

/* Version + changelog */
.sidebar .brand .version { font-size: 11px; font-weight: 500; color: #8b96ad; margin-left: 4px; }
.sidebar .brand .version:hover { color: #fff; }
.flash.whats-new { border-color: var(--accent); }
.changelog-release h3 { margin: 12px 0 4px; }
.changelog-release ul { margin: 4px 0 8px; padding-left: 20px; }
.changelog-release li { margin-bottom: 4px; max-width: 900px; }
.changelog-added { color: #12805c !important; }
.changelog-changed { color: var(--accent) !important; }
.changelog-fixed { color: #b54708 !important; }

/* Users page: one colour per role */
.role-admin { --role: #7c3aed; } .role-editor { --role: #2563eb; } .role-viewer { --role: #059669; }
.role-none { --role: #b54708; } .role-disabled { --role: #8a94a6; }
.role-summary { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 16px; }
.role-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; color: var(--text);
  border: 1px solid color-mix(in srgb, var(--role) 35%, transparent); background: color-mix(in srgb, var(--role) 10%, var(--panel)); }
.role-chip:hover { background: color-mix(in srgb, var(--role) 18%, var(--panel)); }
.role-chip strong { color: var(--role); }
.role-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--role); display: inline-block; flex: none; }
.role-section { border-top: 4px solid var(--role); }
.role-section-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 8px; }
.role-section-head h2 { display: flex; align-items: center; gap: 8px; margin: 0; }
.role-count { font-size: 12px; font-weight: 600; color: var(--role); background: color-mix(in srgb, var(--role) 12%, transparent);
  border-radius: 999px; padding: 0 8px; }
.role-disabled .user-table td { opacity: .75; }
.user-table { table-layout: fixed; width: 100%; min-width: 980px; }
.user-table td { overflow-wrap: anywhere; }
.user-table select, .user-table input[type=password] { max-width: 100%; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; background: var(--role); }
.badge.src-local { background: var(--code); color: var(--muted); }
.badge.src-entra { background: color-mix(in srgb, #2563eb 12%, transparent); color: #2563eb; }
.badge.group-chip { background: var(--code); color: var(--text); font-weight: 400; margin: 1px 0; }
.badge.override { background: color-mix(in srgb, var(--role) 14%, transparent); color: var(--role); font-size: 11px; }

/* List filter bar: search box, dropdowns, a <details class="more-filters"> panel, removable chips */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.filter-bar > select { width: auto; max-width: 220px; }
.search-field { flex: 1 1 280px; min-width: 220px; position: relative; display: flex; align-items: center; margin: 0; }
.search-field svg { position: absolute; left: 10px; color: var(--muted); pointer-events: none; }
.search-field input { width: 100%; padding-left: 32px; }
.more-filters { position: relative; }
.more-filters > summary { list-style: none; user-select: none; }
.more-filters > summary::-webkit-details-marker { display: none; }
.more-filters[open] > summary { border-color: var(--accent); color: var(--accent); }
.more-panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: min(520px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12); display: grid; gap: 10px; }
.more-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.more-row > select, .more-row > input[type=text] { width: auto; flex: 1 1 120px; }
.more-row > input[type=number] { width: 90px; }
.more-label { flex: 0 0 150px; font-size: 13px; color: var(--muted); }
.more-actions { display: flex; justify-content: flex-end; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 0 12px; }
/* Field filters (_filters.html): searchable field, condition, value; chips for the active ones */
.field-filters { margin: -4px 0 10px; }
.ff-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0; }
.ff-row > .ff-field { width: auto; flex: 1 1 220px; max-width: 320px; min-width: 0; }
.ff-row > .ff-op { width: auto; flex: 0 0 auto; }
.ff-row > .ff-text { width: auto; flex: 1 1 140px; max-width: 240px; min-width: 0; }
.ff-row > .ff-text[hidden] { display: none; }
.ff-foot { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin-top: 4px; }
.filter-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 6px 3px 10px; border-radius: 999px; font-size: 13px;
  background: color-mix(in srgb, var(--accent) 10%, var(--panel)); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); color: var(--text); }
.filter-chip:hover { text-decoration: none; border-color: var(--accent); }
.chip-label { color: var(--muted); }
.chip-label::after { content: ":"; }
.chip-x { display: inline-flex; width: 18px; height: 18px; align-items: center; justify-content: center; border-radius: 50%; font-size: 11px; color: var(--muted); }
.filter-chip:hover .chip-x { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
#results.loading { opacity: .55; transition: opacity .15s; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; }

/* Click-to-sort column headers */
.sort-link { color: inherit; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
button.sort-link { background: none; border: 0; padding: 0; font: inherit; text-align: inherit; cursor: pointer; }
.sort-link:hover { text-decoration: none; color: var(--accent); }
.sort-arrow { font-size: 10px; color: var(--muted); opacity: .45; }
.sort-link:hover .sort-arrow { opacity: 1; }
.sort-link.on, .sort-link.on .sort-arrow { color: var(--accent); opacity: 1; }

/* Integrations: menu sub-items with a status dot */
.sidebar nav a.sub { padding: 5px 10px 5px 24px; font-size: 13px; display: flex; align-items: center; gap: 7px; }
.nav-dot, .state-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; background: #8a94a6; }
.state-ok { background: #22a06b; } .state-error { background: #e5484d; } .state-off { background: #e2a336; }
.state-setup { background: #8a94a6; }

/* Integrations overview cards */
.tool-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tool-card { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.tool-card h2 { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 17px; }
.tool-card .state-line { font-size: 13px; display: flex; align-items: center; gap: 6px; }
.tool-card dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.tool-card dt { color: var(--muted); }
.tool-card dd { margin: 0; }
.tool-card .card-actions { display: flex; gap: 8px; margin-top: auto; flex-wrap: wrap; }

/* Integration page: tabs and the sticky save bar */
.tool-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.tool-head h1 { margin: 0; }
.tool-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.tool-summary { font-size: 13px; color: var(--muted); margin-bottom: 14px; display: flex; gap: 6px 16px; flex-wrap: wrap; align-items: center; }
.tab-panel[hidden] { display: none !important; }
.tab-panel { max-width: 920px; }
.tab-panel h3 { margin: 18px 0 8px; }
.tab-panel h3:first-child { margin-top: 0; }
.save-bar { position: sticky; bottom: 0; z-index: 15; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin-top: 14px;
  box-shadow: 0 -4px 16px rgba(15, 23, 42, .06); max-width: 920px; }
.save-bar .dirty { color: var(--warn); font-size: 13px; }
.choice-grid { display: flex; gap: 4px 14px; flex-wrap: wrap; }
.field-list { columns: 2; column-gap: 16px; }
@media (max-width: 700px) { .field-list { columns: 1; } }
.dup-group.name-match { border-left: 4px solid var(--warn); }
td.serial-differs { color: var(--warn); font-weight: 600; }
.dup-section { margin-top: 18px; }
.dup-section > summary { cursor: pointer; list-style: none; }
.dup-section > summary::-webkit-details-marker { display: none; }
.dup-section > summary h2 { display: inline-flex; align-items: center; gap: 8px; margin: 0 0 6px; }
.dup-section > summary h2::before { content: "▸"; color: var(--muted); font-size: 14px; transition: transform .15s; }
.dup-section[open] > summary h2::before { transform: rotate(90deg); }
.result-count { font-size: 13px; color: var(--muted); margin-right: 4px; }
.result-count strong { color: var(--text); font-size: 14px; }

/* Filter chips: click the chip to change it, the ✕ to remove it */
.filter-chip .chip-edit { all: unset; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.filter-chip.editable:hover { border-color: var(--accent); }
.filter-chip .chip-edit:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.filter-chip a.chip-x { color: var(--muted); text-decoration: none; }
.filter-chip a.chip-x:hover { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.sidebar nav a.view-item::before { content: "☆"; color: #8b96ad; margin-right: 1px; }
.nav-count { margin-left: auto; font-size: 11px; color: #8b96ad; }
.views-group { margin: 22px 0 10px; display: flex; align-items: center; gap: 8px; }
.views-group:first-of-type { margin-top: 6px; }
.view-card.is-shared { border-left: 4px solid var(--accent); }
.view-card.is-private { border-left: 4px solid var(--warn); }
.view-scope { font-size: 11px; white-space: nowrap; }
.is-shared .view-scope { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.is-private .view-scope { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }

/* App icon beside the name (side menu) and above the sign-in form */
.sidebar .brand { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sidebar .brand .brand-home { color: #fff; display: inline-flex; align-items: center; gap: 8px; }
.sidebar .brand .brand-home:hover { text-decoration: none; }
.sidebar .brand .brand-home img { display: block; flex: none; }
.login-logo { display: block; margin: 0 0 12px; }

/* Light / Auto / Dark switch (side menu) */
.theme-switch { display: inline-flex; align-self: flex-start; border: 1px solid #263046; border-radius: 6px; overflow: hidden; margin: -6px 10px 12px; }
.theme-switch button { background: none; border: 0; color: var(--sidebar-text); font: inherit; font-size: 13px; line-height: 1; padding: 5px 10px; cursor: pointer; text-decoration: none; }
.theme-switch button + button { border-left: 1px solid #263046; }
.theme-switch button:hover { background: var(--sidebar-active); }
.theme-switch button[aria-pressed="true"] { background: var(--sidebar-active); color: #fff; }
