:root {
    --bg-color: #F9F6F0;
    --text-color: #2D2522;
    --heading-color: #4E3629;
    --accent-color: #B07A5A;
    --accent-dark: #9c6a4c;
    --accent-darker: #8a5d42;
    --code-bg: #F0ECE3;
    --border-color: #D1C7BD;
    --sidebar-width: 260px;
    --topbar-height: 56px;
    --sidebar-bg: #4E3629;
    --sidebar-hover: #5c4033;
    --sidebar-active: #B07A5A;
    --danger: #9b3b3b;

    /* Bootstrap theme overrides — warm palette */
    --bs-primary: #B07A5A;
    --bs-primary-rgb: 176, 122, 90;
    --bs-body-bg: #F9F6F0;
    --bs-body-color: #2D2522;
    --bs-border-color: #D1C7BD;
    --bs-heading-color: #4E3629;
    --bs-link-color: #8f6349;
    --bs-link-color-rgb: 143, 99, 73;
    --bs-link-hover-color: #6f4c38;
    --bs-emphasis-color: #4E3629;
    --bs-border-radius: 0.6rem;
    --bs-border-radius-sm: 0.4rem;
    --bs-body-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background-color: var(--bg-color);
}

/* —— Themed Bootstrap components —— */
.btn-primary {
    --bs-btn-bg: var(--accent-color);
    --bs-btn-border-color: var(--accent-color);
    --bs-btn-hover-bg: var(--accent-dark);
    --bs-btn-hover-border-color: var(--accent-dark);
    --bs-btn-active-bg: var(--accent-darker);
    --bs-btn-active-border-color: var(--accent-darker);
    --bs-btn-disabled-bg: var(--accent-color);
    --bs-btn-disabled-border-color: var(--accent-color);
}

.btn-outline-primary {
    --bs-btn-color: var(--accent-dark);
    --bs-btn-border-color: var(--accent-color);
    --bs-btn-hover-bg: var(--accent-color);
    --bs-btn-hover-border-color: var(--accent-color);
    --bs-btn-active-bg: var(--accent-darker);
    --bs-btn-active-border-color: var(--accent-darker);
}

.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: #c9a98f;
    box-shadow: 0 0 0 0.2rem rgba(176, 122, 90, 0.25);
}

.form-check-input:checked {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

.card {
    --bs-card-border-color: var(--border-color);
    --bs-card-cap-bg: #faf8f4;
    box-shadow: 0 2px 12px rgba(78, 54, 41, 0.05);
}

.table {
    --bs-table-hover-bg: #f7f1e9;
    --bs-table-striped-bg: #fcfaf7;
}

.text-accent { color: var(--accent-color) !important; }

/* —— App shell —— */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    color: #f0ece3;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}

.sidebar-brand {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-brand a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.3rem;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
}

.sidebar-brand-icon {
    width: 36px; height: 36px;
    background: var(--accent-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-nav { padding: 1rem 0.75rem; }
.sidebar-nav ul { list-style: none; margin: 0; padding: 0; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1rem;
    border-radius: 8px;
    color: #d1c7bd;
    text-decoration: none;
    font-weight: 500;
    margin-bottom: 2px;
}

.sidebar-nav a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-nav a.active { background: var(--sidebar-active); color: #fff; }

.sidebar-group-item { margin-bottom: 0.35rem; }

.sidebar-group summary {
    list-style: none;
}

.sidebar-group summary::-webkit-details-marker {
    display: none;
}

.sidebar-group-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    border-radius: 8px;
    color: #f0ece3;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

.sidebar-group-summary:hover {
    background: var(--sidebar-hover);
}

.sidebar-group[open] > .sidebar-group-summary {
    color: #fff;
}

.sidebar-group[open] .sidebar-group-chevron {
    transform: rotate(180deg);
}

.sidebar-group-chevron {
    font-size: 0.75rem;
    opacity: 0.85;
    transition: transform 0.15s ease;
}

.sidebar-subnav {
    list-style: none;
    margin: 0.25rem 0 0;
    padding: 0 0 0.35rem 0.5rem;
}

.sidebar-subnav a {
    padding: 0.45rem 1rem 0.45rem 1.25rem;
    font-size: 0.925rem;
    font-weight: 500;
}

.main-area {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-account { display: flex; align-items: center; gap: 0.75rem; }
.topbar-divider { width: 1px; height: 24px; background: var(--border-color); }
.topbar-username { font-weight: 600; font-size: 0.875rem; }

.content { flex: 1; padding: 1.75rem 2rem; }
.page-header { margin-bottom: 1.5rem; }

/* —— Dashboard hero —— */
.welcome-card {
    background: linear-gradient(135deg, var(--heading-color), var(--accent-color));
    color: #fff;
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 1.5rem;
}

.welcome-card h2 { color: #fff; margin: 0 0 0.5rem; }
.welcome-card p { margin: 0; opacity: 0.9; }

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--heading-color);
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6E6259;
}

.dashboard-table thead th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6E6259;
    white-space: nowrap;
}

.event-history-table .event-detail-row > td {
    background: var(--code-bg, #f8f6f2);
}

.event-detail-panel {
    border-left: 3px solid var(--accent-color, #b07a5a);
}

/* —— Client list filter card —— */
.filter-card .form-label,
.filter-card legend.form-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6E6259;
    margin-bottom: 0.35rem;
}

.filter-card .input-group-text { border-right: 0; color: #8a7d70; }

.filter-pill {
    --bs-btn-color: #6E6259;
    --bs-btn-border-color: var(--border-color);
    --bs-btn-hover-color: var(--accent-dark);
    --bs-btn-hover-bg: rgba(176, 122, 90, 0.08);
    --bs-btn-hover-border-color: var(--accent-color);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--accent-color);
    --bs-btn-active-border-color: var(--accent-color);
    padding-inline: 0.9rem;
}

/* —— Status badges (client stay status) —— */
.status-badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-badge.status-active { background: #e8f5e9; color: #2e7d32; }
.status-badge.status-in_release { background: #e3f2fd; color: #1565c0; }
.status-badge.status-exspired { background: #fce8e6; color: #c0564a; }
.status-badge.status-released { background: #ede7f6; color: #5e35b1; }
.status-badge.status-none { background: #f0ebe3; color: #6e6259; }

/* —— Login / standalone pages —— */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-color);
}

.login-card {
    width: 100%;
    max-width: 420px;
}

/* —— Admin Data form: bespoke shell around Bootstrap components —— */
.data-form-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
}

@media (min-width: 992px) {
    .data-form-layout.has-nav {
        grid-template-columns: 240px minmax(0, 1fr);
    }
}

.data-form-nav {
    position: sticky;
    top: calc(var(--topbar-height) + 1rem);
    align-self: start;
}

@media (max-width: 991px) {
    .data-form-nav { position: static; }
}

.data-form-nav .list-group-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border: none;
    cursor: pointer;
}

.data-form-nav .list-group-item.active {
    background: rgba(176, 122, 90, 0.12);
    color: var(--accent-dark);
    font-weight: 600;
}

.data-form-nav .list-group-item.has-error {
    color: var(--danger);
}

.data-form-nav-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.5rem;
    height: 1.5rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: #6E6259;
    background: var(--code-bg);
    border-radius: 50%;
}

.data-form-nav .list-group-item.active .data-form-nav-num {
    background: var(--accent-color);
    color: #fff;
}

.data-form-nav .list-group-item.has-error .data-form-nav-num {
    background: var(--danger);
    color: #fff;
}

.data-form-section { scroll-margin-top: calc(var(--topbar-height) + 1rem); }

.data-form-section-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.85rem;
    height: 1.85rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: #fff;
    background: var(--accent-color);
    border-radius: 50%;
}

.data-form-section.has-section-error .data-form-section-num { background: var(--danger); }
.data-form-section.has-section-error { border-color: rgba(155, 59, 59, 0.5); }

.data-form-footer {
    position: sticky;
    bottom: 0;
    z-index: 5;
}

/* Field table cells */
.dt-label { width: 34%; vertical-align: top; }
.dt-control { width: 66%; vertical-align: top; }
.dt-fieldname {
    font-size: 0.72rem;
    color: #8a7d70;
    background: var(--code-bg);
    padding: 0.05rem 0.35rem;
    border-radius: 4px;
}
.dt-req { color: var(--danger); font-weight: 700; }

.input-mono {
    font-family: ui-monospace, "Cascadia Code", "Source Code Pro", monospace;
    font-size: 0.9em;
    letter-spacing: 0.02em;
}

.error-list { margin: 0; padding-left: 1.25rem; }

/* —— Process map (pan/zoom viewport) —— */
.process-map-viewport {
    position: relative;
    height: min(70vh, 720px);
    overflow: hidden;
    background:
        linear-gradient(to right, rgba(78, 54, 41, 0.04) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(78, 54, 41, 0.04) 1px, transparent 1px);
    background-size: 24px 24px;
    background-color: #faf8f4;
    touch-action: none;
    cursor: grab;
}

.process-map-viewport:active {
    cursor: grabbing;
}

.process-map-diagram-host {
    width: 100%;
    height: 100%;
}

.process-map-diagram-host .mermaid,
.process-map-diagram-host svg {
    width: 100%;
    height: 100%;
    max-width: none !important;
    display: block;
}

.process-map-error {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
}

.scan-preview-modal {
    width: 90vw;
    max-width: 90vw;
    height: 90vh;
    margin: 5vh auto;
}

.scan-preview-modal .modal-content {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.scan-preview-modal .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scan-preview-modal .modal-body:has(.scan-preview-frame) {
    align-items: stretch;
    justify-content: stretch;
}

#scanPreviewModalBody img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.scan-preview-frame {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
    flex: 1 1 auto;
}

.audit-diff-card {
    overflow: hidden;
}

.audit-diff-table td {
    vertical-align: top;
    white-space: pre-wrap;
    word-break: break-word;
}

.audit-diff-removed-cell {
    background: rgba(155, 59, 59, 0.08);
}

.audit-diff-added-cell {
    background: rgba(40, 120, 60, 0.08);
}

.audit-diff-added {
    background: rgba(40, 120, 60, 0.08);
    color: var(--text-color);
}

.audit-diff-removed {
    background: rgba(155, 59, 59, 0.08);
    color: var(--text-color);
}

.audit-context-json {
    max-height: 20rem;
    overflow: auto;
}

.it-work-stat-card .h4 {
    color: var(--heading-color);
}

.it-work-table .it-work-row-job {
    background-color: rgba(40, 120, 60, 0.06);
}

.it-work-table .it-work-row-payment {
    background-color: rgba(255, 193, 7, 0.12);
}

.it-work-dashboard-table tbody th {
    max-width: 7rem;
    white-space: normal;
    line-height: 1.25;
}

.sign-in-template-editor .CodeMirror {
    height: min(70vh, 640px);
    border: none;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
    font-size: 0.875rem;
}

.release-admonition dt {
    font-weight: 600;
}
.release-admonition dd {
    margin-bottom: 0.75rem;
}
