/* ==========================================================================
   Knowledge Base admin
   ==========================================================================
   An admin console: a dark sidebar of sections, one section at a time, each a
   heading, its list as one card, and forms in drawers that slide in from the
   right (nav.js). Light by default, dark when the system is. Colours are
   tokens on :root, in the aveloris palette (blue #4f7fff,
   Lexend wordmark, Inter text). Class names are the ones app.js, library.js and
   field-map.js render.
   ========================================================================== */

/* aveloris type, served with the page (relative URLs: the KB may be mounted under a path). */
@font-face {
    font-family: 'Inter'; font-style: normal; font-weight: 300 900; font-display: swap;
    src: url(fonts/inter-latin-ext.woff2) format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: 'Inter'; font-style: normal; font-weight: 300 900; font-display: swap;
    src: url(fonts/inter-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Lexend'; font-style: normal; font-weight: 200 600; font-display: swap;
    src: url(fonts/lexend-latin-ext.woff2) format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: 'Lexend'; font-style: normal; font-weight: 200 600; font-display: swap;
    src: url(fonts/lexend-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --surface-3: #eef0f5;
    --border: #e3e6ee;
    --border-strong: #cdd2dd;
    --text: #141a2a;
    --text-2: #475069;
    --muted: #6c748a;
    --accent: #3463f2;
    --accent-hover: #2a53d6;
    --accent-soft: #edf2ff;
    --accent-text: #2a55d8;
    --brand: #4f7fff;
    --brand-2: #7aa3ff;
    --brand-violet: #a78bfa;
    --danger: #d22f3b;
    --danger-soft: #fdeeef;
    --ok: #198754;
    --ok-soft: #e8f6ee;
    --warn-soft: #fff7e2;
    --side: #06080f;
    --side-2: #111830;
    --side-text: #c3cae2;
    --side-muted: #727c9c;
    --side-active: #ffffff;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow: 0 1px 3px rgba(15, 23, 42, .07), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-lg: 0 24px 48px -12px rgba(15, 23, 42, .25);
    --radius: 12px;
    --radius-sm: 8px;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --display: "Lexend", "Inter", system-ui, sans-serif;
    --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color-scheme: light;
}

/* Dark only when chosen (the switch in the sidebar, nav.js): light is the default everywhere. */
:root[data-theme="dark"] {
    --bg: #080b16;
    --surface: #0e1324;
    --surface-2: #121831;
    --surface-3: #19213d;
    --border: #1f2844;
    --border-strong: #2d3758;
    --text: #e9ecf5;
    --text-2: #b9c0d4;
    --muted: #8a93ad;
    --accent: #4f7fff;
    --accent-hover: #7aa3ff;
    --accent-soft: #15214a;
    --accent-text: #9bb8ff;
    --danger: #ff6b76;
    --danger-soft: #3a1c24;
    --ok: #4cc38a;
    --ok-soft: #12301f;
    --warn-soft: #362d14;
    --side: #04060c;
    --side-2: #0f1630;
    --shadow-sm: none;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.55 var(--sans);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
body.drawer-open { overflow: hidden; }

code { font-family: var(--mono); font-size: .88em; background: var(--surface-3); padding: 1px 6px; border-radius: 5px; }
h1, h2, h3 { margin: 0; color: var(--text); letter-spacing: -.015em; }
strong { font-weight: 650; }
.mono { font-family: var(--mono); }

/* --- Views ------------------------------------------------------------------ */
.view { display: none; }
.view.active { display: block; }
#main-view.active { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }

/* --- Sign in ---------------------------------------------------------------- */
.login-split { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); min-height: 100vh; }
.login-hero {
    position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between;
    padding: 40px 56px; color: #e8ebff;
    background:
        radial-gradient(1100px 620px at -10% -20%, rgba(79, 127, 255, .42), transparent 60%),
        radial-gradient(900px 520px at 115% 120%, rgba(167, 139, 250, .26), transparent 60%),
        linear-gradient(160deg, #06080f 0%, #0b1024 100%);
}
.hero-brand { display: flex; align-items: center; gap: 12px; color: #fff; }
.hero-brand .brand-word { font-size: 24px; }
.hero-brand .brand-product { padding-left: 12px; border-left: 1px solid rgba(255, 255, 255, .18); }
.hero-copy { max-width: 520px; }
.hero-copy h1 { color: #fff; font-family: var(--display); font-size: 40px; line-height: 1.16; letter-spacing: .005em; font-weight: 300; }
.hero-copy p { color: #b9c2ec; font-size: 16px; margin: 18px 0 26px; }
.hero-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.hero-points li { display: flex; gap: 12px; align-items: center; color: #dde2ff; }
.hero-points li span { width: 24px; height: 24px; border-radius: 999px; display: grid; place-items: center; background: rgba(255, 255, 255, .1); color: var(--brand-2); font-size: 13px; font-weight: 700; }
.hero-foot { color: #7f89ad; font-size: 13px; }
.login-side { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: var(--surface); }
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { font-family: var(--display); font-size: 28px; font-weight: 400; letter-spacing: 0; }
.login-card .sub { color: var(--muted); margin: 6px 0 22px; }
.login-card .btn-block { margin-top: 22px; }
.fine { color: var(--muted); font-size: 12.5px; margin: 18px 0 0; }

/* The aveloris mark: the glowing blue orb, the lower-case Lexend wordmark with its blue full stop. */
.brand-orb {
    width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
    background: radial-gradient(circle at 36% 34%, #9dbaff 0%, var(--brand) 46%, #2f56d6 100%);
    box-shadow: 0 0 14px rgba(79, 127, 255, .65), 0 0 34px rgba(79, 127, 255, .28);
}
.brand-word { font-family: var(--display); font-weight: 300; letter-spacing: .06em; font-size: 20px; line-height: 1; color: #fff; }
.brand-dot { color: var(--brand); }
.brand-product { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .14em; color: #8d97bb; }
.brand-text { display: flex; flex-direction: column; gap: 5px; }

/* --- Sidebar ---------------------------------------------------------------- */
.sidebar {
    position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
    background: var(--side); color: var(--side-text); padding: 20px 14px 14px;
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; padding: 4px 8px 24px; }
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-group { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted); padding: 16px 10px 6px; }
.nav-group:first-child { padding-top: 0; }
.nav a {
    display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 8px;
    color: var(--side-text); text-decoration: none; font-weight: 500; transition: background .12s, color .12s;
}
.nav a:hover { background: var(--side-2); color: #fff; }
.nav a.active { background: var(--side-2); color: var(--side-active); box-shadow: inset 2px 0 0 var(--brand); }
.nav-ico { width: 18px; display: grid; place-items: center; opacity: .85; }
.nav a.active .nav-ico { opacity: 1; color: var(--brand-2); }
.nav-label { flex: 1; }
.nav .count { background: rgba(255, 255, 255, .08); color: var(--side-text); }
.nav a.active .count { background: rgba(125, 139, 255, .25); color: #fff; }

.who { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 12px 4px 4px 8px; border-top: 1px solid rgba(255, 255, 255, .08); }
.avatar {
    width: 34px; height: 34px; border-radius: 999px; display: grid; place-items: center; flex-shrink: 0;
    background: linear-gradient(135deg, #2f56d6, #7c63d8); color: #fff; font-weight: 700; font-size: 13px; text-transform: uppercase;
}
.who-text { flex: 1; min-width: 0; }
.who-name { color: #fff; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-role { color: var(--side-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .icon-btn { padding: 6px; }
.sidebar .icon-btn { color: var(--side-muted); }
.sidebar .icon-btn:hover { background: var(--side-2); color: #fff; }

.count {
    display: inline-block; min-width: 22px; padding: 0 7px; border-radius: 999px; text-align: center;
    background: var(--surface-3); color: var(--muted); font-size: 11.5px; font-weight: 600; line-height: 20px;
}
.count:empty { display: none; }

/* --- Content ---------------------------------------------------------------- */
.content { padding: 36px 48px 72px; min-width: 0; }
.pane { display: none; max-width: 1080px; margin: 0 auto; animation: pane-in .18s ease-out; }
.pane.active { display: block; }
@keyframes pane-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.pane-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.eyebrow { margin: 0 0 6px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--accent-text); }
.pane-head h1 { font-family: var(--display); font-size: 28px; font-weight: 400; letter-spacing: 0; }
.lead { color: var(--text-2); margin: 8px 0 0; max-width: 74ch; font-size: 14.5px; }
.pane-head > .btn-primary { flex-shrink: 0; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 16px; }
.card-pad { padding: 16px 18px; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 15px; font-weight: 650; }
.card-body { padding: 4px 20px 20px; }

/* A list: one card, rows separated by lines. */
.list-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 18px; overflow: hidden; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--surface); }
.list-head h2 { font-size: 15px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.list-filter { max-width: 300px; padding-left: 34px !important;
    background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236c748a' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 12px center !important; }

/* Overview */
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
/* How a section fills up, when that happens somewhere else (the extension). */
.how-card { display: flex; gap: 14px; align-items: flex-start; color: var(--text-2); margin-bottom: 18px; }
.how-ico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; background: var(--accent-soft); color: var(--accent-text); }
.how-card strong { color: var(--text); }
.lead a, .how-card a { color: var(--accent-text); font-weight: 600; text-decoration: none; }
.lead a:hover, .how-card a:hover { text-decoration: underline; }
.stat {
    display: flex; flex-direction: column; gap: 4px; padding: 18px; border-radius: var(--radius); text-decoration: none;
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm); color: var(--text);
    transition: border-color .12s, transform .12s, box-shadow .12s;
}
.stat:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat-num { font-size: 32px; font-weight: 750; letter-spacing: -.03em; line-height: 1.1; }
.stat-hint { color: var(--muted); font-size: 12.5px; }
.actions-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 16px 20px 20px; }
.action {
    text-align: left; display: flex; flex-direction: column; gap: 3px; padding: 14px 16px 14px 48px; position: relative;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-weight: 600;
}
.action::before {
    content: "+"; position: absolute; left: 14px; top: 14px; width: 24px; height: 24px; border-radius: 7px;
    display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); font-weight: 700;
}
.action:hover { border-color: var(--accent); background: var(--surface); }
.action-sub { color: var(--muted); font-weight: 400; font-size: 13px; }

/* --- Forms ------------------------------------------------------------------ */
label { display: block; font-weight: 600; font-size: 13px; color: var(--text); margin: 16px 0 6px; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.hint { color: var(--muted); font-weight: 400; font-size: 12px; text-transform: none; letter-spacing: 0; }
.help { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

input[type="text"], input[type="password"], input[type="search"], select, textarea {
    width: 100%; font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 12px;
    transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; line-height: 1.55; }
select { width: auto; padding: 8px 32px 8px 11px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .75; }

.lib-text { font-family: var(--mono); font-size: 13px; }
.form-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; margin-top: 14px; }
.inline-field { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-weight: 500; color: var(--text-2); }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { flex: 1; min-width: 0; }
.inline-label { font-weight: 600; white-space: nowrap; margin-right: 4px; }
.err { color: var(--danger); font-size: 13px; margin: 12px 0 0; }
.err:empty { display: none; }

.check-row { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; margin: 16px 0 0; cursor: pointer; }
.check-row input { margin-top: 3px; accent-color: var(--accent); }
.check-text { display: flex; flex-direction: column; gap: 2px; }
.check-hint { color: var(--muted); font-weight: 400; font-size: 12.5px; }

/* A choice shown as a card: what a connector reaches, an accounts manager. */
.choice { display: grid; gap: 8px; }
.option {
    display: flex; gap: 12px; align-items: flex-start; margin: 0; padding: 12px 14px; cursor: pointer; font-weight: 400;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
}
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
.option input { margin-top: 3px; accent-color: var(--accent); }
.option > span { display: flex; flex-direction: column; gap: 2px; }
.option-sub { color: var(--muted); font-size: 12.5px; }
label.option.admin-only { margin-top: 18px; }

/* --- Buttons ---------------------------------------------------------------- */
button { font: inherit; cursor: pointer; border-radius: var(--radius-sm); border: 1px solid transparent; padding: 9px 15px; font-weight: 600; line-height: 1.2; transition: background .12s, border-color .12s, color .12s, box-shadow .12s; }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(52, 99, 242, .3); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary, .btn-edit, .btn-table { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover:not(:disabled), .btn-edit:hover:not(:disabled), .btn-table:hover:not(:disabled) { background: var(--surface-2); border-color: var(--muted); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-del { background: transparent; color: var(--danger); }
.btn-del:hover:not(:disabled) { background: var(--danger-soft); }
.btn-link { background: none; border: 0; padding: 0; color: var(--accent-text); font-weight: 600; font-size: 13px; }
.btn-link:hover { text-decoration: underline; }
.btn-sm, .btn-edit, .btn-del, .btn-table { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; padding: 11px 15px; }
.btn-inline { width: auto; }
.icon-btn { background: transparent; color: var(--muted); padding: 6px 9px; font-size: 20px; line-height: 1; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* --- List rows ---------------------------------------------------------------- */
.entry-list { display: flex; flex-direction: column; }
.entry {
    display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
    padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--surface); transition: background .1s;
}
.entry:last-child { border-bottom: 0; }
.entry:hover { background: var(--surface-2); }
.entry-icon {
    width: 36px; height: 36px; flex-shrink: 0; border-radius: 9px; display: grid; place-items: center;
    background: var(--accent-soft); font-size: 16px;
}
.entry-body { flex: 1 1 280px; min-width: 0; }
.entry-url { font-weight: 600; overflow-wrap: anywhere; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.entry-meta { color: var(--muted); font-size: 12.5px; margin-top: 3px; overflow-wrap: anywhere; }
.entry a { color: var(--accent-text); }
.entry-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { color: var(--muted); text-align: center; padding: 40px 24px; margin: 0; }
.empty strong { color: var(--text); }
/* An empty list outside a list card (the test result). */
#test-result .empty { padding: 12px 0 0; text-align: left; }

.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); }
.tag-accent { background: var(--accent-soft); color: var(--accent-text); }

/* Row icons: a line icon per kind of list, in the accent colour, for the emoji
   the rows are drawn with. Guides keep theirs — they tell a document from a table. */
#note-list .entry-icon, #group-list .entry-icon, #style-list .entry-icon, #connector-list .entry-icon,
#connector-all .entry-icon, #people-list .entry-icon { font-size: 0; color: var(--accent-text); }
#note-list .entry-icon::before, #group-list .entry-icon::before, #style-list .entry-icon::before, #connector-list .entry-icon::before,
#connector-all .entry-icon::before, #people-list .entry-icon::before {
    content: ""; width: 18px; height: 18px; background: currentColor;
    -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat;
}
#note-list .entry-icon { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpolyline points='14 2 14 8 20 8'/%3E%3Cline x1='8' y1='13' x2='16' y2='13'/%3E%3Cline x1='8' y1='17' x2='13' y2='17'/%3E%3C/svg%3E"); }
#group-list .entry-icon { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z'/%3E%3C/svg%3E"); }
#style-list .entry-icon { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4z'/%3E%3C/svg%3E"); }
#connector-list .entry-icon, #connector-all .entry-icon { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71'/%3E%3Cpath d='M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71'/%3E%3C/svg%3E"); }
#people-list .entry-icon { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2'/%3E%3Ccircle cx='12' cy='7' r='4'/%3E%3C/svg%3E"); }
#people-list .entry:has(.tag-accent) .entry-icon { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z'/%3E%3C/svg%3E"); }
#test-result .entry-icon { background: var(--surface-3); }

/* --- Page guides and automations: a table, grouped by site ------------------------
   Fixed columns, so "Applies to", "Who sees it" and the buttons line up on every
   row — a row without buttons keeps its place with a "Private" marker. */
.entry-row, .entry-head {
    display: grid; grid-template-columns: 36px minmax(0, 1fr) 140px 168px 168px; align-items: center; gap: 16px;
}
.entry-head {
    padding: 9px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2);
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
}
.entry-site {
    display: flex; align-items: center; gap: 8px; padding: 14px 18px 6px; background: var(--surface);
    font-size: 12.5px; font-weight: 650; color: var(--text-2);
}
.entry-site:not(:nth-child(2)) { border-top: 1px solid var(--border); }
.site-count { font-size: 11px; font-weight: 600; padding: 0 7px; border-radius: 999px; background: var(--surface-3); color: var(--muted); }
.entry-site + .entry-row { border-top: 0; }
.entry-row { padding: 10px 18px; border-bottom: 0; }
.entry-row + .entry-site { margin-top: 4px; }
.entry-name { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.entry-row .entry-meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; margin-top: 2px; }
.entry-path { font-family: var(--mono); font-size: 12px; color: var(--text-2); overflow-wrap: anywhere; }
.entry-size { white-space: nowrap; }
.entry-row .entry-actions { justify-content: flex-end; flex-wrap: nowrap; }
.entry-who .sel-scope, .entry-applies .sel-sub { width: 100%; }
.sel-sub { font-size: 12.5px; padding: 5px 28px 5px 10px; border-radius: 999px; }
.sel-sub:has(option[value="sub"]:checked) { background-color: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
/* Between two pages of one site: a hairline from the name on. */
.entry-row { position: relative; }
.entry-row + .entry-row::before { content: ""; position: absolute; top: 0; left: 70px; right: 18px; border-top: 1px solid var(--border); }
.scope-tag { font-size: 12.5px; color: var(--text-2); }
.entry-locked { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); padding: 6px 4px; cursor: help; }
.entry-locked::before {
    content: ""; width: 13px; height: 13px; background: currentColor;
    -webkit-mask: var(--lock) center / contain no-repeat; mask: var(--lock) center / contain no-repeat;
    --lock: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='11' width='18' height='11' rx='2'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E");
}
/* Styles, notes and groups: the same table, without "Applies to". */
.entry-row.lib-row, .entry-head.lib-head { grid-template-columns: 36px minmax(0, 1fr) 168px 168px; }
.lib-row .entry-meta .tag { font-size: 11px; }
.entry-gist { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; max-width: 100%; }
.entry-row .entry-meta:has(.entry-gist) { flex-wrap: nowrap; }
.entry-row .entry-meta:has(.entry-gist) > span:not(.entry-gist) { white-space: nowrap; }
/* Customers (the main knowledge base): name and address, status, three buttons. */
.entry-row.cust-row, .entry-head.cust-head { grid-template-columns: 36px minmax(0, 1fr) 150px auto; }
.cust-row .entry-path { color: var(--accent-text); text-decoration: none; }
.cust-row .entry-path:hover { text-decoration: underline; }
.cust-row.is-suspended .entry-name, .cust-row.is-suspended .entry-meta { opacity: .6; }
#customer-list .entry-icon { font-size: 0; color: var(--accent-text); }
#customer-list .entry-icon::before {
    content: ""; width: 18px; height: 18px; background: currentColor;
    -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat;
    --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4' y='2' width='16' height='20' rx='2'/%3E%3Cpath d='M9 22v-4h6v4'/%3E%3Cpath d='M8 6h.01M16 6h.01M12 6h.01M12 10h.01M12 14h.01M16 10h.01M16 14h.01M8 10h.01M8 14h.01'/%3E%3C/svg%3E");
}
#customer-list .is-suspended .entry-icon { color: var(--muted); background: var(--surface-3); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-on { background: var(--ok-soft); color: var(--ok); }
.status-off { background: var(--warn-soft); color: #a86b00; }
:root[data-theme="dark"] .status-off { color: #f0b54a; }
.address-preview { font-family: var(--mono); font-size: 13px; padding: 9px 12px; border-radius: var(--radius-sm); background: var(--surface-3); color: var(--text-2); margin: 6px 0 4px; overflow-wrap: anywhere; }
.address-preview span { color: var(--accent-text); font-weight: 600; }
.once { margin: 16px 0 0; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--text); font-size: 13px; }
.entry-kind-doc, .entry-kind-auto, .entry-kind-table { font-size: 0; }
.entry-kind-doc::before, .entry-kind-auto::before, .entry-kind-table::before {
    content: ""; width: 18px; height: 18px; background: currentColor;
    -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat;
}
.entry-kind-doc { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpolyline points='14 2 14 8 20 8'/%3E%3Cline x1='8' y1='13' x2='16' y2='13'/%3E%3Cline x1='8' y1='17' x2='13' y2='17'/%3E%3C/svg%3E"); background: var(--surface-3); color: var(--text-2); }
.entry-kind-auto { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='13 2 3 14 12 14 11 22 21 10 12 10 13 2'/%3E%3C/svg%3E"); background: var(--accent-soft); color: var(--accent-text); }
.entry-kind-table { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Cline x1='3' y1='9' x2='21' y2='9'/%3E%3Cline x1='3' y1='15' x2='21' y2='15'/%3E%3Cline x1='9' y1='9' x2='9' y2='21'/%3E%3C/svg%3E"); background: var(--ok-soft); color: var(--ok); }

/* A guide's own controls in its row. */
.entry-sub {
    display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 5px 10px; border-radius: 999px;
    border: 1px solid var(--border); font-size: 12px; font-weight: 500; color: var(--muted); cursor: pointer; background: var(--surface);
}
.entry-sub:hover { border-color: var(--border-strong); color: var(--text); }
.entry-sub:has(input:checked) { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.entry-sub input { margin: 0; accent-color: var(--accent); }
.sel-scope { font-size: 12.5px; padding: 5px 28px 5px 10px; border-radius: 999px; }
.sel-scope:has(option[value="global"]:checked) { background-color: var(--ok-soft); border-color: transparent; color: var(--ok); }

/* People: a new password, in the row. */
.row-form { display: flex; gap: 6px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.row-form input { flex: 1; min-width: 180px; font-family: var(--mono); }

/* Checklists: a group's notes, a connector's reach. */
.lib-checks {
    display: flex; flex-direction: column; gap: 1px; max-height: 340px; overflow-y: auto; margin: 6px 0 4px;
    padding: 6px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2);
}
.lib-check { display: flex; align-items: center; gap: 10px; padding: 7px 9px; border-radius: 6px; font-weight: 500; margin: 0; cursor: pointer; }
.lib-check:hover { background: var(--surface-3); }
.lib-check:has(input:checked) { background: var(--accent-soft); }
.lib-check input { width: auto; margin: 0; accent-color: var(--accent); }
.lib-check .hint { margin-left: auto; }
.lib-check-head { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 8px 9px 3px; }
.lib-search { margin: 6px 0 0; }

/* A new connector address, shown once. */
.callout { background: var(--ok-soft); border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px; }
.callout-title { font-weight: 650; margin-bottom: 10px; color: var(--ok); }
#connector-url { font-family: var(--mono); font-size: 12.5px; background: var(--surface); }

/* --- Drawers -------------------------------------------------------------------- */
.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(10, 14, 28, .42); opacity: 0; transition: opacity .2s; }
.drawer-panel {
    position: absolute; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); display: flex; flex-direction: column;
    background: var(--surface); box-shadow: var(--shadow-lg); transform: translateX(24px); opacity: 0;
    transition: transform .22s cubic-bezier(.2, .8, .2, 1), opacity .2s;
}
.drawer-wide .drawer-panel { width: min(820px, 100vw); }
.drawer.shown .drawer-backdrop { opacity: 1; }
.drawer.shown .drawer-panel { transform: none; opacity: 1; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 24px 16px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-family: var(--display); font-size: 19px; font-weight: 400; letter-spacing: 0; }
.drawer-sub { color: var(--muted); margin: 4px 0 0; font-size: 13px; }
.drawer-form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 4px 24px 24px; }
.drawer-body > label:first-of-type, .drawer-body > input[type="hidden"] + label { margin-top: 18px; }
.drawer-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 24px; border-top: 1px solid var(--border); background: var(--surface-2); }
.drawer-wide .lib-text.grow { min-height: 46vh; }

/* --- Add a guide: the file drop ---------------------------------------------- */
.dropzone {
    border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 24px 16px; text-align: center;
    color: var(--muted); background: var(--surface-2); cursor: pointer; transition: border-color .12s, background .12s;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); outline: none; }
.dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { color: var(--accent); margin-bottom: 6px; }
.dz-text { color: var(--text-2); }
.dz-text strong { color: var(--text); }
.dz-browse { color: var(--accent-text); font-weight: 600; text-decoration: underline; }
.dz-sub { font-size: 12px; margin-top: 4px; }
.dz-file { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); }
.dz-file.hidden, .dropzone.hidden { display: none; }
.dz-file-name { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
.dz-file-size { color: var(--muted); font-size: 12.5px; }
.dz-clear { background: transparent; color: var(--muted); padding: 2px 8px; font-size: 18px; }
.dz-clear:hover { color: var(--danger); background: var(--danger-soft); }

/* --- Test an address --------------------------------------------------------- */
#test-result:not(:empty) { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
#test-result .entry { border: 1px solid var(--border); border-radius: var(--radius-sm); }
.chain { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.chain-step { font-family: var(--mono); font-size: 12px; padding: 3px 9px; border-radius: 6px; background: var(--surface-3); color: var(--muted); }
.chain-step.hit { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.chain-step.hit::after { content: " ✓"; }
.chain-step.miss { opacity: .75; }

/* --- Modals ------------------------------------------------------------------ */
.modal { position: fixed; inset: 0; background: rgba(10, 14, 28, .45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 50; overflow-y: auto; }
.modal.hidden { display: none; }
.modal-box { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 640px; display: flex; flex-direction: column; max-height: 90vh; }
.modal-box.modal-wide { max-width: 1100px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 18px; font-weight: 700; }
.modal-body { padding: 4px 24px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 24px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 14px 14px; }
.editor-file-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.editor-file-actions { display: flex; gap: 6px; margin-bottom: 6px; }
.editor-text { width: 100%; min-height: 380px; font-family: var(--mono); font-size: 13px; line-height: 1.6; padding: 14px; }

/* The fields of a learnt form, as rows. */
.field-map { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 8px 0 12px; background: var(--surface-2); }
.field-map.hidden { display: none; }
.fm-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.fm-title { font-weight: 650; }
.fm-tools { margin-left: auto; }
.fm-wrap { overflow-x: auto; }
.fm-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.fm-table th, .fm-table td { border-bottom: 1px solid var(--border); padding: 6px; text-align: left; vertical-align: middle; }
.fm-table th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.fm-table .fm-num { color: var(--muted); width: 28px; }
.fm-table .fm-req { text-align: center; width: 44px; }
.fm-table .fm-act { white-space: nowrap; width: 1%; }
.fm-table .fm-act button { padding: 3px 7px; font-size: 12px; background: transparent; color: var(--muted); }
.fm-table .fm-act button:hover { background: var(--surface-3); color: var(--text); }
.fm-table .fm-input { padding: 5px 8px; font-size: 12.5px; border-radius: 6px; }
.fm-table .fm-input.mono { font-family: var(--mono); }
.fm-table .fm-type { width: 120px; }
.fm-table input[type="checkbox"] { accent-color: var(--accent); }
.fm-tag { display: inline-block; font-size: 10.5px; padding: 0 6px; border-radius: 999px; background: var(--surface-3); color: var(--muted); }
.fm-table tr.fm-bad .fm-ref { border-color: var(--danger); }

/* A knowledge table's rows. */
.table-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 14px 0; }
.table-tools input[type="search"] { flex: 1; min-width: 220px; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); max-height: 58vh; }
.kb-table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.kb-table th, .kb-table td { border-bottom: 1px solid var(--border); padding: 7px 11px; text-align: left; white-space: nowrap; }
.kb-table th { position: sticky; top: 0; background: var(--surface-2); font-weight: 650; z-index: 1; }
.kb-table tr:hover td { background: var(--surface-2); }
.kb-table td[contenteditable="true"] { cursor: text; }
.kb-table td[contenteditable="true"]:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--accent-soft); }
.kb-table td.saving { background: var(--warn-soft); }
.kb-table td.saved { background: var(--ok-soft); }
.kb-table td.row-actions { width: 1%; }
.kb-table td.row-actions button { padding: 2px 8px; font-size: 12px; background: transparent; color: var(--danger); }
.table-pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; color: var(--muted); }

/* --- Toast ------------------------------------------------------------------- */
.toast {
    position: fixed; right: 24px; bottom: 24px; transform: translateY(12px); opacity: 0; pointer-events: none;
    background: #0e1324; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-lg);
    max-width: min(460px, calc(100vw - 48px)); font-weight: 500; transition: opacity .18s, transform .18s; z-index: 60;
    border-left: 3px solid var(--brand);
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #3a1219; border-left-color: #ff6b76; }

/* --- Narrow screens ------------------------------------------------------------ */
@media (max-width: 1100px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
    .login-split { grid-template-columns: minmax(0, 1fr); }
    .login-hero { padding: 28px 24px; gap: 28px; }
    .hero-copy h1 { font-size: 28px; }
    #main-view.active { grid-template-columns: minmax(0, 1fr); }
    .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 14px; }
    .brand { padding: 2px 4px; }
    .nav { flex-direction: row; order: 3; width: 100%; overflow-x: auto; }
    .nav-group { display: none; }
    .nav a { white-space: nowrap; }
    .nav a.active { box-shadow: none; }
    .who { margin: 0 0 0 auto; padding: 0; border: 0; }
    .who-role { display: none; }
    .content { padding: 22px 16px 56px; }
    .pane-head { flex-direction: column; align-items: stretch; }
    .form-grid, .actions-grid { grid-template-columns: 1fr; }
    .list-head { flex-wrap: wrap; }
    .list-filter { max-width: none; }
    .entry-head { display: none; }
    .entry-row { grid-template-columns: 36px minmax(0, 1fr); row-gap: 8px; }
    .entry-row > .entry-applies, .entry-row > .entry-who, .entry-row > .entry-actions { grid-column: 2; justify-content: flex-start; }
    .inline-form { flex-wrap: wrap; }
}
