/* ruisin-dms — single stylesheet. Mobile-first, light + dark, no external assets. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1b2430;
  --muted: #5d6877;
  --border: #d9dee5;
  --accent: #1f5fbf;
  --accent-hover: #194d9b;
  --accent-fg: #ffffff;
  --accent-soft: #e4edfb;
  --ok: #17794a;
  --ok-soft: #dff3e8;
  --warn: #946200;
  --warn-soft: #fdf0cf;
  --bad: #b3261e;
  --bad-soft: #fbe3e1;
  --info-soft: #e4edfb;
  --shadow: 0 1px 2px rgba(20, 30, 45, .06), 0 2px 8px rgba(20, 30, 45, .05);
  --radius: 12px;
  /* Density (menu > Theme): html[data-density] = comfortable | compact. Every size below reads these tokens. */
  --dms-density-tap: 46px;      /* buttons, inputs, selects */
  --dms-density-tap-sm: 36px;   /* button.small */
  --dms-density-card: 1rem;     /* card / tile / list-card padding */
  --dms-density-gap: .9rem;     /* vertical gap between stacked blocks and grid cells */
  --dms-density-row: 46px;      /* minimum height of a list row / menu row */
  --dms-density-cell: .65rem;   /* table cell padding (vertical) */
  --tap: var(--dms-density-tap);
  /* --dms-bottom-offset: height of whatever is pinned to the bottom edge of the screen (the phone tab bar + the iPhone
     home-indicator inset). 0px on desktop and on the login page. Anything that floats at the bottom (assistant button,
     feedback button, toasts, tips, install card) must sit at `bottom: calc(var(--dms-bottom-offset) + 1rem)` so it never
     covers the tab bar. Defined here; set by html.has-tabbar in feat-w6-mobile.css (phones only). */
  --dms-bottom-offset: 0px;
}
/* Colour theme (menu > Theme): html[data-theme] = auto (unset) | light | dark. Same token set, three ways in. */
html[data-density="compact"] {
  --dms-density-tap: 44px; --dms-density-tap-sm: 40px; --dms-density-card: .7rem; --dms-density-gap: .55rem;
  --dms-density-row: 44px; --dms-density-cell: .4rem;
}
@media (min-width: 641px) { html[data-density="compact"] { --dms-density-tap: 38px; --dms-density-tap-sm: 32px; --dms-density-row: 38px; } }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) { /* Auto only: any chosen theme (light, paper, grey, ...) beats the phone's dark mode */
    --bg: #12161c;
    --surface: #1b2129;
    --surface-2: #242b35;
    --text: #e8ecf1;
    --muted: #9aa5b4;
    --border: #323b47;
    --accent: #6ea3f2;
    --accent-hover: #8bb7f6;
    --accent-fg: #0c1624;
    --accent-soft: #22324a;
    --ok: #5ccf94;
    --ok-soft: #173326;
    --warn: #f1c35a;
    --warn-soft: #3a2f13;
    --bad: #ff8d84;
    --bad-soft: #43201d;
    --info-soft: #22324a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c;
  --surface: #1b2129;
  --surface-2: #242b35;
  --text: #e8ecf1;
  --muted: #9aa5b4;
  --border: #323b47;
  --accent: #6ea3f2;
  --accent-hover: #8bb7f6;
  --accent-fg: #0c1624;
  --accent-soft: #22324a;
  --ok: #5ccf94;
  --ok-soft: #173326;
  --warn: #f1c35a;
  --warn-soft: #3a2f13;
  --bad: #ff8d84;
  --bad-soft: #43201d;
  --info-soft: #22324a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
/* Ready-made themes (Theme sheet). Every pair of text/background colours below is checked for WCAG AA (4.5:1) by
   scripts/check-theme-contrast.mjs; the numbers are in docs/FEATURE-theme.md. data-theme="light" = Classic Light (the :root
   values), "dark" = Dark Slate (above). */
:root[data-theme="paper"] { /* Light Paper: warm off-white, ink text */
  --bg: #f5efe3; --surface: #fffcf5; --surface-2: #ece4d3; --text: #2a251e; --muted: #645a4b; --border: #d6ccb6;
  --accent: #1a5490; --accent-hover: #134272; --accent-fg: #ffffff; --accent-soft: #e0eaf4;
  --ok: #17663f; --ok-soft: #dbeedf; --warn: #7d5200; --warn-soft: #f6e6bd; --bad: #a3231b; --bad-soft: #f6dcd7; --info-soft: #e0eaf4;
  --shadow: 0 1px 2px rgba(60, 45, 20, .08), 0 2px 8px rgba(60, 45, 20, .06); color-scheme: light;
}
:root[data-theme="grey"] { /* Soft Grey: neutral light grey, low glare */
  --bg: #e6e8eb; --surface: #f3f4f6; --surface-2: #d9dce1; --text: #1f242b; --muted: #4f5967; --border: #bcc2cb;
  --accent: #244f93; --accent-hover: #1b3d73; --accent-fg: #ffffff; --accent-soft: #d5deec;
  --ok: #17603c; --ok-soft: #d3e6da; --warn: #745000; --warn-soft: #eadcb3; --bad: #9c231c; --bad-soft: #ecd3d0; --info-soft: #d5deec;
  --shadow: 0 1px 2px rgba(20, 30, 45, .08), 0 2px 8px rgba(20, 30, 45, .06); color-scheme: light;
}
:root[data-theme="midnight"] { /* Midnight: true black for OLED screens */
  --bg: #000000; --surface: #0a0c0f; --surface-2: #14181d; --text: #e9edf2; --muted: #9aa4b2; --border: #262d36;
  --accent: #7db0f5; --accent-hover: #9bc3f8; --accent-fg: #04101f; --accent-soft: #11213a;
  --ok: #5ccf94; --ok-soft: #0c2217; --warn: #f1c35a; --warn-soft: #272008; --bad: #ff8d84; --bad-soft: #321410; --info-soft: #11213a;
  --shadow: none; color-scheme: dark;
}
:root[data-theme="hc-light"] { /* High Contrast Light */
  --bg: #ffffff; --surface: #ffffff; --surface-2: #ececec; --text: #000000; --muted: #333333; --border: #1a1a1a;
  --accent: #0030a8; --accent-hover: #00227a; --accent-fg: #ffffff; --accent-soft: #d9e4ff;
  --ok: #004d26; --ok-soft: #d2f0de; --warn: #593b00; --warn-soft: #ffe9ad; --bad: #8a0000; --bad-soft: #ffd9d4; --info-soft: #d9e4ff;
  --shadow: 0 0 0 1px #1a1a1a; color-scheme: light;
}
:root[data-theme="hc-dark"] { /* High Contrast Dark */
  --bg: #000000; --surface: #000000; --surface-2: #1c1c1c; --text: #ffffff; --muted: #d4d4d4; --border: #c4c4c4;
  --accent: #6fc3ff; --accent-hover: #9ad7ff; --accent-fg: #000000; --accent-soft: #002b45;
  --ok: #6dffa6; --ok-soft: #003d1a; --warn: #ffd84d; --warn-soft: #3d3000; --bad: #ff9d95; --bad-soft: #4d0000; --info-soft: #002b45;
  --shadow: 0 0 0 1px #c4c4c4; color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
/* Text size (menu > Text size). Default: Small on phones, Normal elsewhere; feat-w6-mobile.js sets html[data-text-size]. */
html[data-text-size="small"] { font-size: 15px; }
html[data-text-size="normal"] { font-size: 16px; }
html[data-text-size="large"] { font-size: 18px; }
@media (max-width: 640px) { html:not([data-text-size]) { font-size: 15px; } }
body {
  margin: 0; background: var(--bg); color: var(--text); padding-bottom: var(--dms-bottom-offset);
  font: 1rem/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: .88em; }
.hidden { display: none !important; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: var(--dms-density-gap); }
.grow { flex: 1 1 auto; min-width: 0; }

/* ---------- header / nav ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex; align-items: center; gap: .6rem; padding: .5rem 1rem; max-width: 1200px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand svg { width: 30px; height: 30px; flex: none; }
.brand span small { display: block; font-weight: 500; font-size: .7rem; color: var(--muted); letter-spacing: .04em; }
.spacer { flex: 1; }
.topbar select { max-width: 9.5rem; min-height: 38px; padding: .3rem .5rem; }
.navstrip { border-top: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.navstrip::-webkit-scrollbar { display: none; }
.nav { display: flex; gap: .25rem; padding: .35rem 1rem; max-width: 1200px; margin: 0 auto; }
.nav a {
  display: inline-flex; align-items: center; gap: .35rem; min-height: 40px; padding: 0 .85rem;
  border-radius: 999px; color: var(--muted); font-weight: 600; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.badge {
  display: inline-block; min-width: 1.35rem; padding: 0 .4rem; border-radius: 999px; text-align: center;
  background: var(--bad); color: #fff; font-size: .75rem; line-height: 1.35rem; font-weight: 700;
}
main { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: var(--dms-density-gap); }
.pagehead h1 { margin: 0; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .4rem; }

/* ---------- controls ---------- */
button, .btn {
  font: inherit; min-height: var(--tap); padding: 0 1.1rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; text-decoration: none;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover, button.primary:hover { background: var(--accent-hover); }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.danger { background: var(--surface); color: var(--bad); border-color: var(--bad); }
button.danger.solid { background: var(--bad); color: #fff; }
button.small, .btn.small { min-height: var(--dms-density-tap-sm); padding: 0 .75rem; font-size: .88rem; }
button.ghost { background: transparent; border-color: transparent; color: var(--accent); }
button.big { min-height: 58px; font-size: 1.1rem; }
input, select, textarea {
  font: inherit; width: 100%; min-height: var(--tap); padding: .5rem .7rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: 1.25rem; min-height: 0; height: 1.25rem; accent-color: var(--accent); flex: none; }
input[type=file] { padding: .6rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
label.field { display: block; font-weight: 600; font-size: .9rem; }
label.field > .lbl { display: block; margin-bottom: .25rem; }
label.field > input, label.field > select, label.field > textarea { font-weight: 400; }
.hint { font-weight: 400; color: var(--muted); font-size: .82rem; margin-top: .2rem; }
.check { display: flex; align-items: center; gap: .55rem; min-height: 40px; font-weight: 500; cursor: pointer; }
.checks { display: flex; flex-wrap: wrap; gap: .25rem 1.1rem; }
.form-grid { display: grid; gap: var(--dms-density-gap); grid-template-columns: 1fr; }
@media (min-width: 720px) { .form-grid.two { grid-template-columns: 1fr 1fr; } .form-grid .span2 { grid-column: span 2; } }

.seg { display: grid; grid-template-columns: 1fr; gap: .4rem; }
@media (min-width: 720px) { .seg { grid-template-columns: repeat(3, 1fr); } }
.seg label {
  display: flex; gap: .6rem; align-items: flex-start; padding: .65rem .8rem; border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer; background: var(--surface); min-height: var(--tap);
}
.seg label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.seg label b { display: block; }
.seg label small { color: var(--muted); display: block; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: var(--dms-density-card);
}
.card > h2:first-child, .card > .cardhead:first-child { margin-top: 0; }
.cardhead { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; flex-wrap: wrap; }
.cardhead h2 { margin: 0; }
.grid { display: grid; gap: var(--dms-density-gap); grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.side { grid-template-columns: 2fr 1fr; align-items: start; } }
.tiles { display: grid; gap: calc(var(--dms-density-gap) * .8); grid-template-columns: repeat(2, 1fr); }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(5, 1fr); } }
.tile {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: calc(var(--dms-density-card) * .8) var(--dms-density-card); color: var(--text); box-shadow: var(--shadow);
}
.tile:hover { text-decoration: none; border-color: var(--accent); }
.tile .n { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.tile .l { color: var(--muted); font-size: .85rem; text-transform: capitalize; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.kv dt { color: var(--muted); font-size: .88rem; }
.kv dd { margin: 0; font-weight: 500; word-break: break-word; }

/* ---------- chips ---------- */
.chip {
  display: inline-flex; align-items: center; padding: .12rem .6rem; border-radius: 999px; font-size: .78rem;
  font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; text-transform: capitalize;
}
.chip.effective, .chip.approved, .chip.done { background: var(--ok-soft); color: var(--ok); }
.chip.in_review, .chip.in_workflow, .chip.running, .chip.open, .chip.current, .chip.queued { background: var(--info-soft); color: var(--accent); }
.chip.draft, .chip.pending, .chip.dry_run, .chip.skipped { background: var(--surface-2); color: var(--muted); }
.chip.obsolete, .chip.rejected, .chip.superseded, .chip.withdrawn, .chip.failed, .chip.denied, .chip.disabled { background: var(--bad-soft); color: var(--bad); }
.chip.warn, .chip.missing { background: var(--warn-soft); color: var(--warn); }
.chip.sent { background: var(--ok-soft); color: var(--ok); }
.chips { display: flex; gap: .45rem; overflow-x: auto; padding-bottom: .2rem; scrollbar-width: thin; }
.chips a, .chips button {
  min-height: 38px; padding: 0 .85rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-weight: 600; font-size: .9rem; white-space: nowrap; display: inline-flex; align-items: center;
}
.chips .on { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }

/* ---------- list: table on desktop, cards on mobile ---------- */
.only-wide { display: none; }
@media (min-width: 820px) { .only-wide { display: block; } .only-narrow { display: none; } }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .55rem .7rem; border-bottom: 1px solid var(--border); background: var(--surface-2); }
td { padding: var(--dms-density-cell) .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--surface-2); }
.tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.doccard { display: block; color: var(--text); padding: calc(var(--dms-density-card) * .85) var(--dms-density-card); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.doccard:hover { text-decoration: none; border-color: var(--accent); }
.doccard + .doccard { margin-top: calc(var(--dms-density-gap) * .65); }
.doccard .t { font-weight: 700; margin: .15rem 0 .35rem; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-top: 1rem; }

/* ---------- timeline / workflow ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline > li { position: relative; padding: 0 0 1rem 1.6rem; border-left: 2px solid var(--border); margin-left: .45rem; }
.timeline > li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline > li::before {
  content: ""; position: absolute; left: -.5rem; top: .2rem; width: .85rem; height: .85rem; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--muted);
}
.timeline > li.done::before { background: var(--ok); border-color: var(--ok); }
.timeline > li.current::before { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.timeline > li.rejected::before { background: var(--bad); border-color: var(--bad); }
.task { margin-top: .4rem; padding: .5rem .7rem; background: var(--surface-2); border-radius: 8px; font-size: .92rem; }
.task .c { font-style: italic; color: var(--muted); }
.progress { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ok); }

/* ---------- notices ---------- */
.notice { padding: .8rem 1rem; border-radius: 10px; background: var(--info-soft); color: var(--text); border: 1px solid var(--border); }
.notice.warn { background: var(--warn-soft); border-color: var(--warn); }
.notice.bad { background: var(--bad-soft); border-color: var(--bad); }
.notice.soon { text-align: center; padding: 2rem 1rem; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 2rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }
#toasts { position: fixed; left: 0; right: 0; bottom: 1rem; display: flex; flex-direction: column; align-items: center; gap: .5rem; z-index: 100; pointer-events: none; padding: 0 1rem; }
.toast { pointer-events: auto; max-width: 560px; width: 100%; padding: .75rem 1rem; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: 0 6px 24px rgba(0,0,0,.3); font-weight: 600; }
.toast.error { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 1.2rem; width: min(480px, calc(100vw - 2rem)); }
dialog::backdrop { background: rgba(10, 15, 22, .55); }

/* ---------- login ---------- */
.login { max-width: 460px; margin: 1.5rem auto; }
.login .logo { display: flex; flex-direction: column; align-items: center; gap: .4rem; margin-bottom: 1.2rem; text-align: center; }
.login .logo svg { width: 64px; height: 64px; }
.namebtns { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.namebtns button { min-height: 76px; font-size: 1.25rem; border-radius: 14px; background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.namebtns button:hover { background: var(--accent); color: var(--accent-fg); }
.divider { display: flex; align-items: center; gap: .8rem; color: var(--muted); font-size: .85rem; margin: 1.1rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- workflow designer ---------- */
.stepcard { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: .9rem; }
.stepcard + .stepcard { margin-top: .7rem; }
.stepno { display: inline-flex; width: 1.9rem; height: 1.9rem; border-radius: 50%; background: var(--accent); color: var(--accent-fg); align-items: center; justify-content: center; font-weight: 700; flex: none; }
.cond { margin-top: .7rem; padding: .7rem; border: 1px dashed var(--border); border-radius: 10px; }
.tabs { display: flex; gap: .3rem; overflow-x: auto; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.tabs[role=tablist] { flex-wrap: wrap; overflow-x: visible; } /* admin tabs: wrap, so Permissions is never hidden off-screen on a phone */
.tabs a { padding: .6rem .9rem; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs a:hover { text-decoration: none; background: var(--surface-2); }

@media (max-width: 600px) { .uname { display: none; } }
@media (max-width: 480px) {
  .brand { font-size: .95rem; white-space: nowrap; }
  .topbar button { white-space: nowrap; }
  main { padding: .75rem; }
  .topbar select { max-width: 7.5rem; }
  .brand span small { display: none; }
  .brand span:last-child { line-height: 1.1; }
}
@media print { .topbar, #toasts { display: none; } }

/* wave 4 / isolation: persistent banner while the sample (fictional) world is active */
.sample-banner { background: #fff3cd; color: #5c4400; border-bottom: 2px solid #e0a800; padding: .45rem 1rem; display: flex; flex-wrap: wrap; gap: .4rem .75rem; align-items: center; font-size: .92rem; }
.sample-banner button { margin-left: auto; min-height: 36px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) .sample-banner { background: #3b3000; color: #ffe08a; border-bottom-color: #a37900; } }
:root[data-theme="dark"] .sample-banner, :root[data-theme="midnight"] .sample-banner, :root[data-theme="hc-dark"] .sample-banner { background: #3b3000; color: #ffe08a; border-bottom-color: #a37900; }
.topbar-inner select optgroup { font-style: normal; font-weight: 700; }
