:root {
    --color-bg: #eef0f3;
    --color-surface: #ffffff;
    --color-border: #d6dbe2;
    --color-text: #1c2430;
    --color-text-muted: #5b6472;
    --color-primary: #1b4f8c;
    --color-primary-dark: #123863;
    --color-primary-light: #3d74b8;
    --color-danger: #9c3b2f;
    --radius: 8px;
    --preview-sky: #eef2f5;
    --preview-grass: #dfe8dc;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.45;
}

a { color: var(--color-primary-dark); }

.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}
.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}
.topbar .brand {
    font-weight: 700;
    text-decoration: none;
    color: var(--color-text);
}
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { text-decoration: none; color: var(--color-text-muted); }
.topbar nav a:hover { color: var(--color-text); }
.topbar-user { display: flex; align-items: center; gap: 0.75rem; color: var(--color-text-muted); font-size: 0.9rem; }

.page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.page-header h1 { margin: 0; font-size: 1.5rem; }

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--color-border); }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-text-muted); }
tbody tr:hover { background: #fafbf9; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.btn {
    display: inline-block;
    padding: 0.55rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--color-primary);
    background: var(--color-primary);
    color: #fff;
    text-decoration: none;
    font-size: 0.9rem;
    cursor: pointer;
}
.btn:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }
.btn-secondary { background: transparent; color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: #f0f1ee; }
.btn-danger { background: transparent; color: var(--color-danger); border-color: var(--color-danger); }
.btn-danger:hover { background: #fbeceA; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.form-row { margin-bottom: 1rem; }
.form-row label { display: block; font-size: 0.85rem; color: var(--color-text-muted); margin-bottom: 0.3rem; }
input, select, textarea {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
    color: var(--color-text);
}
textarea { resize: vertical; }

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 99px;
    font-size: 0.75rem;
    background: #eef1ea;
    color: var(--color-text-muted);
}
.swatch { display: inline-block; width: 0.9rem; height: 0.9rem; border-radius: 50%; border: 1px solid var(--color-border); vertical-align: middle; margin-right: 0.4rem; }

.badge-new_lead { background: #fdf0d8; color: #96650c; }
.badge-draft { background: #eef1ea; color: #676f60; }
.badge-sent { background: #e7eefb; color: #2e5aa8; }
.badge-approved { background: #e6f3e6; color: #2c6e2c; }
.badge-completed { background: #efe6f7; color: #6a3ba1; }
.badge-cancelled { background: #fbeceA; color: #9c3b2f; }
.badge-accepted { background: #e6f3e6; color: #2c6e2c; }
.badge-declined { background: #fbeceA; color: #9c3b2f; }
.badge-partial { background: #fdf0d8; color: #96650c; }
.badge-paid { background: #e6f3e6; color: #2c6e2c; }
.badge-overdue { background: #fde2e1; color: #b3261e; }
.badge-void { background: #fbeceA; color: #9c3b2f; }
.doc-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.gate-row { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 0.75rem; align-items: end; margin-bottom: 0.75rem; }

.contact-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-top: 1.25rem; }
.contact-actions form { margin: 0; }
.badge-callback { background: #fde2e1; color: #b3261e; }
.totals { max-width: 320px; margin-left: auto; }
.totals div { display: flex; justify-content: space-between; padding: 0.25rem 0; }
.totals .total-line { font-weight: 700; font-size: 1.1rem; border-top: 1px solid var(--color-border); margin-top: 0.4rem; padding-top: 0.6rem; }

.muted { color: var(--color-text-muted); }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--color-text-muted); }

.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert-error { background: #fbeceA; color: var(--color-danger); border: 1px solid #f0c9c3; }

.login-wrap { max-width: 380px; margin: 4rem auto; }

.quote-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.5rem; }
.quote-header h1 { margin: 0 0 0.25rem; }

.checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin-top: 0.75rem;
}
.checkbox-row input { width: auto; margin-top: 0.2rem; }

.estimate-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1.25rem;
    align-items: start;
}
.preview-card { position: sticky; top: 1rem; }
.fence-preview-svg {
    width: 100%;
    height: auto;
    aspect-ratio: 900 / 340;
    background: var(--preview-sky);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
}

@media (max-width: 900px) {
    .estimate-layout { grid-template-columns: 1fr; }
    .preview-card { position: static; }
}

/* ---- Public landing / quote tool ---- */
.public-header {
    background: var(--color-primary);
    color: #fff;
}
.public-header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0.9rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.public-brand { display: flex; align-items: center; gap: 0.6rem; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.public-brand svg { flex-shrink: 0; }
.public-login-link { color: #cfe0f2; font-size: 0.85rem; text-decoration: none; }
.public-login-link:hover { color: #fff; }

.hero {
    background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: #fff;
    padding: 2.5rem 1.25rem 3rem;
    text-align: center;
}
.hero h1 { margin: 0 0 0.5rem; font-size: 1.9rem; }
.hero p { margin: 0 auto 1.25rem; max-width: 640px; color: #dce8f5; }
.hero .btn { background: #fff; color: var(--color-primary-dark); border-color: #fff; font-weight: 600; }
.hero .btn:hover { background: #eef2f5; }

.public-page {
    max-width: 780px;
    margin: -1.5rem auto 3rem;
    padding: 0 1.25rem;
}
.quote-tool-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 12px; padding: 1.5rem; box-shadow: 0 8px 30px rgba(20, 40, 70, 0.08); margin-bottom: 1.25rem; }
.quote-tool-card h2 { margin-top: 0; font-size: 1.15rem; }
.step-label { display: inline-block; background: var(--color-primary); color: #fff; border-radius: 99px; width: 1.6rem; height: 1.6rem; text-align: center; line-height: 1.6rem; font-size: 0.85rem; margin-right: 0.5rem; }

.lead-gate { text-align: center; padding: 1.5rem 1rem; }
.lead-gate .btn { font-size: 1.05rem; padding: 0.85rem 1.75rem; }

.public-footer { text-align: center; color: var(--color-text-muted); font-size: 0.85rem; padding: 2rem 1.25rem 3rem; }
.public-footer a { color: var(--color-primary-dark); }

@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
    .page { max-width: none; padding: 0; }
    .card { border: none; padding: 0; }
}

@media (max-width: 700px) {
    .form-grid { grid-template-columns: 1fr; }
    .gate-row { grid-template-columns: 1fr; }
}
