:root {
    --ams-primary: #2563eb;
    --sidebar-width: 256px;
    --topbar-height: 56px;
}

/* Primary color comes from Settings → Display. */
.btn-primary { --bs-btn-bg: var(--ams-primary); --bs-btn-border-color: var(--ams-primary); --bs-btn-hover-bg: color-mix(in srgb, var(--ams-primary) 85%, black); --bs-btn-hover-border-color: color-mix(in srgb, var(--ams-primary) 85%, black); --bs-btn-active-bg: color-mix(in srgb, var(--ams-primary) 75%, black); --bs-btn-disabled-bg: var(--ams-primary); --bs-btn-disabled-border-color: var(--ams-primary); }
.btn-outline-primary { --bs-btn-color: var(--ams-primary); --bs-btn-border-color: var(--ams-primary); --bs-btn-hover-bg: var(--ams-primary); --bs-btn-hover-border-color: var(--ams-primary); --bs-btn-active-bg: var(--ams-primary); }
a { color: var(--ams-primary); }
.text-primary { color: var(--ams-primary) !important; }
.form-check-input:checked { background-color: var(--ams-primary); border-color: var(--ams-primary); }

body.app { background: var(--bs-tertiary-bg); min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width); z-index: 1040;
    background: #0f172a; color: #cbd5e1; display: flex; flex-direction: column;
    transition: transform .2s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: .6rem; height: var(--topbar-height); padding: 0 1.1rem; color: #fff; font-weight: 600; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.08); flex-shrink: 0; }
.sidebar-brand i { color: var(--ams-primary); font-size: 1.4rem; }
.sidebar-brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* No smooth scrolling here: the saved position must be restored instantly (see layout script). */
.sidebar-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: auto; padding: .5rem 0 2rem; scrollbar-width: thin; scrollbar-color: #334155 transparent; }
.sidebar-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 1rem 1.25rem .35rem; }
.sidebar .nav-link { color: #cbd5e1; display: flex; align-items: center; gap: .7rem; padding: .45rem 1.25rem; font-size: .92rem; border-left: 3px solid transparent; }
.sidebar .nav-link i { width: 1.1rem; text-align: center; opacity: .85; }
.sidebar .nav-link:hover { color: #fff; background: rgba(255,255,255,.05); }
.sidebar .nav-link.active { color: #fff; background: rgba(255,255,255,.08); border-left-color: var(--ams-primary); }
.sidebar-backdrop { display: none; }

.main { margin-left: var(--sidebar-width); min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 1030; height: var(--topbar-height); background: var(--bs-body-bg); border-bottom: 1px solid var(--bs-border-color); display: flex; align-items: center; padding: 0 1rem; gap: .25rem; }
.topbar-search { position: relative; flex: 0 1 460px; }
.topbar-search i { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--bs-secondary-color); }
.topbar-search input { padding-left: 2.2rem; background: var(--bs-tertiary-bg); }
.content { padding: 1.5rem; flex: 1; }

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    body.sidebar-open .sidebar { transform: none; }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1035; }
    .main { margin-left: 0; }
    .content { padding: 1rem; }
}

/* ---------- page anatomy ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.45rem; margin: 0; font-weight: 600; }
.page-header .subtitle { color: var(--bs-secondary-color); font-size: .9rem; }
.page-header .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: .5rem; }
.card { border-color: var(--bs-border-color-translucent); box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.card-header { background: transparent; font-weight: 600; }
.filters .form-control, .filters .form-select { min-width: 150px; }
.table > :not(caption) > * > * { vertical-align: middle; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--bs-secondary-color); white-space: nowrap; }
.table thead th a { color: inherit; text-decoration: none; }
.dl-grid { display: grid; grid-template-columns: minmax(130px, 34%) 1fr; gap: .45rem 1rem; margin: 0; }
.dl-grid dt { font-weight: 500; color: var(--bs-secondary-color); }
.dl-grid dd { margin: 0; word-break: break-word; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--bs-secondary-color); }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .5rem; }
.badge-dot { display: inline-flex; align-items: center; gap: .35rem; font-weight: 500; padding: .3em .6em; border-radius: 999px; font-size: .78rem; background: color-mix(in srgb, var(--c, #64748b) 14%, transparent); color: color-mix(in srgb, var(--c, #64748b) 80%, var(--bs-body-color)); }
.badge-dot::before { content: ""; width: .5em; height: .5em; border-radius: 50%; background: var(--c, #64748b); }
.stat { display: block; text-decoration: none; color: inherit; }
.stat .value { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.stat .label { color: var(--bs-secondary-color); font-size: .85rem; }
.stat:hover .card { border-color: var(--ams-primary); }
.bar { height: .5rem; border-radius: 999px; background: var(--bs-secondary-bg); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--ams-primary); }
.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 1rem 1.6rem; }
.timeline li::before { content: ""; position: absolute; left: .42rem; top: .4rem; bottom: -.4rem; width: 2px; background: var(--bs-border-color); }
.timeline li:last-child::before { display: none; }
.timeline li .dot { position: absolute; left: 0; top: .2rem; width: 1rem; height: 1rem; border-radius: 50%; background: var(--bs-body-bg); border: 3px solid var(--c, var(--ams-primary)); }
.qr-box img { width: 100%; max-width: 220px; image-rendering: pixelated; }
.picker-list { max-height: 420px; overflow-y: auto; }
.required::after { content: " *"; color: var(--bs-danger); }
.help-body table { font-size: .85rem; }
.help-body pre { background: var(--bs-tertiary-bg); padding: .75rem; border-radius: .375rem; font-size: .8rem; }
kbd { font-size: .75rem; }

/* ---------- public / login ---------- */
body.public { background: var(--bs-tertiary-bg); min-height: 100vh; }
.public-main { max-width: 560px; margin: 0 auto; padding: 2rem 1rem; }
.public-brand { font-weight: 700; font-size: 1.2rem; margin-bottom: 1rem; text-align: center; }
.public-brand i { color: var(--ams-primary); }

/* ---------- printing ---------- */
.print-only { display: none; }
@media print {
    .sidebar, .topbar, .no-print, .toast-container, .page-header .actions, .btn { display: none !important; }
    .main { margin-left: 0; }
    .content { padding: 0; }
    body.app { background: #fff; }
    .card { border: none; box-shadow: none; }
    .print-only { display: block; }
    a { color: inherit; text-decoration: none; }
}
