/* ============================================================
   Version 1.0.2 – Fully responsive, mobile-first
   ============================================================ */

/* ----- Reset & Base ----- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Roboto, system-ui, sans-serif;
}
body {
    background: #f5f7fc;
    display: flex;
    min-height: 100vh;
    flex-direction: column;
}

/* ----- Auth Section ----- */
#authSection {
    max-width: 400px;
    margin: 5rem auto;
    background: #fff;
    padding: 2.5rem;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    width: 90%;
}
#authSection h2 { text-align: center; margin-bottom: 1.5rem; }
.auth-form input {
    width: 100%;
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid #ccc;
    margin-bottom: 1rem;
}
#authSection .btn { width: 100%; justify-content: center; }

/* ----- Main App Layout ----- */
#mainApp {
    display: none;
    width: 100%;
    min-height: 100vh;
    flex-direction: column;
}
#mainApp.show {
    display: flex;
}

/* ----- Top Bar (mobile & tablet) ----- */
.top-bar {
    display: flex;
    background: #1a2b4a;
    color: #fff;
    padding: 0.7rem 1rem;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid #2e4166;
    min-height: 56px;
}
.top-bar .menu-toggle {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.6rem;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    line-height: 1;
}
.top-bar .brand-mobile {
    font-size: 1.1rem;
    font-weight: 700;
    white-space: nowrap;
}
.top-bar .brand-mobile i {
    color: #6c9fff;
    margin-right: 6px;
}
.top-bar .logout-mobile {
    background: none;
    border: none;
    color: #a0b7d9;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
}

/* ----- Sidebar ----- */
.sidebar {
    width: 280px;
    max-width: 80vw;
    background: #1a2b4a;
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1.2rem;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
    box-shadow: 2px 0 20px rgba(0,0,0,0.3);
}
.sidebar.open {
    transform: translateX(0);
}
.sidebar .brand {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 2rem;
    padding-left: 0.5rem;
}
.sidebar .brand i {
    color: #6c9fff;
    margin-right: 8px;
}
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #a0b7d9;
    text-decoration: none;
    padding: 0.7rem 1rem;
    border-radius: 10px;
    margin-bottom: 4px;
    transition: 0.2s;
    font-weight: 500;
    cursor: pointer;
}
.sidebar nav a:hover {
    background: #2a3e62;
    color: #fff;
}
.sidebar nav a.active {
    background: #1f5fcf;
    color: #fff;
}
.sidebar nav a i {
    width: 22px;
    text-align: center;
}
.sidebar .logout-btn {
    margin-top: auto;
    border-top: 1px solid #2e4166;
    padding-top: 1.5rem;
}
.sidebar .logout-btn a {
    color: #a0b7d9;
    text-decoration: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.7rem 1rem;
}

/* ----- Overlay for sidebar ----- */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 150;
}
.sidebar-overlay.active {
    display: block;
}

/* ----- Main Content ----- */
.app-layout {
    display: flex;
    flex: 1;
    flex-direction: column;
}
.main-content {
    flex: 1;
    padding: 1rem;
    background: #f5f7fc;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}
.main-content > * {
    width: 100%;
}

/* ----- Sections ----- */
.section {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
}
.section.active {
    display: flex;
}

/* ----- Page Header ----- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.8rem;
    margin-bottom: 1.5rem;
}
.page-header h2 {
    font-weight: 600;
    color: #1a2b4a;
    font-size: 1.3rem;
}

/* ----- Stats Grid ----- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: #fff;
    padding: 1.2rem;
    border-radius: 16px;
    border: 1px solid #e9edf4;
}
.stat-card .label {
    font-size: 0.8rem;
    color: #6f87a8;
    font-weight: 500;
}
.stat-card .value {
    font-size: 1.8rem;
    font-weight: 700;
    color: #1a2b4a;
    margin-top: 2px;
}

/* ----- Tables (generic) ----- */
.table-wrap {
    background: #fff;
    border-radius: 16px;
    border: 1px solid #e9edf4;
    overflow-x: auto;
    width: 100%;
    margin-bottom: 1rem;
}
table {
    width: 100%;
    border-collapse: collapse;
    min-width: 400px;
}
th, td {
    padding: 0.8rem 1rem;
    text-align: left;
    border-bottom: 1px solid #edf2f8;
    word-wrap: break-word;
}
th {
    background: #f8fafd;
    color: #2a4a6a;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
}
.badge-status {
    background: #e5edf9;
    padding: 0.2rem 0.7rem;
    border-radius: 40px;
    font-size: 0.65rem;
    font-weight: 600;
    color: #1f4b7a;
    display: inline-block;
}

/* ----- Inline Forms ----- */
.inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
    margin-bottom: 1rem;
}
.inline-form input, .inline-form select {
    padding: 0.5rem 0.8rem;
    border: 1px solid #d7e0eb;
    border-radius: 30px;
    font-size: 0.9rem;
    background: #fff;
    flex: 1 0 120px;
    min-width: 100px;
}

/* ----- Buttons ----- */
.btn {
    padding: 0.5rem 1.2rem;
    border: none;
    border-radius: 30px;
    font-weight: 600;
    font-size: 0.85rem;
    background: #eef3fa;
    color: #1a3a5e;
    cursor: pointer;
    transition: 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.btn-primary { background: #1f5fcf; color: #fff; }
.btn-primary:hover { background: #174bb0; }
.btn-success { background: #1d9c5e; color: #fff; }
.btn-success:hover { background: #157d4a; }
.btn-danger { background: #d32f2f; color: #fff; }
.btn-danger:hover { background: #b71c1c; }
.btn-outline { background: transparent; border: 1px solid #b8c9e0; }
.btn-outline:hover { background: #eaf0f8; }

.flex { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }

/* ============================================================
   INVOICE / RECEIPT PREVIEW – RESPONSIVE
   ============================================================ */
.receipt-preview {
    background: #fff;
    border-radius: 16px;
    padding: 1.5rem;
    border: 1px solid #e2eaf3;
    box-shadow: 0 8px 24px rgba(0,0,0,0.06);
    margin: 1rem 0;
    width: 100%;
}
.receipt-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.2rem;
    padding-bottom: 0.8rem;
    border-bottom: 2px solid #f0f4fa;
}
.logo-area {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-wrap: wrap;
}
.logo-placeholder {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    background: #f4f8fe;
    border: 2px dashed #c5d6e8;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}
.logo-placeholder img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-placeholder input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}
.receipt-meta {
    text-align: right;
    font-size: 0.85rem;
    color: #2b4a6e;
    margin-left: auto;
}
.receipt-client {
    background: #f7faff;
    padding: 0.7rem 1rem;
    border-radius: 12px;
    margin: 0 0 1rem 0;
    border-left: 6px solid #1f5fcf;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ---------- INVOICE TABLE – FULLY RESPONSIVE ---------- */
.receipt-items {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0.5rem 0 1rem 0;
    width: 100%;
}
.receipt-items table {
    width: 100%;
    min-width: 400px;
    border-collapse: collapse;
    table-layout: fixed;
}
.receipt-items th,
.receipt-items td {
    padding: 0.5rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid #eef3f9;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    font-size: 0.85rem;
}
.receipt-items th {
    background: #f8fafd;
    color: #1f3f62;
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
}
/* Column widths */
.receipt-items th:nth-child(1),
.receipt-items td:nth-child(1) { width: 40%; }
.receipt-items th:nth-child(2),
.receipt-items td:nth-child(2) { width: 15%; }
.receipt-items th:nth-child(3),
.receipt-items td:nth-child(3) { width: 20%; }
.receipt-items th:nth-child(4),
.receipt-items td:nth-child(4) { width: 25%; }

.receipt-summary {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.5rem;
    padding-top: 0.8rem;
    border-top: 2px solid #e3ecf7;
}
.summary-grid {
    width: 220px;
}
.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
    font-size: 0.9rem;
    color: #1f3f62;
}
.summary-row.grand-total {
    font-weight: 700;
    font-size: 1.1rem;
    border-top: 2px solid #1f5fcf;
    padding-top: 0.5rem;
    margin-top: 0.2rem;
    color: #0d2b4a;
}

.signature-area {
    display: flex;
    justify-content: flex-start;
    margin-top: 1.2rem;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    padding-top: 0.8rem;
    border-top: 1px solid #eef3f9;
}
.signature-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.signature-pad {
    width: 120px;
    height: 45px;
    border-bottom: 2px solid #2a4b74;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fafdff;
    border-radius: 8px 8px 0 0;
    position: relative;
    cursor: pointer;
    overflow: hidden;
}
.signature-pad img { max-height: 100%; max-width: 100%; object-fit: contain; }
.signature-pad input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

/* ============================================================
   RESPONSIVE BREAKPOINTS – 480px minimum
   ============================================================ */

/* Hide top bar on large screens, show sidebar permanently */
@media (min-width: 769px) {
    .top-bar {
        display: none;
    }
    .sidebar {
        position: sticky;
        transform: none !important;
        width: 250px;
        max-width: 250px;
        height: 100vh;
        flex-shrink: 0;
        box-shadow: none;
        z-index: 1;
        padding: 2rem 1.5rem;
    }
    .sidebar-overlay {
        display: none !important;
    }
    .app-layout {
        flex-direction: row;
    }
    .main-content {
        padding: 2rem 2.5rem;
        max-width: 1200px;
        margin: 0 auto;
    }
    .receipt-preview {
        padding: 2rem 2.5rem;
    }
    .receipt-items table {
        min-width: 500px;
    }
}

/* Tablets and small desktops */
@media (max-width: 768px) {
    .top-bar {
        display: flex;
    }
    .app-layout {
        flex-direction: column;
    }
    .main-content {
        padding: 0.8rem;
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.8rem;
    }
    .stat-card .value {
        font-size: 1.4rem;
    }
    .receipt-preview {
        padding: 1rem;
    }
    .receipt-header {
        flex-direction: column;
        align-items: stretch;
    }
    .receipt-meta {
        text-align: left;
        margin-left: 0;
    }
    .receipt-client {
        flex-direction: column;
        gap: 0.3rem;
    }
    .receipt-summary {
        justify-content: flex-start;
    }
    .summary-grid {
        width: 100%;
    }
    .signature-area {
        justify-content: flex-start;
    }
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .inline-form input, .inline-form select {
        flex: 1 1 100%;
    }
}

/* Mobile phones (480px and below) */
@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .stat-card {
        padding: 0.8rem;
    }
    .stat-card .value {
        font-size: 1.2rem;
    }
    .receipt-preview {
        padding: 0.8rem;
    }
    .receipt-items table {
        min-width: 320px;
    }
    .receipt-items th,
    .receipt-items td {
        padding: 0.3rem 0.3rem;
        font-size: 0.7rem;
    }
    .receipt-items th:nth-child(1),
    .receipt-items td:nth-child(1) { width: 35%; }
    .receipt-items th:nth-child(2),
    .receipt-items td:nth-child(2) { width: 15%; }
    .receipt-items th:nth-child(3),
    .receipt-items td:nth-child(3) { width: 20%; }
    .receipt-items th:nth-child(4),
    .receipt-items td:nth-child(4) { width: 30%; }
    .btn {
        font-size: 0.75rem;
        padding: 0.4rem 0.8rem;
    }
    .top-bar .brand-mobile {
        font-size: 0.95rem;
    }
    .sidebar {
        width: 260px;
        max-width: 80vw;
    }
    .receipt-summary .summary-row {
        font-size: 0.8rem;
    }
    .summary-row.grand-total {
        font-size: 1rem;
    }
    .signature-pad {
        width: 100px;
        height: 38px;
    }
}

/* Landscape phones – use extra width, keep top bar and sidebar hidden */
@media (max-width: 768px) and (orientation: landscape) {
    .main-content {
        padding: 0.5rem 1rem;
    }
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.5rem;
    }
    .stat-card {
        padding: 0.5rem;
    }
    .stat-card .value {
        font-size: 1.2rem;
    }
    .receipt-preview {
        padding: 0.8rem 1.2rem;
    }
    .receipt-items table {
        min-width: 450px;
    }
    .sidebar {
        max-width: 60vw;
    }
}

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
    body * {
        visibility: hidden;
    }
    .receipt-preview,
    .receipt-preview * {
        visibility: visible;
    }
    .receipt-preview {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        padding: 1.5rem 2rem;
        border: none;
        box-shadow: none;
        border-radius: 0;
        background: #fff;
        margin: 0;
    }
    .sidebar,
    .top-bar,
    .page-header,
    .btn,
    .stats-grid,
    .table-wrap,
    .inline-form,
    .logo-placeholder input[type="file"],
    .signature-pad input[type="file"],
    .sidebar-overlay {
        display: none !important;
    }
}
/* Settings form – single column with clean spacing */
#settingsForm label {
    font-size: 0.9rem;
    color: #1a2b4a;
}
#settingsForm input[type="text"],
#settingsForm input[type="number"] {
    height: 44px; /* better touch target on mobile */
}
#settingsForm input[type="color"] {
    height: 48px;
}
@media (max-width: 480px) {
    #settingsForm .flex {
        flex-direction: column;
        align-items: stretch;
    }
    #settingsForm .flex input {
        flex: 1 1 auto;
        width: 100%;
    }
}

@media (max-width: 600px) {
    .receipt-header {
        flex-direction: column;
        align-items: stretch;
    }
    .receipt-meta {
        text-align: left;
        margin-left: 0;
        margin-top: 0.5rem;
    }
    .logo-area {
        flex-wrap: wrap;
    }
}




/* ============================================================
   UTILITIES
   ============================================================ */
.hidden { display: none !important; }
.text-muted { color: #6f87a8; }
.text-center { text-align: center; }