/* ==========================================================================
   Botsan.app — CRM / Invoice / Tracker pages
   assets/css/business.css
   --------------------------------------------------------------------------
   Shared by crm.php, invoice.php and tracking.php. Each of those has
   two faces: a public landing page when signed out, and the working app when
   signed in. Both live here so the two never drift apart visually.

   Depends on the tokens in assets/css/app.css.
   ========================================================================== */

/* ── Public landing (signed out) ─────────────────────────────────────────── */

.biz-hero {
    padding: 3.5rem 0 3rem;
    background: linear-gradient(180deg, var(--brand-tint) 0%, var(--surface) 100%);
    text-align: center;
}
.biz-hero h1 {
    font-size: clamp(1.75rem, 4.5vw, 2.75rem);
    font-weight: 800;
    letter-spacing: -.02em;
    line-height: 1.15;
    margin-bottom: .85rem;
    color: var(--ink);
}
.biz-hero p.lead {
    font-size: clamp(1rem, 2vw, 1.15rem);
    color: var(--text-muted);
    max-width: 40rem;
    margin: 0 auto 1.6rem;
    line-height: 1.65;
}
.biz-hero-cta { display: flex; gap: .65rem; justify-content: center; flex-wrap: wrap; }

/* The "type this, get that" demo that explains the product faster than prose */
.biz-demo {
    max-width: 34rem;
    margin: 2.5rem auto 0;
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}
.biz-demo-head {
    background: var(--brand);
    color: #fff;
    padding: .6rem .9rem;
    font-size: .8rem;
    font-weight: 600;
    display: flex; align-items: center; gap: .45rem;
}
.biz-demo-body {
    padding: 1rem .9rem;
    display: flex; flex-direction: column; gap: .5rem;
    background: var(--surface-2);
}
.biz-bubble {
    max-width: 85%;
    padding: .5rem .75rem;
    border-radius: 14px;
    font-size: .85rem;
    line-height: 1.55;
    white-space: pre-wrap;
}
.biz-bubble.me  { align-self: flex-end;   background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.biz-bubble.bot { align-self: flex-start; background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.biz-bubble code {
    font-family: var(--font-mono); font-size: .85em;
    background: rgba(255,255,255,.2); padding: .1em .35em; border-radius: 4px;
}
.biz-bubble.bot code { background: rgba(15,23,42,.07); }

.biz-features {
    display: grid;
    gap: 1.1rem;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    padding: 3rem 0;
}
.biz-feature {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.4rem;
}
.biz-feature-icon { font-size: 1.6rem; margin-bottom: .6rem; }
.biz-feature h3 { font-size: 1rem; font-weight: 700; margin-bottom: .35rem; color: var(--ink); }
.biz-feature p  { font-size: .875rem; color: var(--text-muted); line-height: 1.6; }

/* ── App shell (signed in) ───────────────────────────────────────────────── */

.biz-toolbar {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    margin-bottom: 1.1rem;
}
.biz-toolbar .grow { flex: 1; min-width: 10rem; }

.biz-stats {
    display: grid;
    gap: .8rem;
    grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
    margin-bottom: 1.25rem;
}
.biz-stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--brand);
    border-radius: var(--radius-lg);
    padding: .85rem 1rem;
}
.biz-stat .k {
    font-size: .66rem; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-muted); font-weight: 700; margin-bottom: .25rem;
}
.biz-stat .v { font-size: 1.4rem; font-weight: 800; line-height: 1.15; color: var(--ink); }
.biz-stat .n { font-size: .73rem; color: var(--text-muted); margin-top: .15rem; }
.biz-stat.ok   { border-left-color: var(--success); }
.biz-stat.warn { border-left-color: var(--warning); }
.biz-stat.bad  { border-left-color: var(--danger); }
.biz-stat .v.ok   { color: var(--success-dark); }
.biz-stat .v.bad  { color: var(--danger); }

/* ── Split layout: list on the left, detail on the right ─────────────────── */

.biz-split {
    display: grid;
    gap: 1.1rem;
    grid-template-columns: 1fr;
    align-items: start;
}
@media (min-width: 1100px) {
    .biz-split { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
    .biz-split .biz-detail { position: sticky; top: 5.5rem; }
}

.biz-detail-empty {
    text-align: center;
    padding: 2.5rem 1.25rem;
    color: var(--text-muted);
    font-size: .875rem;
}

/* ── Rows ────────────────────────────────────────────────────────────────── */

.biz-row {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .7rem .9rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background .12s;
}
.biz-row:last-child { border-bottom: none; }
.biz-row:hover      { background: var(--surface-2); }
.biz-row.is-active  { background: var(--brand-tint); }

.biz-avatar {
    width: 2.15rem; height: 2.15rem;
    border-radius: 50%;
    background: var(--brand-tint);
    color: var(--brand);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .82rem;
    flex-shrink: 0;
}

.biz-row-main  { flex: 1; min-width: 0; }
.biz-row-title {
    font-weight: 600; font-size: .875rem; color: var(--ink);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.biz-row-sub {
    font-size: .75rem; color: var(--text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.biz-row-right { text-align: right; flex-shrink: 0; }
.biz-row-amt   { font-weight: 700; font-size: .875rem; }
.biz-row-amt.in  { color: var(--success-dark); }
.biz-row-amt.out { color: var(--danger); }

/* ── Notes timeline ──────────────────────────────────────────────────────── */

.biz-note {
    padding: .6rem .8rem;
    border-left: 2px solid var(--border-strong);
    margin-bottom: .6rem;
    font-size: .82rem;
    line-height: 1.55;
    color: var(--text);
    background: var(--surface-2);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    white-space: pre-wrap;
}
.biz-note.from-chat   { border-left-color: var(--brand); }
.biz-note.from-system { border-left-color: var(--success); background: var(--success-tint); }
.biz-note-meta { font-size: .68rem; color: var(--text-faint); margin-top: .3rem; }

/* ── Stage pills ─────────────────────────────────────────────────────────── */

.biz-stage {
    display: inline-block;
    padding: .12rem .5rem;
    border-radius: 999px;
    font-size: .66rem;
    font-weight: 700;
    white-space: nowrap;
}
.stage-new       { background: #EFF6FF; color: #1D4ED8; }
.stage-contacted { background: #FEF3C7; color: #92400E; }
.stage-qualified { background: #F5F3FF; color: #6D28D9; }
.stage-customer  { background: var(--success-tint); color: var(--success-dark); }
.stage-lost      { background: #F3F4F6; color: #6B7280; }

.st-draft     { background: #F3F4F6; color: #4B5563; }
.st-sent      { background: #EFF6FF; color: #1D4ED8; }
.st-partial   { background: #FEF3C7; color: #92400E; }
.st-paid      { background: var(--success-tint); color: var(--success-dark); }
.st-overdue   { background: var(--danger-tint); color: var(--danger-dark); }
.st-cancelled { background: #F3F4F6; color: #9CA3AF; }

/* ── Simple bar chart, no library ────────────────────────────────────────── */

.biz-chart {
    display: flex;
    align-items: flex-end;
    gap: .35rem;
    height: 8rem;
    padding: .5rem 0;
}
.biz-chart-col {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; gap: .2rem;
    min-width: 0;
}
.biz-chart-bars {
    width: 100%;
    height: 6.2rem;
    display: flex; align-items: flex-end; justify-content: center; gap: 2px;
}
.biz-chart-bar {
    width: 45%;
    min-height: 2px;
    border-radius: 2px 2px 0 0;
    transition: height .3s ease;
}
.biz-chart-bar.in  { background: var(--success); }
.biz-chart-bar.out { background: #FCA5A5; }
.biz-chart-label {
    font-size: .62rem; color: var(--text-faint);
    white-space: nowrap; overflow: hidden;
}

.biz-legend { display: flex; gap: 1rem; font-size: .72rem; color: var(--text-muted); }
.biz-legend i { width: .7rem; height: .7rem; border-radius: 2px; display: inline-block; margin-right: .3rem; }

/* ── Category bars ───────────────────────────────────────────────────────── */

.biz-cat { margin-bottom: .55rem; }
.biz-cat-top {
    display: flex; justify-content: space-between;
    font-size: .78rem; margin-bottom: .2rem;
}
.biz-cat-name { color: var(--text); font-weight: 500; }
.biz-cat-val  { color: var(--text-muted); }
.biz-cat-track { height: .35rem; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.biz-cat-fill  { height: 100%; background: var(--brand); border-radius: 999px; }

/* ── Invoice builder ─────────────────────────────────────────────────────── */

.biz-items { width: 100%; border-collapse: collapse; font-size: .82rem; }
.biz-items th {
    text-align: left; padding: .4rem .45rem;
    font-size: .65rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-muted); font-weight: 700;
    border-bottom: 1px solid var(--border);
}
.biz-items td { padding: .3rem .25rem; vertical-align: middle; }
.biz-items input {
    width: 100%; padding: .35rem .45rem;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font: inherit; font-size: .82rem; background: var(--surface); color: var(--ink);
    outline: none;
}
.biz-items input:focus { border-color: var(--brand); }
.biz-items input[type=number] { text-align: right; }
.biz-items .col-del { width: 2rem; text-align: center; }

.biz-del {
    background: none; border: 0; cursor: pointer;
    color: var(--text-faint); font-size: 1rem; line-height: 1; padding: .2rem;
}
.biz-del:hover { color: var(--danger); }

.biz-totals { margin-left: auto; max-width: 17rem; font-size: .85rem; }
.biz-totals dl { display: grid; grid-template-columns: 1fr auto; gap: .3rem .8rem; }
.biz-totals dt { color: var(--text-muted); }
.biz-totals dd { text-align: right; font-weight: 600; margin: 0; }
.biz-totals .grand {
    border-top: 1px solid var(--border);
    padding-top: .45rem; margin-top: .3rem;
    font-size: 1.05rem; font-weight: 800;
}

/* Wide tables must scroll inside their card, never push the page sideways. */
.biz-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 640px) {
    .biz-toolbar { gap: .4rem; }
    .biz-stat .v { font-size: 1.2rem; }
}

/* ── Landing-page sections ───────────────────────────────────────────────
   Used by /crm, /invoice and
   /tracking whenever they grow the same sections. */

.biz-h2 {
    margin: 2.75rem 0 1.1rem;
    font-size: clamp(1.35rem, 3.4vw, 1.75rem);
    font-weight: 800;
    letter-spacing: -.01em;
    color: var(--ink);
}

/* A feature heading that is also a link still has to read as a heading —
   the underline appears on hover, not at rest. */
.biz-feature h3 a {
    color: inherit;
    text-decoration: none;
    border-bottom: 2px solid var(--brand-line);
}
.biz-feature h3 a:hover { border-bottom-color: var(--brand); color: var(--brand); }
.biz-feature p a { color: var(--brand); }

/* ── FAQ ─────────────────────────────────────────────────────────────────
   <details>, so it works with JavaScript off and needs no ARIA of our own.
   The answers are real text in the page, not hidden behind a script: an FAQ
   marked up as FAQPage but not visible to a reader is what gets structured
   data ignored. */

.biz-faq {
    max-width: 48rem;
    border-top: 1px solid var(--border);
}

.biz-faq-item { border-bottom: 1px solid var(--border); }

.biz-faq-item > summary {
    cursor: pointer;
    padding: .95rem .5rem .95rem 0;
    font-weight: 650;
    font-size: 1rem;
    color: var(--ink);
    list-style: none;
    position: relative;
    padding-right: 2rem;
}
.biz-faq-item > summary::-webkit-details-marker { display: none; }

/* The chevron is drawn rather than added as an element, so the markup stays
   the two tags a screen reader expects to find. */
.biz-faq-item > summary::after {
    content: "";
    position: absolute;
    right: .5rem; top: 1.25rem;
    width: .5rem; height: .5rem;
    border-right: 2px solid var(--text-faint);
    border-bottom: 2px solid var(--text-faint);
    transform: rotate(45deg);
    transition: transform .18s ease;
}
.biz-faq-item[open] > summary::after { transform: rotate(-135deg); top: 1.45rem; }
.biz-faq-item > summary:hover { color: var(--brand); }

.biz-faq-item > p {
    margin: 0 0 1.1rem;
    padding-right: 2rem;
    color: var(--text);
    line-height: 1.7;
}

/* ── Closing call to action ──────────────────────────────────────────── */

.biz-endcta {
    margin: 3rem 0 1rem;
    padding: 2.25rem 1.5rem;
    text-align: center;
    background: var(--brand-tint);
    border: 1px solid var(--brand-line);
    border-radius: var(--radius-lg, .75rem);
}
.biz-endcta h2 {
    margin: 0 0 .6rem;
    font-size: clamp(1.3rem, 3.2vw, 1.6rem);
    font-weight: 800;
    color: var(--ink);
}
.biz-endcta p {
    margin: 0 auto 1.35rem;
    max-width: 34rem;
    color: var(--text);
    line-height: 1.65;
}
.biz-endcta a { color: var(--brand); }
.biz-endcta .btn-signup { color: #fff; }

/* ══════════════════════════════════════════════════════════════════════════
   CRM Mobile & Responsive Layout Polish
   ══════════════════════════════════════════════════════════════════════════ */

.crm-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.crm-toolbar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.crm-search-wrap {
    flex: 1 1 12rem;
}

.crm-search-input {
    width: 100%;
    min-width: 11rem;
}

.crm-actions {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
}

.crm-btn-upload {
    margin: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}

/* CRM Add Contact Grid */
.crm-add-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}
.crm-add-grid .crm-field {
    display: flex;
    flex-direction: column;
}
.crm-add-grid .crm-field-full {
    grid-column: 1 / -1;
}

/* Status Badges */
.crm-badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.crm-status-none { background: #f1f5f9; color: #475569; }
.crm-status-paid { background: #dcfce7; color: #15803d; }
.crm-status-due  { background: #fee2e2; color: #dc2626; }

/* Desktop CRM Table Styling */
@media (min-width: 769px) {
    .crm-table-scroller {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .biz-crm-table {
        width: 100%;
        text-align: left;
        border-collapse: collapse;
        min-width: 780px;
    }
    .biz-crm-table thead tr {
        border-bottom: 2px solid #f1f5f9;
        background: #f8fafc;
    }
    .biz-crm-table th {
        padding: 0.85rem 1rem;
        font-weight: 600;
        color: #475569;
        font-size: 0.8rem;
        letter-spacing: 0.03em;
        text-transform: uppercase;
    }
    .biz-crm-table td {
        padding: 0.95rem 1rem;
        vertical-align: top;
        border-bottom: 1px solid #e2e8f0;
    }
    .crm-card-header-mobile .crm-status-mobile { display: none; }
    .crm-mobile-finance { display: none; }
    .crm-action-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 0.4rem;
        align-items: center;
    }
    .crm-btn-wa {
        display: inline-flex;
        align-items: center;
        gap: 0.3rem;
        background: #22c55e;
        color: #fff;
        font-weight: 600;
        font-size: 0.8rem;
        padding: 0.25rem 0.65rem;
        border-radius: 6px;
        text-decoration: none;
    }
    .crm-btn-wa:hover { background: #16a34a; }
    .crm-link {
        color: #64748b;
        text-decoration: none;
        font-size: 0.85rem;
    }
    .crm-link:hover { color: var(--brand); text-decoration: underline; }
    .crm-contacts {
        margin-top: 0.25rem;
        display: flex;
        flex-wrap: wrap;
        gap: 0.35rem;
        font-size: 0.85rem;
    }
    .crm-note-preview {
        background: #f8fafc;
        border-left: 3px solid #cbd5e1;
        padding: 0.4rem 0.6rem;
        border-radius: 0 4px 4px 0;
        font-size: 0.8rem;
        color: #475569;
        margin-top: 0.45rem;
    }
}

/* Mobile & Small Screen Card Transformation */
@media (max-width: 768px) {
    .crm-header-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.85rem;
    }
    .crm-toolbar {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0.6rem;
    }
    .crm-search-wrap,
    .crm-search-input {
        width: 100% !important;
        min-width: 0 !important;
    }
    .crm-actions {
        width: 100%;
        display: flex;
        gap: 0.4rem;
    }
    .crm-actions > * {
        flex: 1 1 0;
        text-align: center;
        justify-content: center;
        font-size: 0.8rem;
        padding: 0.45rem 0.3rem !important;
    }

    .crm-add-grid {
        grid-template-columns: 1fr;
        gap: 0.65rem;
    }

    /* Stats 2x2 grid */
    .crm-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.55rem !important;
        margin-bottom: 1rem !important;
    }
    .crm-stats-grid .biz-stat {
        padding: 0.65rem 0.75rem !important;
        border-radius: 10px !important;
    }
    .crm-stats-grid .biz-stat .k {
        font-size: 0.62rem !important;
        margin-bottom: 0.15rem !important;
    }
    .crm-stats-grid .biz-stat .v {
        font-size: 1.15rem !important;
    }

    /* Card transformation for table */
    .crm-table-card {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
    }
    .crm-table-scroller {
        overflow: visible !important;
    }
    .biz-crm-table {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        border: none !important;
    }
    .biz-crm-table thead {
        display: none !important;
    }
    .biz-crm-table tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.85rem !important;
        width: 100% !important;
    }
    .biz-crm-table tr.crm-row {
        display: flex !important;
        flex-direction: column !important;
        background: #ffffff !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 12px !important;
        padding: 1rem !important;
        box-shadow: 0 2px 6px rgba(15, 23, 42, 0.05) !important;
        gap: 0.65rem !important;
    }
    .biz-crm-table tr.crm-row.is-active {
        border-color: var(--brand) !important;
        box-shadow: 0 0 0 2px var(--brand-tint) !important;
    }
    .biz-crm-table td.crm-col {
        display: block !important;
        padding: 0 !important;
        border: none !important;
        width: 100% !important;
    }
    .crm-col-billed,
    .crm-col-paid,
    .crm-col-status {
        display: none !important;
    }

    /* Inside the mobile card */
    .crm-card-header-mobile {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 0.5rem !important;
        padding-bottom: 0.4rem;
        border-bottom: 1px solid #f1f5f9;
    }
    .crm-name {
        font-size: 1.05rem !important;
        font-weight: 700 !important;
        color: #0f172a !important;
    }
    .crm-id {
        color: #94a3b8 !important;
        font-size: 0.8rem !important;
        margin-left: 0.35rem !important;
    }
    .crm-contacts {
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        gap: 0.45rem !important;
        margin-top: 0.35rem !important;
    }
    .crm-link {
        display: inline-flex !important;
        align-items: center !important;
        gap: 0.3rem !important;
        padding: 0.3rem 0.55rem !important;
        background: #f8fafc !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 6px !important;
        color: #334155 !important;
        text-decoration: none !important;
        font-size: 0.82rem !important;
        font-weight: 500 !important;
    }
    .crm-link:active {
        background: #e2e8f0 !important;
    }
    .crm-sep { display: none !important; }

    .crm-note-preview {
        background: #f8fafc !important;
        border-left: 3px solid #cbd5e1 !important;
        padding: 0.45rem 0.65rem !important;
        border-radius: 0 6px 6px 0 !important;
        font-size: 0.8rem !important;
        color: #475569 !important;
        margin-top: 0.35rem !important;
    }

    .crm-mobile-finance {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.4rem !important;
        background: #f8fafc !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 8px !important;
        padding: 0.55rem 0.75rem !important;
        margin-top: 0.35rem !important;
    }
    .crm-fin-box {
        display: flex !important;
        flex-direction: column !important;
    }
    .crm-fin-k {
        font-size: 0.65rem !important;
        text-transform: uppercase !important;
        letter-spacing: 0.04em !important;
        color: #64748b !important;
        font-weight: 600 !important;
    }
    .crm-fin-v {
        font-size: 0.92rem !important;
        font-weight: 700 !important;
        color: #0f172a !important;
    }
    .crm-fin-paid { color: #15803d !important; }
    .crm-fin-due  { color: #dc2626 !important; }

    .crm-col-actions {
        margin-top: 0.4rem !important;
        padding-top: 0.55rem !important;
        border-top: 1px dashed #e2e8f0 !important;
    }
    .crm-action-buttons {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.45rem !important;
    }
    .crm-btn-wa {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 100% !important;
        background: #22c55e !important;
        color: #ffffff !important;
        font-weight: 600 !important;
        font-size: 0.875rem !important;
        padding: 0.55rem 1rem !important;
        border-radius: 8px !important;
        text-decoration: none !important;
        box-shadow: 0 1px 2px rgba(34, 197, 94, 0.2) !important;
    }
    .crm-btn-wa:active {
        background: #16a34a !important;
    }
    .crm-action-buttons .crm-btn-act {
        flex: 1 1 0 !important;
        padding: 0.45rem 0.25rem !important;
        font-size: 0.8rem !important;
        text-align: center !important;
        justify-content: center !important;
    }
    /* Group the 3 standard buttons in one row below WhatsApp */
    .crm-action-buttons {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.4rem !important;
    }
    .crm-btn-wa {
        grid-column: 1 / -1 !important;
    }
}
