/* SPDX-License-Identifier: AGPL-3.0-or-later */
/* BordWerk base styles. No external fonts or frameworks. */

:root {
    --bg: #f4f5f2;
    --surface: #ffffff;
    --surface-2: #eceee8;
    --text: #1d2420;
    --muted: #5d6762;
    --border: #d5d9d2;
    --accent: #2f6b4f;
    --accent-strong: #24543e;
    --accent-contrast: #ffffff;
    --focus: #e0a43a;
    --ok: #2f7a4a;
    --ok-bg: #e3f2e7;
    --warn: #8a5a00;
    --warn-bg: #fbf0d9;
    --fail: #a3302b;
    --fail-bg: #fbe5e3;
    --info-bg: #e5eef6;
    --info: #24527a;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .05);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #131715;
        --surface: #1b201d;
        --surface-2: #242a26;
        --text: #e5e9e6;
        --muted: #9aa49e;
        --border: #333b36;
        --accent: #6fbf95;
        --accent-strong: #8fd3ad;
        --accent-contrast: #0f1a14;
        --ok: #7fcf9a;
        --ok-bg: #1e3326;
        --warn: #e6b45a;
        --warn-bg: #362b17;
        --fail: #f08a82;
        --fail-bg: #3a1f1d;
        --info-bg: #1b2a36;
        --info: #8fbde3;
        --shadow: none;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #131715;
    --surface: #1b201d;
    --surface-2: #242a26;
    --text: #e5e9e6;
    --muted: #9aa49e;
    --border: #333b36;
    --accent: #6fbf95;
    --accent-strong: #8fd3ad;
    --accent-contrast: #0f1a14;
    --ok: #7fcf9a;
    --ok-bg: #1e3326;
    --warn: #e6b45a;
    --warn-bg: #362b17;
    --fail: #f08a82;
    --fail-bg: #3a1f1d;
    --info-bg: #1b2a36;
    --info: #8fbde3;
    --shadow: none;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 var(--font);
}

a { color: var(--accent); }
a:hover { color: var(--accent-strong); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }

code, pre, .mono { font-family: var(--mono); font-size: .92em; }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
}

.skip-link { position: absolute; left: -999px; top: 0; }
.skip-link:focus { left: 1rem; top: .5rem; background: var(--surface); padding: .4rem .8rem; z-index: 10; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
    max-width: 1180px; margin: 0 auto; padding: .6rem 16px;
    display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); text-decoration: none; }
.brand-text { display: flex; flex-direction: column; }
.brand-title { font-weight: 700; letter-spacing: .01em; }
.brand-subtitle { font-size: .8rem; color: var(--muted); }

.main-nav { display: flex; align-items: center; gap: .25rem; flex: 1; flex-wrap: wrap; }
.main-nav > a {
    color: var(--text); text-decoration: none; padding: .45rem .7rem; border-radius: 8px;
}
.main-nav > a:hover { background: var(--surface-2); }
.main-nav > a[aria-current="page"] { background: var(--surface-2); font-weight: 600; }
.nav-spacer { flex: 1; }
.nav-user { color: var(--muted) !important; }
.nav-toggle { display: none; margin-left: auto; background: none; border: 1px solid var(--border); border-radius: 8px; padding: .35rem .5rem; color: var(--text); }

.inline-form { display: inline; margin: 0; }
.link-button {
    background: none; border: 0; padding: .45rem .7rem; color: var(--text);
    font: inherit; cursor: pointer; border-radius: 8px;
}
.link-button:hover { background: var(--surface-2); }

.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin: 0; }
.lang-switch button {
    background: var(--surface); color: var(--muted); border: 0; padding: .3rem .55rem;
    font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer;
}
.lang-switch button + button { border-left: 1px solid var(--border); }
.lang-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); }

@media (max-width: 760px) {
    .nav-toggle { display: inline-flex; }
    .main-nav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; }
    .main-nav.open { display: flex; }
    .nav-spacer { display: none; }
    .main-nav .lang-switch { align-self: flex-start; margin: .4rem .7rem; }
}

/* Page */
.page { max-width: 1180px; margin: 0 auto; padding: 1.5rem 16px 3rem; }
.page-header { margin-bottom: 1.2rem; }
.page-header.with-actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.page-header.with-actions h1 { margin: 0; }
.lead { color: var(--muted); margin: 0; }
.breadcrumb { margin: 0 0 .3rem; font-size: .9rem; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .86rem; margin: .3rem 0 0; }

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.25rem; margin-bottom: 1.2rem; box-shadow: var(--shadow);
}
.card.narrow { max-width: 440px; margin-left: auto; margin-right: auto; }
.card.wide { max-width: 860px; margin-left: auto; margin-right: auto; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 1.2rem; }
.grid-2 > .card { margin-bottom: 1.2rem; }

/* Forms */
.form .field { margin-bottom: 1rem; }
label { display: block; font-weight: 600; margin-bottom: .3rem; }
label.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="number"],
input:not([type]), select, textarea {
    width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface); color: var(--text); font: inherit;
}
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--fail); }
input[type="checkbox"] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.field-error { color: var(--fail); font-size: .88rem; margin: .3rem 0 0; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; }

.button {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
    text-decoration: none; cursor: pointer;
}
.button:hover { background: var(--surface-2); color: var(--text); }
.button-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.button-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-contrast); }
.button-block { width: 100%; }

/* Tabs */
.tabs { display: flex; gap: .3rem; margin-bottom: 1rem; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.tabs a { padding: .5rem .9rem; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .85rem; color: var(--muted); font-weight: 600; }
.table.compact td { padding: .35rem .5rem; font-size: .92rem; }
.table tr:last-child td { border-bottom: 0; }

/* Badges and status */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge-ok, .badge-admin { background: var(--ok-bg); color: var(--ok); }
.badge-warn, .badge-warning { background: var(--warn-bg); color: var(--warn); }
.badge-fail { background: var(--fail-bg); color: var(--fail); }
.badge-user { background: var(--info-bg); color: var(--info); }
.status-ok { color: var(--ok); }
.status-warn { color: var(--warn); }
.status-fail { color: var(--fail); }

/* Messages */
.flashes { margin-bottom: 1rem; }
.flash, .notice { padding: .7rem 1rem; border-radius: 8px; margin-bottom: .6rem; border: 1px solid transparent; }
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-error, .notice-error { background: var(--fail-bg); color: var(--fail); }
.flash-info { background: var(--info-bg); color: var(--info); }
.notice-warning { background: var(--warn-bg); color: var(--warn); }

pre.code {
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
    padding: .8rem 1rem; overflow-x: auto; white-space: pre-wrap; word-break: break-all;
}

dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.2rem; margin: 0; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; }

.roadmap { list-style: none; padding: 0; margin: 0; }
.roadmap li { padding: .35rem 0 .35rem 1.8rem; position: relative; color: var(--muted); }
.roadmap li::before { content: ""; position: absolute; left: .3rem; top: .7rem; width: .7rem; height: .7rem; border-radius: 50%; border: 2px solid var(--border); }
.roadmap li.done { color: var(--text); }
.roadmap li.done::before { background: var(--accent); border-color: var(--accent); }

.empty-state { text-align: center; }
.error-code { font-size: 3rem; font-weight: 800; color: var(--muted); margin: 0; }

/* Setup steps */
.steps { list-style: none; display: flex; gap: .5rem; padding: 0; margin: 0 0 1.2rem; flex-wrap: wrap; }
.steps li { display: flex; align-items: center; gap: .4rem; color: var(--muted); padding-right: .6rem; }
.step-number { display: inline-flex; width: 1.6rem; height: 1.6rem; border-radius: 50%; align-items: center; justify-content: center; border: 2px solid var(--border); font-size: .85rem; font-weight: 700; }
.steps li.current { color: var(--text); font-weight: 600; }
.steps li.current .step-number { border-color: var(--accent); color: var(--accent); }
.steps li.done .step-number { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }

/* Minimal layout (sign-in, setup) */
body.minimal { min-height: 100vh; }
.minimal-main { max-width: 900px; margin: 0 auto; padding: 2.5rem 16px; }
.minimal-brand { display: flex; align-items: center; gap: .8rem; justify-content: center; margin-bottom: 1rem; }
.minimal-brand .brand-title { font-size: 1.3rem; }
.minimal-lang { display: flex; justify-content: center; margin-bottom: 1.2rem; }
.minimal-footer { text-align: center; color: var(--muted); font-size: .82rem; margin-top: 2rem; }

.footer {
    max-width: 1180px; margin: 0 auto; padding: 1rem 16px 2rem;
    color: var(--muted); font-size: .82rem; display: flex; gap: .5rem; flex-wrap: wrap;
}
.footer a { color: var(--muted); }

.intro { margin-top: 0; }

/* ---------------------------------------------------------------- Phase 2 */
.uid { font-family: var(--mono); font-size: .88em; font-weight: 600; color: var(--accent); margin-right: .35rem; }
h1 .uid { font-size: .8em; }
.badges { display: flex; gap: .35rem; flex-wrap: wrap; margin: .4rem 0 0; }
.num { text-align: right; }
.grow { flex: 1; }

.filter-bar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; padding: .8rem; }
.filter-bar .field { margin: 0; min-width: 160px; }
.filter-bar .grow { min-width: 220px; }

.tree-indent { display: inline-block; width: 0; }
.depth-1 { width: 1.25rem; } .depth-2 { width: 2.5rem; } .depth-3 { width: 3.75rem; }
.depth-4 { width: 5rem; } .depth-5 { width: 6.25rem; } .depth-6 { width: 7.5rem; }
.depth-7 { width: 8.75rem; } .depth-8 { width: 10rem; } .depth-9 { width: 11.25rem; } .depth-10 { width: 12.5rem; }
.tree-indent:not(.depth-0)::before { content: "└"; color: var(--border); float: right; margin-right: .35rem; }
.asset-link { text-decoration: none; color: var(--text); }
.asset-link:hover span:last-child { text-decoration: underline; }
tr.status-row-removed td { opacity: .6; }

.badge-status-active { background: var(--ok-bg); color: var(--ok); }
.badge-status-spare { background: var(--info-bg); color: var(--info); }
.badge-status-planned { background: var(--warn-bg); color: var(--warn); }
.badge-status-removed { background: var(--surface-2); color: var(--muted); }
.badge-clearance { background: var(--surface-2); color: var(--muted); border: 1px dashed var(--border); }
.badge-create { background: var(--ok-bg); color: var(--ok); }
.badge-update { background: var(--info-bg); color: var(--info); }
.badge-delete { background: var(--fail-bg); color: var(--fail); }

.link-list { list-style: none; margin: 0; padding: 0; }
.link-list li { padding: .45rem 0; border-bottom: 1px solid var(--border); display: flex; gap: .6rem; flex-wrap: wrap; align-items: baseline; }
.link-list li:last-child { border-bottom: 0; }
.link-list a { text-decoration: none; }
.link-list a:hover { text-decoration: underline; }

.relation-list { list-style: none; margin: 0 0 1rem; padding: 0; }
.relation-list li { padding: .45rem 0; border-bottom: 1px solid var(--border); display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; }
.relation-type { color: var(--muted); min-width: 11rem; }
.relation-form { border-top: 1px solid var(--border); padding-top: 1rem; }
.relation-form h3 { font-size: 1rem; }
.relation-row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: .6rem; }
.relation-row select, .relation-row input { width: auto; flex: 1; min-width: 180px; }
.link-button.danger { color: var(--fail); font-size: 1.1rem; line-height: 1; padding: .1rem .45rem; }

.observed { display: inline-flex; gap: .35rem; align-items: baseline; margin-left: .4rem; color: var(--info); }
.observed .source { font-size: .75rem; color: var(--muted); }
.observed.differs { color: var(--warn); }

.prose { line-height: 1.6; overflow-wrap: anywhere; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline > li { padding: .6rem 0; border-bottom: 1px solid var(--border); }
.timeline > li:last-child { border-bottom: 0; }
.timeline-head { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; font-size: .92rem; }
.changes { margin: .4rem 0 0; padding-left: 1.2rem; font-size: .9rem; }
.change-field { color: var(--muted); margin-right: .4rem; }
.changes del { color: var(--fail); text-decoration: line-through; }
.changes ins { color: var(--ok); text-decoration: none; }

.danger-zone { margin: 1.5rem 0; display: flex; gap: .8rem; align-items: center; }
.button-danger { border-color: var(--fail); color: var(--fail); background: var(--surface); }
.button-danger:hover { background: var(--fail-bg); color: var(--fail); }
.button[disabled] { opacity: .5; cursor: not-allowed; }

.more-attributes summary { cursor: pointer; color: var(--accent); margin: .4rem 0 1rem; font-weight: 600; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .4rem 1rem; }
fieldset.field { border: 0; padding: 0; margin: 0 0 1rem; }
fieldset.field legend { font-weight: 600; margin-bottom: .3rem; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: .8rem 0; border-top: 1px solid var(--border); }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions a + a { margin-left: .8rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.stat { display: flex; flex-direction: column; gap: .2rem; text-decoration: none; color: var(--text); margin: 0; }
a.stat:hover { border-color: var(--accent); }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-label { color: var(--muted); }
.quick-search input { min-width: 260px; }
.steps-list { margin: 0; padding-left: 1.2rem; line-height: 2; }
.recent-list li { align-items: center; }

input[type="search"], input[type="date"] {
    width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface); color: var(--text); font: inherit;
}

/* User menu (works without JavaScript) */
.user-menu { position: relative; }
.user-menu summary {
    list-style: none; cursor: pointer; padding: .45rem .7rem; border-radius: 8px; color: var(--text);
    display: flex; align-items: center; gap: .35rem;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary::after { content: "▾"; color: var(--muted); font-size: .8em; }
.user-menu summary:hover, .user-menu[open] summary, .user-menu[data-active] summary { background: var(--surface-2); }
.user-menu-items {
    position: absolute; right: 0; top: calc(100% + .3rem); min-width: 200px; z-index: 20;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: .4rem; display: flex; flex-direction: column;
}
.user-menu-items a, .user-menu-items .link-button {
    display: block; padding: .5rem .7rem; border-radius: 6px; color: var(--text); text-decoration: none; text-align: left; width: 100%;
}
.user-menu-items a:hover, .user-menu-items .link-button:hover { background: var(--surface-2); }
.user-menu-items a[aria-current="page"] { font-weight: 600; }
.user-menu-items form { margin: 0; border-top: 1px solid var(--border); margin-top: .3rem; padding-top: .3rem; }
@media (max-width: 760px) {
    .user-menu-items { position: static; box-shadow: none; border: 0; padding: 0 0 0 1rem; }
}

@media (max-width: 760px) {
    .col-optional { display: none; }
    .filter-bar .field, .filter-bar .grow { min-width: 100%; }
}
