:root {
    --primary: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --white: #ffffff;
    --text: #1e293b;
    --secondary: #64748b;
    --border: #e2e8f0;
    --card-bg: #ffffff;
    --input-bg: #ffffff;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
    --shadow-soft: 0 6px 18px rgba(15, 23, 42, 0.05);
}

[data-theme="dark"] {
    --bg: #0f172a;
    --white: #1e293b;
    --text: #f1f5f9;
    --secondary: #94a3b8;
    --border: #334155;
    --card-bg: #1e293b;
    --primary-light: #1e3a8a;
    --input-bg: #0f172a;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
    --shadow-soft: 0 6px 18px rgba(0, 0, 0, 0.22);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

html, body {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

body {
    font-family: 'Hind Siliguri', sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background 0.3s, color 0.3s;
}

/* Loader */
#loading-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #0f172a, #1e293b);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    color: white;
}

.spinner {
    border: 4px solid rgba(255,255,255,0.1);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border-left-color: #3b82f6;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Layout */
.sidebar {
    width: 260px;
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 2100;
    left: 0;
    top: 0;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.main-content {
    margin-left: 260px;
    min-height: 100vh;
    padding-bottom: 90px;
    width: calc(100% - 260px);
}

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 2050;
}

.overlay.active {
    display: block;
}

header {
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(10px);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1000;
}

[data-theme="dark"] header {
    background: rgba(30, 41, 59, 0.92);
}

/* Dashboard grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(150px, 1fr));
    gap: 14px;
    padding: 15px;
}

/* only stat cards */
.stats-grid > .stat-card {
    min-height: 132px;
}

/* full width blocks inside stats grid */
.stats-grid > div:not(.stat-card) {
    grid-column: 1 / -1;
}

.stat-card {
    background: var(--card-bg);
    padding: 16px;
    border-radius: 16px;
    border: 1px solid var(--border);
    border-bottom: 3px solid var(--primary);
    box-shadow: var(--shadow-soft);
}

.stat-card h4 {
    margin: 0 0 10px;
    font-size: 13px;
    color: var(--secondary);
    font-weight: 700;
}

.stat-card .val {
    font-size: 22px;
    font-weight: 800;
    line-height: 1.2;
}

/* Table */
.table-container {
    background: var(--card-bg);
    margin: 0 15px 15px;
    border-radius: 16px;
    overflow-x: auto;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
    width: auto;
}

.stats-grid .table-container {
    margin: 0;
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 500px;
}

th {
    background: var(--bg);
    padding: 12px;
    text-align: left;
    font-size: 12px;
    color: var(--secondary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text);
    vertical-align: middle;
}

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

/* Landing */
#auth-screen {
    background: var(--white);
    min-height: 100vh;
}

.auth-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 5%;
    background: rgba(255,255,255,0.95);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-logo {
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
}

.hero {
    padding: 60px 5%;
    text-align: center;
    background: linear-gradient(180deg, var(--bg), var(--white));
}

.hero h1 {
    font-size: 32px;
    font-weight: 800;
    margin-bottom: 20px;
    line-height: 1.3;
    color: var(--text);
}

.hero h1 span {
    color: var(--primary);
}

.hero p {
    max-width: 780px;
    margin: 0 auto 26px;
    color: var(--secondary);
    line-height: 1.7;
}

.feat-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    padding: 40px 5%;
    background: var(--white);
}

.feat-card {
    padding: 30px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    text-align: center;
    box-shadow: var(--shadow-soft);
}

.feat-icon {
    width: 58px;
    height: 58px;
    margin: 0 auto 10px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 22px;
}

/* Pending/support */
.pending-box {
    max-width: 620px;
    margin: 28px auto 0;
    padding: 22px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
}

.support-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.support-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 14px;
    border-radius: 12px;
    text-decoration: none;
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
}

/* Forms */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 3000;
    padding: 15px;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--card-bg);
    color: var(--text);
    width: 100%;
    max-width: 480px;
    border-radius: 18px;
    padding: 20px;
    border: 1px solid var(--border);
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    font-size: 17px;
}

input,
select,
textarea {
    width: 100%;
    padding: 11px 12px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 14px;
    background: var(--input-bg);
    color: var(--text);
}

textarea {
    min-height: 92px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

/* Buttons */
.btn {
    padding: 10px 15px;
    border-radius: 10px;
    border: none;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    font-size: 13px;
    text-decoration: none !important;
    transition: 0.2s ease;
}

.btn-primary {
    background: var(--primary);
    color: white !important;
}

.btn-danger {
    background: var(--danger);
    color: white !important;
}

.btn-cancel {
    background: var(--bg);
    color: var(--secondary) !important;
    border: 1px solid var(--border);
    width: 100%;
    margin-top: 10px;
}

/* Nav */
.nav-item {
    padding: 14px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--secondary);
    font-size: 14px;
    transition: 0.2s ease;
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 700;
    border-right: 4px solid var(--primary);
}

.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(255,255,255,0.98);
    border-top: 1px solid var(--border);
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
    justify-content: space-around;
    z-index: 2200;
}

[data-theme="dark"] .bottom-nav {
    background: rgba(30, 41, 59, 0.98);
}

.nav-btn {
    text-align: center;
    color: var(--secondary);
    font-size: 11px;
    flex: 1;
    cursor: pointer;
    text-decoration: none !important;
    padding: 4px 2px;
}

.nav-btn.active {
    color: var(--primary);
    font-weight: 700;
}

/* Utility */
.bank-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.form-section {
    display: none;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px dashed var(--border);
}

/* Desktop */
@media (min-width: 993px) {
    .bottom-nav {
        display: none !important;
    }

    .sidebar {
        transform: translateX(0) !important;
    }
}

/* Tablet */
@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(3, minmax(150px, 1fr));
    }

    .feat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .support-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Mobile / tablet sidebar collapse */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .bottom-nav {
        display: flex;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .feat-grid,
    .support-grid {
        grid-template-columns: 1fr;
    }
}

/* Small mobile */
@media (max-width: 576px) {
    header {
        padding: 10px 14px;
    }

    .hero {
        padding: 42px 5%;
    }

    .hero h1 {
        font-size: 24px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        padding: 12px;
    }

    .stat-card {
        padding: 14px;
        min-height: auto;
    }

    .stat-card .val {
        font-size: 18px;
    }

    .table-container {
        margin: 0 12px 12px;
        border-radius: 14px;
    }

    .stats-grid .table-container {
        margin: 0;
    }

    .modal-content {
        padding: 16px;
        border-radius: 16px;
    }

    th, td {
        padding: 10px;
        font-size: 12px;
    }

    .nav-logo {
        font-size: 18px;
    }
}

/* Print */
@media print {
    .no-print,
    .sidebar,
    .bottom-nav,
    .overlay,
    .btn,
    header {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding-bottom: 0 !important;
    }

    #invoiceModal {
        position: static !important;
        display: block !important;
        background: white !important;
        padding: 0 !important;
    }

    #invoiceModal .modal-content {
        box-shadow: none;
        border: none;
        max-width: 100%;
        max-height: none;
        padding: 0;
    }
}

#section-suppliers .table-container,

@media (display-mode: standalone) {
    body {
        overscroll-behavior: none;
    }
}
#section-customers .table-container,
#section-banks .table-container {
    margin-bottom: 15px;
}

[data-theme="dark"] #offlineBanner {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.35);
}
