/* ==========================================================================
   Next Point Management — base stylesheet (light theme)
   Design tokens first; components below. No inline styles anywhere (CSP).
   ========================================================================== */

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --text: #141a24;
    --text-muted: #5a6474;
    --border: #e2e5ea;
    --border-strong: #cdd2da;

    --accent: #1f4fb8;
    --accent-hover: #193f94;
    --accent-soft: #e9effb;
    --on-accent: #ffffff;

    --success: #157a3c;
    --success-soft: #e7f5ec;
    --warning: #9a5b07;
    --warning-soft: #fdf3e2;
    --danger: #b42318;
    --danger-soft: #fdecea;
    --info: #0b6aa2;
    --info-soft: #e6f2fa;

    --sidebar-bg: #121826;
    --sidebar-text: #c6ccd8;
    --sidebar-active: #ffffff;
    --sidebar-active-bg: rgba(255, 255, 255, 0.08);

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
    --focus: 0 0 0 3px rgba(31, 79, 184, 0.35);

    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

    --sidebar-w: 248px;
    --topbar-h: 60px;
    --gutter: 24px;
}

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 var(--font);
    font-variant-numeric: tabular-nums;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
p { margin: 0 0 .75em; }
code, .mono { font-family: var(--mono); font-size: .88em; }
img { max-width: 100%; height: auto; }

.muted { color: var(--text-muted); }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
    position: absolute; left: 8px; top: -48px; z-index: 100;
    background: var(--accent); color: var(--on-accent); padding: 8px 14px; border-radius: var(--radius-sm);
}
.skip-link:focus { top: 8px; }

.icon { flex: none; vertical-align: middle; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
    background: var(--sidebar-bg); color: var(--sidebar-text);
    display: flex; flex-direction: column; z-index: 40;
    transition: transform .2s ease, width .2s ease;
    overflow-y: auto;
}
.sidebar__brand {
    display: flex; align-items: center; gap: 10px;
    height: var(--topbar-h); padding: 0 18px; border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.brand-mark {
    display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
    background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; letter-spacing: .5px;
}
.brand-name { font-weight: 600; color: #fff; white-space: nowrap; }
.sidebar__nav { padding: 12px 10px 24px; }
.nav-heading {
    margin: 18px 10px 6px; font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .08em; color: #8892a6;
}
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-link {
    display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px;
    color: var(--sidebar-text); white-space: nowrap;
}
.nav-link:hover { background: var(--sidebar-active-bg); color: #fff; text-decoration: none; }
.nav-link.is-active { background: var(--sidebar-active-bg); color: var(--sidebar-active); box-shadow: inset 3px 0 0 #7aa2ff; }

.main-column { flex: 1; min-width: 0; margin-left: var(--sidebar-w); transition: margin-left .2s ease; }

/* Collapsed (desktop) */
.shell.is-collapsed .sidebar { width: 72px; }
.shell.is-collapsed .brand-name,
.shell.is-collapsed .nav-link span,
.shell.is-collapsed .nav-heading { display: none; }
.shell.is-collapsed .nav-link { justify-content: center; }
.shell.is-collapsed .main-column { margin-left: 72px; }

.sidebar-backdrop { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); z-index: 35; }

.topbar {
    position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
    display: flex; align-items: center; gap: 12px; padding: 0 var(--gutter);
    background: rgba(255, 255, 255, .92); backdrop-filter: saturate(1.2) blur(6px);
    border-bottom: 1px solid var(--border);
}
.topbar__title { font-size: 17px; font-weight: 600; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__actions { display: flex; align-items: center; gap: 12px; }

.icon-button {
    display: inline-grid; place-items: center; width: 38px; height: 38px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer;
}
.icon-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__btn {
    border: 0; background: var(--surface); color: var(--text-muted); padding: 6px 10px; font: 600 12px var(--font); cursor: pointer;
}
.lang-switch__btn.is-active { background: var(--accent-soft); color: var(--accent); }
.lang-switch--center { margin: 20px auto 0; display: flex; width: fit-content; }
.lang-switch--center .lang-switch__btn { font-size: 13px; padding: 6px 14px; }

.user-menu { position: relative; }
.user-menu summary {
    list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer;
    padding: 4px 6px; border-radius: 8px;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: var(--surface-2); }
.avatar {
    display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
    background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.user-menu__name { font-weight: 500; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu__panel {
    position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; padding: 8px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(16, 24, 40, .14);
}
.user-menu__email { font-size: 13px; color: var(--text-muted); padding: 6px 10px; margin: 0 0 4px; border-bottom: 1px solid var(--border); word-break: break-all; }
.user-menu__panel a, .user-menu__panel button {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 6px;
    color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; text-align: left;
}
.user-menu__panel a:hover, .user-menu__panel button:hover { background: var(--surface-2); text-decoration: none; }
.user-menu__panel form { margin: 0; }

.content { padding: var(--gutter); max-width: 1320px; }
.content:focus { box-shadow: none; }

/* ---------- Cards, layout ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 20px;
}
.card--narrow { max-width: 560px; }
.card__title { font-size: 16px; font-weight: 600; margin-bottom: 14px; }
.subheading { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin: 14px 0 6px; }
.section-title { font-size: 15px; margin: 18px 0 10px; }
.page-intro { margin-bottom: 18px; }
.page-intro h2 { font-size: 22px; margin-bottom: 2px; }

.layout-split { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.layout-split--even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.layout-split__side { position: sticky; top: calc(var(--topbar-h) + 16px); }

.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.toolbar .muted { margin: 0; max-width: 640px; }
.toolbar__search { display: flex; gap: 8px; flex: 1; max-width: 460px; }
.toolbar__search input { flex: 1; }

.breadcrumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0 0 14px; font-size: 14px; }
.breadcrumbs li + li::before { content: "/"; color: var(--border-strong); margin-right: 6px; }
.breadcrumbs span[aria-current] { color: var(--text-muted); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 40px; padding: 8px 16px; border-radius: 8px; border: 1px solid transparent;
    font: 600 14px var(--font); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--danger-outline { background: var(--surface); color: var(--danger); border-color: #f1b8b2; }
.btn--danger-outline:hover { background: var(--danger-soft); }
.btn--sm { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.btn--block { width: 100%; }

/* ---------- Forms ---------- */
.form { display: block; }
.form--inline { max-width: 420px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 20px; }
.field { margin-bottom: 16px; }
.field label, .field__label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.req { color: var(--danger); }
.field__hint { font-size: 13px; color: var(--text-muted); margin: 6px 0 0; }
.field__error { font-size: 13px; color: var(--danger); margin: 6px 0 0; font-weight: 500; }
.field__static { margin: 0; padding: 9px 0; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="date"],
input[type="number"], input[type="tel"], input[type="url"], select, textarea {
    width: 100%; min-height: 42px; padding: 9px 12px;
    font: 15px var(--font); color: var(--text);
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: var(--focus); outline: none; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
input[type="file"] { font: 14px var(--font); }

.password-input { position: relative; }
.password-input input { padding-right: 46px; }
.password-toggle {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    width: 36px; height: 34px; border: 0; background: none; color: var(--text-muted); cursor: pointer; border-radius: 6px;
}
.password-toggle[aria-pressed="true"] { color: var(--accent); }

.fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin: 4px 0 18px; }
.fieldset legend { font-weight: 600; font-size: 14px; padding: 0 6px; }
.fieldset.has-error { border-color: var(--danger); }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 16px; }
.checkbox { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; padding: 4px 0; }
.checkbox input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.checkbox input:disabled + span { color: var(--text-muted); }

.form__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

.permission-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.permission-group { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px 12px; margin: 0; }
.permission-group legend { padding: 0 6px; }
.checkbox--group span { font-weight: 600; }
.perm-key { display: block; color: var(--text-muted); font-size: 11.5px; }

.filters {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 14px; align-items: end;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 0; margin-bottom: 16px;
}
.filters__actions { display: flex; gap: 8px; margin-bottom: 16px; }

.danger-zone { margin-top: 24px; }

/* ---------- Alerts, banners, badges ---------- */
.alert {
    display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius);
    margin-bottom: 16px; border: 1px solid;
}
.alert--success { background: var(--success-soft); border-color: #b5dfc4; color: #0e5a2c; }
.alert--error { background: var(--danger-soft); border-color: #f4c0ba; color: #8a1c12; }
.alert__list { margin: 4px 0 0; padding-left: 18px; }

.banner {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 14px 16px; margin-bottom: 20px;
    border-radius: var(--radius); background: var(--info-soft); border: 1px solid #bcdcf0; color: #0a4c75;
}
.banner p { margin: 0; flex: 1; min-width: 220px; }
.banner--attention { background: var(--warning-soft); border-color: #f0d4a6; color: #6e4106; }
.banner--ok { background: var(--success-soft); border-color: #b5dfc4; color: #0e5a2c; }

.badge {
    display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
    font-size: 12px; font-weight: 600; white-space: nowrap; margin: 1px 4px 1px 0;
}
.badge .icon { width: 14px; height: 14px; }
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--info { background: var(--info-soft); color: var(--info); }
.badge--neutral { background: #eef0f4; color: #3c4554; }
.badge--muted { background: #f0f1f3; color: var(--text-muted); }

.secret { background: #fff; border: 1px dashed var(--border-strong); padding: 3px 8px; border-radius: 6px; font-size: 15px; user-select: all; }
.hash { word-break: break-all; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
.card .table-wrap { box-shadow: none; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table thead th { background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; white-space: nowrap; }
.table tbody tr:last-child td, .table tbody tr:last-child th { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfc; }
.table .num { text-align: right; }
.table__actions { text-align: right; white-space: nowrap; }
.table .empty { text-align: center; color: var(--text-muted); padding: 28px; }
.table tr.is-changed { background: #fffbeb; }

.pagination { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin: 14px 0; font-size: 14px; }
.pagination__controls { display: flex; align-items: center; gap: 10px; }

/* ---------- Lists ---------- */
.check-list { list-style: none; margin: 0; padding: 0; }
.check-list li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.check-list li:last-child { border-bottom: 0; }
.check-list .is-ok .icon, .check-list .is-done .icon { color: var(--success); }
.check-list .is-fail .icon, .check-list .is-todo .icon { color: var(--warning); }
.check-list .is-later .icon { color: var(--text-muted); }
.check-list .is-later { color: var(--text-muted); }
.check-list__status { display: block; font-size: 12px; color: var(--text-muted); }

.plain-list { margin: 0; padding-left: 18px; }
.plain-list li { padding: 3px 0; }
.plain-list--compact { columns: 2; column-gap: 24px; font-size: 14px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
.kv dt { color: var(--text-muted); font-weight: 500; }
.kv dd { margin: 0; }

.roadmap { list-style: none; margin: 0; padding: 0; }
.roadmap__item { display: grid; grid-template-columns: 80px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.roadmap__item:last-child { border-bottom: 0; }
.roadmap__phase { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.roadmap__item.is-done .roadmap__label { font-weight: 600; }

.stepper { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 0 0 18px; counter-reset: step; }
.stepper__item a {
    display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); font-size: 14px;
}
.stepper__item a:hover { text-decoration: none; border-color: var(--border-strong); }
.stepper__num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: #eef0f4; font-weight: 700; font-size: 12px; }
.stepper__item.is-current a { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.stepper__item.is-current .stepper__num { background: var(--accent); color: #fff; }
.stepper__item.is-done .stepper__num { background: var(--success-soft); color: var(--success); }
.wizard-skip { margin: 14px 0 0; font-size: 14px; }

.logo-preview { margin-bottom: 14px; }
.logo-preview img { max-height: 90px; border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: #fff; }

/* ---------- Auth & error pages ---------- */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; }
.auth-card {
    width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; box-shadow: 0 10px 30px rgba(16, 24, 40, .08); padding: 32px 30px;
}
.auth-card__brand { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.auth-card__brand .brand-name { color: var(--text); }
.auth-card__title { font-size: 22px; margin-bottom: 6px; }
.auth-card .form { margin-top: 18px; }
.auth-card__links { text-align: center; margin: 16px 0 0; font-size: 14px; }

.error-page { text-align: center; }
.error-page__code { font-size: 48px; font-weight: 800; color: var(--accent); margin: 0; }
.debug-detail { text-align: left; white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); padding: 10px; border-radius: 8px; font-size: 12px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .layout-split { grid-template-columns: 1fr; }
    .layout-split__side { position: static; }
}

@media (max-width: 900px) {
    :root { --gutter: 16px; }
    .sidebar { transform: translateX(-100%); width: var(--sidebar-w); }
    .shell.is-open .sidebar { transform: translateX(0); }
    .main-column, .shell.is-collapsed .main-column { margin-left: 0; }
    .shell.is-collapsed .sidebar { width: var(--sidebar-w); }
    .shell.is-collapsed .brand-name, .shell.is-collapsed .nav-link span, .shell.is-collapsed .nav-heading { display: revert; }
    .shell.is-collapsed .nav-link { justify-content: flex-start; }
    .user-menu__name { display: none; }
    .form-grid, .layout-split--even { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .table--cards thead { display: none; }
    .table--cards, .table--cards tbody, .table--cards tr, .table--cards td, .table--cards th { display: block; width: 100%; }
    .table--cards tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
    .table--cards td, .table--cards th { border: 0; padding: 4px 14px; text-align: left; }
    .table--cards td[data-label]::before, .table--cards th[data-label]::before {
        content: attr(data-label); display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600;
    }
    .table--cards .num { text-align: left; }
    .table__actions { text-align: left; padding-top: 8px !important; }
    .roadmap__item { grid-template-columns: 1fr; gap: 4px; }
    .plain-list--compact { columns: 1; }
    .card { padding: 16px; }
    .toolbar__search { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

@media print {
    .sidebar, .topbar, .skip-link, .form__actions, .filters { display: none !important; }
    .main-column { margin: 0 !important; }
    .card, .table-wrap { box-shadow: none; }
}

/* ==========================================================================
   Phase 2 components: CRM, pipeline, proposals, contracts
   ========================================================================== */
.small { font-size: 13px; }
.prewrap { white-space: pre-wrap; }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
form.inline, .page-header__actions form, .contact-list__actions form { display: inline; margin: 0; }

.topbar__search { flex: 0 1 320px; margin: 0; }
.topbar__search input { min-height: 38px; padding: 7px 12px; background: var(--surface-2); }
.icon-button--accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.quick-menu summary { padding: 0; }

.page-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.page-header p { margin: 0 0 4px; }
.page-header__title { font-size: 22px; margin: 2px 0 6px; }
.page-header__actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.toolbar__buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.filters--inline { flex: 1; margin: 0; }
.filters__check { align-self: end; margin-bottom: 18px; }

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; }
.kpi__label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi__value { font-size: 22px; font-weight: 700; }
.kpi__sub { font-size: 12px; color: var(--text-muted); }

.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.segmented a { padding: 7px 14px; color: var(--text-muted); font-weight: 600; font-size: 14px; background: var(--surface); }
.segmented a + a { border-left: 1px solid var(--border-strong); }
.segmented a.is-active { background: var(--accent-soft); color: var(--accent); }
.segmented a:hover { text-decoration: none; }

.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.board__col { background: #eceff3; border-radius: var(--radius); padding: 10px; min-height: 120px; }
.board__col.is-won { background: var(--success-soft); }
.board__col.is-lost { background: #f4eded; }
.board__head { margin-bottom: 8px; font-size: 13px; }
.board__head h2 { font-size: 14px; margin: 0 0 2px; display: flex; justify-content: space-between; }
.board__count { background: rgba(0, 0, 0, .07); border-radius: 999px; padding: 0 8px; font-size: 12px; }
.deal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 3px; font-size: 13px; box-shadow: var(--shadow); }
.deal-card__title { font-weight: 600; font-size: 14px; }
.deal-card__value { font-weight: 600; }
.deal-card__due { display: inline-flex; align-items: center; gap: 4px; color: var(--text-muted); }
.deal-card__due .icon { width: 14px; height: 14px; }
.deal-card__due.is-due { color: var(--danger); font-weight: 600; }
.deal-card__move { display: flex; gap: 6px; margin-top: 4px; }
.deal-card__move select { min-height: 32px; padding: 4px 8px; font-size: 13px; }

.contact-list { list-style: none; margin: 0 0 12px; padding: 0; }
.contact-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.contact-list__actions { display: flex; gap: 6px; align-items: flex-start; flex-wrap: wrap; }
.inline-form summary { cursor: pointer; font-weight: 600; color: var(--accent); margin: 8px 0; }
.note { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.note p { margin: 0; }
.note__meta { font-size: 12px; margin-top: 4px !important; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 12px 10px; display: flex; flex-direction: column; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: -21px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }
.timeline__summary { color: var(--text); }

.plain-list--rows { list-style: none; padding: 0; }
.plain-list--rows li { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.plain-list--rows li:last-child { border-bottom: 0; }

.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 20px; }

.kv--stack { grid-template-columns: 1fr; gap: 2px; }
.kv--stack dd { margin-bottom: 8px; }

.totals { display: grid; grid-template-columns: 1fr auto; gap: 6px 24px; max-width: 360px; margin: 16px 0 0 auto; }
.totals dt { color: var(--text-muted); }
.totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.totals .totals__grand { font-weight: 700; font-size: 17px; color: var(--text); border-top: 2px solid var(--text); padding-top: 6px; }

.line-items td { padding: 6px; vertical-align: top; }
.line-items textarea { min-width: 220px; min-height: 42px; }
.line-items select { min-width: 150px; }
.input--narrow { max-width: 90px; }
input.num { text-align: right; }
.card.has-error { border-color: var(--danger); }
.fieldset--plain { border: 1px solid var(--border); }
.fieldset--plain:disabled { opacity: .85; }
.upload-form { display: flex; flex-wrap: wrap; gap: 0 12px; align-items: end; margin-top: 12px; }
.search-page { max-width: 640px; margin-bottom: 18px; }
.search-results { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 0 20px; }

@media (max-width: 900px) {
    .topbar__search { display: none; }
}
@media (max-width: 720px) {
    .board { grid-auto-flow: row; grid-auto-columns: auto; }
    .line-items thead { display: none; }
    .line-items tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; border-bottom: 1px solid var(--border); padding: 8px 0; }
    .line-items td:first-child { grid-column: 1 / -1; }
    .line-items td { display: block; padding: 2px; }
    .input--narrow { max-width: none; }
}

/* ==========================================================================
   Phase 3 components: finance
   ========================================================================== */
.amount-in { color: var(--success); }
.amount-out { color: var(--danger); }
.segmented--wrap { flex-wrap: wrap; margin-bottom: 16px; }
.form-inline-row { display: flex; flex-wrap: wrap; gap: 0 14px; align-items: end; margin-bottom: 12px; }
.form-inline-row .field { min-width: 160px; }
.form-inline-row .btn { margin-bottom: 16px; }
.aging { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.aging__cell { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.aging__cell.is-late { border-color: #f1b8b2; background: var(--danger-soft); }
.aging__cell--total { background: var(--surface-2); }
.aging__value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.table .inline-form summary { font-size: 13px; }
.table .inline-form .form { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.table .inline-form input { min-height: 32px; padding: 4px 8px; font-size: 13px; }

/* ==========================================================================
   Phase 5: dashboard KPIs, charts, reports, budgets, print
   ========================================================================== */
:root {
    --chart-1: #1f4fb8;
    --chart-2: #e07a1f;
    --chart-3: #157a3c;
    --chart-4: #7a3db8;
    --chart-neg: #b42318;
    --chart-grid: #e8ebf0;
}
.section-title { font-size: 17px; margin: 26px 0 12px; }
.filters--dashboard { margin-bottom: 6px; }
.dashboard-period { margin: 0 0 14px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi--card { gap: 4px; }
.kpi__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.kpi__basis { font-size: 10.5px; padding: 1px 6px; white-space: nowrap; }
.kpi__warn { color: var(--warning); display: flex; gap: 4px; align-items: center; }
.kpi__warn svg { width: 14px; height: 14px; }
.kpi__help { margin-top: 4px; font-size: 12.5px; color: var(--text-muted); }
.kpi__help summary { cursor: pointer; display: inline-flex; gap: 4px; align-items: center; list-style: none; color: var(--accent); }
.kpi__help summary::-webkit-details-marker { display: none; }
.kpi__help summary svg { width: 14px; height: 14px; }
.kpi__help p { margin: 6px 0 0; }
.trend { font-weight: 600; white-space: nowrap; }
.trend--up { color: var(--success); }
.trend--down { color: var(--danger); }
.trend--flat { color: var(--text-muted); }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 0 20px; }
.chart-card__head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart-grid line, .chart .chart-grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart .chart-axis { stroke: var(--border-strong); stroke-width: 1; }
.chart .chart-label { font: 11px var(--font); fill: var(--text-muted); }
.chart .chart-label--row { text-anchor: end; fill: var(--text); font-size: 12px; }
.chart .chart-label--legend { fill: var(--text); }
.chart .chart-value { font: 600 12px var(--font); fill: var(--text); }
.chart .chart-s1 { fill: var(--chart-1); }
.chart .chart-s2 { fill: var(--chart-2); }
.chart .chart-s3 { fill: var(--chart-3); }
.chart .chart-s4 { fill: var(--chart-4); }
.chart .chart-neg { fill: var(--chart-neg); }
.chart rect:hover, .chart circle:hover { opacity: .8; }
.chart .chart-line { fill: none; stroke-width: 2.5; }
.chart polyline.chart-s1 { stroke: var(--chart-1); }
.chart polyline.chart-s2 { stroke: var(--chart-2); }
.chart polyline.chart-s3 { stroke: var(--chart-3); }
.chart polyline.chart-s4 { stroke: var(--chart-4); }
.chart .chart-dot { stroke: var(--surface); stroke-width: 1.5; }
.card--warning { border-color: #f0c98a; background: var(--warning-soft); }

.report-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 0 20px; }
.report-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.report-list a { display: inline-flex; gap: 8px; align-items: center; font-weight: 600; }
.report-list a svg { width: 16px; height: 16px; }
.report-list p { margin: 2px 0 0 24px; }
.report-definition { max-width: 820px; }
.report-badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; }
.report-table__title { font-size: 15px; margin: 0 0 10px; }
.report-table tbody th, .report-table tfoot th { text-align: left; font-weight: 500; }
.report-table .report-indent { padding-left: 28px; font-weight: 400; }
.report-row--heading th { background: var(--surface-2); text-transform: uppercase; font-size: 12px; letter-spacing: .04em; color: var(--text-muted); font-weight: 700; }
.report-row--subtotal th, .report-row--subtotal td { font-weight: 700; border-top: 1px solid var(--border-strong); }
.report-row--total th, .report-row--total td { font-weight: 700; border-top: 2px solid var(--text); background: var(--surface-2); }
.report-notes ul { margin: 0; padding-left: 18px; color: var(--text-muted); font-size: 13.5px; }
.report-notes li + li { margin-top: 4px; }
.page-header__actions .btn svg, .print-actions .btn svg { width: 16px; height: 16px; }

.budget-grid-wrap { overflow-x: auto; }
.budget-grid { min-width: 1180px; }
.budget-grid th[scope="row"] { min-width: 180px; font-weight: 500; text-align: left; }
.budget-grid td { padding: 4px; }
.budget-input { width: 86px; min-height: 32px; padding: 4px 6px; text-align: right; font-variant-numeric: tabular-nums; }

.print-page { background: #fff; padding: 24px; max-width: 1200px; margin: 0 auto; }
.print-header h1 { margin: 0 0 6px; font-size: 22px; }
.print-meta { list-style: none; margin: 0 0 12px; padding: 0; color: var(--text-muted); font-size: 13px; }
.print-chart { margin: 8px 0 16px; max-width: 760px; }
.print-notes, .print-definition { color: var(--text-muted); font-size: 12.5px; }
.print-page .table-wrap { box-shadow: none; border: 0; margin-bottom: 16px; }

@media (max-width: 720px) {
    .chart-grid { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
}
@media print {
    .print-actions, .page-header__actions, .kpi__help summary { display: none !important; }
    .print-page { padding: 0; }
    .report-table { font-size: 11px; }
    .report-row--total th, .report-row--total td, .report-row--heading th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
