/* ==========================================================================
   design tokens — neutral, biased a few degrees toward a teal accent
   rather than a flat R=G=B grey.
   ========================================================================== */
:root {
  --ink:        #1B2223;
  --ink-line:   rgba(255,255,255,.08);
  --ink-text:   rgba(255,255,255,.92);
  --ink-text-2: rgba(255,255,255,.55);
  --ink-text-3: rgba(255,255,255,.32);

  --paper:   #F2F5F4;
  --surface: #FFFFFF;
  --line:    #DFE5E4;
  --text:    #202829;
  --text-2:  #6C7476;

  --accent:      #1ABC9C;
  --accent-dark: #149885;
  --accent-soft: rgba(26,188,156,.12);

  /* semantic — status colors, independent of the brand accent above */
  --danger:      #DC3545;
  --danger-soft: rgba(220,53,69,.12);
  --success:     #198754;

  --font: 'Plus Jakarta Sans', -apple-system, 'Segoe UI', sans-serif;

  --sidebar-w: 232px;
  --topbar-h:  58px;
  --radius:    9px;
  --radius-sm: 7px;
  --t: .16s cubic-bezier(.4,0,.2,1);

  --shadow-sm: 0 1px 2px rgba(20,28,28,.05), 0 2px 6px rgba(20,28,28,.05);
}

body { font-family: var(--font); }

/* ==========================================================================
   Bootstrap bridge — swap --accent above and this section re-skins the
   Bootstrap primitives this template actually uses. Bootstrap 5.3 bakes
   most component colors as literal hex values into its compiled CSS
   (e.g. .btn-primary's --bs-btn-bg is a hardcoded #0d6efd, not
   var(--bs-primary)), so overriding --bs-primary alone does nothing —
   each component needs its own override here.
   Using a new Bootstrap component on a page? Add its override here too
   (a plain `<a>` link, for instance, only needs --bs-link-color-rgb /
   --bs-link-hover-color-rgb overridden, since Bootstrap's own `a`/`a:hover`
   rules genuinely read those two as variables).
   ========================================================================== */
.btn-primary {
  --bs-btn-bg: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent-dark);
  --bs-btn-hover-border-color: var(--accent-dark);
  --bs-btn-active-bg: var(--accent-dark);
  --bs-btn-active-border-color: var(--accent-dark);
  --bs-btn-disabled-bg: var(--accent);
  --bs-btn-disabled-border-color: var(--accent);
  --bs-btn-focus-shadow-rgb: 26, 188, 156;
  --bs-btn-border-radius: var(--radius-sm);
}

/* buttons sit with 13.5–14px UI text; Bootstrap's 16px default reads as
   a size larger than everything around it */
.btn { --bs-btn-font-size: 14px; --bs-btn-font-weight: 500; }
.btn-sm { --bs-btn-font-size: 13px; }

:focus-visible { outline-color: var(--accent); }

/* ==========================================================================
   brand mark — the one recurring signature (dark square + accent dot),
   reused as-is by the sidebar header and by shell-less pages (error)
   so they read as the same product instead of each inventing its own
   logo treatment.
   ========================================================================== */
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), inset 0 0 0 1px rgba(255,255,255,.04);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand-word {
  font-family: var(--font);
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--text);
}

/* modifier for placing the lockup directly on an --ink surface (the
   sidebar) — the plain .brand-mark assumes a light surface behind it,
   so on --ink it needs a lighter tint to read as a distinct chip
   instead of vanishing into its own background */
.brand-mark--on-ink { background: rgba(255,255,255,.08); }
.brand-word--on-ink { color: var(--ink-text); }

.brand-dot { fill: var(--accent); }

/* ==========================================================================
   sidebar
   ========================================================================== */
.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background-color: var(--ink);
  /* faint dot-grid, shared with the login page's brand panel so the two
     ink surfaces read as one material rather than a decorative wall that
     turns into a different, denser nav once you're signed in */
  background-image: radial-gradient(rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 22px 22px;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sb-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 20px;
  border-bottom: 1px solid var(--ink-line);
}

.sb-nav { flex: 1; padding: 14px 10px; overflow-y: auto; }

.sb-section {
  font-family: var(--font);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-text-3);
  padding: 14px 10px 7px;
}
.sb-section:first-child { padding-top: 2px; }

.sb-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 11px 8px 15px;
  margin: 1px 0;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink-text-2);
  text-decoration: none;
  transition: background var(--t), color var(--t);
}
.sb-item svg { flex-shrink: 0; opacity: .85; }
.sb-item .sb-ext { margin-left: auto; opacity: .45; }
.sb-item:hover .sb-ext { opacity: .8; }
.sb-item:hover { background: rgba(255,255,255,.055); color: var(--ink-text); }

/* accent indicator floats independently of the item's own border-radius
   instead of a border-left, which got visibly clipped by the rounded
   corners it shared a box with */
.sb-item::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 50%;
  width: 2.5px;
  height: 58%;
  border-radius: 2px;
  background: var(--accent);
  transform: translateY(-50%) scaleY(0);
  transform-origin: center;
  transition: transform var(--t);
}

.sb-item.active {
  background: var(--accent-soft);
  color: #fff;
}
.sb-item.active::before { transform: translateY(-50%) scaleY(1); }
.sb-item.active svg { opacity: 1; color: var(--accent); }

.sb-bottom { padding: 14px 12px 18px; border-top: 1px solid var(--ink-line); }

/* collapsible folder — the toggle is styled as a regular .sb-item so the
   folder reads as part of the same list; its children hang off a thin
   guide line, like files under a folder */
.sb-group-toggle, .sb-rail-toggle {
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  font-family: var(--font);
}
.sb-group-toggle .sb-label { flex: 1; }
.sb-chev { opacity: .55 !important; transition: transform var(--t); }
.sb-group:not(.is-open) .sb-chev { transform: rotate(-90deg); }

.sb-group-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .2s cubic-bezier(.4,0,.2,1);
}
.sb-group.is-open .sb-group-body { grid-template-rows: 1fr; }
.sb-group-inner {
  overflow: hidden;
  margin-left: 22px;
  padding-left: 6px;
  border-left: 1px solid var(--ink-line);
}
.sb-group:not(.is-open) .sb-group-inner { visibility: hidden; transition: visibility 0s .2s; }

.sb-subitem { font-size: 13px; padding-top: 7px; padding-bottom: 7px; }
.sb-subitem svg { width: 15px; height: 15px; }

.sb-no-anim .sb-group-body, .sb-no-anim .sb-chev { transition: none; }

/* ==========================================================================
   sidebar rail — html.sb-rail collapses the sidebar to an icon column
   (desktop only; on mobile the sidebar is off-canvas anyway). Labels turn
   into tooltips, section headings into thin dividers, and a folder opens
   as a flyout beside its icon.
   ========================================================================== */
.sb-flyout-title { display: none; }
.sb-when-rail { display: none; }
.sb-rail-arrow { transform-box: fill-box; transform-origin: center; transition: transform var(--t); }

@media (min-width: 861px) {
  :root { --rail-w: 64px; }

  .sidebar { transition: width .2s cubic-bezier(.4,0,.2,1); }
  .main { transition: margin-left .2s cubic-bezier(.4,0,.2,1); }
  .sb-no-anim, .sb-no-anim ~ .main { transition: none; }

  html.sb-rail .sidebar { width: var(--rail-w); }
  html.sb-rail .main { margin-left: var(--rail-w); }

  html.sb-rail .sb-logo { justify-content: center; padding-left: 0; padding-right: 0; }
  html.sb-rail .brand-word,
  html.sb-rail .sb-logo .god-tag { display: none; }

  html.sb-rail .sb-nav { overflow: visible; }
  html.sb-rail .sb-section {
    height: 1px;
    padding: 0;
    margin: 10px 8px;
    font-size: 0;
    background: var(--ink-line);
  }
  html.sb-rail .sb-section:first-child { margin-top: 2px; }

  html.sb-rail .sb-item { justify-content: center; padding-left: 0; padding-right: 0; }
  html.sb-rail .sb-bottom { padding-left: 10px; padding-right: 10px; }
  html.sb-rail .sb-chev, html.sb-rail .sb-ext { display: none; }

  /* label → tooltip to the right of the icon */
  html.sb-rail .sb-item > .sb-label {
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translate(-4px, -50%);
    padding: 5px 9px;
    border-radius: 6px;
    background: var(--ink);
    border: 1px solid var(--ink-line);
    box-shadow: 0 6px 18px rgba(0,0,0,.25);
    color: var(--ink-text);
    font-size: 12.5px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t), transform var(--t);
    z-index: 300;
  }
  html.sb-rail .sb-item:hover > .sb-label,
  html.sb-rail .sb-item:focus-visible > .sb-label { opacity: 1; transform: translate(0, -50%); }

  html.sb-rail .sb-when-wide { display: none; }
  html.sb-rail .sb-when-rail { display: inline; }
  html.sb-rail .sb-rail-arrow { transform: rotate(180deg); }

  /* folder → flyout; the folder icon carries the "you are in here" state */
  html.sb-rail .sb-group { position: relative; }
  html.sb-rail .sb-group-toggle > .sb-label { display: none; }
  html.sb-rail .sb-group[data-has-active] > .sb-group-toggle { background: var(--accent-soft); color: #fff; }
  html.sb-rail .sb-group[data-has-active] > .sb-group-toggle svg { color: var(--accent); opacity: 1; }

  html.sb-rail .sb-group-body {
    display: block;
    position: absolute;
    left: 100%;
    top: -7px;
    padding-left: 12px; /* hover bridge between icon and panel */
    visibility: hidden;
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity var(--t), transform var(--t), visibility 0s .16s;
    z-index: 300;
  }
  html.sb-rail .sb-group:hover .sb-group-body,
  html.sb-rail .sb-group:focus-within .sb-group-body,
  html.sb-rail .sb-group.is-flyout .sb-group-body {
    visibility: visible;
    opacity: 1;
    transform: none;
    transition: opacity var(--t), transform var(--t);
  }
  html.sb-rail .sb-group-inner,
  html.sb-rail .sb-group:not(.is-open) .sb-group-inner {
    visibility: inherit;
    overflow: visible;
    min-width: 184px;
    margin: 0;
    padding: 6px;
    border: 1px solid var(--ink-line);
    border-radius: var(--radius);
    background-color: var(--ink);
    box-shadow: 0 10px 28px rgba(0,0,0,.3);
  }
  html.sb-rail .sb-flyout-title {
    display: block;
    padding: 6px 10px 6px 15px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--ink-text-3);
  }
  html.sb-rail .sb-subitem { justify-content: flex-start; padding: 7px 11px 7px 15px; }
  html.sb-rail .sb-subitem > .sb-label {
    position: static;
    transform: none;
    padding: 0;
    border: none;
    background: none;
    box-shadow: none;
    color: inherit;
    font-size: inherit;
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 860px) {
  .sb-rail-toggle { display: none; }
}

/* ==========================================================================
   main / topbar / content
   ========================================================================== */
.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title { font-family: var(--font); font-size: 14.5px; font-weight: 600; color: var(--text); }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 8px 4px 4px;
  margin-right: -8px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-2);
  transition: background var(--t), color var(--t);
}
.topbar-user:hover, .topbar-user[aria-expanded="true"] { background: var(--paper); color: var(--text); }
.topbar-chev { opacity: .6; transition: transform var(--t); }
.topbar-user[aria-expanded="true"] .topbar-chev { transform: rotate(180deg); }

/* user menu — Bootstrap dropdown, bridged to the tokens */
.user-menu {
  --bs-dropdown-min-width: 220px;
  --bs-dropdown-padding-y: 6px;
  --bs-dropdown-border-color: var(--line);
  --bs-dropdown-border-radius: var(--radius);
  --bs-dropdown-box-shadow: 0 10px 28px rgba(20,28,28,.12);
  --bs-dropdown-font-size: 13.5px;
  --bs-dropdown-link-color: var(--text);
  --bs-dropdown-link-hover-color: var(--text);
  --bs-dropdown-link-hover-bg: var(--paper);
  --bs-dropdown-link-active-color: var(--text);
  --bs-dropdown-link-active-bg: var(--accent-soft);
  --bs-dropdown-item-padding-x: 10px;
  --bs-dropdown-item-padding-y: 7px;
  --bs-dropdown-divider-bg: var(--line);
  --bs-dropdown-divider-margin-y: 6px;
  box-shadow: var(--bs-dropdown-box-shadow);
  font-family: var(--font);
}
.user-menu .dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: auto;
  margin: 0 6px;
  border-radius: var(--radius-sm);
}
.user-menu .dropdown-item svg { color: var(--text-2); flex-shrink: 0; }
.user-menu-head { display: flex; flex-direction: column; gap: 1px; padding: 6px 16px 4px; }
.user-menu-head strong { font-size: 13.5px; font-weight: 600; color: var(--text); }
.user-menu-head span { font-size: 12px; color: var(--text-2); }

.user-avatar {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--ink);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 11.5px; font-weight: 700;
}

.content { flex: 1; padding: 32px 28px 48px; max-width: 880px; }

.content h1 { font-family: var(--font); font-size: 19px; font-weight: 700; letter-spacing: -.01em; margin-bottom: 4px; }
.content .lede { color: var(--text-2); font-size: 13.5px; margin-bottom: 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 14px; }
.card h2 { font-family: var(--font); font-size: 13.5px; font-weight: 600; margin-bottom: 6px; }
.card p { color: var(--text-2); font-size: 13px; }

/* flush card: for tables / lists that run edge to edge, the card keeps
   its surface and border but gives its padding to the rows inside */
.card--flush { padding: 0; overflow: hidden; }

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.card-head h2 { margin-bottom: 2px; }
.card-head p { margin: 0; }

/* ==========================================================================
   page head — title + one-line explanation on the left, the page's
   primary action on the right
   ========================================================================== */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.page-head .lede { margin-bottom: 0; max-width: 560px; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  text-decoration: none;
  margin-bottom: 10px;
  transition: color var(--t);
}
.back-link:hover { color: var(--text); }

.btn-icon { display: inline-flex; align-items: center; gap: 7px; }

/* ==========================================================================
   data table
   ========================================================================== */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.table-count { font-size: 12.5px; color: var(--text-2); white-space: nowrap; }

.search {
  position: relative;
  flex: 0 1 280px;
}
.search svg {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-2);
  pointer-events: none;
}
.search .input { padding-left: 34px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-align: left;
  padding: 10px 18px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr[data-href], .data-table tbody tr.is-clickable { cursor: pointer; transition: background var(--t); }
.data-table tbody tr[data-href]:hover, .data-table tbody tr.is-clickable:hover { background: #F7F9F9; }
.data-table .col-muted { color: var(--text-2); }
.data-table .col-action { text-align: right; width: 1%; white-space: nowrap; }

.row-link {
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}
.row-link:hover { color: var(--accent-dark); }
.row-link ~ .kind-chip { margin-left: 6px; }

.table-empty {
  padding: 40px 18px;
  text-align: center;
  font-size: 13px;
  color: var(--text-2);
}

/* list pages hold wide tables; let them use more of the screen */
.content--wide { max-width: 1200px; }

.table-scroll { overflow-x: auto; }

.cell-strong { font-weight: 600; }
.cell-sub { margin-left: 6px; font-size: 12px; color: var(--text-2); }
.cell-num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* organization kind — neutral chip; color is not the only cue, the word is */
.kind-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--paper);
  border: 1px solid var(--line);
  white-space: nowrap;
}

/* pagination */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.pager-info { font-size: 12.5px; color: var(--text-2); }
.pager-pages { display: flex; align-items: center; gap: 4px; }
.pager-btn {
  min-width: 30px; height: 30px;
  padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-decoration: none;
  transition: background var(--t), color var(--t);
}
a.pager-btn:hover { background: var(--paper); }
.pager-btn.is-current { background: var(--ink); color: #fff; font-weight: 600; }
.pager-gap { padding: 0 4px; color: var(--text-2); }

.table-empty a { color: var(--accent-dark); margin-left: 4px; }

.empty-state { text-align: center; padding: 44px 24px; }
.empty-state h2 { font-size: 15px; margin-bottom: 6px; }
.empty-state p { max-width: 420px; margin: 0 auto 18px; }

.tag-self {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-dark);
  background: var(--accent-soft);
  vertical-align: 1px;
}

/* status pill — dot + word, so the state never relies on color alone */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
}
.status-pill::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #B7C0BF;
}
.status-pill--on { color: var(--success); }
.status-pill--on::before { background: var(--success); }

/* ==========================================================================
   form fields — same input treatment as the login page, so a field looks
   the same wherever it appears
   ========================================================================== */
.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.field-label .optional { font-weight: 500; color: var(--text-2); margin-left: 4px; }

.input {
  width: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  transition: border-color var(--t), box-shadow var(--t);
}
.input::placeholder { color: #A6AFAE; }
.input:hover { border-color: #c7cfce; }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select.input {
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%236C7476' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 8 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  cursor: pointer;
}
select.input:disabled { background-color: var(--paper); color: var(--text-2); cursor: not-allowed; }
.input.is-invalid { border-color: var(--danger); }
.input.is-invalid:focus { box-shadow: 0 0 0 3px var(--danger-soft); }

.field-hint { font-size: 12px; color: var(--text-2); margin-top: 6px; }
.field-error { display: none; font-size: 12px; color: var(--danger); margin-top: 6px; }
.field.has-error .field-error { display: block; }
.field.has-error .field-hint { display: none; }

/* a grid row of fields: spacing lives on the grid, so a field that happens
   to be the last in its row doesn't collapse the gap to the next row */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 16px; margin-bottom: 18px; }
.field-grid:last-child { margin-bottom: 0; }
.field-grid > .field { margin-bottom: 0; }

/* segmented choice (e.g. 啟用 / 停用) */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  padding: 6px 16px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--t), color var(--t), box-shadow var(--t);
}
.segmented input:checked + label {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.segmented input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 1px; }
.segmented.is-disabled { opacity: .6; }
.segmented.is-disabled label { cursor: not-allowed; }

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.form-actions .form-status { margin-left: auto; font-size: 12.5px; color: var(--text-2); }

/* form-level error: collapses to nothing until there is something to say */
.form-alert {
  display: none;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 18px;
}
.form-alert svg { flex-shrink: 0; margin-top: 2px; }
.form-alert.is-visible { display: flex; }

/* button busy state */
.btn .btn-spinner {
  display: none;
  width: 13px; height: 13px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: ui-spin .7s linear infinite;
}
.btn.is-loading .btn-spinner { display: inline-block; }
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* danger zone — the one destructive action, set apart from the form */
.card--danger { border-color: rgba(220,53,69,.28); }
.card--danger .card-head { margin-bottom: 0; align-items: center; }

/* ==========================================================================
   list of actions (home)
   ========================================================================== */
.action-list { list-style: none; margin: 0; padding: 0; }
.action-list li + li { border-top: 1px solid var(--line); }
.action-list a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 20px;
  color: var(--text);
  text-decoration: none;
  transition: background var(--t);
}
.action-list a:hover { background: #F7F9F9; }
.action-list .al-icon {
  width: 34px; height: 34px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  display: flex; align-items: center; justify-content: center;
}
.action-list .al-text { flex: 1; min-width: 0; }
.action-list .al-title { display: block; font-size: 13.5px; font-weight: 600; }
.action-list .al-desc { display: block; font-size: 12.5px; color: var(--text-2); margin-top: 1px; }
.action-list .al-chev { color: #B7C0BF; transition: transform var(--t), color var(--t); }
.action-list a:hover .al-chev { color: var(--accent-dark); transform: translateX(2px); }

.facts { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 0; }
.facts div { display: flex; flex-direction: column; gap: 2px; }
.facts dt { font-size: 12px; font-weight: 500; color: var(--text-2); }
.facts dd { margin: 0; font-size: 15px; font-weight: 600; color: var(--text); }
.facts dd small { font-size: 12.5px; font-weight: 500; color: var(--text-2); margin-left: 4px; }

/* ==========================================================================
   switch — a checkbox drawn as an on/off toggle (role="switch")
   ========================================================================== */
.switch {
  position: relative;
  flex-shrink: 0;
  width: 34px; height: 20px;
  margin: 0;
  appearance: none;
  border-radius: 999px;
  background: #CDD5D4;
  cursor: pointer;
  transition: background var(--t);
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(20,28,28,.25);
  transition: transform var(--t);
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(14px); }
/* group switch with only some children on */
.switch:indeterminate { background: rgba(26,188,156,.45); }
.switch:indeterminate::after { transform: translateX(7px); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch:disabled { cursor: not-allowed; opacity: .55; }

/* ==========================================================================
   role editor — permissions on the left, a live preview of the menu the
   role will see on the right
   ========================================================================== */
.role-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 20px;
  align-items: start;
}
.role-layout > .role-side { position: sticky; top: calc(var(--topbar-h) + 20px); }

.perm-toolbar { display: flex; align-items: center; gap: 6px; }
.perm-count { font-size: 12.5px; color: var(--text-2); margin-right: 6px; font-variant-numeric: tabular-nums; }

.perm-section + .perm-section { margin-top: 18px; }
.perm-section-title { font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.perm-list { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }

.perm-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 14px;
  margin: 0;
  cursor: pointer;
  transition: background var(--t);
}
.perm-row + .perm-row, .perm-group + .perm-row, .perm-row + .perm-group, .perm-group + .perm-group { border-top: 1px solid var(--line); }
.perm-row:hover { background: #F7F9F9; }
.perm-row.is-locked { cursor: default; }
.perm-row.is-locked:hover { background: none; }
.perm-row > svg { color: var(--text-2); flex-shrink: 0; }
.perm-name { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 500; color: var(--text); }
.perm-note { font-size: 12px; color: var(--text-2); white-space: nowrap; }

.perm-group > .perm-row { font-weight: 600; }
.perm-group-items { position: relative; }
.perm-group-items .perm-row { padding-left: 40px; border-top: 1px solid var(--line); }
.perm-group-items::before {
  content: '';
  position: absolute;
  left: 21px; top: 0; bottom: 14px;
  border-left: 1px solid var(--line);
}

.notice {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 11px 13px;
  margin-bottom: 16px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
}
.notice svg { flex-shrink: 0; margin-top: 2px; color: var(--accent-dark); }

/* menu preview — a miniature of the sidebar, same ink material */
.menu-preview {
  border-radius: var(--radius);
  background-color: var(--ink);
  background-image: radial-gradient(rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 22px 22px;
  padding: 12px 8px;
  box-shadow: var(--shadow-sm);
}
.mp-caption { font-size: 12px; color: var(--text-2); margin: 8px 2px 0; line-height: 1.55; }
.mp-title { font-size: 12.5px; font-weight: 600; color: var(--text); margin: 0 2px 8px; }
.mp-section { font-size: 10px; font-weight: 600; color: var(--ink-text-3); padding: 10px 9px 5px; }
.mp-section:first-child { padding-top: 0; }
.mp-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 9px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-text-2);
  animation: mp-in .18s ease-out;
}
.mp-item svg { width: 14px; height: 14px; flex-shrink: 0; opacity: .85; }
.mp-group-items { margin-left: 16px; padding-left: 5px; border-left: 1px solid var(--ink-line); }
.mp-group-items .mp-item { font-size: 12px; }
.menu-preview [hidden] { display: none !important; }
@keyframes mp-in { from { opacity: 0; transform: translateX(-3px); } to { opacity: 1; transform: none; } }

/* member chips */
.member-list { display: flex; flex-wrap: wrap; gap: 6px; }
.member-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--text);
  text-decoration: none;
  transition: border-color var(--t), background var(--t);
}
a.member-chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.member-chip .user-avatar { width: 20px; height: 20px; border-radius: 50%; }

/* role list — how much of the product a role can use */
.meter { display: inline-flex; align-items: center; gap: 9px; font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.meter-bar { width: 64px; height: 5px; border-radius: 999px; background: var(--paper); overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.meter-bar span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.cell-desc { display: block; font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* contextual save bar — appears only while there is something to save */
.save-bar {
  position: sticky;
  bottom: 16px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
  padding: 10px 10px 10px 16px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--ink-text);
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(20,28,28,.22);
  transform: translateY(12px);
  opacity: 0;
  visibility: hidden;
  transition: transform .2s cubic-bezier(.16,1,.3,1), opacity .2s, visibility 0s .2s;
}
.save-bar.is-visible { transform: none; opacity: 1; visibility: visible; transition: transform .2s cubic-bezier(.16,1,.3,1), opacity .2s; }
.save-bar .save-bar-text { flex: 1; }
.save-bar .btn-ghost-ink { --bs-btn-color: var(--ink-text-2); --bs-btn-hover-color: #fff; --bs-btn-hover-bg: rgba(255,255,255,.08); --bs-btn-border-color: transparent; --bs-btn-hover-border-color: transparent; --bs-btn-active-bg: rgba(255,255,255,.12); --bs-btn-active-color: #fff; }

@media (max-width: 1080px) {
  .role-layout { grid-template-columns: minmax(0, 1fr); }
  .role-layout > .role-side { position: static; }
}

/* ==========================================================================
   view as — while acting as another user, the avatar in the top bar wears a
   small eye badge, and the user menu says who is viewing and how to go back
   ========================================================================== */
.user-avatar { position: relative; }
.viewas-badge {
  position: absolute;
  right: -4px; bottom: -4px;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--ink);
  box-shadow: 0 0 0 2px var(--surface);
  display: flex; align-items: center; justify-content: center;
}

.user-menu-viewas {
  margin-top: 6px;
  padding: 3px 8px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent-dark) !important;
  font-weight: 600;
  align-self: flex-start;
}
.user-menu button.dropdown-item { font-family: var(--font); }

/* the "view as" entry point on a user's page */
.viewas-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
}
.viewas-preview .user-avatar { width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; }
.viewas-preview strong { display: block; font-size: 14px; color: var(--text); }
.viewas-preview span { font-size: 12.5px; color: var(--text-2); }
.viewas-points { margin: 0; padding-left: 18px; }
.viewas-points li + li { margin-top: 4px; }

/* ==========================================================================
   audit log — a day-grouped timeline; each entry reads as one sentence and
   opens to show exactly what changed
   ========================================================================== */
.audit-filter { padding: 14px 16px; margin-bottom: 14px; }
.audit-filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.audit-filter-row + .audit-filter-row { margin-top: 10px; }
.audit-filter select.input { width: auto; min-width: 150px; }
.audit-dates { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.audit-dates .input { width: auto; padding-top: 7px; padding-bottom: 7px; }
.audit-search { flex: 1 1 240px; }
.audit-clear { font-size: 13px; color: var(--accent-dark); text-decoration: none; white-space: nowrap; }
.audit-clear:hover { text-decoration: underline; }

.audit-day {
  position: sticky;
  top: var(--topbar-h);
  z-index: 2;
  padding: 8px 18px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}
.audit-entry { border-bottom: 1px solid var(--line); }
.audit-entry:last-of-type { border-bottom: none; }

.audit-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 18px;
  list-style: none;
  cursor: pointer;
  transition: background var(--t);
}
.audit-row::-webkit-details-marker { display: none; }
.audit-row:hover { background: #F7F9F9; }
.audit-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.audit-time { width: 40px; flex-shrink: 0; font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.audit-icon {
  width: 28px; height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper);
  color: var(--text-2);
}
.tone-create .audit-icon { background: var(--accent-soft); color: var(--accent-dark); }
.tone-danger .audit-icon { background: var(--danger-soft); color: var(--danger); }
.tone-viewas .audit-icon { background: var(--ink); color: var(--accent); }

.audit-text { flex: 1; min-width: 0; }
.audit-line { display: block; font-size: 13.5px; color: var(--text); line-height: 1.5; }
.audit-line strong { font-weight: 600; }
.audit-entity { color: var(--text-2); margin-left: 2px; }
.audit-label { font-weight: 500; color: var(--text); text-decoration: none; }
a.audit-label:hover { color: var(--accent-dark); text-decoration: underline; }
.tone-danger .audit-line { color: var(--text); }
.audit-sub { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 1px; font-size: 12px; color: var(--text-2); }
.tone-danger .audit-sub { color: var(--danger); }

.audit-ip { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.audit-chev { flex-shrink: 0; color: #B7C0BF; transition: transform var(--t); }
.audit-entry[open] .audit-chev { transform: rotate(180deg); }
.audit-entry[open] > .audit-row { background: #F7F9F9; }

.audit-detail {
  padding: 4px 18px 18px 110px;
  background: #F7F9F9;
  animation: audit-open .16s ease-out;
}
@keyframes audit-open { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

.audit-diff {
  width: 100%;
  max-width: 720px;
  margin-bottom: 14px;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  font-size: 13px;
}
.audit-diff th { padding: 7px 12px; background: var(--paper); font-size: 12px; font-weight: 600; color: var(--text-2); text-align: left; border-bottom: 1px solid var(--line); }
.audit-diff td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.audit-diff tr:last-child td { border-bottom: none; }
.audit-diff-field { width: 120px; color: var(--text-2); white-space: nowrap; }
/* the old value struck through, the new one marked — readable without color */
.diff-from { color: var(--danger); text-decoration: line-through; text-decoration-color: rgba(220,53,69,.45); }
.diff-to { color: var(--success); font-weight: 500; }

.audit-facts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px 24px;
  margin: 0;
  max-width: 720px;
}
.audit-facts div { min-width: 0; }
.audit-facts dt { font-size: 11.5px; font-weight: 500; color: var(--text-2); }
.audit-facts dd { margin: 1px 0 0; font-size: 13px; color: var(--text); overflow-wrap: anywhere; }
.audit-facts .audit-wide { grid-column: 1 / -1; }
.audit-token { font-family: var(--bs-font-monospace); font-size: 12px !important; color: var(--text-2) !important; }

@media (max-width: 860px) {
  .audit-ip { display: none; }
  .audit-detail { padding-left: 18px; }
  .audit-filter select.input { flex: 1 1 140px; }
}

/* ==========================================================================
   face thumbnails — the stored image is already the face crop (facecard's
   cropFaceImage), so a tile just covers; used by the citizen edit page
   and by the recognition result cards
   ========================================================================== */
.face-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--paper);
}
.face-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.face-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 12px; }
.face-tile {
  position: relative;
  margin: 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: box-shadow var(--t), border-color var(--t);
}
.face-tile:hover { border-color: #c7cfce; box-shadow: var(--shadow-sm); }
.face-type { font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.face-type--masked { color: var(--accent-dark); }

/* ==========================================================================
   god console marks — the only place the console differs from the
   regular product shell: a tag on the brand and on the signed-in account
   ========================================================================== */
.god-tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--ink);
  background: var(--accent);
}
.topbar-user .god-tag { font-size: 10px; padding: 1px 6px; }

/* ==========================================================================
   toast — ink chip at the bottom right, same material as the sidebar
   ========================================================================== */
.toast-stack {
  position: fixed;
  right: 20px; bottom: 20px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.ui-toast {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 220px;
  max-width: 360px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--ink-text);
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(20,28,28,.18);
  animation: ui-toast-in .22s cubic-bezier(.16,1,.3,1);
  pointer-events: auto;
}
.ui-toast svg { flex-shrink: 0; color: var(--accent); }
.ui-toast--error svg { color: #F2828D; }
.ui-toast.is-leaving { opacity: 0; transform: translateY(4px); transition: opacity .18s, transform .18s; }
@keyframes ui-toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Bootstrap bridge for the confirm modal */
.modal-content {
  --bs-modal-border-radius: var(--radius);
  --bs-modal-border-color: var(--line);
  font-family: var(--font);
}
.modal-title { font-size: 15px; font-weight: 700; }
.modal-body { font-size: 13.5px; color: var(--text-2); line-height: 1.65; }
.btn-danger, .btn-outline-danger, .btn-outline-secondary, .btn-light { --bs-btn-border-radius: var(--radius-sm); }

/* ==========================================================================
   mobile
   ========================================================================== */
.mob-toggle {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 200;
  width: 36px; height: 36px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius-sm);
  align-items: center; justify-content: center;
}

.sb-overlay { display: none; position: fixed; inset: 0; background: rgba(15,18,18,.45); z-index: 99; }
.sb-overlay.show { display: block; }

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s cubic-bezier(.4,0,.2,1); }
  .sidebar.open { transform: translateX(0); }
  .mob-toggle { display: flex; }
  .main { margin-left: 0; }
  .topbar { padding: 0 18px 0 58px; }
  .content { padding: 24px 18px 40px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .field-grid { grid-template-columns: 1fr; }
  .data-table .col-hide-sm { display: none; }
  .table-toolbar { flex-wrap: wrap; }
  .search { flex: 1 1 100%; }
  .toast-stack { left: 16px; right: 16px; }
  .ui-toast { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .main, .sb-item, .sb-item::before, .sb-group-body, .sb-chev, .sb-label, .sb-rail-arrow { transition-duration: .001ms !important; }
  .ui-toast, .btn .btn-spinner, .mp-item, .audit-detail { animation: none; }
  .switch, .switch::after, .save-bar { transition-duration: .001ms; }
}
