@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Plus+Jakarta+Sans:wght@500;700;800&family=JetBrains+Mono:wght@400;600&display=swap');

/* ==========================================================================
   DESIGN TOKENS & ROOT VARIABLES
   ========================================================================== */
:root {
    /* Brand Hierarchy (70/30 Nexsas Brand + Neo-Ledger) */
    --brand-red: #DE4A40;         /* Primary Action (Nexsas) */
    --brand-red-hover: #c43c33;
    --brand-aqua: #83E7EE;        /* Brand Aqua Link (Nexsas) */
    --brand-border: #B6C6E6;      /* Soft Blue Gray border */
    
    /* Neo-Ledger Fintech Palette */
    --canvas: #F8F9FA;            /* Off-white canvas */
    --surface: #FFFFFF;           /* Pure white */
    --text-slate: #0F172A;        /* Deep Slate primary text */
    --text-muted: #64748B;        /* Muted slate */
    
    /* Semantic Ledger Statuses */
    --emerald-verified: #059669;  /* Verified positive cash flow */
    --emerald-light: #ecfdf5;
    --amber-warning: #D97706;     /* Unverified, pending */
    --amber-light: #fef3c7;
    --crimson-risk: #DC2626;      /* Discrepancies, deteriorating health */
    --crimson-light: #fef2f2;
    --ledger-blue: #2563EB;       /* Active ledger details */
    --ledger-blue-light: #eff6ff;

    /* Spacing system (4px base) */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-8: 32px;
    --sp-10: 40px;
    --sp-12: 48px;
    --sp-16: 64px;
    --sp-20: 80px;

    /* Borders & Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-pill: 9999px;
    --border-width: 1px;
}

/* ==========================================================================
   RESET & RESET OVERRIDES
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
    background-color: var(--canvas);
    color: var(--text-slate);
}

body {
    font-family: 'Inter', sans-serif;
    line-height: 1.6;
    overflow-x: hidden;
    padding-bottom: 60px; /* Space for telemetry pill */
}

/* ==========================================================================
   TYPOGRAPHY
   ========================================================================== */
h1, h2, h3, h4, h5, h6 {
    font-family: 'Plus Jakarta Sans', sans-serif;
    color: var(--text-slate);
    font-weight: 700;
    line-height: 1.25;
}

h1 {
    font-size: clamp(2.5rem, 5vw, 4rem); /* Up to 64px hero */
    letter-spacing: -0.03em;
}

h2 {
    font-size: clamp(1.8rem, 3.5vw, 2.5rem);
    letter-spacing: -0.02em;
    margin-bottom: var(--sp-4);
}

h3 {
    font-size: clamp(1.4rem, 2.5vw, 1.8rem);
    margin-bottom: var(--sp-3);
}

p {
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    color: var(--text-muted);
}

.lead {
    font-size: clamp(1.1rem, 2vw, 1.25rem);
    color: var(--text-muted);
    line-height: 1.5;
}

/* JetBrains Mono is strictly for ₹ currency, ratios, confidence metrics, and log outputs */
.mono-data, .currency, .pct, .confidence, .log-line {
    font-family: 'JetBrains Mono', monospace;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

/* ==========================================================================
   LAYOUTS & UTILITIES
   ========================================================================== */
.container {
    width: 100%;
    max-width: 1280px;
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--sp-6);
    padding-right: var(--sp-6);
}

section {
    padding-top: var(--sp-16);
    padding-bottom: var(--sp-16);
    position: relative;
    border-bottom: 1px solid rgba(182, 198, 230, 0.3);
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--sp-8);
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--sp-6);
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--sp-6);
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.d-flex {
    display: flex;
}

.flex-column {
    flex-direction: column;
}

.justify-between {
    justify-content: space-between;
}

.align-center {
    align-items: center;
}

.gap-2 { gap: var(--sp-2); }
.gap-4 { gap: var(--sp-4); }

.w-full { width: 100%; }

.text-center { text-align: center; }
.text-right { text-align: right; }

.text-verified { color: var(--emerald-verified); }
.bg-verified-light { background-color: var(--emerald-light); }
.text-warning { color: var(--amber-warning); }
.bg-warning-light { background-color: var(--amber-light); }
.text-risk { color: var(--crimson-risk); }
.bg-risk-light { background-color: var(--crimson-light); }
.text-blue { color: var(--ledger-blue); }

.my-4 { margin-top: var(--sp-4); margin-bottom: var(--sp-4); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-8 { margin-bottom: var(--sp-8); }

/* ==========================================================================
   COMPONENTS
   ========================================================================== */

/* Header Navigation (70% Brand Red dominance in weight) */
.main-header {
    background-color: var(--surface);
    border-bottom: 2px solid var(--brand-border);
    position: sticky;
    top: 0;
    z-index: 1000;
    padding: var(--sp-4) 0;
}

.nav-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand-container {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    text-decoration: none;
}

.brand-master {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 800;
    font-size: 1.35rem;
    color: var(--text-slate);
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Master Brand Logo Mark */
.brand-mark {
    width: 24px;
    height: 24px;
    background-color: var(--brand-red);
    border-radius: 4px;
    display: inline-block;
}

.brand-divider {
    width: 1px;
    height: 20px;
    background-color: var(--brand-border);
}

.brand-product {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-slate);
    letter-spacing: -0.01em;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
}

.nav-link {
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-slate);
    text-decoration: none;
    transition: color 0.2s ease;
}

.nav-link:hover, .nav-link.active {
    color: var(--brand-red);
}

/* Hamburger mobile menu */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--text-slate);
    padding: var(--sp-2);
}

/* Buttons (Nexsas Red Anchor, rounded-md, no shadow) */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    padding: var(--sp-3) var(--sp-6);
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    cursor: pointer;
    text-decoration: none;
}

.btn-primary {
    background-color: var(--brand-red);
    color: #FCFCFC;
    border: none;
}

.btn-primary:hover {
    background-color: var(--brand-red-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: var(--surface);
    color: var(--text-slate);
    border: 1px solid var(--brand-border);
}

.btn-secondary:hover {
    background-color: var(--canvas);
    border-color: var(--text-slate);
}

/* Neo-Ledger Cards */
.card {
    background-color: var(--surface);
    border: 1px solid var(--brand-border);
    border-radius: var(--radius-md);
    padding: var(--sp-6);
    transition: border-color 0.25s ease, transform 0.25s ease;
}

.card:hover {
    border-color: var(--brand-red);
}

.card-title {
    margin-bottom: var(--sp-2);
}

/* Badge System */
.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--sp-1) var(--sp-3);
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Split Visual Sections */
.split-hero {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: var(--sp-8);
    align-items: center;
}

.img-container {
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--brand-border);
}

.img-overlay-fintech {
    position: absolute;
    inset: 0;
    background-color: var(--text-slate);
    mix-blend-mode: multiply;
    opacity: 0.12;
    pointer-events: none;
}

/* ==========================================================================
   SPECIFIC WEB INTERFACES (E.g. WhatsApp Ingestion, Split-Ledgers, Dashboards)
   ========================================================================== */

/* WhatsApp Interface Mockup */
.whatsapp-chat {
    width: 100%;
    max-width: 420px;
    background-color: #E5DDD5;
    border-radius: var(--radius-lg);
    border: 4px solid var(--text-slate);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 520px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
}

.whatsapp-header {
    background-color: #075E54;
    color: var(--surface);
    padding: var(--sp-3) var(--sp-4);
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}

.whatsapp-avatar {
    width: 36px;
    height: 36px;
    background-color: #128C7E;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.9rem;
}

.whatsapp-status-info {
    flex-grow: 1;
}

.whatsapp-status-info span {
    font-size: 0.75rem;
    opacity: 0.8;
    display: block;
}

.whatsapp-body {
    flex-grow: 1;
    padding: var(--sp-4);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    background-image: radial-gradient(rgba(0, 0, 0, 0.05) 1px, transparent 0);
    background-size: 16px 16px;
}

.whatsapp-msg {
    max-width: 80%;
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    line-height: 1.4;
    position: relative;
}

.whatsapp-msg-in {
    background-color: var(--surface);
    align-self: flex-start;
    border-top-left-radius: 0;
}

.whatsapp-msg-out {
    background-color: #DCF8C6;
    align-self: flex-end;
    border-top-right-radius: 0;
}

.whatsapp-msg-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Ingestion Ledger Split Screen */
.translation-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-6);
    background-color: var(--surface);
    border: 1px solid var(--brand-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.translation-left {
    padding: var(--sp-8);
    border-right: 1px solid var(--brand-border);
    background-color: var(--canvas);
}

.translation-right {
    padding: var(--sp-8);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Traditional Ledger vs CreditGraph Comparison Table */
.comparison-table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--brand-border);
    border-radius: var(--radius-lg);
    background-color: var(--surface);
}

.comp-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.comp-table th, .comp-table td {
    padding: var(--sp-4) var(--sp-6);
    border-bottom: 1px solid rgba(182, 198, 230, 0.4);
}

.comp-table th {
    background-color: var(--canvas);
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 700;
    color: var(--text-slate);
}

.comp-table tr:last-child td {
    border-bottom: none;
}

.comp-table .traditional-col {
    color: var(--crimson-risk);
    font-weight: 500;
}

.comp-table .creditgraph-col {
    color: var(--emerald-verified);
    font-weight: 600;
}

/* ==========================================================================
   PORTFOLIO & LENDER CONSOLE COMPLEX DATA TABLES
   ========================================================================== */
.data-table-container {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--brand-border);
    border-radius: var(--radius-md);
    background-color: var(--surface);
}

.fintech-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.fintech-table th {
    background-color: var(--canvas);
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    padding: var(--sp-4) var(--sp-5);
    color: var(--text-slate);
    border-bottom: 2px solid var(--brand-border);
}

.fintech-table td {
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid rgba(182, 198, 230, 0.4);
    vertical-align: middle;
}

.fintech-table tbody tr:hover {
    background-color: rgba(248, 249, 250, 0.8);
}

/* Audit Drawer Interaction Styles */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(15, 23, 42, 0.6);
    z-index: 1050;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.audit-drawer {
    position: fixed;
    right: -500px;
    top: 0;
    bottom: 0;
    width: 100%;
    max-width: 500px;
    background-color: var(--surface);
    border-left: 1px solid var(--brand-border);
    z-index: 1060;
    padding: var(--sp-8);
    overflow-y: auto;
    transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: -10px 0 30px rgba(0,0,0,0.05);
}

.audit-drawer.open {
    right: 0;
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--sp-6);
    border-bottom: 1px solid var(--brand-border);
    padding-bottom: var(--sp-4);
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-slate);
}

/* ==========================================================================
   AI TELEMETRY PILL (Fixed Bottom-Right)
   ========================================================================== */
.telemetry-pill {
    position: fixed;
    bottom: var(--sp-4);
    right: var(--sp-4);
    background-color: var(--text-slate);
    color: #FCFCFC;
    padding: var(--sp-3) var(--sp-5);
    border-radius: var(--radius-pill);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    z-index: 9999;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    opacity: 0.85;
    transition: opacity 0.2s ease;
    border: 1px solid rgba(255,255,255,0.1);
}

.telemetry-pill:hover {
    opacity: 1;
}

.pulsing-dot {
    width: 8px;
    height: 8px;
    background-color: var(--emerald-verified);
    border-radius: 50%;
    display: inline-block;
    animation: pulse-green 1.5s infinite ease-in-out;
}

@keyframes pulse-green {
    0% {
        transform: scale(0.9);
        box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.7);
    }
    70% {
        transform: scale(1.1);
        box-shadow: 0 0 0 6px rgba(5, 150, 105, 0);
    }
    100% {
        transform: scale(0.9);
        box-shadow: 0 0 0 0 rgba(5, 150, 105, 0);
    }
}

/* ==========================================================================
   Interactive SVG Node Graph
   ========================================================================== */
.graph-container {
    width: 100%;
    height: 480px;
    background-color: var(--surface);
    border: 1px solid var(--brand-border);
    border-radius: var(--radius-lg);
    position: relative;
    overflow: hidden;
}

.graph-container svg {
    width: 100%;
    height: 100%;
}

.node-group circle {
    stroke: var(--surface);
    stroke-width: 2px;
    cursor: pointer;
    transition: stroke-width 0.15s ease, r 0.15s ease;
}

.node-group circle:hover {
    stroke-width: 3px;
    r: 12px;
}

.edge-path {
    stroke: var(--brand-border);
    stroke-opacity: 0.6;
    stroke-width: 1.5px;
    fill: none;
}

/* ==========================================================================
   FOOTER (70/30 Brand rule enforcement)
   ========================================================================== */
.site-footer {
    background-color: var(--text-slate);
    color: var(--surface);
    padding: var(--sp-16) 0 var(--sp-8) 0;
    border-top: 4px solid var(--brand-red);
}

.footer-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr;
    gap: var(--sp-10);
    margin-bottom: var(--sp-12);
}

.footer-brand {
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
}

.footer-brand .brand-master {
    color: var(--surface);
}

.footer-brand p {
    color: rgba(255,255,255,0.6);
    font-size: 0.9rem;
}

.footer-links-col {
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
}

.footer-links-col h4 {
    color: var(--surface);
    font-size: 1rem;
    font-family: 'Plus Jakarta Sans', sans-serif;
}

.footer-links-col ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}

.footer-links-col a {
    color: rgba(255,255,255,0.6);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s ease;
}

.footer-links-col a:hover {
    color: var(--brand-red);
}

.footer-bottom {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: var(--sp-6);
    text-align: center;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.4);
}

/* ==========================================================================
   STRICT RESPONSIVE RULES (Mobile/Tablet Override)
   ========================================================================== */

/* Mobile Mode Rules (< 768px) */
@media (max-width: 768px) {
    /* Touch targets check */
    .btn, .nav-link, select, input, button {
        min-height: 48px;
        min-width: 48px;
    }

    .main-nav {
        display: none; /* Controlled by mobile menu toggle */
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background-color: var(--surface);
        border-bottom: 2px solid var(--brand-border);
        flex-direction: column;
        padding: var(--sp-6);
        gap: var(--sp-4);
        box-shadow: 0 10px 20px rgba(0,0,0,0.05);
    }

    .main-nav.open {
        display: flex;
    }

    .nav-toggle {
        display: block;
    }

    .split-hero, .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
        gap: var(--sp-6);
    }

    .translation-split {
        grid-template-columns: 1fr;
    }

    .translation-left {
        border-right: none;
        border-bottom: 1px solid var(--brand-border);
        padding: var(--sp-6);
    }

    .translation-right {
        padding: var(--sp-6);
    }

    .whatsapp-chat {
        max-width: 100% !important;
    }

    .footer-grid {
        grid-template-columns: 1fr;
        gap: var(--sp-8);
    }

    /* Complex table conversion to stacked "Receipt Cards" */
    .data-table-container {
        border: none;
        background-color: transparent;
        overflow-x: visible;
    }

    .fintech-table {
        display: block;
        width: 100%;
    }

    .fintech-table thead {
        display: none; /* Hide tabular header completely */
    }

    .fintech-table tbody {
        display: flex;
        flex-direction: column;
        gap: var(--sp-4);
        width: 100%;
    }

    .fintech-table tr {
        display: block;
        background-color: var(--surface);
        border: 1px solid var(--brand-border);
        border-radius: var(--radius-md);
        padding: var(--sp-5);
        position: relative;
        box-shadow: 0 4px 10px rgba(0,0,0,0.02);
    }

    .fintech-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--sp-2) 0;
        border-bottom: 1px dashed rgba(182, 198, 230, 0.3);
        font-size: 0.9rem;
    }

    .fintech-table td:last-child {
        border-bottom: none;
    }

    /* Add labels on the fly using standard HTML custom attributes data-label */
    .fintech-table td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--text-slate);
        font-family: 'Plus Jakarta Sans', sans-serif;
        font-size: 0.8rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }

    /* Node graph converts to dynamic vertical hierarchy list on mobile */
    .graph-container {
        height: auto;
        padding: var(--sp-4);
    }

    .mobile-graph-fallback {
        display: flex !important;
        flex-direction: column;
        gap: var(--sp-3);
    }

    .graph-container svg {
        display: none;
    }
}

/* Tablet Mode Rules (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .lender-console-layout {
        display: grid;
        grid-template-columns: 1fr; /* 2-column converts to stacked or modified 2-col */
        gap: var(--sp-6);
    }
}

/* Hide fallback on desktop */
.mobile-graph-fallback {
    display: none;
}
