/* ============================================================
   MintX CRM - Mobile-first SaaS UI
   ============================================================ */

:root {
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --brand-soft: #eff6ff;
    --ink: #0f172a;
    --muted: #64748b;
    --border: #e5e7eb;
    --bg: #f6f8fb;
    --card: #ffffff;
    --shadow-sm: 0 1px 2px rgba(15,23,42,.05), 0 1px 3px rgba(15,23,42,.06);
    --shadow: 0 4px 10px -2px rgba(15,23,42,.06), 0 10px 20px -8px rgba(15,23,42,.08);
    --radius: 14px;
    --radius-sm: 10px;
    --topbar-h: 56px;
    --sidebar-w: 260px;
    --bottom-nav-h: 64px;
    --touch: 44px;
}

*, *::before, *::after { box-sizing: border-box; }
* { -webkit-tap-highlight-color: transparent; }

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

html, body {
    background: var(--bg);
    color: var(--ink);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    margin: 0;
    overflow-x: hidden;
    max-width: 100vw;
}

img, svg, canvas, video { max-width: 100%; height: auto; }

a { color: var(--brand); }
a:hover { color: var(--brand-dark); }

/* ---------- Buttons / Forms (touch friendly) ---------- */
.btn {
    border-radius: 10px;
    font-weight: 500;
    min-height: var(--touch);
    padding: .55rem 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
}
.btn-sm {
    min-height: 40px;
    padding: .4rem .75rem;
}
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover, .btn-primary:focus { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-outline-primary { color: var(--brand); border-color: var(--brand); }
.btn-outline-primary:hover { background: var(--brand); border-color: var(--brand); color: #fff; }

.form-control, .form-select {
    border-radius: 10px;
    border-color: var(--border);
    padding: .65rem .85rem;
    font-size: 16px; /* prevents iOS zoom on focus */
    min-height: var(--touch);
}
.form-control:focus, .form-select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-control-lg { font-size: 16px; padding: .75rem .9rem; }
.form-label { font-weight: 500; margin-bottom: .35rem; }
.input-group-text { border-radius: 10px; min-height: var(--touch); }

/* ---------- Top bar ---------- */
.app-topbar {
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: #fff;
    min-height: var(--topbar-h);
    height: auto;
    position: sticky;
    top: 0;
    z-index: 1030;
    padding: env(safe-area-inset-top) 12px 0;
    display: flex;
    align-items: center;
}
.app-topbar > .container-fluid {
    min-height: var(--topbar-h);
    padding-left: 4px;
    padding-right: 4px;
}
.brand { font-weight: 600; font-size: 15px; }
.brand-badge {
    width: 34px; height: 34px; background: rgba(255,255,255,.18);
    border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 16px;
}
.brand-badge-lg { width: 44px; height: 44px; font-size: 20px; background: var(--brand); color: #fff; }

.sidebar-toggle {
    width: var(--touch);
    height: var(--touch);
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}

.avatar {
    width: 34px; height: 34px; background: rgba(255,255,255,.18); color: #fff;
    border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 13px; text-transform: uppercase; flex-shrink: 0;
}
.avatar-sm { width: 28px; height: 28px; font-size: 12px; }
.avatar-lg { width: 44px; height: 44px; font-size: 18px; background: var(--brand-soft); color: var(--brand); }

/* ---------- Shell ---------- */
.app-shell {
    display: flex;
    min-height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top));
    width: 100%;
    overflow-x: hidden;
}

/* ---------- Sidebar ---------- */
.app-sidebar {
    width: var(--sidebar-w);
    background: #fff;
    border-right: 1px solid var(--border);
    height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top));
    position: sticky;
    top: calc(var(--topbar-h) + env(safe-area-inset-top));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 8px;
    flex-shrink: 0;
}
.sidebar-inner .nav-link {
    color: var(--ink);
    padding: .75rem .9rem;
    border-radius: 10px;
    font-weight: 500;
    display: flex; align-items: center; gap: .65rem;
    font-size: .95rem;
    min-height: var(--touch);
}
.sidebar-inner .nav-link i { color: var(--muted); font-size: 1.1rem; width: 22px; text-align: center; }
.sidebar-inner .nav-link:hover { background: var(--brand-soft); color: var(--brand); }
.sidebar-inner .nav-link:hover i { color: var(--brand); }
.sidebar-inner .nav-link.active { background: var(--brand); color: #fff; }
.sidebar-inner .nav-link.active i { color: #fff; }
.sidebar-heading {
    font-size: .72rem; font-weight: 600; letter-spacing: .06em;
    color: var(--muted); text-transform: uppercase;
    padding: 14px 12px 6px;
}

.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15,23,42,.45);
    z-index: 1035;
    backdrop-filter: blur(2px);
}
.sidebar-backdrop.show { display: block; }

/* ---------- Main ---------- */
.app-main {
    flex: 1;
    min-width: 0;
    width: 100%;
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 16px);
}
.content-wrap {
    padding: 12px;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

.page-header {
    margin-bottom: 12px;
    gap: 10px !important;
}
.page-title {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -.01em;
    line-height: 1.25;
}
.wave { display: inline-block; animation: wave 2s ease-in-out infinite; transform-origin: 70% 70%; }
@keyframes wave {
    0%,60%,100%{transform:rotate(0deg)}
    10%{transform:rotate(14deg)} 20%{transform:rotate(-8deg)}
    30%{transform:rotate(14deg)} 40%{transform:rotate(-4deg)} 50%{transform:rotate(10deg)}
}

/* ---------- Cards ---------- */
.app-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.app-card .card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: .85rem 1rem;
}
.app-card .card-body { padding: .9rem 1rem; }
.app-card .card-footer {
    background: transparent;
    border-top: 1px solid var(--border);
    padding: .85rem 1rem;
}
.card-header h6 { color: var(--ink); font-weight: 600; letter-spacing: -.01em; margin: 0; }

/* ---------- Stat cards ---------- */
.stat-grid .stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow-sm);
    height: 100%;
    display: flex; flex-direction: column; gap: 4px;
}
.stat-icon {
    width: 38px; height: 38px; border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center; font-size: 1.1rem;
}
.stat-value { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: .78rem; font-weight: 500; line-height: 1.3; }

/* ---------- Tables ---------- */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
    max-width: 100%;
}
.lead-table thead th, .dashboard-table thead th {
    text-transform: uppercase; font-size: .72rem; letter-spacing: .05em;
    color: var(--muted); font-weight: 600; background: #f8fafc;
    white-space: nowrap;
}
.lead-table tbody tr:hover { background: #fbfdff; }

.mini-bar { width: 80px; height: 6px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.mini-bar span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }

.kv span { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; display: block; }
.kv strong { display: block; font-weight: 600; margin-top: 2px; word-break: break-word; }

.lead-note-body { background: #fef9c3; padding: 8px 10px; border-radius: 8px; }

/* Tabs — horizontal scroll on mobile */
.tab-pills {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    padding-bottom: 4px;
    scrollbar-width: none;
}
.tab-pills::-webkit-scrollbar { display: none; }
.tab-pills .nav-item { flex: 0 0 auto; }
.tab-pills .nav-link {
    color: var(--ink);
    font-weight: 500;
    white-space: nowrap;
    border-radius: 999px;
    padding: .5rem .9rem;
    min-height: 40px;
}
.tab-pills .nav-link.active { background: var(--brand); color: #fff; }

/* Activity feed */
.activity-feed { list-style: none; margin: 0; padding: 12px 16px; position: relative; }
.activity-feed::before {
    content: ''; position: absolute; left: 22px; top: 12px; bottom: 12px; width: 2px;
    background: #eef2f7;
}
.activity-feed li {
    position: relative; padding-left: 26px; margin-bottom: 14px;
    display: flex; gap: 8px;
}
.activity-feed .dot {
    position: absolute; left: 4px; top: 6px;
    width: 12px; height: 12px; background: var(--brand); border-radius: 50%;
    box-shadow: 0 0 0 3px #fff;
}
.activity-feed-lead::before { left: 8px; }
.activity-feed-lead .dot { left: -10px; }

/* Quick actions */
.quick-actions .quick-action-btn {
    border-radius: 999px;
    font-size: .85rem;
    font-weight: 500;
    min-height: 42px;
    flex: 1 1 auto;
}
.quick-actions .quick-action-btn:hover,
.quick-actions .quick-action-btn:active {
    background: var(--brand-soft); border-color: var(--brand); color: var(--brand);
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: rgba(255,255,255,.96);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    z-index: 1040;
    padding-bottom: env(safe-area-inset-bottom);
    min-height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(15,23,42,.06);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    transition: transform .2s ease;
}
.bottom-nav a {
    flex: 1;
    text-align: center;
    padding: 8px 2px 6px;
    color: var(--muted);
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: .65rem;
    font-weight: 600;
    min-height: var(--bottom-nav-h);
}
.bottom-nav a i { font-size: 1.3rem; line-height: 1; }
.bottom-nav a.active { color: var(--brand); }
.bottom-nav .bn-fab {
    transform: translateY(-12px);
    color: #fff !important;
    min-height: auto;
}
.bottom-nav .bn-fab-inner {
    width: 54px; height: 54px; border-radius: 50%;
    background: var(--brand); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 20px rgba(37,99,235,.4);
    font-size: 1.4rem;
}

/* Hide old floating FAB — bottom nav center button is enough */
.fab { display: none !important; }

/* ---------- Auth ---------- */
.auth-body {
    background: linear-gradient(160deg, #eff6ff 0%, #f8fafc 55%, #fff 100%);
    min-height: 100dvh;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.auth-shell { width: 100%; max-width: 420px; }
.auth-card {
    background: #fff;
    border-radius: 20px;
    padding: 24px 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.password-toggle {
    position: absolute; top: 50%; right: 8px; transform: translateY(-50%);
    color: var(--muted); text-decoration: none;
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
}

/* ---------- Helpers ---------- */
.min-w-0 { min-width: 0; }
.lead-mini-list .list-group-item { padding: 12px 14px; }
.service-bars li + li { margin-top: 12px; }

.callback-time {
    min-width: 62px;
    text-align: center;
    background: var(--brand-soft);
    color: var(--brand);
    border-radius: 10px;
    padding: 6px 8px;
    flex-shrink: 0;
}
.callback-time .time-val { font-weight: 700; font-size: .8rem; line-height: 1.2; }
.callback-time .time-hint { font-size: .62rem; font-weight: 600; text-transform: uppercase; }
.callback-time.past { background: #fef2f2; color: #dc2626; }
.schedule-past { background: #fff8f8; }

/* Mobile lead / employee cards */
.lead-card .card-body,
.emp-card .card-body { padding: 14px; }
.lead-card .btn,
.emp-card .btn { min-height: 40px; }

/* Collapsible mobile filters */
.filter-toggle {
    display: none;
    width: 100%;
    min-height: var(--touch);
    border: 1px solid var(--border);
    background: #fff;
    border-radius: var(--radius);
    padding: .7rem 1rem;
    font-weight: 600;
    color: var(--ink);
    text-align: left;
    margin-bottom: 10px;
}
.filter-toggle > i:last-child { color: var(--muted); }

/* Sticky form actions above bottom nav on phones */
.form-sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    background: #fff;
}
@media (max-width: 767.98px) {
    .form-sticky-actions {
        bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
        box-shadow: 0 -6px 16px rgba(15,23,42,.06);
        border-top: 1px solid var(--border) !important;
        margin: 0 -1px -1px;
        padding: 12px !important;
    }
}

/* Modals full-ish on small screens */
@media (max-width: 575.98px) {
    .modal-dialog {
        margin: .5rem;
        max-width: calc(100% - 1rem);
    }
    .modal-content { border-radius: 16px; }
    .modal-body { padding: 1rem; }
    .modal-footer {
        flex-direction: column;
        gap: 8px;
    }
    .modal-footer .btn { width: 100%; }
}

/* Alerts */
.alert { border-radius: 12px; }

/* ---------- Breakpoints ---------- */
@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        top: calc(var(--topbar-h) + env(safe-area-inset-top));
        z-index: 1036;
        transform: translateX(-105%);
        transition: transform .22s ease;
        height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top));
        width: min(86vw, 300px);
        box-shadow: 8px 0 24px rgba(15,23,42,.12);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .app-sidebar.open { transform: translateX(0); }
    body.sidebar-open { overflow: hidden; }
}

@media (min-width: 992px) {
    .sidebar-backdrop { display: none !important; }
    .app-main { padding-bottom: 24px; }
    .content-wrap { padding: 20px 24px; }
    .bottom-nav { display: none !important; }
}

@media (max-width: 767.98px) {
    .filter-toggle { display: flex; align-items: center; justify-content: space-between; }
    .filter-panel { display: none; }
    .filter-panel.is-open { display: block; }

    .page-header .btn-sm { min-height: 40px; }
    .page-header > .d-flex { width: 100%; }
    .page-header > .d-flex .btn { flex: 1; }
    .lead-detail-actions .btn { flex: 1 1 calc(50% - 6px); }

    .quick-actions .d-flex { gap: 8px !important; }
    .quick-actions .quick-action-btn {
        flex: 1 1 calc(50% - 8px);
        max-width: calc(50% - 4px);
        justify-content: center;
        font-size: .8rem;
        padding-left: .5rem;
        padding-right: .5rem;
    }

    .stat-grid > [class*="col-"] { padding-left: 6px; padding-right: 6px; }
    .stat-grid.row { margin-left: -6px; margin-right: -6px; }

    .page-header .d-flex.flex-wrap .btn { flex: 1 1 auto; }
    .schedule-actions .btn { min-height: 40px; }

    canvas { max-width: 100% !important; }
}

@media (max-width: 575.98px) {
    .content-wrap { padding: 10px; }
    .stat-value { font-size: 1.25rem; }
    .stat-label { font-size: .72rem; }
    .page-title { font-size: 1.1rem; }
    .auth-card { padding: 22px 16px; border-radius: 18px; }

    .col-6 .kv strong { font-size: .92rem; }

    /* Keep action row buttons equal */
    .lead-card .d-flex.gap-1 .btn { font-size: .82rem; padding-left: .4rem; padding-right: .4rem; }
}

@media (min-width: 768px) {
    .filter-toggle { display: none !important; }
    .filter-panel { display: block !important; }
    .form-control, .form-select { font-size: .95rem; }
    .w-md-auto { width: auto !important; }
    .flex-md-grow-0 { flex-grow: 0 !important; }
}

/* Landscape phones */
@media (max-height: 500px) and (orientation: landscape) {
    .bottom-nav { min-height: 52px; }
    .bottom-nav .bn-fab { transform: translateY(-6px); }
    .bottom-nav .bn-fab-inner { width: 44px; height: 44px; }
    .app-main { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
}

/* Print */
@media print {
    .app-topbar, .app-sidebar, .bottom-nav, .fab, .btn, .filter-toggle { display: none !important; }
    .app-main { padding: 0 !important; }
    .content-wrap { padding: 0 !important; }
}
