/* ---------- Tokens ---------- */
:root {
    --font: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --pine: #16302b;
    --pine-2: #1f423a;
    --chalk: #e6eee9;
    --chalk-dim: #9db3aa;
    --accent: #e3a72f;          /* chalk-yellow: marks the active menu item only */
    --brand: #1f6f5c;
    --brand-dark: #185a4a;
    --paper: #f3f5f4;
    --card: #ffffff;
    --line: #dde3e0;
    --ink: #14201d;
    --muted: #66736f;
    --sb-w: 264px;
    --radius: 10px;

    --bs-body-font-family: var(--font);
    --bs-body-color: var(--ink);
    --bs-body-bg: var(--paper);
    --bs-primary: var(--brand);
    --bs-primary-rgb: 31, 111, 92;
    --bs-link-color: var(--brand);
    --bs-link-hover-color: var(--brand-dark);
    --bs-border-color: var(--line);
    --bs-border-radius: 8px;
    --bs-secondary-color: var(--muted);
}
html.sidebar-collapsed { --sb-w: 76px; }

body { font-family: var(--font); background: var(--paper); color: var(--ink); -webkit-font-smoothing: antialiased; }

.btn-primary {
    --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-dark); --bs-btn-hover-border-color: var(--brand-dark);
    --bs-btn-active-bg: var(--brand-darker); --bs-btn-active-border-color: var(--brand-darker);
    --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand);
}
.btn-outline-secondary { --bs-btn-color: #3f4d49; --bs-btn-border-color: var(--line); --bs-btn-hover-bg: #eef2f0; --bs-btn-hover-color: var(--ink); --bs-btn-hover-border-color: #c9d2ce; --bs-btn-active-bg: #e4eae7; --bs-btn-active-color: var(--ink); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(var(--brand-rgb), .18); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }

/* ---------- Shell ---------- */
.app-shell { min-height: 100vh; }
.app-main { margin-left: var(--sb-w); min-width: 0; min-height: 100vh; display: flex; flex-direction: column; transition: margin-left .2s ease; }
.app-content { padding: 1.5rem; flex: 1; }
.page-head { margin-bottom: 1.25rem; }
.page-title { font-size: 1.5rem; font-weight: 650; letter-spacing: -.01em; margin: 0; }
.page-sub { color: var(--muted); margin: .25rem 0 0; max-width: 70ch; }

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sb-w); z-index: 1040;
    background: var(--pine); color: var(--chalk);
    display: flex; flex-direction: column;
    transition: width .2s ease, transform .2s ease;
    overflow: hidden;
}
.sidebar-brand { display: flex; align-items: center; gap: .75rem; height: 60px; padding: 0 1.25rem; color: #fff; text-decoration: none; font-weight: 650; font-size: 1.05rem; flex-shrink: 0; border-bottom: 1px solid rgba(255, 255, 255, .08); white-space: nowrap; }
.brand-mark { width: 34px; height: 34px; flex: 0 0 34px; display: grid; place-items: center; border-radius: 8px; background: var(--brand); color: #fff; font-size: 1.1rem; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem; }
.nav-list, .nav-children { list-style: none; margin: 0; padding: 0; }
.nav-item-x + .nav-item-x { margin-top: 2px; }

.nav-link-x { position: relative; display: flex; align-items: center; gap: .75rem; padding: .6rem .75rem; border-radius: 8px; color: var(--chalk-dim); text-decoration: none; white-space: nowrap; transition: background .15s, color .15s; }
.nav-link-x > .bi:first-child { font-size: 1.15rem; width: 1.25rem; text-align: center; flex: 0 0 1.25rem; }
.nav-link-x:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link-x.is-active { color: #fff; background: rgba(255, 255, 255, .09); }
.nav-link-x.is-active::before { content: ''; position: absolute; left: -.75rem; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav-caret { margin-left: auto; font-size: .75rem; transition: transform .2s; }
.nav-group-toggle[aria-expanded="true"] .nav-caret { transform: rotate(180deg); }

.nav-children { margin: 2px 0 4px 1.65rem; padding-left: .75rem; border-left: 1px solid rgba(255, 255, 255, .12); }
.nav-child { display: block; padding: .42rem .75rem; border-radius: 6px; color: var(--chalk-dim); text-decoration: none; font-size: .925rem; white-space: nowrap; }
.nav-child:hover { color: #fff; background: rgba(255, 255, 255, .05); }
.nav-child.is-active { color: #fff; font-weight: 600; }

.sidebar-foot { padding: .9rem 1.25rem; border-top: 1px solid rgba(255, 255, 255, .08); font-size: .8rem; color: var(--chalk-dim); display: flex; flex-direction: column; line-height: 1.3; white-space: nowrap; }
.sidebar-foot strong { color: #fff; font-weight: 600; font-size: .9rem; }

/* Collapsed rail (desktop) */
html.sidebar-collapsed .brand-text,
html.sidebar-collapsed .nav-label,
html.sidebar-collapsed .nav-caret,
html.sidebar-collapsed .nav-children,
html.sidebar-collapsed .sidebar-foot { display: none !important; }
html.sidebar-collapsed .sidebar-brand,
html.sidebar-collapsed .nav-link-x { justify-content: center; padding-left: 0; padding-right: 0; }
html.sidebar-collapsed .nav-link-x.is-active::before { left: -.75rem; }

.app-backdrop { display: none; }

/* ---------- Topbar ---------- */
.topbar { position: sticky; top: 0; z-index: 1020; height: 60px; display: flex; align-items: center; gap: .75rem; padding: 0 1.25rem; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-spacer { flex: 1; }
.btn-icon { width: 38px; height: 38px; display: grid; place-items: center; font-size: 1.4rem; padding: 0; border: 0; background: transparent; border-radius: 8px; color: var(--ink); }
.btn-icon:hover { background: #eef2f0; }
.role-switch { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--line); background: #fff; padding: .35rem .7rem; }
.role-switch:hover, .role-switch.show { background: #eef2f0; border-color: #c9d2ce; }
.role-switch .bi-person-badge { color: var(--brand); }
.role-badge { background: var(--brand-soft); color: var(--brand-dark); font-weight: 500; padding: .5rem .7rem; }
.user-btn { display: inline-flex; align-items: center; gap: .5rem; border: 0; background: transparent; }
.user-btn:hover, .user-btn.show { background: #eef2f0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--pine); color: #fff; display: grid; place-items: center; font-size: .75rem; font-weight: 600; text-transform: uppercase; }
.dropdown-item:active { background: var(--brand); }

/* ---------- Content blocks ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-title { font-size: 1rem; font-weight: 600; margin: 0 0 1rem; }
.stat { display: flex; align-items: center; gap: 1rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.stat > .bi { font-size: 1.5rem; color: var(--brand); width: 44px; height: 44px; display: grid; place-items: center; background: var(--brand-soft); border-radius: 10px; }
.stat-value { font-size: 1.6rem; font-weight: 650; line-height: 1.1; letter-spacing: -.01em; }
.stat-label { color: var(--muted); font-size: .875rem; }
.empty { display: flex; flex-direction: column; align-items: flex-start; gap: .5rem; color: var(--muted); padding: .5rem 0 1rem; }
.empty > .bi { font-size: 1.6rem; color: #9aa9a4; }
.empty p { margin: 0; max-width: 46ch; }

/* ---------- DataTables ---------- */
.fs-sm { font-size: .875rem; }

.dt-card { padding: .25rem 0; overflow: hidden; }
.dt-card div.dt-container { padding: .75rem 1rem .25rem; font-size: .875rem; }
.dt-card .dt-layout-table { overflow-x: auto; }                 /* table-responsive behaviour, scoped to the table only */
.dt-card table.dataTable { margin-top: .5rem !important; margin-bottom: .5rem !important; width: 100% !important; }
.dt-card table.dataTable thead th { font-weight: 600; font-size: .8rem; color: var(--muted); white-space: nowrap; border-bottom-color: var(--line); }
.dt-card table.dataTable tbody td { vertical-align: middle; }
.dt-card .dt-search input { min-width: 230px; }
.dt-card .dt-length select { width: auto; display: inline-block; }
.dt-card .dt-buttons { gap: .35rem; flex-wrap: wrap; }
.dt-card .dt-buttons .btn { border-radius: 8px !important; }
.dt-card .dt-processing { z-index: 5; }
.dt-card .page-link { color: var(--brand); padding: .25rem .6rem; }
.dt-card .active > .page-link { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (max-width: 575.98px) { .dt-card .dt-search input { min-width: 0; width: 100%; } .dt-card .dt-search { width: 100%; } .dt-card .dt-search label { display: none; } }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-aside { position: relative; background: var(--pine); color: #fff; display: flex; align-items: flex-end; padding: 3rem; overflow: hidden; }
/* ruled-register motif: horizontal rules with column dividers */
.auth-aside::before { content: ''; position: absolute; inset: 0; background-image: repeating-linear-gradient(to bottom, transparent 0 47px, rgba(255, 255, 255, .07) 47px 48px), repeating-linear-gradient(to right, transparent 0 191px, rgba(255, 255, 255, .07) 191px 192px); }
.auth-aside__inner { position: relative; max-width: 420px; }
.auth-aside h2 { font-size: 2.4rem; font-weight: 650; letter-spacing: -.02em; line-height: 1.1; margin: 1.5rem 0 .75rem; }
.auth-aside p { color: var(--chalk-dim); font-size: 1.05rem; margin: 0; }
.auth-form { display: grid; place-items: center; padding: 2rem 1.25rem; background: var(--card); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { font-size: 1.75rem; font-weight: 650; letter-spacing: -.01em; margin: 0 0 .25rem; }

/* ---------- Mobile ---------- */
@media (max-width: 991.98px) {
    html.sidebar-collapsed { --sb-w: 264px; }
    .app-main { margin-left: 0; }
    .sidebar { width: 280px; transform: translateX(-100%); }
    body.sidebar-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
    .app-backdrop { position: fixed; inset: 0; z-index: 1030; background: rgba(10, 20, 18, .5); }
    body.sidebar-open .app-backdrop { display: block; }
    .app-content { padding: 1rem; }
    .auth { grid-template-columns: 1fr; }
    .auth-aside { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar, .app-main, .nav-caret { transition: none; }
}

/* ---------- Branding images ---------- */
.brand-logo { height: 34px; max-width: 150px; width: auto; flex: 0 0 auto; object-fit: contain; border-radius: 6px; }
html.sidebar-collapsed .brand-logo { max-width: 34px; object-fit: cover; object-position: left center; }
.auth-logo { height: 250px; max-width: 220px; width: auto; object-fit: contain; display: block; border-radius: 2px; }

/* ---------- Settings ---------- */
.settings-nav .nav-link { display: flex; align-items: center; gap: .6rem; color: var(--ink); border-radius: 8px; white-space: nowrap; padding: .55rem .75rem; }
.settings-nav .nav-link:hover { background: #eef2f0; }
.settings-nav .nav-link.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.settings-nav .nav-link .bi { color: var(--brand); }
.settings-nav .nav { overflow-x: auto; }
.settings-head { padding: 1.25rem 1.5rem .75rem; }
.settings-head h2 { font-size: 1.15rem; font-weight: 650; margin: 0; }
.settings-head p { color: var(--muted); margin: .25rem 0 0; }
.settings-fields { padding: .5rem 1.5rem; }
.setting-row { display: grid; grid-template-columns: minmax(0, 17rem) minmax(0, 1fr); gap: 1rem 2rem; padding: 1rem 0; border-top: 1px solid var(--line); }
.setting-row:first-child { border-top: 0; }
.setting-label .form-text { font-size: .825rem; }
.settings-foot { padding: 1rem 1.5rem 1.25rem; border-top: 1px solid var(--line); background: #fafbfa; border-radius: 0 0 var(--radius) var(--radius); }
.form-control-color { width: 3rem; padding: .25rem; }
.img-current { margin-bottom: .6rem; padding: .6rem; display: inline-block; border: 1px dashed var(--line); border-radius: 8px; background: repeating-conic-gradient(#f1f3f2 0 25%, #fff 0 50%) 0 0 / 14px 14px; }
.img-current img { display: block; max-height: 56px; max-width: 220px; }
.brand-preview { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; height: 84px; }
.bp-side { width: 90px; background: var(--pine); position: relative; padding: 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.bp-accent { position: absolute; left: 0; top: 14px; width: 3px; height: 14px; background: var(--accent); border-radius: 0 3px 3px 0; }
.bp-line { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, .5); }
.bp-line.short { width: 60%; background: rgba(255, 255, 255, .25); }
.bp-body { flex: 1; display: flex; align-items: center; gap: .75rem; padding: 0 1rem; background: var(--paper); flex-wrap: wrap; }
.bp-btn { background: var(--brand); color: #fff; padding: .35rem .8rem; border-radius: 8px; font-size: .85rem; font-weight: 500; }
.bp-soft { background: var(--brand-soft); color: var(--brand-dark); padding: .35rem .8rem; border-radius: 8px; font-size: .85rem; }
@media (max-width: 767.98px) { .setting-row { grid-template-columns: 1fr; gap: .5rem; } .settings-head, .settings-fields, .settings-foot { padding-left: 1rem; padding-right: 1rem; } }
