@import url('https://fonts.googleapis.com/css2?family=Hind+Siliguri:wght@400;500;600;700&family=Inter:wght@400;500;600;700;800;900&display=swap');

:root {
    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --primary-light: #EFF6FF;
    --bg-main: #F8FAFC;
    --surface: #FFFFFF;
    --text-main: #0F172A;
    --text-muted: #64748B;
    --border: #E2E8F0;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.02);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Inter', 'Hind Siliguri', sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    font-size: 14px;
    line-height: 1.5;
}

a { text-decoration: none; color: inherit; transition: color 0.2s; }
img { max-width: 100%; height: auto; }

/* ================= Buttons ================= */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; 
    padding: 10px 20px; border-radius: var(--radius-sm); font-weight: 600; font-size: 13px; 
    cursor: pointer; border: 1px solid transparent; transition: all 0.2s ease-in-out; 
    white-space: nowrap; letter-spacing: 0.3px;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #DC2626; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #D97706; }
.btn-secondary { background: var(--surface); color: var(--text-main); border-color: var(--border); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--bg-main); border-color: #CBD5E1; color: var(--primary); }
.btn-whatsapp { background: #25D366; color: #fff; }
.btn-whatsapp:hover { background: #16A34A; }

.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 15px; }
.btn-block { width: 100%; }

.mobile-only-btn { display: none; }
.hide-mobile { display: inline-block; }

/* ================= Forms ================= */
.form-group { margin-bottom: 16px; width: 100%; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-main); margin-bottom: 6px; }
.form-control { width: 100%; padding: 10px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; font-family: inherit; color: var(--text-main); background: var(--surface); transition: all 0.2s ease; box-shadow: var(--shadow-sm); }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
select.form-control { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; padding-right: 40px; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ================= Modern Settings Tabs ================= */
.settings-tabs-container { display: flex; gap: 4px; background: #F1F5F9; padding: 6px; border-radius: var(--radius-md); margin-bottom: 24px; border: 1px solid var(--border); overflow-x: auto; width: 100%; }
.settings-tabs-container a { flex: 1; text-align: center; padding: 12px 16px; font-weight: 600; font-size: 14px; color: var(--text-muted); border-radius: var(--radius-sm); transition: all 0.3s; white-space: nowrap; }
.settings-tabs-container a.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.settings-tabs-container a:hover:not(.active) { color: var(--text-main); background: rgba(255, 255, 255, 0.5); }

/* ================= Cards ================= */
.card { background: var(--surface); border-radius: var(--radius-md); box-shadow: var(--shadow-md); border: 1px solid var(--border); overflow: hidden; width: 100%; margin-bottom: 20px;}
.card-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; background: #FAFAF9; }
.card-header h3 { font-size: 16px; font-weight: 700; margin:0; color: var(--text-main); }
.card-body { padding: 24px; }

/* ================= Badges ================= */
.badge { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; letter-spacing: 0.3px; }
.badge-paid, .badge-approved, .badge-active { background: #DCFCE7; color: #166534; }
.badge-draft, .badge-cancelled { background: #F1F5F9; color: #475569; }
.badge-sent { background: #DBEAFE; color: #1E40AF; }
.badge-partial, .badge-pending { background: #FEF3C7; color: #92400E; }
.badge-overdue, .badge-rejected { background: #FEE2E2; color: #991B1B; }
.badge-pro { background: linear-gradient(135deg,#F59E0B,#FCD34D); color: #78350F; font-weight: 800; }
.badge-free { background: #F1F5F9; color: #475569; }

/* ================= Tables ================= */
.table-wrap { overflow-x: auto; width: 100%; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { background: var(--bg-main); color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text-main); }
tbody tr:hover td { background: var(--bg-main); }

/* ================= Grids & Stats ================= */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(200px,1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border-radius: var(--radius-md); padding: 20px; border: 1px solid var(--border); box-shadow: var(--shadow-sm); transition: transform 0.2s; }
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-icon { font-size: 28px; margin-bottom: 12px; }
.stat-value { font-size: 24px; font-weight: 800; color: var(--text-main); }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; width: 100%; margin-bottom: 20px;}
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; width: 100%; margin-bottom: 20px;}

.d-flex { display: flex; } .gap-2 { gap: 10px; } .flex-wrap { flex-wrap: wrap; }
.mt-3 { margin-top: 16px; } .mt-4 { margin-top: 24px; } .mb-4 { margin-bottom: 24px; }

/* ================= Navbar (Fixed & Absolute) ================= */
.navbar { 
    background: #0F172A; color: #fff; padding: 0 24px; height: 64px; 
    display: flex; align-items: center; justify-content: space-between; 
    position: fixed; top: 0; left: 0; right: 0; z-index: 1000; box-shadow: var(--shadow-md); width: 100%;
}
.navbar-left { display: flex; align-items: center; gap: 12px; }
.navbar-brand { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 800; color: #fff; text-decoration: none; white-space: nowrap;}
.navbar-brand img { max-height: 32px; object-fit: contain; border-radius: 4px; }

.navbar-menu { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.navbar-menu a { color: #CBD5E1; padding: 8px 14px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; transition: all 0.2s; }
.navbar-menu a:hover { background: rgba(255,255,255,0.1); color: #fff; }
.login-link { font-size: 14px; font-weight: 600; margin-right: 8px; }

/* ================= Layout & Sidebar (Fixed Gap Issue) ================= */
.layout { 
    display: flex; 
    padding-top: 64px; /* Push content exactly below the 64px navbar */
    min-height: 100vh; 
    width: 100%; 
    max-width: 100vw; 
    overflow-x: hidden; 
}

.sidebar { 
    width: 260px; background: #1E293B; flex-shrink: 0; display: flex; flex-direction: column; 
    overflow-y: auto; height: calc(100vh - 64px); position: fixed; top: 64px; left: 0; 
    box-shadow: inset -1px 0 0 rgba(255,255,255,0.05); z-index: 999;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

.sidebar a { display: flex; align-items: center; gap: 14px; padding: 12px 20px; margin: 4px 12px; color: #CBD5E1; font-size: 14px; font-weight: 500; transition: all 0.2s; border-radius: var(--radius-sm); }
.sidebar a:hover { background: rgba(255,255,255,0.05); color: #fff; }
.sidebar a.active { background: var(--primary); color: #fff; font-weight: 600; box-shadow: 0 4px 12px rgba(37,99,235,0.3); }
.sidebar .nav-icon { font-size: 18px; width: 24px; text-align: center; opacity: 0.9; }

.sidebar-section { padding: 24px 20px 8px; font-size: 11px; font-weight: 700; color: #94A3B8; text-transform: uppercase; letter-spacing: 1px; }
.sidebar-bottom { margin-top: auto; padding: 24px 16px; background: #0F172A; border-top: 1px solid rgba(255,255,255,0.05); display: flex; flex-direction: column; gap: 12px; }

/* Main Content Area */
.main-content { 
    margin-left: 260px; /* Leave space for the fixed sidebar */
    width: calc(100% - 260px); 
    min-height: calc(100vh - 64px);
    padding: 32px; 
    box-sizing: border-box; 
}
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 32px; flex-wrap: wrap; gap: 16px; }
.page-title { font-size: 26px; font-weight: 800; color: var(--text-main); letter-spacing: -0.5px;}
.page-subtitle { font-size: 14px; color: var(--text-muted); margin-top: 6px; }

/* ================= Invoice Builder ================= */
.item-row td { padding: 8px 6px; }
.item-row input, .item-row select { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; width: 100%; background: var(--surface); box-shadow: var(--shadow-sm); transition: border-color 0.2s; }
.item-row input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); }

.total-box { background: var(--bg-main); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 24px; width: 100%;}
.total-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; font-size: 14px; border-bottom: 1px solid var(--border); color: var(--text-main); font-weight: 500;}
.total-row:last-child { border: none; font-size: 20px; font-weight: 800; color: var(--primary); padding-top: 16px; margin-top: 8px; }

.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(140px,1fr)); gap: 16px; }
.tpl-card { border: 2px solid var(--border); border-radius: var(--radius-md); overflow: hidden; cursor: pointer; transition: all 0.2s; background: var(--surface); }
.tpl-card:hover { border-color: var(--primary); transform: translateY(-3px); box-shadow: var(--shadow-md); }
.tpl-card.selected { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(37,99,235,0.15); }
.tpl-hdr { padding: 16px; text-align: center; color: #fff; font-weight: 600; font-size: 12px; letter-spacing: 0.5px;}
.tpl-bdy { padding: 12px; background: var(--surface); }
.tpl-line { height: 6px; border-radius: 4px; margin-bottom: 6px; opacity: 0.2; }
.tpl-name { font-size: 12px; font-weight: 700; color: var(--text-main); text-align: center; padding: 8px; }
.invoice-paper { max-width: 850px; margin: 0 auto; background: #fff; padding: 50px; box-shadow: var(--shadow-lg); border-radius: var(--radius-sm); border: 1px solid var(--border); overflow-x: auto; width: 100%;}

/* ================= 100% BULLETPROOF MOBILE FIX ================= */
@media(max-width: 768px) {
    /* Safe Navbar Single Line */
    .navbar { 
        padding: 0 12px !important; 
        height: 60px !important; 
        flex-wrap: nowrap !important;
    }
    
    .navbar-left { gap: 6px !important; overflow: hidden; }
    
    .mobile-only-btn { 
        display: flex !important; 
        align-items: center; justify-content: center;
        background: transparent; border: none; color: #fff; font-size: 26px; 
        cursor: pointer; padding: 0 6px 0 0 !important; margin: 0 !important; 
        touch-action: manipulation; flex-shrink: 0; outline: none;
    }
    
    .navbar-brand { font-size: 16px !important; text-overflow: ellipsis; }
    .navbar-brand img { max-height: 24px !important; }
    
    .navbar-menu { gap: 6px !important; }
    .login-link { font-size: 13px !important; padding: 4px !important; margin-right: 0 !important; }
    .btn-sm { padding: 6px 10px !important; font-size: 11px !important; }
    
    .hide-mobile { display: none !important; }

    /* Fix Sidebar slide */
    .sidebar { 
        position: fixed !important; 
        left: -300px !important; 
        top: 60px !important; 
        height: calc(100vh - 60px) !important; 
        z-index: 1005 !important; 
        transition: left 0.3s ease-in-out !important; 
        box-shadow: 4px 0 15px rgba(0,0,0,0.5) !important;
        width: 260px !important; 
        background: #1E293B !important; 
    }
    .sidebar.open { left: 0 !important; }
    
    /* Layout & Table Fixes */
    .layout { padding-top: 60px !important; flex-direction: column; }
    .main-content { margin-left: 0 !important; width: 100% !important; padding: 15px 12px; }
    
    .stat-grid { grid-template-columns: repeat(2,1fr) !important; gap: 12px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr !important; gap: 16px; }
    .invoice-paper { padding: 20px; }
    .table-wrap { display: block; overflow-x: auto; width: 100%; -webkit-overflow-scrolling: touch; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .page-header .d-flex { width: 100%; }
    .settings-tabs-container { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
    .settings-tabs-container a { padding: 10px 12px; font-size: 13px; }
}

@media print {
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
    .no-print, .navbar, .sidebar, .page-header { display: none !important; }
    body, html { background: #fff !important; margin: 0 !important; padding: 0 !important; max-width: none !important; }
    .layout { padding-top: 0 !important; display: block !important; }
    .main-content { margin-left: 0 !important; width: 100% !important; padding: 0 !important; display: block !important; }
    .invoice-paper { box-shadow: none !important; margin: 0 !important; padding: 0 !important; max-width: 100% !important; border: none !important; }
    @page { size: A4; margin: 0mm; }
}