/* Diem ERP design system v0.1 — tokens first, components second. */
:root {
    --c-primary: #1f4e8c;
    --c-primary-dark: #173a69;
    --c-accent: #d9640b;
    --c-ink: #1b2430;
    --c-muted: #5b6776;
    --c-bg: #f3f5f8;
    --c-surface: #ffffff;
    --c-border: #dde3ea;
    --c-side: #14202e;
    --c-side-ink: #b9c4d2;
    --c-ok: #1d7a46;
    --c-warn: #a86400;
    --c-bad: #b3261e;
    --sp-1: .25rem; --sp-2: .5rem; --sp-3: 1rem; --sp-4: 1.5rem; --sp-5: 2rem;
    --radius: 8px;
    --sidebar-w: 248px;
    --sidebar-w-collapsed: 68px;
    --topbar-h: 56px;
    --bs-primary: var(--c-primary);
    --bs-primary-rgb: 31, 78, 140;
    --bs-body-color: var(--c-ink);
    --bs-body-bg: var(--c-bg);
    --bs-border-color: var(--c-border);
    --bs-link-color: var(--c-primary);
    --bs-font-sans-serif: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

body { font-size: .925rem; }
.btn-primary { --bs-btn-bg: var(--c-primary); --bs-btn-border-color: var(--c-primary); --bs-btn-hover-bg: var(--c-primary-dark); --bs-btn-hover-border-color: var(--c-primary-dark); --bs-btn-active-bg: var(--c-primary-dark); --bs-btn-disabled-bg: var(--c-primary); --bs-btn-disabled-border-color: var(--c-primary); }
.btn-outline-primary { --bs-btn-color: var(--c-primary); --bs-btn-border-color: var(--c-primary); --bs-btn-hover-bg: var(--c-primary); --bs-btn-hover-border-color: var(--c-primary); }
.form-control:focus, .form-select:focus, .btn:focus-visible { border-color: var(--c-primary); box-shadow: 0 0 0 .2rem rgba(31, 78, 140, .2); }
.form-label { font-weight: 600; font-size: .82rem; color: var(--c-ink); margin-bottom: .25rem; }
.btn { min-height: 38px; }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar { width: var(--sidebar-w); background: var(--c-side); color: var(--c-side-ink); position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 1040; transition: width .15s ease, transform .2s ease; overflow-y: auto; }
.app-main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; transition: margin-left .15s ease; }
.brand { display: flex; align-items: center; gap: .65rem; padding: 0 1rem; height: var(--topbar-h); color: #fff; font-weight: 700; letter-spacing: .02em; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 8px; background: var(--c-accent); color: #fff; font-weight: 800; flex: none; }
.brand-mark-lg { width: 44px; height: 44px; font-size: 1.3rem; border-radius: 10px; }
.nav-sections { padding: .75rem .5rem; flex: 1; }
.nav-section + .nav-section { margin-top: 1rem; }
.nav-section-title { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; padding: 0 .75rem .35rem; color: #7d8a9b; }
.nav-link-item { display: flex; align-items: center; gap: .75rem; padding: .55rem .75rem; border-radius: 6px; color: var(--c-side-ink); text-decoration: none; min-height: 40px; }
.nav-link-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-link-item.active { background: rgba(255, 255, 255, .12); color: #fff; box-shadow: inset 3px 0 0 var(--c-accent); }
.nav-link-item .bi { font-size: 1.1rem; width: 1.25rem; text-align: center; flex: none; }
.sidebar-foot { padding: .75rem 1rem; font-size: .72rem; color: #6f7c8d; border-top: 1px solid rgba(255, 255, 255, .08); }
.app-backdrop { display: none; }

.app-topbar { height: var(--topbar-h); background: var(--c-surface); border-bottom: 1px solid var(--c-border); display: flex; align-items: center; gap: .75rem; padding: 0 1rem; position: sticky; top: 0; z-index: 1030; }
.topbar-spacer { flex: 1; }
.btn-icon { width: 40px; padding: 0; font-size: 1.35rem; line-height: 1; }
.company-switch { max-width: 220px; }
.user-chip { display: flex; align-items: center; gap: .5rem; padding: .25rem .5rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--c-primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: .75rem; font-weight: 700; }
.app-content { padding: 1.25rem; max-width: 1400px; width: 100%; }

body.sidebar-collapsed .app-sidebar { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .app-main { margin-left: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .brand-text, body.sidebar-collapsed .nav-label, body.sidebar-collapsed .nav-section-title, body.sidebar-collapsed .sidebar-foot { display: none; }
body.sidebar-collapsed .nav-link-item { justify-content: center; padding: .55rem 0; }

@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; }
    .app-main { margin-left: 0 !important; }
    body.sidebar-open .app-sidebar { transform: none; }
    body.sidebar-open .app-backdrop { display: block; position: fixed; inset: 0; background: rgba(10, 16, 24, .5); z-index: 1035; }
    body.sidebar-collapsed .brand-text, body.sidebar-collapsed .nav-label, body.sidebar-collapsed .nav-section-title, body.sidebar-collapsed .sidebar-foot { display: initial; }
    body.sidebar-collapsed .nav-link-item { justify-content: flex-start; padding: .55rem .75rem; }
    .app-content { padding: .9rem; }
}

/* ---------- Page ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-title { font-size: 1.35rem; font-weight: 700; margin: 0; }
.page-sub { color: var(--c-muted); margin: .15rem 0 0; }
.form-narrow { max-width: 520px; }
.state-loading, .state-empty, .state-error { padding: 2rem 1rem; text-align: center; color: var(--c-muted); }
.state-error { color: var(--c-bad); }

/* ---------- Cards / stats ---------- */
.card { border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(20, 32, 46, .04); }
.card-head { padding: .85rem 1rem; border-bottom: 1px solid var(--c-border); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .85rem; margin-bottom: 1rem; }
.stat { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: .9rem 1rem; }
.stat-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--c-muted); }
.stat-value { font-size: 1.7rem; font-weight: 700; line-height: 1.2; }
.stat-note { font-size: .75rem; color: var(--c-muted); }
.chart-box { position: relative; height: 260px; padding: 1rem; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); overflow: hidden; }
.table { margin: 0; --bs-table-bg: transparent; }
.table thead th { background: #f7f9fb; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--c-muted); border-bottom: 1px solid var(--c-border); white-space: nowrap; }
.table td { vertical-align: middle; }
.toolbar { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: .85rem; align-items: center; }
.toolbar .search { flex: 1; min-width: 200px; max-width: 420px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .65rem 1rem; border-top: 1px solid var(--c-border); font-size: .82rem; color: var(--c-muted); flex-wrap: wrap; }
.row-actions { display: flex; gap: .35rem; justify-content: flex-end; white-space: nowrap; }

@media (max-width: 767.98px) {
    .table-cards thead { display: none; }
    .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
    .table-cards tr { border-bottom: 1px solid var(--c-border); padding: .6rem .85rem; }
    .table-cards td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .2rem 0; text-align: right; }
    .table-cards td::before { content: attr(data-label); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--c-muted); text-align: left; flex: none; }
    .table-cards td.cell-actions::before { content: none; }
    .table-cards td.cell-actions { justify-content: flex-end; padding-top: .5rem; }
}

/* ---------- Badges ---------- */
.badge-soft { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 600; }
.badge-ok { background: #e3f4ea; color: var(--c-ok); }
.badge-off { background: #eceff3; color: var(--c-muted); }
.badge-warn { background: #fff1d6; color: var(--c-warn); }
.badge-bad { background: #fbe4e2; color: var(--c-bad); }

/* ---------- Forms in modals ---------- */
.multi-box { border: 1px solid var(--c-border); border-radius: 6px; padding: .5rem .75rem; max-height: 220px; overflow-y: auto; background: #fff; }
.multi-group { font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--c-muted); margin: .4rem 0 .15rem; }
.field-error { color: var(--c-bad); font-size: .78rem; margin-top: .2rem; }
.json-view { background: #f7f9fb; border: 1px solid var(--c-border); border-radius: 6px; padding: .6rem; font-size: .78rem; max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-word; }

/* ---------- Auth ---------- */
.auth-body { background: linear-gradient(160deg, #14202e 0%, #1f4e8c 100%); min-height: 100vh; }
.auth-wrap { max-width: 440px; margin: 0 auto; padding: 2.5rem 1rem; }
.auth-brand { display: flex; align-items: center; gap: .85rem; color: #fff; margin-bottom: 1.25rem; }
.auth-brand-name { font-size: 1.35rem; font-weight: 700; }
.auth-brand-sub { font-size: .8rem; opacity: .75; }
.auth-card { background: #fff; border-radius: 12px; padding: 1.75rem; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.auth-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 1rem; }
.auth-help, .auth-foot { font-size: .8rem; color: var(--c-muted); margin: 1rem 0 0; }
.auth-foot { color: rgba(255, 255, 255, .7); text-align: center; }

/* ---------- Roadmap ---------- */
.phase-chip { font-size: .72rem; background: #e8eef7; color: var(--c-primary); border-radius: 4px; padding: .1rem .4rem; font-weight: 600; }

/* ---------- Phase 3: documents, pipeline ---------- */
.filter-select { max-width: 200px; }
.totals > div { padding: .15rem 0; }
.doc-lines th { white-space: nowrap; }
.doc-lines .form-control-sm, .doc-lines .form-select-sm { min-width: 70px; }
.line-error td { background: #fdf2f1; }
@media (min-width: 768px) {
    .doc-lines { min-width: 1020px; }
    .doc-lines td:nth-child(2) { min-width: 190px; }
    .doc-lines td:nth-child(3) { min-width: 200px; }
    .table-wrap:has(.doc-lines) { overflow-x: auto; }
}
.kanban { display: flex; gap: .85rem; overflow-x: auto; padding-bottom: .75rem; align-items: flex-start; }
.kcol { flex: 0 0 270px; background: #eaeff5; border-radius: var(--radius); }
.kcol-head { padding: .7rem .8rem; border-bottom: 1px solid var(--c-border); }
.kcol-body { padding: .6rem; display: flex; flex-direction: column; gap: .55rem; max-height: 70vh; overflow-y: auto; }
.kcard { background: #fff; border: 1px solid var(--c-border); border-radius: 6px; padding: .6rem .7rem; }
