/* ============================================================
   Solar CRM — власна дизайн-система (без зовнішніх залежностей)
   ============================================================ */

:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --border: #e3e8ee;
    --border-strong: #cbd5e1;

    --text: #16212e;
    --text-muted: #6b7a8d;

    --brand: #0f766e;
    --brand-dark: #0b5952;
    --brand-soft: #e6f4f1;

    --accent: #f59e0b;
    --accent-soft: #fef3c7;

    --info: #2563eb;
    --info-soft: #e0ecff;
    --success: #15803d;
    --success-soft: #dcfce7;
    --warning: #b45309;
    --warning-soft: #fef0d5;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;

    --radius: 10px;
    --radius-sm: 7px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
    --shadow-lg: 0 8px 24px rgba(16, 24, 40, .12);

    --sidebar-w: 248px;
    --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    font-size: 14.5px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

h1 { font-size: 1.5rem; margin: 0 0 .25rem; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; font-weight: 640; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }

.muted { color: var(--text-muted); }
.small { font-size: .82rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.pre { white-space: pre-wrap; }
.pad { padding: 1rem 1.25rem; }
.pad-lg { padding: 1.35rem 1.5rem; }
.req { color: var(--danger); }
.wrap-cell { max-width: 260px; }
.plain { list-style: none; margin: 0; padding: 0; }

/* ------------------------------------------------ каркас застосунку */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: #10212b;
    color: #cbd8e2;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand, .public-brand {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: 1.1rem 1.1rem;
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}

.sidebar-brand:hover, .public-brand:hover { text-decoration: none; }

.logo-mark {
    display: grid;
    place-items: center;
    width: 34px; height: 34px;
    flex: 0 0 34px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--brand), #14b8a6);
    color: #fff;
    font-size: 1.05rem;
}

.logo-title { display: block; font-weight: 650; color: #fff; font-size: .98rem; }
.logo-sub { display: block; font-size: .74rem; color: #8ba0b2; }

.nav { padding: .6rem 0 2rem; }
.nav-section {
    padding: .9rem 1.15rem .35rem;
    font-size: .68rem;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: #6f8598;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .5rem 1.15rem;
    color: #c3d2de;
    font-size: .9rem;
    border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255, 255, 255, .05); color: #fff; text-decoration: none; }
.nav-item.active {
    background: rgba(20, 184, 166, .14);
    border-left-color: #14b8a6;
    color: #fff;
    font-weight: 560;
}
.nav-ico { width: 1.1rem; text-align: center; opacity: .85; }

.app-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .55rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-spacer { flex: 1 1 auto; }

.user-box { display: flex; align-items: center; gap: .65rem; }
.avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: grid; place-items: center;
    background: var(--brand-soft);
    color: var(--brand-dark);
    font-weight: 650;
    font-size: .78rem;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-weight: 570; font-size: .87rem; }
.user-role { font-size: .74rem; color: var(--text-muted); }
.logout-form { margin: 0; }

.content { padding: 1.5rem; flex: 1 1 auto; }

#nav-scrim { display: none; }

/* ------------------------------------------------ заголовок сторінки */

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.1rem;
    flex-wrap: wrap;
}
.page-header p { margin: 0; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ------------------------------------------------ картки */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.15rem;
    overflow: hidden;
}
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .75rem;
}
.card-head h2 { margin: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.15rem; align-items: start; }
.stack { display: flex; flex-direction: column; }
.stack > .card:last-child { margin-bottom: 1.15rem; }

/* ------------------------------------------------ KPI */

.kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.15rem;
    margin-bottom: 1.15rem;
}
.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.15rem;
}
.kpi-label { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi-value { font-size: 1.8rem; font-weight: 660; margin: .2rem 0 .35rem; letter-spacing: -.02em; }
.kpi-warn { font-size: .8rem; color: var(--danger); font-weight: 500; }
.kpi-link { font-size: .82rem; }

/* ------------------------------------------------ воронка */

.pipeline { padding: 0 1.25rem 1.1rem; }
.pipe-row {
    display: grid;
    grid-template-columns: 210px 1fr 110px;
    align-items: center;
    gap: .75rem;
    padding: .35rem 0;
}
.pipe-label { display: flex; align-items: center; gap: .5rem; }
.pipe-bar { background: var(--surface-2); border-radius: 999px; height: 9px; overflow: hidden; }
.pipe-bar span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--brand), #14b8a6);
    border-radius: 999px;
}
.pipe-amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 560; }

/* ------------------------------------------------ таблиці */

.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th {
    text-align: left;
    padding: .6rem 1rem;
    font-size: .73rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    white-space: nowrap;
}
.table td { padding: .65rem 1rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--brand-soft); }
.table.compact td { padding: .5rem .75rem; }
.table .row-muted { opacity: .55; }
.table .row-danger td { background: #fff5f5; }
.table-foot {
    display: flex; justify-content: space-between; gap: 1rem;
    padding: .65rem 1rem; font-size: .82rem;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}
.edit-row td { background: var(--surface-2); }

/* ------------------------------------------------ форми */

.field { margin-bottom: .9rem; flex: 1 1 180px; min-width: 0; }
.field label { display: block; font-size: .8rem; font-weight: 560; margin-bottom: .3rem; color: #33465c; }
.field-row { display: flex; gap: .85rem; flex-wrap: wrap; }

.input {
    width: 100%;
    padding: .5rem .7rem;
    font-family: inherit;
    font-size: .9rem;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color .12s, box-shadow .12s;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12); }
.input:disabled { background: var(--surface-2); color: var(--text-muted); }
textarea.input { resize: vertical; min-height: 60px; }
select.input { appearance: auto; }
.input.narrow { max-width: 160px; }

.check { display: flex; align-items: flex-start; gap: .5rem; margin-bottom: .9rem; font-size: .88rem; cursor: pointer; }
.check.inline { margin-bottom: 0; align-items: center; white-space: nowrap; }
.check input { margin-top: .18rem; }
.check.consent { background: var(--surface-2); padding: .7rem .85rem; border-radius: var(--radius-sm); }

.filters {
    display: flex;
    gap: .7rem;
    align-items: center;
    flex-wrap: wrap;
    padding: .9rem 1.1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
.filters .input { width: auto; min-width: 190px; flex: 0 1 auto; }
.filters .input:first-child { flex: 1 1 260px; }

.validation-message, .validation-errors { color: var(--danger); font-size: .8rem; margin-top: .22rem; }
.invalid { border-color: var(--danger) !important; }

.form-note { font-size: .78rem; color: var(--text-muted); margin-top: .8rem; }
.note-form { display: flex; gap: .6rem; align-items: flex-start; margin-bottom: 1rem; flex-wrap: wrap; }
.note-form textarea { flex: 1 1 320px; }
.role-row { display: flex; gap: 1rem; flex-wrap: wrap; }

/* ------------------------------------------------ кнопки */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .48rem .9rem;
    font-family: inherit;
    font-size: .875rem;
    font-weight: 540;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    transition: background .12s, border-color .12s, opacity .12s;
    white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-sm { padding: .28rem .55rem; font-size: .8rem; }
.btn-block { width: 100%; margin-top: .4rem; }
.btn-row { display: flex; gap: .55rem; flex-wrap: wrap; margin-top: .6rem; }

.icon-btn {
    border: 0; background: transparent; cursor: pointer;
    font-size: 1.15rem; padding: .25rem .45rem; border-radius: var(--radius-sm);
}
.icon-btn:hover { background: var(--surface-2); }
.only-mobile { display: none; }

.link-btn {
    background: none; border: 0; padding: 0; margin: .2rem 0 .9rem;
    color: var(--brand); font: inherit; font-size: .86rem; cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }
.link { font-size: .84rem; }

/* ------------------------------------------------ чіпи та алерти */

.chip {
    display: inline-block;
    padding: .13rem .5rem;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 570;
    line-height: 1.5;
    margin-right: .25rem;
    white-space: nowrap;
}
.chip-neutral { background: #eef1f5; color: #52616f; }
.chip-info { background: var(--info-soft); color: var(--info); }
.chip-success { background: var(--success-soft); color: var(--success); }
.chip-warning { background: var(--warning-soft); color: var(--warning); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }
.chip-accent { background: var(--accent-soft); color: #92620a; }
.chip-row { display: flex; gap: .3rem; flex-wrap: wrap; }

.alert {
    padding: .7rem .95rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: .88rem;
    border: 1px solid transparent;
}
.alert-info { background: var(--info-soft); border-color: #c3dafe; color: #1e40af; }
.alert-success { background: var(--success-soft); border-color: #bbf7d0; color: #14532d; }
.alert-warning { background: var(--warning-soft); border-color: #fde68a; color: #7c2d12; }
.alert-error { background: var(--danger-soft); border-color: #fecaca; color: #7f1d1d; }

/* ------------------------------------------------ списки визначень і таймлайн */

.deflist { display: grid; grid-template-columns: 170px 1fr; gap: .4rem .9rem; margin: 0; font-size: .88rem; }
.deflist dt { color: var(--text-muted); }
.deflist dd { margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.tl-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: .42rem; flex: 0 0 9px; background: var(--border-strong); }
.tl-note { background: var(--info); }
.tl-call { background: var(--success); }
.tl-email { background: var(--accent); }
.tl-meeting { background: #8b5cf6; }
.tl-statuschange { background: var(--warning); }
.tl-system { background: var(--border-strong); }
.tl-body { flex: 1 1 auto; min-width: 0; }
.tl-head { display: flex; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.tl-text { margin-top: .2rem; color: #3d4b5c; font-size: .86rem; }

/* ------------------------------------------------ КП */

.add-line { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.add-line select { min-width: 320px; }
.quote-lines td { padding: .35rem .5rem; }
.quote-lines .input { padding: .32rem .45rem; font-size: .84rem; }

.totals {
    margin-left: auto;
    width: 340px;
    padding: 1rem 1.25rem;
    font-size: .9rem;
}
.totals > div { display: flex; justify-content: space-between; padding: .2rem 0; }
.totals .grand {
    border-top: 2px solid var(--border-strong);
    margin-top: .4rem; padding-top: .5rem;
    font-size: 1.05rem;
}

/* ------------------------------------------------ авторизація */

.blank-layout { min-height: 100vh; background: var(--bg); }

.auth-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem 1rem;
    background: radial-gradient(1000px 500px at 50% -10%, #d7ede9 0%, var(--bg) 60%);
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    padding: 1.9rem;
}
.auth-brand { display: flex; align-items: center; gap: .7rem; margin-bottom: 1.4rem; }
.auth-brand .logo-title { color: var(--text); }
.auth-brand .logo-sub { color: var(--text-muted); }
.auth-card h1 { font-size: 1.25rem; margin-bottom: 1.1rem; }
.auth-foot { margin-top: 1.2rem; font-size: .84rem; color: var(--text-muted); text-align: center; }

/* ------------------------------------------------ публічні сторінки */

.public-shell { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.public-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; padding: .7rem 2rem;
    background: #10212b;
}
.public-header .logo-sub { color: #8ba0b2; }
.public-nav { display: flex; align-items: center; gap: 1.1rem; }
.public-nav a { color: #cbd8e2; font-size: .9rem; }
.public-nav .btn-ghost { color: #cbd8e2; border-color: rgba(255,255,255,.2); }
.public-nav .btn-ghost:hover { background: rgba(255,255,255,.08); color: #fff; }

.public-main { flex: 1 1 auto; max-width: 1080px; width: 100%; margin: 0 auto; padding: 2rem 1.5rem 3rem; }
.public-footer {
    display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
    padding: 1rem 2rem; font-size: .82rem; color: var(--text-muted);
    border-top: 1px solid var(--border); background: var(--surface);
}

.apply-hero { margin-bottom: 1.5rem; max-width: 720px; }
.apply-hero h1 { font-size: 1.85rem; }
.apply-hero p { color: var(--text-muted); }

.apply-grid { display: grid; grid-template-columns: 1.55fr 1fr; gap: 1.3rem; align-items: start; }
.apply-form { }
.extra-block {
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 1rem 1rem .1rem;
    margin-bottom: 1rem;
    background: var(--surface-2);
}
.hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.apply-aside h2 { margin-top: 1.2rem; }
.apply-aside h2:first-child { margin-top: 0; }
.steps { margin: 0 0 .5rem; padding-left: 1.1rem; font-size: .88rem; color: #3d4b5c; }
.steps li { margin-bottom: .45rem; }
.ticks { list-style: none; margin: 0; padding: 0; font-size: .88rem; color: #3d4b5c; }
.ticks li { position: relative; padding-left: 1.2rem; margin-bottom: .35rem; }
.ticks li::before { content: "✓"; position: absolute; left: 0; color: var(--brand); font-weight: 700; }
.contact-box {
    margin-top: 1.3rem; padding: .85rem 1rem;
    background: var(--brand-soft); border-radius: var(--radius-sm); font-size: .88rem;
}

.thanks-card { max-width: 560px; margin: 2rem auto; text-align: center; }
.thanks-mark {
    width: 56px; height: 56px; margin: 0 auto 1rem;
    border-radius: 50%; display: grid; place-items: center;
    background: var(--success-soft); color: var(--success); font-size: 1.7rem;
}
.thanks-number { font-size: 1.05rem; }
.thanks-actions { display: flex; gap: .6rem; justify-content: center; margin-top: 1.2rem; flex-wrap: wrap; }

/* ------------------------------------------------ друк КП */

.print-sheet { max-width: 860px; margin: 0 auto; padding: 2rem; background: #fff; }
.print-bar { display: flex; justify-content: space-between; gap: 1rem; align-items: center; margin-bottom: 1.5rem; }
.print-head { display: flex; justify-content: space-between; gap: 2rem; border-bottom: 2px solid var(--brand); padding-bottom: 1rem; }
.print-company { font-size: 1.15rem; font-weight: 660; color: var(--brand-dark); }
.print-title { text-align: right; }
.print-title h1 { font-size: 1.3rem; }
.print-party { display: flex; justify-content: space-between; gap: 2rem; margin: 1.3rem 0; }
.print-table { width: 100%; border-collapse: collapse; font-size: .85rem; margin-bottom: 1rem; }
.print-table th {
    text-align: left; padding: .5rem .6rem; background: var(--surface-2);
    border-bottom: 1.5px solid var(--border-strong); font-size: .76rem; text-transform: uppercase;
}
.print-table td { padding: .45rem .6rem; border-bottom: 1px solid var(--border); }
.print-totals { margin-left: auto; width: 320px; font-size: .9rem; }
.print-totals > div { display: flex; justify-content: space-between; padding: .18rem 0; }
.print-totals .grand { border-top: 2px solid var(--border-strong); margin-top: .35rem; padding-top: .45rem; font-size: 1.05rem; }
.print-notes { margin-top: 1.5rem; font-size: .86rem; }
.print-foot { margin-top: 2.5rem; border-top: 1px solid var(--border); padding-top: .6rem; }

@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
    .print-sheet { padding: 0; max-width: none; }
}

/* ------------------------------------------------ помилка Blazor */

#blazor-error-ui {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
    background: #fff3cd; color: #664d03;
    padding: .7rem 1.25rem; box-shadow: 0 -2px 8px rgba(0, 0, 0, .12);
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 1rem; top: .6rem; }

/* ------------------------------------------------ адаптив */

@media (max-width: 1100px) {
    .kpi-row { grid-template-columns: repeat(2, 1fr); }
    .grid-2, .apply-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
    .only-mobile { display: inline-flex; }
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; z-index: 40;
        transform: translateX(-100%); transition: transform .18s ease;
    }
    .sidebar.open { transform: translateX(0); }
    #nav-scrim.show {
        display: block; position: fixed; inset: 0; z-index: 30;
        background: rgba(10, 20, 30, .4);
    }
    .content { padding: 1rem; }
    .kpi-row { grid-template-columns: 1fr; }
    .deflist { grid-template-columns: 1fr; gap: .1rem .5rem; }
    .deflist dt { margin-top: .5rem; }
    .totals { width: 100%; }
    .public-main { padding: 1.25rem 1rem 2rem; }
    .public-header { padding: .7rem 1rem; }
    .table { display: block; overflow-x: auto; white-space: nowrap; }
}
