/* =========================================================
   GNM POWER, LLC — CRM
   Brand inherited from the public website: blue + yellow.
   Mobile-first: crews open this on a phone in the field.
   ========================================================= */

:root {
    --blue-900: #0b2a5b;
    --blue-800: #103a7a;
    --blue-700: #1e4ea0;
    --blue-600: #2563c4;
    --yellow-500: #fbbf24;
    --yellow-600: #f59e0b;

    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --white: #ffffff;

    --green-600: #16a34a;
    /* Darker green for buttons: #16a34a on white text only reaches 3.3:1. */
    --green-700: #15803d;
    --green-800: #166534;
    --red-600: #dc2626;
    --amber-600: #d97706;
    /* Amber dark enough to be read as text: #fbbf24 measures 2.15:1 on white
       and #d97706 only 3.1:1. This one clears AA at 5:1. */
    --amber-700: #b45309;

    /* Semantic text tokens. Secondary text uses gray-600, not gray-500:
       gray-500 on white measures 4.34:1 and fails WCAG AA for body sizes. */
    --text-strong: var(--gray-900);
    --text-body: var(--gray-700);
    --text-muted: var(--gray-600);
    --border: var(--gray-200);

    --radius: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, .08);
    --shadow-md: 0 6px 18px rgba(15, 23, 42, .10);

    --font-head: 'Montserrat', system-ui, sans-serif;
    --font-body: 'Inter', system-ui, sans-serif;

    --sidebar-w: 240px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
    font-family: var(--font-body);
    background: var(--gray-100);
    color: var(--gray-700);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--blue-700); text-decoration: none; }
a:hover { color: var(--amber-700); }

h1, h2, h3 { font-family: var(--font-head); color: var(--gray-900); line-height: 1.25; }

/* =========================================================
   Signed-out screens
   ========================================================= */

.auth-body {
    background: linear-gradient(160deg, var(--blue-900) 0%, var(--blue-700) 100%);
    min-height: 100vh;
}

.auth-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 24px 16px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 32px 28px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, .25);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
}

.auth-brand__mark,
.sidebar__mark {
    font-family: var(--font-head);
    font-weight: 700;
    letter-spacing: .5px;
    background: var(--yellow-500);
    color: var(--blue-900);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 14px;
}

.auth-brand__name {
    font-family: var(--font-head);
    font-weight: 600;
    font-size: 13px;
    letter-spacing: .6px;
    color: var(--gray-600);
}

.auth-title { font-size: 24px; margin-bottom: 6px; }
.auth-subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }

.auth-footnote {
    margin-top: 20px;
    color: rgba(255, 255, 255, .65);
    font-size: 12px;
    text-align: center;
}

/* =========================================================
   Forms
   ========================================================= */

.form .field { margin-bottom: 18px; }

.field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    font-family: inherit;
    font-size: 16px; /* 16px stops iOS from zooming on focus */
    color: var(--gray-800);
    background: var(--white);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    padding: 11px 13px;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--blue-600);
    box-shadow: 0 0 0 3px rgba(37, 99, 196, .15);
}

/* =========================================================
   Buttons
   ========================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    padding: 12px 18px;
    min-height: 40px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.btn--primary { background: var(--blue-700); color: var(--white); }
.btn--primary:hover { background: var(--blue-800); color: var(--white); }

.btn--ghost {
    background: transparent;
    color: var(--gray-600);
    border-color: var(--gray-300);
}
.btn--ghost:hover { background: var(--gray-100); color: var(--gray-800); }

.btn--sm { padding: 8px 12px; font-size: 13px; min-height: 32px; }
.btn--block { width: 100%; }

/* Touch sizing. Applies on phones and on any coarse pointer, so a tablet in
   the truck gets 44px targets even though it is wide. */
@media (max-width: 899px), (pointer: coarse) {
    .btn { min-height: 44px; }
    .btn--sm { min-height: 44px; padding: 10px 14px; }

    .field input,
    .field select,
    .field textarea,
    .filter-bar input[type="search"],
    .filter-bar select,
    .lines input,
    .lines select,
    .lines__totals input { min-height: 44px; }

    .table__sort { padding: 12px 0; }
}

/* =========================================================
   Application shell
   ========================================================= */

.layout { min-height: 100vh; }

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--blue-900);
    display: flex;
    flex-direction: column;
    padding: 20px 0;
    transform: translateX(-100%);
    transition: transform .22s ease;
    z-index: 40;
}

.sidebar.is-open { transform: translateX(0); }

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 22px;
}

.sidebar__name {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 1px;
    color: var(--white);
}

.sidebar__nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 0 12px; }

.sidebar__link {
    display: block;
    padding: 11px 14px;
    border-radius: var(--radius);
    color: rgba(255, 255, 255, .72);
    font-size: 14px;
    font-weight: 500;
}

.sidebar__link:hover { background: rgba(255, 255, 255, .08); color: var(--white); }

.sidebar__link.is-active {
    background: var(--blue-700);
    color: var(--white);
    box-shadow: inset 3px 0 0 var(--yellow-500);
}

.sidebar__footer { padding: 16px 20px 0; border-top: 1px solid rgba(255, 255, 255, .12); }

.sidebar__user strong { display: block; color: var(--white); font-size: 14px; }
.sidebar__user span { display: block; color: rgba(255, 255, 255, .55); font-size: 12px; }

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    z-index: 30;
}

/* --- Topbar --- */

.topbar {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 12px 16px;
    z-index: 20;
}

.topbar__toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 44px;
    height: 44px;
    padding: 11px;
    background: transparent;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    cursor: pointer;
}

.topbar__toggle span {
    display: block;
    height: 2px;
    background: var(--gray-700);
    border-radius: 2px;
}

.topbar__title {
    flex: 1;
    font-size: 17px;
    font-weight: 600;
}

.content { padding: 20px 16px 48px; }

.page-intro { color: var(--text-muted); font-size: 14px; margin-bottom: 20px; }

/* =========================================================
   Panels, stats, tables
   ========================================================= */

.stat-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.stat {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.stat__label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat__value {
    display: block;
    font-family: var(--font-head);
    font-size: 26px;
    font-weight: 700;
    color: var(--gray-900);
}

.stat__value--accent { color: var(--amber-700); }

.panel {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
    overflow: hidden;
}

.panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--gray-200);
}

.panel__head h2 { font-size: 15px; font-weight: 600; }

.grid-2 { display: grid; gap: 20px; }

/* --- Pipeline --- */

.pipeline {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1px;
    background: var(--gray-200);
}

.pipeline__stage {
    background: var(--white);
    padding: 16px;
    display: block;
    color: inherit;
    transition: background .15s ease;
}

.pipeline__stage:hover { background: var(--gray-50); color: inherit; }

.pipeline__name {
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.pipeline__count {
    display: block;
    font-family: var(--font-head);
    font-size: 24px;
    font-weight: 700;
    color: var(--blue-800);
}

.pipeline__value { display: block; font-size: 13px; color: var(--text-muted); }

/* --- Table --- */

.table { width: 100%; border-collapse: collapse; font-size: 14px; }

.table th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-muted);
    padding: 10px 16px;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--gray-50); }

/* Tables scroll on their own instead of breaking the page on small screens. */
.panel > .table { display: table; }
.table-scroll { overflow-x: auto; }

/* --- Task list --- */

.task-list { list-style: none; }

.task {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
}

.task:last-child { border-bottom: none; }
.task__subject { flex: 1; min-width: 160px; font-size: 14px; color: var(--gray-800); }
.task__meta { font-size: 12px; color: var(--text-muted); }

.task__badge {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--gray-200);
    color: var(--gray-600);
}

/* Darker than the plain red/amber: these badges are 11px uppercase, so they
   need the full 4.5:1 rather than the large-text allowance. */
.task--overdue .task__badge { background: #fee2e2; color: #991b1b; }
.task__badge--today { background: #fef3c7; color: #92400e; }

/* --- Stage pills --- */

.pill {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    padding: 4px 9px;
    border-radius: 999px;
    background: var(--gray-100);
    color: var(--gray-600);
    white-space: nowrap;
}

.pill--new           { background: #fef3c7; color: #92400e; }
.pill--contacted     { background: #dbeafe; color: #1e40af; }
.pill--walkthrough   { background: #e0e7ff; color: #3730a3; }
.pill--estimate_sent { background: #cffafe; color: #155e75; }
.pill--negotiation   { background: #ede9fe; color: #5b21b6; }
.pill--won           { background: #dcfce7; color: #166534; }
.pill--lost          { background: #fee2e2; color: #991b1b; }

/* --- Empty states --- */

.empty-state { padding: 40px 20px; text-align: center; }
.empty-state--inline { padding: 28px 20px; }
.empty-state h2 { font-size: 18px; margin-bottom: 8px; }
.empty-state p { color: var(--text-muted); font-size: 14px; margin-bottom: 16px; }
.empty-state--inline p { margin-bottom: 0; }

/* =========================================================
   Flash messages
   ========================================================= */

.flashes { margin-bottom: 18px; }

.flash {
    padding: 12px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    border: 1px solid transparent;
    margin-bottom: 10px;
}

.flash--success { background: #dcfce7; border-color: #86efac; color: #14532d; }
.flash--error   { background: #fee2e2; border-color: #fca5a5; color: #7f1d1d; }
.flash--warning { background: #fef3c7; border-color: #fcd34d; color: #78350f; }
.flash--info    { background: #dbeafe; border-color: #93c5fd; color: #1e3a8a; }

/* =========================================================
   Accessibility helpers
   ========================================================= */

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

:focus-visible { outline: 2px solid var(--blue-600); outline-offset: 2px; }

/* =========================================================
   Page header and forms
   ========================================================= */

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.page-header .page-intro { margin-bottom: 0; }
.page-header__actions { display: flex; flex-wrap: wrap; gap: 8px; }

.form-row { display: grid; gap: 0 16px; }
.form-row--end { align-items: end; }
.field--grow { flex: 1; }

.field__hint { font-weight: 400; color: var(--text-muted); font-size: 12px; }
.field__hint--block { display: block; margin-top: 6px; }

.field__error { color: var(--red-600); font-size: 13px; margin-top: 6px; }

.field.has-error input,
.field.has-error select,
.field.has-error textarea { border-color: var(--red-600); }

.field textarea { resize: vertical; }

.form--panel .panel__body { padding: 16px; }
.panel__body { padding: 16px; }

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 32px;
}

.btn--won { background: var(--green-700); color: var(--white); }
.btn--won:hover { background: var(--green-800); color: var(--white); }

/* =========================================================
   Filter bar
   ========================================================= */

.filter-bar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 14px;
    margin-bottom: 18px;
}

.filter-bar input[type="search"],
.filter-bar select {
    width: 100%;
    font-family: inherit;
    font-size: 16px;
    color: var(--gray-800);
    background: var(--white);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    padding: 10px 12px;
}

.filter-bar__filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.filter-bar__filters select { width: auto; flex: 1 1 140px; }
.filter-bar__clear { font-size: 13px; color: var(--text-muted); }

/* =========================================================
   Table extras
   ========================================================= */

.table__sort { display: inline-block; padding: 6px 0; color: inherit; white-space: nowrap; }
.table__sort:hover { color: var(--blue-700); }
.table__sort.is-active { color: var(--blue-700); }

.table__primary { font-weight: 600; }
.table tbody tr.is-inactive { opacity: .55; }
.table__sub { display: block; font-size: 12px; color: var(--text-muted); }
.table__num { text-align: right; }

/* =========================================================
   Pagination
   ========================================================= */

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 32px;
}

.pagination__summary { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.pagination .pagination__summary { margin-bottom: 0; }
.pagination__pages { display: flex; flex-wrap: wrap; gap: 4px; }

.pagination__link {
    display: inline-block;
    min-width: 38px;
    text-align: center;
    padding: 8px 10px;
    font-size: 13px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background: var(--white);
    color: var(--gray-600);
}

.pagination__link:hover { background: var(--gray-100); color: var(--gray-900); }

.pagination__link.is-current {
    background: var(--blue-700);
    border-color: var(--blue-700);
    color: var(--white);
    font-weight: 600;
}

.pagination__gap { padding: 8px 4px; color: var(--text-muted); }

/* =========================================================
   Pipeline board
   ========================================================= */

.board {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(250px, 1fr);
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 12px;
    margin-bottom: 32px;
}

.board__column {
    background: var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 12px;
    min-width: 250px;
}

.board__head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }

.board__title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--gray-600);
    flex: 1;
}

.board__count {
    background: var(--white);
    color: var(--gray-700);
    font-size: 12px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
}

.board__value { width: 100%; font-size: 12px; color: var(--gray-600); }
.board__cards { display: flex; flex-direction: column; gap: 8px; }
.board__empty { font-size: 13px; color: var(--text-muted); padding: 8px 4px; }

.card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow-sm);
}

.card__title { display: block; font-weight: 600; font-size: 14px; color: var(--gray-900); }
.card__title:hover { color: var(--blue-700); }
.card__customer { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.card__meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; font-size: 12px; }
.card__value { font-weight: 600; color: var(--gray-800); }
.card__owner { color: var(--text-muted); }

.card__actions {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--gray-100);
}

.card__actions form:only-child { margin-left: auto; }

.card__move {
    background: transparent;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 6px 10px;
    min-width: 36px;
    min-height: 32px;
}

/* Moving a card is the main gesture on the board — it must be thumb-sized. */
@media (max-width: 899px), (pointer: coarse) {
    .card__move { min-width: 44px; min-height: 44px; }
}

.card__move:hover { background: var(--blue-700); border-color: var(--blue-700); color: var(--white); }

/* =========================================================
   Record detail
   ========================================================= */

.record-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 16px;
}

.record-head__title { font-size: 20px; margin: 8px 0 4px; }
.record-head__sub { font-size: 13px; color: var(--text-muted); }
.record-head__value { text-align: right; }

.stage-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}

.stage-bar__label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-muted);
}

.stage-bar__lost { display: flex; gap: 6px; flex: 1 1 260px; }

.stage-bar__lost input {
    flex: 1;
    min-width: 0;
    font-family: inherit;
    font-size: 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    padding: 8px 10px;
}

.stage-bar--closed { justify-content: space-between; font-size: 14px; color: var(--gray-600); }

.detail-list { padding: 4px 16px 16px; }

.detail-list > div {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-100);
}

.detail-list > div:last-child { border-bottom: none; }

.detail-list dt {
    flex: 0 0 130px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.detail-list dd { flex: 1; font-size: 14px; color: var(--gray-800); }

.quoted-message { margin: 0 16px 16px; padding: 14px; background: var(--gray-50); border-left: 3px solid var(--yellow-500); border-radius: 0 var(--radius) var(--radius) 0; }
.quoted-message h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); margin-bottom: 6px; }
.quoted-message p { font-size: 14px; color: var(--gray-700); }

/* =========================================================
   Estimate line editor
   ========================================================= */

.lines input,
.lines select {
    width: 100%;
    min-width: 90px;
    font-family: inherit;
    font-size: 14px;
    color: var(--gray-800);
    background: var(--white);
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    padding: 8px 10px;
}

.lines input:focus,
.lines select:focus {
    outline: none;
    border-color: var(--blue-600);
    box-shadow: 0 0 0 3px rgba(37, 99, 196, .15);
}

.lines td { padding: 8px; vertical-align: middle; }
.lines__kind { width: 130px; }
.lines__unit { width: 90px; }
.lines__num  { width: 110px; text-align: right; }
.lines__total { font-weight: 600; white-space: nowrap; }

.lines__remove {
    background: transparent;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 6px 10px;
    min-width: 36px;
    min-height: 32px;
}

.lines__remove:hover { background: #fee2e2; border-color: #fca5a5; color: var(--red-600); }

/* Declared after the base rule above, or it would be overridden by it. */
@media (max-width: 899px), (pointer: coarse) {
    .lines__remove { min-width: 44px; min-height: 44px; }
}

.lines__footer {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    border-top: 1px solid var(--gray-200);
}

.lines__footer .field__hint { flex: 1 1 260px; }

.lines__totals {
    flex: 0 0 auto;
    min-width: 240px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lines__totals > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 14px;
}

.lines__totals strong { font-family: var(--font-head); font-size: 17px; color: var(--gray-900); }
.lines__totals input { width: 90px; text-align: right; padding: 8px 10px; border: 1px solid var(--gray-300); border-radius: 8px; font-family: inherit; }

/* =========================================================
   Totals block and internal panel
   ========================================================= */

.totals-block { margin-left: auto; max-width: 340px; }

.totals-block__row {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 8px 0;
    font-size: 14px;
    border-bottom: 1px solid var(--gray-100);
}

.totals-block__row--grand {
    border-bottom: none;
    border-top: 2px solid var(--gray-300);
    margin-top: 4px;
    padding-top: 12px;
    font-family: var(--font-head);
    font-size: 18px;
    font-weight: 700;
    color: var(--gray-900);
}

.panel--internal { border-color: var(--yellow-500); }
.panel--internal .panel__head { background: #fffbeb; }
.stat-row--flush { margin-bottom: 0; padding: 16px; }
.detail-heading { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); margin-bottom: 6px; }

.pill--draft    { background: var(--gray-200); color: var(--gray-700); }
.pill--sent     { background: #dbeafe; color: #1e40af; }
.pill--approved { background: #dcfce7; color: #166534; }
.pill--rejected { background: #fee2e2; color: #991b1b; }
.pill--expired  { background: #fef3c7; color: #92400e; }

/* =========================================================
   Contacts
   ========================================================= */

.contact-list { list-style: none; }

.contact {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--gray-100);
}

.contact:last-child { border-bottom: none; }
.contact__main { flex: 1; min-width: 0; }

.contact__name {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-800);
}

.contact__title { display: block; font-size: 13px; color: var(--text-muted); }
.contact__links { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 13px; }

.pill--primary { background: var(--yellow-500); color: var(--blue-900); margin-left: 6px; }

.record-head__note { display: block; font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Native disclosure: no JavaScript needed to fold the "add contact" form. */
.disclosure > summary {
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--blue-700);
    padding: 10px 0;
    list-style: revert;
}

.disclosure > summary:hover { color: var(--amber-700); }
.disclosure[open] > summary { margin-bottom: 12px; }

/* The whole label is the tap target, not just the 20px box. */
.checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    margin-bottom: 14px;
    font-size: 14px;
    cursor: pointer;
}

.checkbox input { width: 20px; height: 20px; accent-color: var(--blue-700); }

/* =========================================================
   Lead → customer conversion
   ========================================================= */

.convert-box {
    margin: 0 16px 16px;
    padding: 16px;
    background: #fffbeb;
    border: 1px solid var(--yellow-500);
    border-radius: var(--radius);
}

.convert-box h3 { font-size: 14px; margin-bottom: 6px; }
.convert-box p { font-size: 13px; color: var(--gray-700); margin-bottom: 14px; }
.convert-form .field { margin-bottom: 12px; }

/* =========================================================
   Destructive actions
   ========================================================= */

.btn--danger { background: var(--red-600); color: var(--white); }
.btn--danger:hover { background: #b91c1c; color: var(--white); }

.danger-zone {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px;
    margin-bottom: 32px;
    background: var(--white);
    border: 1px solid #fca5a5;
    border-radius: var(--radius-lg);
}

.danger-zone h3 { font-size: 14px; color: #991b1b; margin-bottom: 4px; }
.danger-zone p { font-size: 13px; color: var(--text-muted); }

/* =========================================================
   Activity timeline
   ========================================================= */

.activity-form { border-bottom: 1px solid var(--gray-200); padding-bottom: 4px; margin-bottom: 4px; }
.activity-form .field { margin-bottom: 12px; }

.timeline { list-style: none; padding: 8px 16px 16px; }

.timeline__item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--gray-100);
}

.timeline__item:last-child { border-bottom: none; }

.timeline__marker {
    flex: 0 0 10px;
    width: 10px;
    height: 10px;
    margin-top: 6px;
    border-radius: 50%;
    background: var(--blue-600);
}

.timeline__item.is-done .timeline__marker { background: var(--green-600); }
.timeline__item.is-overdue .timeline__marker { background: var(--red-600); }
.timeline__item.is-done .timeline__subject { text-decoration: line-through; color: var(--text-muted); }

.timeline__body { flex: 1; min-width: 0; }
.timeline__head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }

.timeline__type {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-muted);
    background: var(--gray-100);
    padding: 2px 7px;
    border-radius: 999px;
}

.timeline__subject { font-size: 14px; font-weight: 600; color: var(--gray-800); }
.timeline__notes { font-size: 14px; color: var(--gray-600); margin-top: 4px; }
.timeline__meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* =========================================================
   Desktop
   ========================================================= */

@media (min-width: 900px) {
    .sidebar { transform: translateX(0); }
    .sidebar-backdrop { display: none !important; }
    .topbar__toggle { display: none; }

    .main { margin-left: var(--sidebar-w); }

    .topbar { padding: 14px 28px; }
    .topbar__title { font-size: 20px; }

    /* Cap the reading width: on a 27" monitor an uncapped table stretches to
       2000px and becomes unreadable. */
    .content { padding: 28px 28px 64px; max-width: 1440px; }

    .stat-row { grid-template-columns: repeat(4, 1fr); }
    .grid-2 { grid-template-columns: 1fr 1fr; }

    .form-row { grid-template-columns: 1fr 1fr; }
    .form-row--thirds { grid-template-columns: 2fr 1fr 1fr; }

    .filter-bar { flex-direction: row; align-items: center; }
    .filter-bar__search { flex: 1 1 320px; }
    .filter-bar__filters { flex: 0 0 auto; }
    .filter-bar__filters select { flex: 0 0 auto; }

    .form--panel .panel__body,
    .panel__body { padding: 20px; }
}

/* Respect users who ask for less motion. */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* =========================================================
   Customer-facing document (estimate print / PDF)
   Sized for US Letter. No cost, no markup, no margin.
   ========================================================= */

.doc-body { background: var(--gray-200); padding: 24px 12px; }

.doc {
    max-width: 8.5in;
    margin: 0 auto;
    background: var(--white);
    padding: 0.7in 0.75in;
    box-shadow: var(--shadow-md);
    color: var(--gray-800);
    font-size: 14px;
}

.doc__head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding-bottom: 18px;
    border-bottom: 3px solid var(--blue-900);
}

.doc__brand { display: flex; align-items: center; gap: 12px; }

.doc__mark {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 18px;
    letter-spacing: .5px;
    background: var(--yellow-500);
    color: var(--blue-900);
    padding: 8px 12px;
    border-radius: 8px;
}

.doc__brand strong { display: block; font-family: var(--font-head); font-size: 16px; color: var(--blue-900); }
.doc__brand span { display: block; font-size: 12px; color: var(--text-muted); }

.doc__meta { text-align: right; }
.doc__meta h1 { font-size: 24px; color: var(--blue-900); letter-spacing: 1px; text-transform: uppercase; }
.doc__meta p { font-size: 13px; color: var(--gray-700); }
.doc__expiry { color: var(--amber-700); font-weight: 600; }

.doc__parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 28px;
    padding: 22px 0;
}

.doc__parties h2 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.doc__parties p { font-size: 13px; line-height: 1.5; }
.doc__party-name { font-weight: 600; color: var(--gray-900); }

.doc__title {
    font-size: 18px;
    padding: 14px 0 6px;
    border-top: 1px solid var(--gray-200);
}

.doc__scope { padding-bottom: 16px; }
.doc__scope h3, .doc__terms h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.doc__scope p, .doc__terms p { font-size: 13px; line-height: 1.6; }

.doc__table { width: 100%; border-collapse: collapse; margin-top: 8px; }

.doc__table th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--white);
    background: var(--blue-900);
    padding: 9px 10px;
}

.doc__table td { padding: 10px; border-bottom: 1px solid var(--gray-200); vertical-align: top; font-size: 13px; }
.doc__table tbody tr:nth-child(even) { background: var(--gray-50); }
.doc__num { text-align: right; white-space: nowrap; }

.doc__kind {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-muted);
    margin-top: 2px;
}

.doc__totals { margin: 16px 0 0 auto; max-width: 300px; }

.doc__totals > div {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 7px 0;
    font-size: 14px;
}

.doc__grand {
    border-top: 2px solid var(--blue-900);
    margin-top: 4px;
    padding-top: 12px !important;
    font-family: var(--font-head);
    font-size: 19px;
    font-weight: 700;
    color: var(--blue-900);
}

.doc__terms { margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--gray-200); }

.doc__foot { display: flex; gap: 40px; margin-top: 44px; }
.doc__sign { flex: 1; }
.doc__sign-line { display: block; border-bottom: 1px solid var(--gray-500); height: 34px; }
.doc__sign span:last-child { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }

.doc__note {
    margin-top: 26px;
    padding-top: 14px;
    border-top: 1px dashed var(--gray-300);
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

@media (max-width: 700px) {
    .doc { padding: 24px 18px; }
    .doc__parties { grid-template-columns: 1fr; gap: 18px; }
    .doc__meta { text-align: left; }
}

@media print {
    .doc-body { background: var(--white); padding: 0; }
    .doc { max-width: none; box-shadow: none; padding: 0; }
    .no-print { display: none !important; }
    .doc__table thead { display: table-header-group; }
    .doc__table tr { break-inside: avoid; }
    .doc__totals, .doc__foot { break-inside: avoid; }

    @page { size: letter; margin: 0.6in; }
}
