:root {
    --ink: #172033;
    --muted: #667085;
    --line: #e4e7ec;
    --surface: #ffffff;
    --surface-soft: #f7f9fc;
    --primary: #3155d9;
    --primary-dark: #243fa8;
    --success: #147d4f;
    --danger: #b42318;
    --warning: #b54708;
    --shadow: 0 12px 35px rgba(23, 32, 51, 0.08);
    --radius: 14px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: #f3f6fb;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.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;
}

.topbar {
    min-height: 68px;
    padding: 0 28px;
    display: flex;
    align-items: center;
    gap: 32px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand, .guest-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    color: var(--ink);
    white-space: nowrap;
}
.brand:hover, .guest-brand:hover { text-decoration: none; }
.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    font-size: 13px;
    letter-spacing: .04em;
}
.primary-nav { display: flex; align-self: stretch; align-items: stretch; gap: 6px; }
.primary-nav a, .nav-pending {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    color: var(--muted);
    font-weight: 650;
    border-bottom: 3px solid transparent;
}
.primary-nav a:hover { color: var(--ink); text-decoration: none; }
.primary-nav a.active { color: var(--primary); border-bottom-color: var(--primary); }
.nav-pending { opacity: .6; }
.nav-pending small { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.workspace-switcher select { min-width: 180px; border-color: var(--line); background: var(--surface-soft); }
.icon-link {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 9px;
    font-weight: 800;
    color: var(--ink);
}
.icon-link:hover { text-decoration: none; background: var(--surface-soft); }
.user-summary { display: flex; flex-direction: column; line-height: 1.2; margin-left: 8px; }
.user-summary span { font-size: 13px; font-weight: 700; }
.user-summary small { color: var(--muted); font-size: 11px; }
.verification-banner { padding: 9px 24px; text-align: center; background: #fff7ed; color: #9a3412; border-bottom: 1px solid #fed7aa; font-size: 13px; }

.page-shell { max-width: 1480px; margin: 0 auto; padding: 30px; }
.page-header, .record-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
}
.page-header.compact { max-width: 920px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(28px, 4vw, 40px); line-height: 1.12; margin-bottom: 8px; letter-spacing: -.03em; }
h2 { font-size: 20px; margin-bottom: 4px; }
h3 { font-size: 16px; }
.page-header p, .panel-heading p, .auth-heading p { color: var(--muted); margin-bottom: 0; }
.eyebrow { margin-bottom: 7px !important; color: var(--primary) !important; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }

.panel, .stat-card, .auth-card, .error-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.panel { overflow: hidden; }
.panel-heading { display: flex; justify-content: space-between; gap: 20px; padding: 21px 24px; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin-bottom: 2px; }

.button {
    min-height: 40px;
    padding: 9px 15px;
    border: 1px solid transparent;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 750;
    line-height: 1.1;
    transition: .15s ease;
}
.button:hover { text-decoration: none; transform: translateY(-1px); }
.button-primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { color: var(--ink); background: #fff; border-color: #cfd5df; }
.button-secondary:hover { background: var(--surface-soft); }
.button-ghost { color: var(--muted); background: transparent; border-color: transparent; }
.button-small { min-height: 32px; padding: 6px 10px; font-size: 12px; }
.button-block { width: 100%; }

.alert { margin-bottom: 18px; padding: 13px 16px; border-radius: 10px; border: 1px solid; }
.alert-success { background: #ecfdf3; color: #027a48; border-color: #abefc6; }
.alert-danger { background: #fef3f2; color: var(--danger); border-color: #fecdca; }

.guest-body { display: grid; place-items: center; padding: 40px 20px; background: radial-gradient(circle at top left, #e0e7ff, transparent 38%), #f5f7fb; }
.guest-shell { width: min(100%, 720px); }
.guest-brand { margin: 0 auto 22px; width: fit-content; font-size: 18px; }
.auth-card { padding: 34px; max-width: 500px; margin: 0 auto; }
.auth-card-wide { max-width: 720px; }
.auth-heading { margin-bottom: 25px; }
.auth-heading h1 { font-size: 31px; }
.auth-footer { margin: 22px 0 0; text-align: center; color: var(--muted); }

.stack-form { display: grid; gap: 18px; }
.form-grid { display: grid; gap: 18px; }
.form-grid.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-two { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, legend { font-size: 13px; font-weight: 750; }
.field small { color: var(--muted); font-size: 12px; }
.label-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.label-row a { font-size: 12px; }
input, select, textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid #cfd5df;
    border-radius: 9px;
    padding: 9px 11px;
    color: var(--ink);
    background: #fff;
    outline: none;
}
textarea { resize: vertical; min-height: 110px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(49, 85, 217, .12); }
.field-error { color: var(--danger); font-size: 12px; font-weight: 650; }
.form-panel { max-width: 920px; padding: 26px; }
.narrow-panel { max-width: 620px; }
.form-section { margin: 4px 0; padding: 20px; border: 1px solid var(--line); border-radius: 11px; }
.form-section legend { padding: 0 8px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 4px; }

.workspace-list { display: grid; gap: 10px; margin-bottom: 18px; }
.workspace-option { display: flex; justify-content: space-between; align-items: center; padding: 15px; border: 1px solid var(--line); border-radius: 10px; }
.workspace-option div { display: flex; flex-direction: column; }
.workspace-option span { color: var(--muted); font-size: 12px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card { padding: 20px; color: var(--ink); display: flex; flex-direction: column; min-height: 150px; }
.stat-card:hover { text-decoration: none; transform: translateY(-2px); }
.stat-card span { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat-card strong { font-size: 38px; letter-spacing: -.04em; margin: auto 0 5px; }
.stat-card small { color: var(--muted); }
.pending-card { box-shadow: none; }
.content-grid { display: grid; gap: 20px; align-items: start; }
.content-grid.two-thirds { grid-template-columns: minmax(0, 1.65fr) minmax(300px, .85fr); }
.list-table { display: grid; }
.list-row { display: flex; justify-content: space-between; gap: 20px; padding: 15px 24px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row > div:first-child { display: flex; flex-direction: column; }
.list-row span { color: var(--muted); font-size: 13px; }
.task-actions { display: flex; align-items: center; gap: 12px; }
.task-actions time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.simple-list { display: grid; }
.simple-list a { display: flex; justify-content: space-between; gap: 18px; padding: 14px 20px; color: var(--ink); border-bottom: 1px solid var(--line); }
.simple-list a:last-child { border-bottom: 0; }
.simple-list a:hover { background: var(--surface-soft); text-decoration: none; }
.simple-list span { display: flex; flex-direction: column; }
.simple-list small, .simple-list time { color: var(--muted); }

.filter-bar { display: grid; grid-template-columns: minmax(240px, 1.5fr) repeat(3, minmax(150px, .8fr)) auto auto; gap: 10px; padding: 18px; border-bottom: 1px solid var(--line); align-items: end; }
.filter-search input { min-width: 0; }
.table-summary { padding: 13px 20px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); }
.responsive-table { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 18px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; background: #fbfcfe; }
td { font-size: 14px; }
td small { display: block; color: var(--muted); margin-top: 2px; }
.record-link { color: var(--ink); font-weight: 750; }
.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 3px 9px; border: 1px solid var(--badge-color); color: var(--badge-color); border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.pagination { display: flex; justify-content: center; gap: 5px; padding: 18px; }
.pagination a { width: 34px; height: 34px; display: grid; place-items: center; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; }
.pagination a.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.pagination a:hover { text-decoration: none; }
.empty-state { padding: 30px 24px; text-align: center; color: var(--muted); }
.empty-state.large { padding: 58px 24px; }
.empty-state strong { display: block; color: var(--ink); font-size: 18px; margin-bottom: 5px; }

.breadcrumb { display: flex; gap: 8px; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.record-badges { display: flex; flex-wrap: wrap; gap: 7px; }
.record-layout { display: grid; grid-template-columns: minmax(280px, .72fr) minmax(0, 1.7fr); gap: 20px; align-items: start; }
.record-sidebar, .record-main { display: grid; gap: 20px; }
.detail-list { margin: 0; padding: 5px 24px 18px; }
.detail-list > div { padding: 13px 0; border-bottom: 1px solid var(--line); }
.detail-list > div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.detail-list dd { margin: 4px 0 0; }
.description-block { margin: 0 24px 24px; padding: 16px; background: var(--surface-soft); border-radius: 10px; }
.description-block h3 { margin-bottom: 7px; }
.description-block p { margin-bottom: 0; color: #475467; }
.related-placeholder { display: flex; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.related-placeholder:last-child { border-bottom: 0; }
.related-placeholder strong { color: var(--muted); font-size: 12px; }
.activity-composer form { padding: 24px; }
.timeline { padding: 24px; }
.timeline-item { display: grid; grid-template-columns: 38px 1fr; gap: 13px; position: relative; padding-bottom: 18px; }
.timeline-item:not(:last-child)::before { content: ''; position: absolute; left: 18px; top: 38px; bottom: 0; width: 2px; background: var(--line); }
.timeline-marker { width: 38px; height: 38px; display: grid; place-items: center; color: #fff; background: #64748b; border-radius: 50%; font-size: 12px; font-weight: 900; z-index: 1; }
.type-call .timeline-marker { background: #0ea5e9; }
.type-email .timeline-marker { background: #7c3aed; }
.type-meeting .timeline-marker { background: #2563eb; }
.type-note .timeline-marker { background: #64748b; }
.type-task .timeline-marker { background: #d97706; }
.timeline-card { padding: 17px; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
.timeline-heading { display: flex; justify-content: space-between; gap: 16px; }
.timeline-heading h3 { margin: 2px 0 9px; font-size: 17px; }
.timeline-heading time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.activity-label { color: var(--muted); font-size: 10px; font-weight: 900; text-transform: uppercase; letter-spacing: .1em; }
.timeline-card > p { color: #475467; }
.timeline-meta { display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted); font-size: 12px; }
.task-status { font-weight: 800; }
.task-status.open { color: var(--warning); }
.task-status.completed { color: var(--success); }
.timeline-action { margin-top: 14px; }

.error-card { max-width: 620px; margin: 10vh auto; padding: 40px; text-align: center; }
.debug-box { margin: 20px 0; padding: 15px; text-align: left; background: #111827; color: #f9fafb; border-radius: 9px; overflow-wrap: anywhere; }
.debug-box p { margin: 8px 0; }
.debug-box small { color: #cbd5e1; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }


.button:disabled, .button[disabled] { cursor: not-allowed; opacity: .55; transform: none; }
.record-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.record-subtitle { margin: -2px 0 10px; color: var(--muted); }
.dashboard-side-stack { display: grid; gap: 20px; }
.contacts-filter { grid-template-columns: minmax(250px, 1.5fr) repeat(4, minmax(145px, .8fr)) auto auto; }
select[multiple] { min-height: 150px; padding: 5px; }
select[multiple] option { padding: 7px 8px; border-radius: 5px; }
.company-association-fields { margin-top: 2px; }
.empty-inline { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.empty-inline p { margin: 0; color: var(--muted); }
.checkbox-field { display: flex; align-items: flex-start; gap: 9px; font-size: 13px; font-weight: 650; }
.checkbox-field input { width: 17px; min-height: 17px; height: 17px; margin-top: 2px; flex: 0 0 auto; }
.duplicate-warning { display: grid; gap: 15px; padding: 18px; border: 1px solid #f7c96b; border-radius: 11px; background: #fffbeb; }
.duplicate-warning > div:first-child p { margin: 4px 0 0; color: #7c5d12; }
.duplicate-list { display: grid; gap: 8px; }
.duplicate-list a { display: flex; justify-content: space-between; gap: 16px; padding: 11px 13px; border: 1px solid #f3d58b; border-radius: 9px; color: var(--ink); background: #fff; }
.duplicate-list a:hover { text-decoration: none; border-color: #dcae3b; }
.duplicate-list a > span { display: flex; flex-direction: column; }
.duplicate-list small { color: var(--muted); }
.panel-heading-action { align-items: center; }
.related-record-list { display: grid; }
.related-record-row { display: flex; align-items: center; justify-content: space-between; gap: 13px; padding: 13px 20px; color: var(--ink); border-bottom: 1px solid var(--line); }
.related-record-row:last-child { border-bottom: 0; }
.related-record-row:hover { text-decoration: none; background: var(--surface-soft); }
.related-record-row > span:first-child { display: flex; min-width: 0; flex-direction: column; }
.related-record-row strong, .related-record-row small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.related-record-row small { color: var(--muted); }
.mini-label { flex: 0 0 auto; padding: 3px 7px; color: var(--primary); background: #eef2ff; border-radius: 999px; font-size: 10px; font-weight: 850; text-transform: uppercase; letter-spacing: .06em; }
.panel-footer-link { padding: 11px 20px; text-align: center; border-top: 1px solid var(--line); font-size: 13px; font-weight: 700; }
.empty-state.compact { padding: 23px 20px; }
.timeline-meta a { font-weight: 650; }

@media (max-width: 1100px) {
    .primary-nav { display: none; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .filter-bar, .contacts-filter { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filter-search { grid-column: 1 / -1; }
}

@media (max-width: 820px) {
    .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 12px; }
    .topbar-actions { width: 100%; margin-left: 0; }
    .user-summary { display: none; }
    .workspace-switcher { flex: 1; }
    .workspace-switcher select { width: 100%; min-width: 0; }
    .page-shell { padding: 20px 15px; }
    .page-header, .record-header { flex-direction: column; }
    .record-actions { justify-content: flex-start; }
    .content-grid.two-thirds, .record-layout { grid-template-columns: 1fr; }
    .form-grid.two-columns { grid-template-columns: 1fr; }
    .span-two { grid-column: auto; }
    .filter-bar, .contacts-filter { grid-template-columns: 1fr; }
    .filter-search { grid-column: auto; }
}

@media (max-width: 560px) {
    .guest-body { padding: 20px 12px; }
    .auth-card { padding: 24px 19px; }
    .stat-grid { grid-template-columns: 1fr; }
    .list-row, .task-actions, .timeline-heading, .duplicate-list a, .empty-inline { align-items: flex-start; flex-direction: column; }
    .timeline { padding: 16px; }
    th, td { padding: 12px; }
}

/* Milestone 3: deals, pipeline, quotes, and secure documents */
.form-section.panel { padding: 0; max-width: none; }
.form-section-body { padding: 24px; }
.sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 8;
    margin: 0 -8px;
    padding: 14px 8px;
    background: linear-gradient(to top, #f3f6fb 76%, rgba(243, 246, 251, 0));
}
.input-suffix { display: flex; align-items: stretch; }
.input-suffix input { border-radius: 9px 0 0 9px; }
.input-suffix span {
    min-width: 42px;
    display: grid;
    place-items: center;
    color: var(--muted);
    background: var(--surface-soft);
    border: 1px solid #cfd5df;
    border-left: 0;
    border-radius: 0 9px 9px 0;
    font-weight: 750;
}
.checkbox-field { display: inline-flex; align-items: center; gap: 9px; color: var(--ink); font-size: 13px; font-weight: 700; }
.checkbox-field input { width: 17px; min-height: 17px; height: 17px; margin: 0; }
.checkbox-aligned { justify-content: flex-end; padding-bottom: 11px; }

.forecast-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}
.forecast-card {
    min-height: 132px;
    padding: 19px 20px;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.forecast-card > span { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; }
.forecast-card strong { margin: auto 0 3px; font-size: clamp(25px, 3vw, 34px); line-height: 1; letter-spacing: -.035em; }
.forecast-card small { color: var(--muted); }

.deals-panel { overflow: visible; }
.deal-view-toolbar {
    min-height: 58px;
    padding: 11px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    border-radius: var(--radius) var(--radius) 0 0;
}
.deal-view-toolbar > small { color: var(--muted); }
.view-tabs { display: inline-flex; gap: 4px; padding: 4px; border-radius: 10px; background: var(--surface-soft); }
.view-tabs a { padding: 7px 13px; color: var(--muted); border-radius: 7px; font-size: 13px; font-weight: 750; }
.view-tabs a:hover { color: var(--ink); text-decoration: none; }
.view-tabs a.active { color: var(--primary); background: #fff; box-shadow: 0 1px 4px rgba(23, 32, 51, .12); }
.deals-filter { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.deals-filter .filter-search { grid-column: span 2; }

.pipeline-shell { overflow-x: auto; overscroll-behavior-inline: contain; padding: 18px; background: #f7f9fc; }
.pipeline-board { min-width: max-content; display: flex; align-items: flex-start; gap: 14px; }
.pipeline-column {
    width: 300px;
    flex: 0 0 300px;
    overflow: hidden;
    background: #eef2f7;
    border: 1px solid #dfe4ec;
    border-radius: 12px;
}
.pipeline-column > header {
    min-height: 81px;
    padding: 14px 15px 11px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 3px 10px;
    background: #fff;
    border-top: 4px solid var(--stage-color, #64748b);
    border-bottom: 1px solid var(--line);
}
.pipeline-column > header > div { min-width: 0; display: flex; align-items: center; gap: 8px; }
.pipeline-column > header strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pipeline-column > header > span { color: var(--muted); font-size: 12px; font-weight: 800; }
.pipeline-column > header small { grid-column: 1 / -1; color: var(--muted); }
.stage-dot { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 999px; background: var(--stage-color, #64748b); }
.pipeline-unassigned > header { border-top-color: #98a2b3; }
.pipeline-dropzone { min-height: 150px; padding: 11px; display: grid; align-content: start; gap: 10px; transition: background .15s, box-shadow .15s; }
.pipeline-dropzone.is-drag-over { background: #e8edff; box-shadow: inset 0 0 0 2px rgba(49, 85, 217, .35); }
.pipeline-empty { display: none; padding: 18px 8px; color: var(--primary); border: 1px dashed #9dabed; border-radius: 9px; text-align: center; font-size: 12px; font-weight: 750; }
.pipeline-dropzone:empty .pipeline-empty, .pipeline-dropzone.is-drag-over .pipeline-empty { display: block; }
.pipeline-dropzone > .pipeline-empty:only-child { display: block; color: var(--muted); border-color: #cfd5df; }
.deal-card {
    background: #fff;
    border: 1px solid #dfe4ec;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(23, 32, 51, .055);
    cursor: grab;
    transition: transform .14s, box-shadow .14s, opacity .14s;
}
.deal-card:hover { transform: translateY(-1px); box-shadow: 0 7px 17px rgba(23, 32, 51, .10); }
.deal-card:active { cursor: grabbing; }
.deal-card.is-dragging { opacity: .34; transform: rotate(1deg); }
.deal-card.is-saving { opacity: .62; cursor: progress; }
.deal-card-link { padding: 14px; display: flex; flex-direction: column; gap: 7px; color: var(--ink); }
.deal-card-link:hover { text-decoration: none; }
.deal-card-link > strong { line-height: 1.35; }
.deal-card-link > span { color: var(--muted); font-size: 12px; }
.deal-card-value { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding-top: 4px; }
.deal-card-value b { font-size: 16px; }
.deal-card-value small { color: var(--primary); font-weight: 800; }
.deal-card footer { padding-top: 9px; display: flex; justify-content: space-between; gap: 12px; color: var(--muted); border-top: 1px solid var(--line); font-size: 11px; }
.pipeline-message { min-height: 36px; padding: 8px 18px 14px; color: var(--success); background: #f7f9fc; font-size: 13px; font-weight: 700; }
.pipeline-message.error { color: var(--danger); }

.record-badges { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 7px; }
.outcome-badge, .quote-status {
    display: inline-flex;
    align-items: center;
    min-height: 25px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 850;
}
.outcome-badge.open { color: #344054; background: #f2f4f7; }
.outcome-badge.won { color: #067647; background: #dcfae6; }
.outcome-badge.lost { color: #b42318; background: #fee4e2; }
.quote-status-draft { color: #344054; background: #f2f4f7; }
.quote-status-sent { color: #175cd3; background: #eff8ff; }
.quote-status-accepted { color: #067647; background: #dcfae6; }
.quote-status-rejected { color: #b42318; background: #fee4e2; }
.quote-status-expired { color: #b54708; background: #fffaeb; }

.stage-settings-layout { display: grid; grid-template-columns: minmax(280px, .62fr) minmax(0, 1.5fr); gap: 20px; align-items: start; }
.stage-editor-list { display: grid; }
.stage-editor-row { display: grid; grid-template-columns: 42px minmax(0, 1fr); border-bottom: 1px solid var(--line); }
.stage-editor-row:last-child { border-bottom: 0; }
.stage-order-controls { padding: 18px 7px; display: flex; flex-direction: column; gap: 5px; background: var(--surface-soft); border-right: 1px solid var(--line); }
.stage-order-controls form { margin: 0; }
.stage-order-controls button {
    width: 28px;
    height: 28px;
    padding: 0;
    color: var(--muted);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 7px;
    font-weight: 850;
}
.stage-order-controls button:hover:not(:disabled) { color: var(--primary); border-color: #9dabed; }
.stage-order-controls button:disabled { opacity: .32; cursor: not-allowed; }
.stage-editor-form { min-width: 0; padding: 16px; }
.stage-editor-main { display: grid; grid-template-columns: 6px minmax(160px, 1.3fr) 72px minmax(110px, .6fr) minmax(130px, .8fr); gap: 12px; align-items: end; }
.stage-color-bar { width: 6px; height: 42px; align-self: end; background: var(--stage-color, #64748b); border-radius: 999px; }
.compact-color-field input[type="color"] { padding: 5px; }
.stage-editor-footer { padding: 11px 0 0 18px; display: flex; justify-content: flex-end; align-items: center; gap: 15px; }
.stage-editor-footer > span { margin-left: auto; color: var(--muted); font-size: 12px; }

.quote-items-wrap { padding: 20px 24px 24px; }
.quote-items { display: grid; gap: 12px; }
.quote-item-row {
    position: relative;
    padding: 17px 45px 17px 17px;
    display: grid;
    grid-template-columns: minmax(170px, 1.2fr) minmax(190px, 1.4fr) repeat(4, minmax(95px, .55fr)) minmax(110px, .7fr);
    gap: 11px;
    align-items: end;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 11px;
}
.quote-item-total { min-height: 42px; display: flex; flex-direction: column; justify-content: center; align-items: flex-end; }
.quote-item-total span { color: var(--muted); font-size: 11px; }
.quote-item-total strong { font-size: 15px; }
.quote-remove {
    position: absolute;
    top: 12px;
    right: 10px;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    color: var(--muted);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 7px;
    font-size: 19px;
    line-height: 1;
}
.quote-remove:hover { color: var(--danger); border-color: #fda29b; }
.quote-total { margin-top: 18px; padding: 16px 4px 0; display: flex; justify-content: flex-end; align-items: baseline; gap: 18px; border-top: 2px solid var(--line); }
.quote-total span { color: var(--muted); font-weight: 750; }
.quote-total strong { min-width: 160px; text-align: right; font-size: 25px; }

.quote-show-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .65fr); gap: 20px; align-items: start; }
.quote-document { overflow: hidden; }
.quote-document-header { padding: 28px; display: flex; justify-content: space-between; gap: 24px; color: #fff; background: linear-gradient(135deg, #243fa8, #3155d9); }
.quote-document-header > div { display: flex; flex-direction: column; }
.quote-document-header span, .quote-document-header small { opacity: .76; text-transform: uppercase; letter-spacing: .09em; font-size: 11px; font-weight: 800; }
.quote-document-header h2 { margin: 4px 0 0; font-size: 27px; }
.quote-document-header strong { margin-top: 4px; font-size: 28px; }
.quote-meta-grid { padding: 22px 28px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 17px; border-bottom: 1px solid var(--line); }
.quote-meta-grid > div { display: flex; flex-direction: column; gap: 3px; }
.quote-meta-grid span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; font-weight: 800; }
.quote-description { padding: 23px 28px; border-bottom: 1px solid var(--line); }
.quote-description p { margin-bottom: 0; color: var(--muted); }
.quote-line-table table { min-width: 760px; }
.quote-line-table tfoot td { background: var(--surface-soft); font-size: 15px; }
.quote-line-table tfoot td:first-child { text-align: right; color: var(--muted); font-weight: 800; }
.quote-side-stack { display: grid; gap: 20px; }
.compact-upload-form { padding: 18px 20px; display: grid; gap: 13px; border-bottom: 1px solid var(--line); }
.document-list { display: grid; }
.document-list a { padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; gap: 14px; color: var(--ink); border-bottom: 1px solid var(--line); }
.document-list a:last-child { border-bottom: 0; }
.document-list a:hover { background: var(--surface-soft); text-decoration: none; }
.document-list a > span { min-width: 0; display: flex; flex-direction: column; }
.document-list strong, .document-list small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.document-list small { color: var(--muted); }
.document-list b { flex: 0 0 auto; color: var(--primary); font-size: 12px; }

@media (max-width: 1280px) {
    .deals-filter { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .deals-filter .filter-search { grid-column: 1 / -1; }
    .quote-item-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .quote-item-name, .quote-item-description { grid-column: span 2; }
}

@media (max-width: 1050px) {
    .forecast-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stage-settings-layout, .quote-show-layout { grid-template-columns: 1fr; }
    .stage-editor-main { grid-template-columns: 6px minmax(150px, 1fr) 72px minmax(100px, .7fr); }
    .stage-editor-main > .field:last-child { grid-column: 2 / -1; }
    .quote-meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .forecast-grid { grid-template-columns: 1fr; }
    .forecast-card { min-height: 110px; }
    .deal-view-toolbar { align-items: flex-start; flex-direction: column; }
    .deals-filter { grid-template-columns: 1fr; }
    .deals-filter .filter-search { grid-column: auto; }
    .pipeline-shell { margin-inline: -15px; border-inline: 0; }
    .pipeline-column { width: 275px; flex-basis: 275px; }
    .stage-editor-row { grid-template-columns: 1fr; }
    .stage-order-controls { padding: 8px 14px; flex-direction: row; border-right: 0; border-bottom: 1px solid var(--line); }
    .stage-editor-main { grid-template-columns: 6px minmax(0, 1fr); }
    .stage-editor-main > .field { grid-column: 2; }
    .stage-editor-footer { padding-left: 0; align-items: flex-start; flex-wrap: wrap; }
    .stage-editor-footer > span { margin-left: 0; }
    .stage-editor-footer .button { margin-left: auto; }
    .quote-item-row { grid-template-columns: 1fr 1fr; }
    .quote-item-name, .quote-item-description { grid-column: 1 / -1; }
    .quote-item-total { align-items: flex-start; }
    .quote-meta-grid { grid-template-columns: 1fr; }
    .quote-document-header { flex-direction: column; }
}

@media (max-width: 480px) {
    .quote-item-row { grid-template-columns: 1fr; padding-right: 42px; }
    .quote-item-name, .quote-item-description { grid-column: auto; }
    .quote-total { align-items: flex-end; flex-direction: column; gap: 3px; }
}

/* Milestone 4: settings, customizable tables, auditing, and document controls */
.alert-info { background: #eff8ff; color: #175cd3; border-color: #b2ddff; }
.action-alert, .verification-banner { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.action-alert { padding: 12px 16px; }
.verification-banner { padding: 10px max(24px, calc((100vw - 1480px) / 2 + 30px)); text-align: left; }
.verification-banner > div:first-child { display: flex; flex-direction: column; }
.verification-actions, .inline-actions, .document-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.verification-actions form, .inline-actions form, .document-actions form { margin: 0; }
.button-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.button-danger:hover { background: #912018; }
.stacked-form { display: grid; gap: 18px; }
.form-grid.three-columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-help, .form-help { color: var(--muted); font-size: 12px; }
.form-help { margin: 15px 0 0; }
.check-control { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.check-control input { width: auto; min-height: 0; }

.settings-nav { margin: -8px 0 22px; display: flex; flex-wrap: wrap; gap: 7px; }
.settings-nav a, .object-tabs a, .view-tabs a { padding: 8px 12px; color: var(--muted); background: #fff; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; font-weight: 750; }
.settings-nav a:hover, .object-tabs a:hover { text-decoration: none; background: var(--surface-soft); }
.settings-nav a.active, .object-tabs a.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.settings-card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.settings-card { min-height: 165px; padding: 24px; display: flex; flex-direction: column; color: var(--ink); }
.settings-card:hover { text-decoration: none; transform: translateY(-2px); }
.settings-card strong { font-size: 18px; }
.settings-card p { margin: auto 0 0; color: var(--muted); }
.settings-two-column { margin-bottom: 20px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.settings-two-column > .panel > form, .settings-two-column > .panel > .stacked-form { padding: 22px 24px; }
.settings-list, .status-settings-list, .custom-field-settings-list { display: grid; }
.settings-list-row { padding: 15px 20px; display: flex; justify-content: space-between; align-items: center; gap: 16px; border-bottom: 1px solid var(--line); }
.settings-list-row:last-child { border-bottom: 0; }
.settings-list-row > div { min-width: 0; display: flex; flex-direction: column; }
.settings-list-row small { color: var(--muted); }
.object-tabs { margin-bottom: 18px; display: flex; gap: 7px; }
.callout { margin: 22px; padding: 16px; border: 1px solid; border-radius: 10px; }
.callout p { margin: 5px 0 0; }
.callout.warning { color: #9a3412; background: #fff7ed; border-color: #fed7aa; }
.callout.success { color: #067647; background: #ecfdf3; border-color: #abefc6; }
.config-example { margin: 0 22px 12px; padding: 16px; overflow-x: auto; color: #d1e9ff; background: #172033; border-radius: 10px; }

.column-picker { padding: 18px 22px; display: grid; gap: 7px; }
.column-picker-row { min-height: 46px; padding: 9px 12px; display: flex; align-items: center; gap: 11px; color: var(--muted); background: var(--surface-soft); border: 1px solid var(--line); border-radius: 9px; cursor: grab; }
.column-picker-row.selected { color: var(--ink); background: #fff; border-color: #b9c5f4; }
.column-picker-row.is-dragging { opacity: .45; }
.column-picker-row.is-drag-over { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(49, 85, 217, .1); }
.column-picker-row input { width: auto; min-height: 0; }
.column-picker-row small { margin-left: auto; color: var(--primary); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.drag-handle { color: #98a2b3; letter-spacing: -3px; }
.sortable-heading { display: inline-flex; align-items: center; gap: 5px; color: inherit; white-space: nowrap; }
.sortable-heading:hover { color: var(--primary); text-decoration: none; }
.sortable-heading.active { color: var(--primary); }

.status-settings-group { margin-bottom: 20px; }
.status-settings-row { padding: 13px 16px; display: grid; grid-template-columns: minmax(130px, .7fr) minmax(180px, 1.4fr) 58px auto auto 95px auto; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); }
.status-settings-row .field input { min-height: 36px; }
.color-field input[type="color"] { min-width: 46px; padding: 4px; }
.reorder-actions { padding: 7px 16px; display: flex; gap: 5px; background: var(--surface-soft); border-bottom: 1px solid var(--line); }
.reorder-actions form { margin: 0; }
.icon-button { width: 31px; height: 31px; color: var(--muted); background: #fff; border: 1px solid var(--line); border-radius: 7px; }
.icon-button:disabled { opacity: .35; cursor: not-allowed; }
.inline-create-form { padding: 18px; display: grid; grid-template-columns: minmax(180px, 1fr) 80px auto auto; gap: 12px; align-items: end; background: var(--surface-soft); }
.custom-field-settings-row { padding: 16px 18px; display: grid; grid-template-columns: 1fr .75fr; gap: 12px; border-bottom: 1px solid var(--line); }
.custom-field-settings-row .span-two { grid-column: 1 / -1; }
.custom-field-settings-row textarea { min-height: 74px; }
.custom-field-settings-row > .inline-actions { justify-content: flex-end; }
.custom-fields-section { margin-top: 20px; }
.custom-fields-display { margin-bottom: 20px; }
.record-supplemental { margin-top: 20px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.audit-list { display: grid; }
.audit-entry { border-bottom: 1px solid var(--line); }
.audit-entry:last-child { border-bottom: 0; }
.audit-entry summary { padding: 15px 20px; display: flex; justify-content: space-between; align-items: center; gap: 15px; cursor: pointer; }
.audit-entry summary > span:first-child { display: flex; flex-direction: column; }
.audit-entry summary small { color: var(--muted); }
.audit-changes { margin: 0; padding: 0 20px 18px; }
.audit-changes > div { padding: 9px 0; border-top: 1px solid var(--line); }
.audit-changes dt { color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 800; }
.audit-changes dd { margin: 5px 0 0; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.audit-changes del, .audit-changes ins { max-width: 100%; padding: 3px 6px; overflow-wrap: anywhere; border-radius: 5px; text-decoration: none; }
.audit-changes del { color: #b42318; background: #fef3f2; }
.audit-changes ins { color: #067647; background: #ecfdf3; }

.document-management-list .document-row { padding: 14px 18px; display: flex; justify-content: space-between; gap: 16px; align-items: center; border-bottom: 1px solid var(--line); }
.document-management-list .document-row:last-child { border-bottom: 0; }
.document-main { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.document-main strong, .document-main small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.document-main small { color: var(--muted); }
.document-main .mini-label { margin-top: 5px; color: var(--badge-color); border: 1px solid var(--badge-color); border-radius: 999px; padding: 2px 7px; font-size: 10px; font-weight: 800; }
.document-replace { position: relative; }
.document-replace summary { list-style: none; cursor: pointer; }
.document-replace summary::-webkit-details-marker { display: none; }
.replacement-form { position: absolute; z-index: 4; right: 0; top: calc(100% + 7px); width: 300px; padding: 14px; display: grid; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.replacement-form label { display: grid; gap: 6px; font-size: 12px; font-weight: 750; }

@media (max-width: 1000px) {
    .settings-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .settings-two-column, .record-supplemental { grid-template-columns: 1fr; }
    .status-settings-row { grid-template-columns: 1fr 1.3fr 58px; }
    .status-settings-row > :nth-child(n+4) { grid-column: auto; }
}
@media (max-width: 720px) {
    .action-alert, .verification-banner { align-items: flex-start; flex-direction: column; }
    .verification-actions { width: 100%; }
    .settings-card-grid, .form-grid.three-columns { grid-template-columns: 1fr; }
    .status-settings-row, .inline-create-form, .custom-field-settings-row { grid-template-columns: 1fr; }
    .custom-field-settings-row .span-two { grid-column: auto; }
    .document-management-list .document-row { align-items: flex-start; flex-direction: column; }
    .replacement-form { left: 0; right: auto; width: min(300px, calc(100vw - 60px)); }
}

/* Milestone 4 responsive filter and document-action refinements. */
.filter-bar { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.filter-bar .filter-search { grid-column: span 2; }
.document-management-list a.button {
    padding: 6px 10px;
    display: inline-flex;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
}
.document-management-list a.button:hover { background: var(--surface-soft); }
.document-actions { justify-content: flex-end; }
.document-replace[open] { flex-basis: 100%; }
.replacement-form {
    position: static;
    width: min(320px, 100%);
    margin-top: 8px;
}
@media (max-width: 720px) {
    .filter-bar .filter-search { grid-column: auto; }
    .document-actions { width: 100%; justify-content: flex-start; }
    .replacement-form { width: 100%; }
}
