:root {
  --bg: #f5f6f8; --panel: #ffffff; --text: #1d2330; --muted: #677085; --line: #dfe3ea;
  --accent: #2563a8; --accent-text: #ffffff; --row-hover: #eef4fb; --banner: #fff4d6; --banner-text: #6b4e00;
  --danger: #b42318; --error-bg: #fdecea; --tag: #eceff4;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --panel: #1c2027; --text: #e4e7ec; --muted: #98a1b2; --line: #2e3440;
    --accent: #5b9be0; --accent-text: #0b1220; --row-hover: #232a35; --banner: #3a3115; --banner-text: #f3dc9b;
    --danger: #f07167; --error-bg: #3b1c1a; --tag: #2a303b;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 12px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.globalsearch { flex: 1; max-width: 420px; }
.globalsearch input { width: 100%; }
.usernav { margin-left: auto; display: flex; gap: 14px; align-items: center; }
.navtoggle { display: none; }
.banner { background: var(--banner); color: var(--banner-text); padding: 6px 16px; font-size: 0.9rem; }

.layout { display: flex; min-height: calc(100vh - 50px); }
.sidebar { width: 230px; flex: none; padding: 12px; border-right: 1px solid var(--line); background: var(--panel);
  overflow-y: auto; max-height: calc(100vh - 50px); position: sticky; top: 50px; }
.sidebar summary { font-weight: 600; cursor: pointer; padding: 6px 4px; }
.sidebar ul { list-style: none; margin: 0 0 8px; padding: 0 0 0 8px; }
.sidebar li a { display: block; padding: 4px 8px; border-radius: 6px; color: var(--text); }
.sidebar li a.active, .sidebar li a:hover { background: var(--row-hover); text-decoration: none; }
main { flex: 1; min-width: 0; padding: 16px 20px 40px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.card.narrow { max-width: 420px; margin: 40px auto; }
.card.narrow label { display: block; margin-bottom: 12px; }
.card.narrow input { width: 100%; margin-top: 4px; }
.appgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
table.plain { width: 100%; border-collapse: collapse; }
table.plain td { padding: 4px 0; border-bottom: 1px solid var(--line); }

.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.pagehead.sticky { position: sticky; top: 50px; background: var(--bg); z-index: 5; padding: 8px 0; }
.actions { display: flex; gap: 8px; align-items: center; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar .count { margin-left: auto; }
.notice { background: var(--banner); color: var(--banner-text); padding: 8px 12px; border-radius: 6px; }
.error { background: var(--error-bg); color: var(--danger); padding: 8px 12px; border-radius: 6px; }
.tag { background: var(--tag); color: var(--muted); border-radius: 4px; padding: 1px 6px; font-size: 0.75rem; font-weight: normal; }

input, select, textarea, button, .button { font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; }
textarea { width: 100%; }
button, .button { cursor: pointer; display: inline-block; }
button:hover, .button:hover { border-color: var(--accent); text-decoration: none; }
.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.danger { color: var(--danger); border-color: var(--danger); }

.tablewrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.card .tablewrap { border: none; }
table.grid { border-collapse: collapse; width: 100%; }
.grid th, .grid td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top;
  max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.grid th { position: sticky; top: 0; background: var(--panel); font-weight: 600; white-space: nowrap; }
.grid th a { color: var(--text); }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: var(--row-hover); }
.grid.compact th, .grid.compact td { padding: 4px 8px; }
.grid input:not([type=checkbox]), .grid select { min-width: 120px; }
.pager { display: flex; gap: 16px; justify-content: center; padding: 14px; }
.check { color: var(--accent); font-weight: 700; }

.recordgrid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; }
dl.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px 20px; margin: 0; }
dl.fields .wide { grid-column: 1 / -1; }
dl.fields dt, .meta dt { color: var(--muted); font-size: 0.8rem; }
dl.fields dd, .meta dd { margin: 2px 0 0; word-break: break-word; }
.meta dl { margin: 0; }
.meta dd { margin-bottom: 8px; }
.history { padding-left: 16px; margin: 0; font-size: 0.85rem; }
.history ul { padding-left: 14px; }

.formgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px 20px; }
.formgrid > label, .formgrid > .readonly { display: flex; flex-direction: column; gap: 4px; }
.formgrid > .wide { grid-column: 1 / -1; }
.formgrid > .checkline { flex-direction: row; align-items: center; gap: 8px; padding-top: 18px; }
.formgrid > label > span:first-child, .readonly > span { color: var(--muted); font-size: 0.8rem; }
.readonly > div { padding: 6px 0; }
.req { color: var(--danger); }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.suffix { display: flex; align-items: center; gap: 6px; }
.suffix input { flex: 1; min-width: 0; }
.suffix i { color: var(--muted); font-style: normal; }
.linkpicker { position: relative; display: block; }
.linkpicker .linksearch { width: 100%; }
.linkresults { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; max-height: 260px; overflow-y: auto; display: none; }
.linkresults.open { display: block; }
.linkresults button { display: block; width: 100%; text-align: left; border: none; border-radius: 0; }
.linkresults button:hover { background: var(--row-hover); }
.roleform { display: grid; grid-template-columns: 220px 1fr auto auto; gap: 8px; align-items: start; margin-bottom: 10px; }
.danger-zone { border-color: var(--danger); }
code { background: var(--tag); padding: 1px 4px; border-radius: 4px; font-size: 0.8rem; word-break: break-all; }

@media (max-width: 900px) {
  .recordgrid { grid-template-columns: 1fr; }
  .roleform { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .navtoggle { display: inline-block; }
  .sidebar { display: none; position: fixed; top: 50px; left: 0; bottom: 0; z-index: 30; max-height: none; }
  body.nav-open .sidebar { display: block; }
  main { padding: 12px 16px 40px; }
  .usernav .muted { display: none; }
  .globalsearch { display: none; }
}
h2.inline { display: inline; }
summary { cursor: pointer; }

/* Company split (Standard E&S / Standard WS) */
.co-badge { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  white-space: nowrap; vertical-align: middle; }
.co-before { background: #e7eefb; color: #1f4f9c; }
.co-after { background: #e3f4ea; color: #1d6b3d; }
@media (prefers-color-scheme: dark) {
  .co-before { background: #1e2c45; color: #a9c4f5; }
  .co-after { background: #1b3326; color: #9fdcb7; }
}
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 10px; }
.segmented a { padding: 6px 14px; color: var(--text); border-right: 1px solid var(--line); }
.segmented a:last-child { border-right: none; }
.segmented a.on { background: var(--accent); color: var(--accent-text); text-decoration: none; }

/* Feedback */
.feedback-fab { position: fixed; right: 18px; bottom: 18px; z-index: 40; border-radius: 999px; padding: 10px 18px;
  background: var(--accent); color: var(--accent-text); border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2); }
.feedback-dialog { border: 1px solid var(--line); border-radius: 12px; padding: 18px; width: min(460px, calc(100vw - 32px));
  background: var(--panel); color: var(--text); }
.feedback-dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.feedback-form label { display: block; margin-bottom: 12px; }
.feedback-form input, .feedback-form textarea { width: 100%; margin-top: 4px; }
.feedback-form .actions { justify-content: flex-end; }
.field-fb { border: none; background: none; padding: 0 4px; margin-left: 2px; font-size: 0.8rem; color: var(--muted);
  opacity: 0.35; cursor: pointer; }
dl.fields > div:hover .field-fb, .formgrid > label:hover .field-fb, .field-fb:focus { opacity: 1; }
.field-fb:hover { color: var(--accent); }
.linkish { border: none; background: none; padding: 0; color: var(--accent); cursor: pointer; text-align: left; }
.linkish:hover { text-decoration: underline; }
.pickhint { padding: 6px 9px; }
.count-badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 999px; background: var(--danger);
  color: #fff; font-size: 0.75rem; text-align: center; }
.feedback-list { list-style: none; margin: 0; padding: 0; }
.feedback-list li { border-bottom: 1px solid var(--line); padding: 10px 0; }
.feedback-list li.done { opacity: 0.6; }
.feedback-list p { margin: 4px 0 8px; white-space: pre-wrap; }
.fb-meta { font-size: 0.85rem; color: var(--muted); }
.inline-actions { display: flex; gap: 6px; }
.grid.static tbody tr { cursor: default; }
main { padding-bottom: 80px; }

[hidden] { display: none !important; }

/* Lists: the header row and the first column(s) stay put while scrolling */
.listwrap { max-height: calc(100vh - 230px); overflow: auto; }
.listwrap .grid th { z-index: 2; }
.listwrap .grid th:first-child, .listwrap .grid td:first-child { position: sticky; left: 0; background: var(--panel); z-index: 1; }
.listwrap .grid th:first-child { z-index: 3; }
.listwrap .grid.has-company th:first-child, .listwrap .grid.has-company td:first-child { min-width: 118px; max-width: 118px; }
.listwrap .grid.has-company th:nth-child(2), .listwrap .grid.has-company td:nth-child(2) {
  position: sticky; left: 118px; background: var(--panel); z-index: 1; box-shadow: 2px 0 0 var(--line); }
.listwrap .grid.has-company th:nth-child(2) { z-index: 3; }
.listwrap .grid:not(.has-company) td:first-child { box-shadow: 2px 0 0 var(--line); }
.listwrap .grid tbody tr:hover td { background: var(--row-hover); }
.columns-dialog { width: min(520px, calc(100vw - 32px)); }
.columns-dialog .colsearch { width: 100%; margin-bottom: 8px; }
.collist { list-style: none; margin: 0 0 12px; padding: 0; max-height: 50vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.collist li { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.collist li:last-child { border-bottom: none; }
.collist label { flex: 1; cursor: pointer; }
.collist .mv button { border: none; background: none; padding: 2px 6px; color: var(--muted); }
.collist .mv button:hover { color: var(--accent); }
/* one line per row so more rows fit on screen; hover shows the full value */
.listwrap .grid td { white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }

/* Sign-in */
.ms-button { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 10px; }
.card.narrow details { margin-top: 14px; }
.pwform { margin-top: 10px; }

.test-banner { background: #b42318; color: #fff; font-weight: 600; text-align: center; }
