/* ========================================================
   BIZWAPI SOLUTIONS: DESIGN SYSTEM (STITCH ALIGNED)
   ======================================================== */

:root {
    --bg-main: #F8FAFC;
    --bg-card: #FFFFFF;
    --bg-subtle: #F1F5F9;
    --border-color: #E2E8F0;
    --border-focus: #0D9488;
    
    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;
    
    --brand-primary: #0F172A; /* Deep Navy */
    --brand-accent: #0D9488;  /* Trust Emerald / Teal */
    --brand-accent-hover: #0F766E;
    
    --status-paid-bg: #ECFDF5;
    --status-paid-text: #065F46;
    --status-paid-border: #A7F3D0;
    
    --status-partial-bg: #FFFBEB;
    --status-partial-text: #92400E;
    --status-partial-border: #FDE68A;
    
    --status-unpaid-bg: #FEF2F2;
    --status-unpaid-text: #991B1B;
    --status-unpaid-border: #FECACA;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--brand-accent);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* APP SHELL LAYOUT */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* SIDEBAR (DESKTOP) */
.sidebar {
    width: 260px;
    background-color: var(--brand-primary);
    color: #F8FAFC;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    min-height: 100vh;
    z-index: 50;
    transition: transform 0.3s ease;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.sidebar::-webkit-scrollbar,
.sidebar-nav::-webkit-scrollbar {
    display: none;
}

@media (min-height: 700px) {
    .sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
    }
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    background: var(--brand-accent);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
}

.sidebar-brand-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #FFFFFF;
}

.sidebar-brand-subtitle {
    font-size: 11px;
    color: var(--text-muted);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    color: #CBD5E1;
    font-weight: 500;
    text-decoration: none !important;
    transition: all 0.15s ease;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.08);
    color: #FFFFFF;
}

.nav-item.active {
    background-color: var(--brand-accent);
    color: #FFFFFF;
}

.nav-item .badge {
    margin-left: auto;
    background: #EF4444;
    color: white;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 10px;
}

.sidebar-footer {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-profile-widget {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: white;
}

.user-info-name {
    font-size: 13px;
    font-weight: 600;
    color: #FFFFFF;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
}

.user-info-role {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* MAIN CONTENT WRAPPER */
.main-wrapper {
    flex: 1;
    margin-left: 0;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* TOP HEADER BAR */
.topbar {
    height: 64px;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 40;
}

.topbar-search {
    display: flex;
    align-items: center;
    position: relative;
    width: 320px;
}

.topbar-search input {
    width: 100%;
    padding: 8px 14px 8px 36px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-subtle);
    font-size: 13px;
    outline: none;
    transition: all 0.2s ease;
}

.topbar-search input:focus {
    background-color: #FFFFFF;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.15);
}

.topbar-search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    font-size: 14px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* CONTENT CANVAS */
.content-area {
    padding: 28px;
    flex: 1;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none !important;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-primary {
    background-color: var(--brand-accent);
    color: #FFFFFF;
}
.btn-primary:hover {
    background-color: var(--brand-accent-hover);
    color: #FFFFFF;
}

.btn-secondary {
    background-color: #FFFFFF;
    border-color: var(--border-color);
    color: var(--text-primary);
}
.btn-secondary:hover {
    background-color: var(--bg-subtle);
}

.btn-dark {
    background-color: var(--brand-primary);
    color: #FFFFFF;
}
.btn-dark:hover {
    background-color: #1E293B;
    color: #FFFFFF;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-danger {
    background-color: #EF4444;
    color: white;
}
.btn-danger:hover {
    background-color: #DC2626;
}

/* CARDS & METRIC WIDGETS */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    margin-bottom: 24px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

/* STAT TILES GRID */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 18px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.kpi-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

.kpi-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

.kpi-success {
    color: #059669;
}
.kpi-danger {
    color: #DC2626;
}

/* TABLES */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: #FFFFFF;
}

.table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 13px;
}

.table th {
    background-color: var(--bg-subtle);
    color: var(--text-secondary);
    font-weight: 600;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    vertical-align: middle;
}

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

.table tr:hover td {
    background-color: #F8FAFC;
}

/* STATUS BADGES */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: 1px solid transparent;
}

.badge-paid, .badge-accepted, .badge-converted {
    background-color: var(--status-paid-bg);
    color: var(--status-paid-text);
    border-color: var(--status-paid-border);
}

.badge-partial, .badge-sent, .badge-pending {
    background-color: var(--status-partial-bg);
    color: var(--status-partial-text);
    border-color: var(--status-partial-border);
}

.badge-unpaid, .badge-rejected, .badge-expired {
    background-color: var(--status-unpaid-bg);
    color: var(--status-unpaid-text);
    border-color: var(--status-unpaid-border);
}

.badge-neutral {
    background-color: var(--bg-subtle);
    color: var(--text-secondary);
    border-color: var(--border-color);
}

/* FORMS */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    font-size: 13px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: #FFFFFF;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s ease;
}

.form-control:focus {
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.15);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

/* FLASH ALERTS */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success {
    background-color: #ECFDF5;
    color: #065F46;
    border: 1px solid #A7F3D0;
}

.alert-danger {
    background-color: #FEF2F2;
    color: #991B1B;
    border: 1px solid #FECACA;
}

/* TABS */
.nav-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
    gap: 24px;
}

.tab-link {
    padding: 10px 4px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    text-decoration: none !important;
    cursor: pointer;
}

.tab-link.active {
    color: var(--brand-accent);
    border-bottom-color: var(--brand-accent);
}

/* CUSTOMER 360 TIMELINE */
.timeline {
    position: relative;
    padding-left: 32px;
    margin-top: 20px;
}

.timeline::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 11px;
    width: 2px;
    background-color: var(--border-color);
}

.timeline-item {
    position: relative;
    margin-bottom: 28px;
}

.timeline-icon {
    position: absolute;
    left: -32px;
    top: 2px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #FFFFFF;
    border: 2px solid var(--brand-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    color: var(--brand-accent);
}

.timeline-content {
    background: #FFFFFF;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    box-shadow: var(--shadow-sm);
}

.timeline-date {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 4px;
}

.timeline-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

/* MODAL & SLIDEOVER */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal-box {
    background: #FFFFFF;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    padding: 24px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-muted);
}

/* MOBILE RESPONSIVE HAMBURGER & DOCK */
.mobile-nav-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-primary);
    cursor: pointer;
}

.mobile-bottom-bar {
    display: none;
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        transform: translateX(-100%);
        overflow-y: auto;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-wrapper {
        margin-left: 0;
        padding-bottom: 70px;
    }
    .mobile-nav-toggle {
        display: block;
    }
    .topbar {
        padding: 0 16px;
    }
    .content-area {
        padding: 16px;
    }
    .topbar-search {
        display: none;
    }
    .mobile-bottom-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 60px;
        background-color: var(--bg-card);
        border-top: 1px solid var(--border-color);
        z-index: 50;
        justify-content: space-around;
        align-items: center;
    }
    .mobile-bar-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        font-size: 10px;
        color: var(--text-secondary);
        text-decoration: none !important;
        font-weight: 600;
        gap: 2px;
    }
    .mobile-bar-item.active {
        color: var(--brand-accent);
    }
}
