:root {
    /* Dark Theme Colors */
    --bg-dark: #121212;
    --bg-card: #1e1e1e;
    --bg-hover: #2c2c2c;
    --bg-main: #121212;
    --bg-panel: #1e1e1e;
    --text-main: #f5f5f5;
    --text-muted: #a0a0a0;
    --primary: #4ade80;
    --primary-hover: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --border: #333333;
    
    --sidebar-width: 220px;
    --radius: 10px;
    --transition: 0.3s ease;
}

/* ── Light Theme ──────────────────────────────────────── */
body.light-theme {
    --bg-dark: #f0f2f5;
    --bg-main: #f0f2f5;
    --bg-card: #ffffff;
    --bg-hover: #e8eaed;
    --bg-panel: #ffffff;
    --text-main: #1a1a2e;
    --text-muted: #6b7280;
    --primary: #16a34a;
    --primary-hover: #15803d;
    --danger: #dc2626;
    --warning: #d97706;
    --border: #d1d5db;
    background-color: var(--bg-dark);
    color: var(--text-main);
}
body.light-theme .sidebar {
    background-color: #ffffff;
    border-right: 1px solid #e5e7eb;
    box-shadow: 2px 0 8px rgba(0,0,0,0.06);
}
body.light-theme .sidebar .sidebar-header h2,
body.light-theme .sidebar .sidebar-header i {
    color: #1a1a2e;
}
body.light-theme .sidebar .nav-category {
    color: #9ca3af;
}
body.light-theme .sidebar .nav-links a {
    color: #4b5563;
}
body.light-theme .sidebar .nav-links a:hover,
body.light-theme .sidebar .nav-links a.active {
    background-color: rgba(22, 163, 74, 0.1);
    color: #16a34a;
}
body.light-theme .sidebar .nav-links a.active i,
body.light-theme .sidebar .nav-links a:hover i {
    color: #16a34a;
}
body.light-theme .topbar {
    background-color: #ffffff;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
body.light-theme .card {
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
body.light-theme .table thead th {
    background-color: #f8fafc;
    color: #374151;
}
body.light-theme .table tbody tr:hover {
    background-color: #f1f5f9;
}
body.light-theme .modal-content {
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}
body.light-theme #btn-theme-toggle {
    border-color: #d1d5db;
    color: #374151;
}
body.light-theme .badge {
    background-color: #e5e7eb;
    color: #374151;
}
body.light-theme input, body.light-theme select, body.light-theme textarea {
    background-color: #f9fafb;
    color: #1a1a2e;
    border-color: #d1d5db;
}
body.light-theme input:focus, body.light-theme select:focus, body.light-theme textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(22,163,74,0.15);
}
body.light-theme .dropdown-menu {
    background-color: #ffffff;
    border-color: #e5e7eb;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
body.light-theme .summary-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid #e5e7eb;
}

/* Light Theme - Login Page Overrides */
body.light-theme #login-wrapper::before,
body.light-theme #login-wrapper::after {
    opacity: 0.15;
}
body.light-theme .login-box {
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(22, 163, 74, 0.2);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0,0,0,0.05);
}
body.light-theme .login-header h2 {
    background: linear-gradient(135deg, #1a1a2e 0%, #16a34a 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
body.light-theme #login-form .input-control {
    background: #ffffff;
    border-color: #d1d5db;
    color: #1a1a2e;
}
body.light-theme #login-form .input-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(22,163,74,0.15);
}
body.light-theme #login-form .form-group label {
    color: #4b5563;
}
body.light-theme #login-error {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #dc2626;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

/* Fluid Typography Base */
html {
    font-size: 15px; /* Base size for large screens */
}

@media (max-width: 1200px) {
    html { font-size: 14px; }
}

@media (max-width: 992px) {
    html { font-size: 13.5px; }
}

@media (max-width: 768px) {
    html { font-size: 13px; }
}

@media (max-width: 480px) {
    html { font-size: 12px; }
}

body.dark-theme {
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
}

#app-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 1.5rem 1rem;
    position: fixed;
    height: 100vh;
    z-index: 10;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 2rem;
    padding-left: 10px;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.sidebar-header i {
    font-size: 1.2rem;
}

.text-primary {
    color: var(--primary);
}
.text-danger {
    color: var(--danger) !important;
}

.nav-links {
    list-style: none;
}

.nav-links li {
    margin-bottom: 0.5rem;
}

.nav-category {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    padding-left: 15px;
}
.nav-category:first-child {
    margin-top: 0;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    text-decoration: none;
    color: var(--text-muted);
    border-radius: var(--radius);
    transition: var(--transition);
    font-weight: 500;
}

.nav-links a:hover, .nav-links a.active {
    background-color: rgba(74, 222, 128, 0.1);
    color: var(--primary);
}

/* Main Content */
.main-content {
    flex: 1;
    min-width: 0; /* Critical: prevents flex child from overflowing */
    margin-left: var(--sidebar-width);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
    width: calc(100% - var(--sidebar-width));
}

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 1.5rem;
    position: relative;
    flex-wrap: nowrap;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.topbar-left h1 {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#page-title {
    font-size: 1.4rem;
    font-weight: 600;
}

.period-selector {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--primary);
    color: var(--bg-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
}

/* Pages */
.page {
    display: none;
    animation: fadeIn 0.4s ease;
    width: 100%;
    flex: 1;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Cards */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.25rem;
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.summary-card {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.card-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
}

.card-icon.income { background-color: rgba(74, 222, 128, 0.2); color: var(--primary); }
.card-icon.expense { background-color: rgba(239, 68, 68, 0.2); color: var(--danger); }
.card-icon.balance { background-color: rgba(245, 158, 11, 0.2); color: var(--warning); }

.card-info p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 5px;
}

/* Dashboard Lists */
.dashboard-lists {
    display: flex;
    gap: 1.5rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    padding-bottom: 15px; /* Space for scrollbar */
}

.dashboard-lists::-webkit-scrollbar {
    height: 8px;
}
.dashboard-lists::-webkit-scrollbar-track {
    background: var(--bg-main); 
    border-radius: 4px;
}
.dashboard-lists::-webkit-scrollbar-thumb {
    background: var(--border); 
    border-radius: 4px;
}
.dashboard-lists::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted); 
}

.dashboard-lists .list-card {
    flex: 0 0 calc(50% - 0.75rem); /* Exactly 2 columns visible */
    scroll-snap-align: start;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.table th, .table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    color: var(--text-muted);
    font-weight: 500;
}

.table tbody tr:hover {
    background-color: var(--bg-hover);
}

.badge {
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge.unpaid { background-color: rgba(239, 68, 68, 0.2); color: var(--danger); }
.dropdown-menu {
    position: absolute;
    right: 0;
    top: 100%;
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    z-index: 50;
    min-width: 140px;
    display: none;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.5), 0 4px 6px -4px rgba(0,0,0,0.5);
    margin-top: 5px;
}
.dropdown-menu.show {
    display: flex !important;
    flex-direction: column;
    gap: 4px;
}
.dropdown-item {
    width: 100%;
    text-align: left;
    background-color: transparent !important;
    color: var(--text-main);
    border: none !important;
    padding: 8px 12px;
    justify-content: flex-start;
    font-size: 0.9rem;
    border-radius: 4px;
}
.dropdown-item:hover {
    background-color: var(--bg-hover) !important;
}
.dropdown-item.text-danger:hover {
    background-color: rgba(239, 68, 68, 0.1) !important;
}

/* Forms & Buttons */
.input-control {
    width: 100%;
    padding: 10px 15px;
    background-color: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s;
}

.input-control:focus {
    border-color: var(--primary);
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 1.5rem;
}

.filters .input-control {
    flex: 1;
    min-width: 150px;
}

/* Settings Layout */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

@media (max-width: 900px) {
    .settings-grid {
        grid-template-columns: 1fr;
    }
}

.settings-group {
    background: var(--bg-hover);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.settings-group h4 {
    margin-top: 0;
    margin-bottom: 15px;
    color: var(--text-main);
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.settings-group h4 i {
    color: var(--primary);
}

.settings-footer {
    text-align: right;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

.file-input-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
    width: 100%;
}
.file-input-wrapper input[type=file] {
    font-size: 100px;
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    cursor: pointer;
    height: 100%;
}
.file-input-button {
    border: 1px dashed var(--primary);
    background: rgba(74, 222, 128, 0.05);
    color: var(--primary);
    padding: 15px;
    text-align: center;
    border-radius: 8px;
    display: block;
    cursor: pointer;
    transition: all 0.3s ease;
}
.file-input-wrapper:hover .file-input-button {
    background: rgba(74, 222, 128, 0.15);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.full-width {
    grid-column: 1 / -1;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background-color: var(--primary);
    color: #000;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-success {
    background-color: #10b981;
    color: white;
}

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

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: var(--bg-hover);
}

.btn-icon {
    padding: 6px 10px;
    font-size: 1rem;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 1rem;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 1rem 0;
}
.filters .input-control {
    flex: 1;
    min-width: 140px;
}

/* Report total rows - visible on both screen and print */
.report-total-row {
    background-color: var(--bg-hover) !important;
    border-top: 2px solid var(--border);
    font-weight: bold;
}
.report-total-row td {
    padding: 6px 12px !important;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

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

.modal-content {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    animation: scaleIn 0.3s ease;
    max-height: 90vh;
    overflow-y: auto;
}

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

.close-modal {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.close-modal:hover { color: var(--text-main); }

.modal-body {
    padding: 1.5rem;
}

@keyframes scaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background-color: var(--bg-card);
    color: var(--text-main);
    border-left: 4px solid var(--primary);
    padding: 12px 20px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.95rem;
    animation: toastSlideIn 0.3s ease forwards;
    opacity: 0;
    transform: translateX(100%);
    min-width: 250px;
    max-width: 350px;
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.warning {
    border-left-color: #f59e0b; /* Amber */
}

.toast-icon {
    font-size: 1.2rem;
}
.toast.success .toast-icon { color: var(--primary); }
.toast.error .toast-icon { color: var(--danger); }
.toast.warning .toast-icon { color: #f59e0b; }

@keyframes toastSlideIn {
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastSlideOut {
    to { opacity: 0; transform: translateX(100%); }
}

/* Image Preview */
.image-preview {
    margin-top: 10px;
    max-width: 200px;
    max-height: 100px;
    border: 1px dashed var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    border-radius: 8px;
}

.image-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Invoice Layout */
.invoice-builder-layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* Left form panel: scrollable, sticky */
.invoice-controls.card {
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
    position: sticky;
    top: 0;
}

.invoice-controls.card::-webkit-scrollbar {
    width: 5px;
}
.invoice-controls.card::-webkit-scrollbar-track {
    background: transparent;
}
.invoice-controls.card::-webkit-scrollbar-thumb {
    background-color: var(--primary);
    border-radius: 10px;
}

/* Right preview panel: always show full invoice */
.invoice-preview-container {
    background-color: #3a3d42;
    padding: 1.5rem;
    border-radius: var(--radius);
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* The actual paper style that mimics the image */
.invoice-paper {
    background-color: white;
    color: black;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    width: 210mm !important; /* Force A4 width */
    min-width: 210mm !important; /* PREVENT SHRINKING ON MOBILE */
    max-width: none !important;
    min-height: 297mm; /* A4 height */
    margin: 0 auto; /* Center horizontally */
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Receipt / BKM Layout */
.receipt-paper {
    background-color: white;
    color: black;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    width: 210mm !important; /* Force A4 width */
    min-width: 210mm !important;
    max-width: none !important;
    min-height: 148mm; /* Half A4 approx */
    margin: 0 auto;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.receipt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 4px double #333;
    padding-bottom: 15px;
    margin-bottom: 25px;
}
.receipt-logo img {
    max-height: 60px;
}
.receipt-logo h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--primary);
}
.receipt-title {
    text-align: right;
}
.receipt-title h1 {
    font-size: 1.8rem;
    margin: 0 0 5px 0;
    letter-spacing: 2px;
}
.receipt-title p {
    margin: 0;
    color: #555;
    font-weight: bold;
}
.receipt-body {
    display: flex;
    flex-direction: column;
    gap: 15px;
    font-size: 1.1rem;
    line-height: 1.6;
    flex: 1;
}
.receipt-row {
    display: flex;
    align-items: flex-end;
}
.receipt-label {
    width: 200px;
    font-weight: 600;
    font-style: italic;
    color: #444;
}
.receipt-value {
    flex: 1;
    border-bottom: 1px dashed #777;
    padding-bottom: 2px;
    padding-left: 10px;
    font-weight: bold;
}
.receipt-value-box {
    background-color: #f8f9fa;
    border: 2px solid #ccc;
    padding: 10px 20px;
    font-size: 1.3rem;
    font-weight: bold;
    display: inline-block;
    border-radius: 4px;
    color: #333;
}
.receipt-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 40px;
    align-items: flex-end;
}
.receipt-signature {
    text-align: center;
    width: 220px;
}
.receipt-sig-img {
    height: 80px;
    margin: 10px 0;
}
.receipt-sig-img img {
    max-height: 100%;
}

/* Report Paper specific for screen */
.report-paper {
    background-color: var(--bg-card);
    padding: 30px;
    border-radius: 8px;
    border: 1px solid var(--border);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* Always 3 columns inside report paper */
.report-paper .summary-cards {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 1rem !important;
    margin-bottom: 1.5rem !important;
}

/* Override: Laba Bersih should NOT span full width inside report */
.report-paper .summary-card:last-child {
    grid-column: span 1 !important;
}

/* Report summary cards: centered text, no icon */
.report-paper .summary-card {
    flex-direction: column !important;
    align-items: center !important;
    text-align: center !important;
    padding: 1rem !important;
    gap: 0.4rem !important;
    justify-content: center !important;
}

.report-paper .card-info {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.report-paper .card-info p {
    font-size: 0.8rem !important;
    margin-bottom: 4px !important;
}

.report-paper .card-info h3 {
    font-size: 1.2rem !important;
    font-weight: 700 !important;
}

/* Report header */
.report-header {
    text-align: center;
    padding-bottom: 20px;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border);
}

.report-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.report-header h3 {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.report-header p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* Report section headings */
.report-section h4 {
    font-size: 0.95rem;
    font-weight: 700;
    padding-bottom: 6px;
    margin-bottom: 8px;
    margin-top: 8px;
}

/* Print utility classes */
.print-only {
    display: none;
}

@media print {
    .print-only {
        display: block;
    }
}

.inv-header {
    text-align: center;
    padding: 15px 40px;
}

.inv-header img {
    max-height: 80px;
    max-width: 100%;
}

.inv-title {
    text-align: center;
    font-size: 24px;
    font-weight: bold;
    text-decoration: underline;
    margin: 30px 0;
}

.inv-top-section {
    display: flex;
    justify-content: space-between;
    padding: 0 40px;
    margin-bottom: 30px;
}

.inv-bill-to h4 {
    background-color: #d1f2eb;
    padding: 5px 10px;
    display: inline-block;
    margin-bottom: 10px;
    color: #117a65;
}

.inv-meta table {
    width: 300px;
}

.inv-meta table td {
    padding: 3px 0;
}

.inv-meta table td:first-child {
    width: 100px;
}

.inv-details {
    padding: 0 40px;
}

.inv-details h4 {
    margin-bottom: 10px;
}

.inv-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.inv-table th {
    background-color: #d1f2eb;
    padding: 10px;
    text-align: left;
}

.inv-table td {
    padding: 10px;
    border-bottom: 1px solid #eee;
}

.inv-summary {
    display: flex;
    justify-content: flex-end;
    padding: 0 40px;
    margin-bottom: 40px;
}

.inv-summary table {
    width: 300px;
}

.inv-summary td {
    padding: 5px 10px;
}

.inv-summary tr.grand-total {
    background-color: #fadbd8;
    font-weight: bold;
}

.inv-bottom-section {
    display: flex;
    justify-content: space-between;
    padding: 0 40px;
    margin-bottom: 100px; /* Space for footer */
}

.inv-terms {
    width: 50%;
}

.inv-terms h4 {
    background-color: #d1f2eb;
    padding: 5px 10px;
    display: inline-block;
    margin-bottom: 10px;
    color: #117a65;
}

.inv-terms ol {
    padding-left: 20px;
}

.inv-terms li {
    margin-bottom: 5px;
}

.inv-payment-box {
    background-color: #d1f2eb;
    padding: 15px;
    margin-top: 20px;
    text-align: center;
    border-left: 10px solid #2ecc71;
}

.inv-approval {
    text-align: center;
    width: 200px;
}

.inv-approval-sig {
    height: 80px;
    margin: 10px 0;
}

.inv-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
}

.inv-footer img {
    width: 100%;
    display: block;
}

.inv-footer-default {
    background-color: #2ecc71;
    color: white;
    padding: 20px;
    text-align: center;
    display: flex;
    justify-content: space-around;
}

/* Invoice Builder Layout */
.invoice-builder-layout {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}

.invoice-controls {
    flex: 0 0 380px;
    max-width: 380px;
    position: sticky;
    top: 0;
    max-height: 100vh;
    overflow-y: auto;
}

.invoice-preview-container {
    flex: 1;
    overflow-x: auto;
}

/* Mobile Navigation */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ============================================
   RESPONSIVE LAYOUTS - Comprehensive Mobile Fix
   ============================================ */
@media (max-width: 768px) {

    /* --- Sidebar Offcanvas --- */
    .sidebar {
        transform: translateX(-100%);
        z-index: 100;
        transition: transform 0.3s ease;
        box-shadow: 4px 0 15px rgba(0,0,0,0.6);
    }
    .sidebar.active {
        transform: translateX(0);
    }
    .menu-toggle {
        display: block;
    }

    /* --- Main Content: full width, no sidebar margin --- */
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 1rem;
        height: 100vh;
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* --- Topbar: single row hamburger | title | logout --- */
    .topbar {
        flex-wrap: nowrap;
        gap: 8px;
        margin-bottom: 1rem;
        align-items: center;
    }
    .topbar-left {
        flex: 1;
        min-width: 0;
        gap: 8px;
    }
    .topbar-left h1 {
        font-size: 1.1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    #page-title { font-size: 1.1rem; }
    .period-selector {
        flex-shrink: 1;
        min-width: 0;
    }
    .period-selector input {
        min-width: 0;
        width: 110px;
        font-size: 0.8rem;
    }
    #company-name-display { display: none; }
    .user-info {
        position: static;
        flex-shrink: 0;
    }
    .avatar {
        width: 34px;
        height: 34px;
        font-size: 0.9rem;
    }

    /* --- Cards & Summary --- */
    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        margin-bottom: 1rem;
    }
    .summary-card {
        flex-direction: column;
        text-align: center;
        padding: 0.75rem 0.4rem;
        gap: 0.4rem;
    }
    .summary-card:last-child {
        grid-column: span 2;
    }
    .card-icon {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }
    .card-info h3 {
        font-size: 1rem;
    }
    .card-info p, .card-info small {
        font-size: 0.75rem;
    }
    .card {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    /* --- Dashboard Lists --- */
    .dashboard-lists .list-card {
        flex: 0 0 calc(100% - 1rem);
    }

    /* --- Card Headers (title + buttons row) --- */
    .card-header.flex-between {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .card-header.flex-between > div {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
    }
    .card-header.flex-between .btn {
        flex: 1;
        min-width: 120px;
        font-size: 0.8rem;
        padding: 8px 10px;
        text-align: center;
        white-space: nowrap;
    }

    /* --- Flex Layouts --- */
    .flex-between {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .flex-between > div {
        width: 100%;
    }

    /* --- PROTECT INVOICE PAPER FROM MOBILE OVERRIDES --- */
    .invoice-paper .flex-between,
    .invoice-paper .gw-header {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
    }
    .invoice-paper .flex-between > div {
        width: auto !important;
    }
    .invoice-paper .inv-top-section {
        flex-direction: row !important;
        align-items: flex-start !important;
    }
    .invoice-paper .inv-top-section > div {
        width: auto !important;
    }
    .invoice-paper .inv-bottom-section {
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
    }
    .invoice-paper .inv-bottom-section > div {
        width: auto !important;
    }

    /* --- Filters --- */
    .filters {
        flex-direction: column;
        gap: 8px;
    }
    .filters .input-control {
        width: 100%;
    }

    /* --- Tables --- */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .table th, .table td {
        padding: 8px 10px;
        font-size: 0.8rem;
        white-space: nowrap;
    }
    .table td button {
        margin-bottom: 4px;
        font-size: 0.75rem;
        padding: 5px 8px;
    }

    /* --- Modals & Toasts --- */
    .modal-content {
        width: 95%;
        max-height: 90vh;
        margin: 5% auto;
        padding: 1.25rem;
        overflow-y: auto;
    }
    #toast-container {
        bottom: 20px;
        right: 10px;
        left: 10px;
        align-items: center;
    }
    .toast {
        min-width: unset;
        width: 100%;
        max-width: 400px;
        font-size: 0.85rem;
    }
    .form-grid {
        grid-template-columns: 1fr !important;
    }

    /* --- Settings --- */
    .settings-grid {
        grid-template-columns: 1fr !important;
        gap: 0;
    }

    /* --- Invoice Builder --- */
    .invoice-builder-layout {
        flex-direction: column !important;
    }
    .invoice-controls {
        flex: unset !important;
        max-width: 100% !important;
        position: static !important;
        max-height: unset !important;
        width: 100%;
    }
    .invoice-preview-container {
        width: 100%;
        margin-top: 20px;
        padding: 0;
        overflow-x: hidden;
    }
    .invoice-preview-container .invoice-paper,
    .invoice-preview-container .receipt-paper {
        transform: scale(0.45);
        transform-origin: top center;
        margin-bottom: -160mm; /* A4 height is 296mm, 45% is ~133mm. This removes the empty space */
    }

    /* --- Laporan (Reports) --- */
    .report-paper {
        padding: 1rem !important;
        overflow-x: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    .report-paper .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    }
}

/* --- Form Clean Modes --- */
#transaction-form.mode-clean-income .group-master-data,
#transaction-form.mode-clean-income .group-qty,
#transaction-form.mode-clean-income .group-ppn,
#transaction-form.mode-clean-income .tx-due-date-group,
#transaction-form.mode-clean-income #tx-customer-group {
    display: none !important;
}

#transaction-form.mode-clean-expense .group-master-data,
#transaction-form.mode-clean-expense .group-qty,
#transaction-form.mode-clean-expense .group-ppn {
    display: none !important;
}

#transaction-form.mode-semi-expense .group-master-data {
    display: none !important;
}

/* Print Styles - Optimized for A4 */
@media print {
    @page {
        size: A4 portrait;
        margin: 0; /* Invoice paper handles its own padding */
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        box-sizing: border-box !important;
    }

    body, html {
        background-color: white !important;
        color: black !important;
        height: 296mm !important;
        max-height: 296mm !important;
        min-height: 0 !important;
        overflow: hidden !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 210mm !important;
        font-size: 10pt !important;
    }

    .invoice-preview-container .invoice-paper,
    .invoice-paper,
    .receipt-paper {
        transform: none !important;
        margin: 0 auto !important;
    }

    /* Hide non-print elements */
    .no-print,
    .sidebar,
    .topbar,
    .table-responsive > ::-webkit-scrollbar {
        display: none !important;
    }

    /* Main layout reset for print */
    #app-wrapper {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
        background: white !important;
        display: block !important;
        height: auto !important;
        overflow: visible !important;
        width: 100% !important;
    }

    .pages-container {
        padding: 0 !important;
        width: 100% !important;
    }

    /* Show only active invoice page */
    .page {
        display: none !important;
    }
    #invoice.page.active {
        display: block !important;
        width: 210mm !important;
        height: 296mm !important;
        max-height: 296mm !important;
        overflow: hidden !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    #reports.page.active {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* ---- REPORT PAPER A4 FIT ---- */
    .report-paper {
        margin: 0 !important;
        padding: 0 !important; /* Rely on @page margin instead */
        width: 100% !important;
        max-width: 100% !important;
        min-height: auto !important;
        box-shadow: none !important;
        background: white !important;
        color: black !important;
        border: none !important;
        overflow: visible !important;
    }

    /* Remove scrollable wrapper for print */
    .report-paper .table-responsive {
        overflow: visible !important;
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Report tables: smaller font, fit all columns */
    .report-paper table {
        width: 100% !important;
        border-collapse: collapse !important;
        font-size: 8pt !important;
        table-layout: auto !important;
        page-break-inside: auto !important;
        overflow: visible !important;
    }
    .report-paper th,
    .report-paper td {
        padding: 3px 5px !important;
        font-size: 8pt !important;
        white-space: normal !important;
        word-break: break-word !important;
        border: 1px solid #999 !important;
        color: black !important;
        background: transparent !important;
    }
    .report-paper tr {
        page-break-inside: avoid !important;
        page-break-after: auto !important;
        page-break-before: auto !important;
    }
    .report-paper th {
        background-color: #e0e0e0 !important;
        font-weight: bold !important;
    }
    /* Total rows (tfoot) - light background so text is visible */
    .report-paper tfoot tr,
    .report-paper tfoot td,
    .report-total-row,
    .report-total-row td {
        background-color: #d5d5d5 !important;
        color: #000 !important;
        font-weight: bold !important;
        border-top: 2px solid #555 !important;
    }
    .report-paper tfoot td:last-child,
    .report-paper tfoot td[style*="right"] {
        color: #000 !important;
        white-space: nowrap !important;
    }
    .report-paper tfoot td {
        white-space: nowrap !important;
    }
    
    /* Native table behavior usually handles footers best, but we moved totals to tbody */
    .report-paper tfoot {
        display: none !important;
    }

    /* Summary cards in report - 3 equal columns, centered */
    .report-paper .summary-cards {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 6px !important;
        margin-bottom: 10px !important;
    }
    .report-paper .summary-card {
        background: #f0f0f0 !important;
        border: 1px solid #ccc !important;
        padding: 6px !important;
        color: black !important;
        border-radius: 4px !important;
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        justify-content: center !important;
        grid-column: span 1 !important;
    }
    .report-paper .summary-card:last-child {
        grid-column: span 1 !important;
    }
    .report-paper .card-info {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    .report-paper .card-info h3 {
        font-size: 11pt !important;
        color: black !important;
        font-weight: bold !important;
        margin: 0 !important;
    }
    .report-paper .card-info p {
        font-size: 7pt !important;
        color: #555 !important;
        margin-bottom: 2px !important;
    }

    /* Report header */
    .report-header {
        text-align: center !important;
        padding-bottom: 8px !important;
        margin-bottom: 10px !important;
        border-bottom: 2px solid #000 !important;
    }

    /* Report headings */
    .report-paper h2 { font-size: 14pt !important; font-weight: bold !important; margin-bottom: 2px !important; }
    .report-paper h3 { font-size: 10pt !important; letter-spacing: 1px !important; margin-bottom: 2px !important; }
    .report-paper p { font-size: 9pt !important; }
    .report-paper h4 { font-size: 9pt !important; margin: 8px 0 3px !important; font-weight: bold !important; }

    /* === PAGE BREAK CONTROLS === */
    /* Let content flow naturally — fill current page first, overflow to next */
    .report-section {
        margin-top: 8px !important;
        margin-bottom: 0 !important;
    }
    
    /* Allow table bodies to break across pages */
    .report-paper tbody {
        page-break-inside: auto !important;
    }

    /* Reset color classes for black print */
    .report-paper .text-danger,
    .report-paper .text-primary,
    .report-paper .text-muted {
        color: black !important;
    }

    /* ---- INVOICE PAPER A4 FIT ---- */

    /* Step 1: Reset ALL wrappers to zero */
    .invoice-builder-layout {
        display: block !important;
        gap: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    .invoice-controls,
    .invoice-builder-panel {
        display: none !important;
    }
    .invoice-preview-container {
        display: block !important;
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        background: white !important;
        overflow: visible !important;
    }
    #invoice.page.active {
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Step 2: The invoice paper — fill entire A4 page */
    .invoice-paper,
    .invoice-paper.template-green-wave {
        display: flex !important;
        flex-direction: column !important;
        margin: 0 !important;
        width: 210mm !important;
        max-width: 210mm !important;
        min-height: 0 !important;
        height: 296mm !important;
        max-height: 296mm !important;
        box-shadow: none !important;
        background: white !important;
        color: black !important;
        border: none !important;
        border-radius: 0 !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
        position: relative !important;
        page-break-after: avoid !important;
        break-after: avoid !important;
    }

    /* ===== PRINT: DEFAULT template ===== */
    .invoice-paper:not(.template-green-wave) {
        padding: 8mm 12mm !important;
    }
    .invoice-paper:not(.template-green-wave) .inv-header { padding: 5px 20px !important; flex-shrink: 0 !important; }
    .invoice-paper:not(.template-green-wave) .inv-title { margin: 12px 0 !important; font-size: 1.4rem !important; flex-shrink: 0 !important; }
    .invoice-paper:not(.template-green-wave) .inv-top-section { margin-bottom: 10px !important; padding: 0 20px !important; flex-shrink: 0 !important; }
    .invoice-paper:not(.template-green-wave) .inv-details { padding: 0 20px !important; flex-shrink: 0 !important; }
    .invoice-paper:not(.template-green-wave) .inv-table { margin-bottom: 5px !important; }
    .invoice-paper:not(.template-green-wave) .inv-table th,
    .invoice-paper:not(.template-green-wave) .inv-table td { padding: 4px 6px !important; font-size: 0.8rem !important; }
    .invoice-paper:not(.template-green-wave) .inv-summary { padding: 0 20px !important; margin-bottom: 10px !important; flex-shrink: 0 !important; display: flex !important; justify-content: flex-end !important; }
    .invoice-paper:not(.template-green-wave) .inv-summary td { padding: 3px 6px !important; font-size: 0.85rem !important; }
    .invoice-paper:not(.template-green-wave) .inv-bottom-section {
        margin-bottom: 0 !important;
        padding: 0 20px !important;
        flex-shrink: 0 !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
    }
    .invoice-paper:not(.template-green-wave) .inv-bottom-section > div { width: auto !important; }
    .invoice-paper:not(.template-green-wave) .inv-terms { width: 50% !important; }
    .invoice-paper:not(.template-green-wave) .inv-terms ol { font-size: 0.75rem !important; }
    .invoice-paper:not(.template-green-wave) .inv-payment-box { padding: 8px !important; margin-top: 8px !important; font-size: 0.8rem !important; }
    .invoice-paper:not(.template-green-wave) .inv-approval-sig { height: 50px !important; margin: 3px 0 !important; }
    .invoice-paper:not(.template-green-wave) .inv-footer {
        position: static !important;
        margin-top: auto !important;
        flex-shrink: 0 !important;
        margin-left: -12mm !important;
        margin-right: -12mm !important;
        margin-bottom: -8mm !important;
        width: calc(100% + 24mm) !important;
    }
    .invoice-paper:not(.template-green-wave) .inv-footer img {
        width: 100% !important;
        display: block !important;
    }
    .invoice-paper:not(.template-green-wave) .inv-footer-default {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-around !important;
        align-items: center !important;
    }

    /* ===== PRINT: GREEN WAVE template ===== */
    .template-green-wave { padding: 0 !important; }
    .template-green-wave .gw-content {
        padding: 40px 50px 180px 50px !important;
        flex: 1 !important;
        position: relative !important;
        z-index: 2 !important;
    }
    /* Waves stay absolute (decorative overlay) so they DON'T waste A4 space */
    .template-green-wave .green-wave-bg.top-wave {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        z-index: 1 !important;
    }
    .template-green-wave .green-wave-bg.bottom-wave {
        position: absolute !important;
        bottom: 0 !important;
        left: 0 !important;
        z-index: 1 !important;
        width: 100% !important;
    }
    .template-green-wave .gw-header {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
    }
    .template-green-wave .gw-header > div { width: auto !important; }
    .template-green-wave .gw-title-container { margin-top: 40px !important; margin-bottom: 8px !important; }
    .template-green-wave .gw-title-container h1 { font-size: 1.8rem !important; }
    .template-green-wave .gw-meta-grid { margin-bottom: 8px !important; gap: 8px !important; font-size: 0.8rem !important; }
    .template-green-wave .gw-table { margin-bottom: 8px !important; }
    .template-green-wave .gw-table th,
    .template-green-wave .gw-table td { padding: 4px 6px !important; font-size: 0.8rem !important; }
    .template-green-wave .gw-bottom-grid { margin-bottom: 5px !important; gap: 8px !important; }
    .template-green-wave .gw-payment-info { font-size: 0.75rem !important; }
    .template-green-wave .gw-summary-table td { padding: 3px 6px !important; font-size: 0.8rem !important; }
    .template-green-wave .gw-footer-grid { margin-bottom: 0 !important; font-size: 0.8rem !important; }

    /* PROTECT INVOICE FROM MOBILE OVERRIDES IN PRINT */
    .invoice-paper .flex-between,
    .invoice-paper .gw-header {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
    }
    .invoice-paper .flex-between > div { width: auto !important; }
    .invoice-paper .inv-top-section {
        flex-direction: row !important;
        align-items: flex-start !important;
    }
    .invoice-paper .inv-top-section > div { width: auto !important; }

}

/* ============================================
   LOGIN SCREEN - Fully Responsive & Premium
   ============================================ */
#login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    width: 100%;
    padding: 1rem;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;

    /* Animated gradient background */
    background: linear-gradient(135deg, #0f0f0f 0%, #1a1a2e 30%, #16213e 60%, #0f3460 100%);
    background-size: 400% 400%;
    animation: loginBgShift 12s ease infinite;
}

@keyframes loginBgShift {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Decorative glowing orbs */
#login-wrapper::before,
#login-wrapper::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.25;
    pointer-events: none;
    animation: orbFloat 8s ease-in-out infinite alternate;
}

#login-wrapper::before {
    width: min(400px, 60vw);
    height: min(400px, 60vw);
    background: radial-gradient(circle, #4ade80 0%, transparent 70%);
    top: -15%;
    left: -10%;
}

#login-wrapper::after {
    width: min(350px, 50vw);
    height: min(350px, 50vw);
    background: radial-gradient(circle, #22d3ee 0%, transparent 70%);
    bottom: -15%;
    right: -10%;
    animation-delay: -4s;
}

@keyframes orbFloat {
    from { transform: translate(0, 0) scale(1); }
    to   { transform: translate(20px, -20px) scale(1.08); }
}

/* The login card box */
.login-box {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    padding: clamp(1.5rem, 5vw, 2.5rem);
    margin: 0 auto;

    /* Glassmorphism */
    background: rgba(30, 30, 30, 0.75);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(74, 222, 128, 0.18);
    border-radius: 20px;
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255,255,255,0.04) inset;

    animation: loginSlideUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes loginSlideUp {
    from { opacity: 0; transform: translateY(40px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

/* Login header / branding */
.login-header {
    text-align: center;
    margin-bottom: clamp(1.25rem, 4vw, 2rem);
}

.login-header i.fa-wallet {
    display: block;
    font-size: clamp(2rem, 8vw, 2.8rem);
    margin-bottom: 12px;
    color: var(--primary);
    filter: drop-shadow(0 0 12px rgba(74, 222, 128, 0.5));
    animation: iconPulse 3s ease-in-out infinite;
}

@keyframes iconPulse {
    0%, 100% { filter: drop-shadow(0 0 8px  rgba(74, 222, 128, 0.4)); }
    50%       { filter: drop-shadow(0 0 18px rgba(74, 222, 128, 0.75)); }
}

.login-header h2 {
    font-size: clamp(1.4rem, 5vw, 2rem);
    font-weight: 700;
    margin-bottom: 6px;
    letter-spacing: 1px;
    background: linear-gradient(135deg, #ffffff 40%, #4ade80 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-header p.text-muted {
    font-size: clamp(0.8rem, 3vw, 0.95rem);
    color: var(--text-muted);
    margin: 0;
}

/* Login form inputs */
#login-form .form-group {
    margin-bottom: clamp(0.75rem, 2.5vw, 1rem);
}

#login-form .input-control {
    padding: clamp(10px, 2.5vw, 13px) clamp(12px, 3vw, 16px);
    font-size: clamp(0.85rem, 3vw, 1rem);
    background: rgba(18, 18, 18, 0.8);
    border: 1px solid rgba(74, 222, 128, 0.2);
    border-radius: 10px;
    transition: border-color 0.25s, box-shadow 0.25s;
}

#login-form .input-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.15);
}

#login-form .form-group label {
    font-size: clamp(0.78rem, 2.5vw, 0.88rem);
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

/* Login button */
#login-form .btn-primary {
    width: 100%;
    padding: clamp(11px, 3vw, 14px);
    font-size: clamp(0.9rem, 3vw, 1rem);
    font-weight: 700;
    border-radius: 10px;
    letter-spacing: 0.5px;
    margin-top: clamp(0.25rem, 1.5vw, 0.5rem);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    box-shadow: 0 4px 15px rgba(74, 222, 128, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#login-form .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(74, 222, 128, 0.45);
}

#login-form .btn-primary:active {
    transform: translateY(0);
}

/* Error message */
#login-error {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: clamp(0.8rem, 2.5vw, 0.9rem);
    color: var(--danger);
    text-align: center;
    animation: shake 0.4s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%       { transform: translateX(-8px); }
    40%       { transform: translateX(8px); }
    60%       { transform: translateX(-5px); }
    80%       { transform: translateX(5px); }
}

/* --- Responsive overrides for very small phones --- */
@media (max-width: 360px) {
    .login-box {
        padding: 1.25rem 1rem;
        border-radius: 14px;
    }
    .login-header h2 {
        font-size: 1.3rem;
    }
}

/* --- Landscape phones (short height) --- */
@media (max-height: 600px) and (orientation: landscape) {
    #login-wrapper {
        align-items: flex-start;
        padding: 0.75rem 1rem;
    }
    .login-box {
        padding: 1.25rem 1.5rem;
    }
    .login-header {
        margin-bottom: 0.75rem;
    }
    .login-header i.fa-wallet {
        font-size: 1.5rem;
        margin-bottom: 6px;
    }
    #login-form .form-group {
        margin-bottom: 0.6rem;
    }
}

/* --- Tablets (768px+) --- */
@media (min-width: 768px) {
    .login-box {
        max-width: 440px;
    }
}

/* --- Large screens --- */
@media (min-width: 1200px) {
    .login-box {
        max-width: 460px;
    }
}

/* ============================================
   ROLE BADGES
   ============================================ */
.role-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.role-admin {
    background: rgba(74, 222, 128, 0.15);
    color: var(--primary);
    border: 1px solid rgba(74, 222, 128, 0.35);
}

.role-staff {
    background: rgba(56, 189, 248, 0.15);
    color: #38bdf8;
    border: 1px solid rgba(56, 189, 248, 0.35);
}

.role-viewer {
    background: rgba(160, 160, 160, 0.15);
    color: var(--text-muted);
    border: 1px solid rgba(160, 160, 160, 0.3);
}

/* ============================================
   TOPBAR USER INFO (company + user badge)
   ============================================ */
.topbar-user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    min-width: 0;
}

.company-name-display {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.topbar-user-meta {
    display: flex;
    align-items: center;
    gap: 6px;
}

.topbar-user-name {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

/* Hide company name on small mobile, keep user name */
@media (max-width: 480px) {
    .company-name-display { display: none; }
    .topbar-user-name { max-width: 80px; }
}
@media (max-width: 360px) {
    .topbar-user-name { display: none; }
}

/* ============================================
   ALERT MESSAGES (success / danger)
   ============================================ */
.alert-msg {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.88rem;
    margin-bottom: 12px;
    font-weight: 500;
}

.alert-danger {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: var(--danger);
}

.alert-success {
    background: rgba(74, 222, 128, 0.12);
    border: 1px solid rgba(74, 222, 128, 0.35);
    color: var(--primary);
}

/* ============================================
   ROLE LEGEND (on users page)
   ============================================ */
.role-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background: var(--bg-hover);
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

/* ============================================
   BTN-SM (small button variant)
   ============================================ */
.btn-sm {
    padding: 5px 12px;
    font-size: 0.8rem;
}

/* ============================================
   SETTINGS TABS
   ============================================ */
.settings-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
}

.settings-tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 8px 16px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius);
    transition: var(--transition);
    white-space: nowrap;
}

.settings-tab-btn:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

.settings-tab-btn.active {
    background: rgba(74, 222, 128, 0.15);
    color: var(--primary);
}

.settings-tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.settings-tab-content.active {
    display: block;
}

/* ============================================
   SETTINGS GRID LAYOUT (Responsive 2-Column)
   ============================================ */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 992px) {
    .settings-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* ============================================
   ROLE-BASED ACCESS CONTROL (RBAC)
   ============================================ */
/* Viewers cannot see staff-level action buttons (add/edit/delete/generate) */
body.role-viewer .action-require-staff {
    display: none !important;
}

/* Viewers cannot see staff-level navigation */
body.role-viewer .nav-require-staff {
    display: none !important;
}

/* Viewers and Staff cannot see admin-only navigation/sections */
body.role-viewer .nav-admin-only,
body.role-staff .nav-admin-only {
    display: none !important;
}

/* ============================================
   INVOICE TEMPLATES
   ============================================ */
/* TEMPLATE 2: GREEN WAVE */
.template-green-wave {
    padding: 0 !important;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    color: #1f2937;
    position: relative;
    overflow: hidden;
    background: #fff;
    min-height: 297mm; /* A4 size */
}

.template-green-wave .gw-content {
    padding: 40px 50px 180px 50px; /* 180px bottom padding protects the bottom wave */
    position: relative;
    z-index: 2;
}

.green-wave-bg {
    position: absolute;
    left: 0;
    width: 100%;
    z-index: 1;
}

.green-wave-bg.top-wave {
    top: 0;
    height: 250px;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 1000 300' preserveAspectRatio='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='%23f3f4f6' d='M0,0 L1000,0 L1000,200 Q500,300 0,280 Z'/%3E%3Cpath fill='%23e5e7eb' opacity='0.5' d='M0,0 L1000,0 L1000,120 Q500,200 0,260 Z'/%3E%3Cpath fill='%2300B050' d='M0,0 L950,0 Q400,80 0,280 Z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: top center;
}

.green-wave-bg.bottom-wave {
    bottom: 0;
    height: 160px;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 1000 200' preserveAspectRatio='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='%23f3f4f6' d='M0,0 C200,0 250,150 0,200 Z'/%3E%3Cpath fill='%2300B050' d='M0,170 Q400,210 1000,0 L1000,200 L0,200 Z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: bottom center;
    display: flex;
    align-items: flex-end;
    padding: 25px 50px;
    box-sizing: border-box;
}

.gw-bottom-contact {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    color: white;
    width: 100%;
    font-size: 0.95rem;
    z-index: 2;
}

.gw-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}
.gw-logo {
    max-height: 80px;
}
.gw-title-container {
    text-align: center;
    margin-top: 70px;
    margin-bottom: 30px;
}
.gw-title-container h1 {
    font-size: 2.8rem;
    color: #111827;
    margin: 0;
    letter-spacing: 1px;
}
.gw-title-container p {
    font-size: 1.2rem;
    margin: 5px 0 0 0;
    color: #4b5563;
}

.gw-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
    font-size: 0.95rem;
}

.gw-label {
    font-weight: bold;
    margin: 0 0 5px 0;
    color: #111827;
}

.gw-bill-to h3 {
    margin: 0 0 15px 0;
    color: #4b5563;
    font-weight: normal;
}

.gw-address {
    margin: 0;
    color: #4b5563;
    line-height: 1.5;
}

.gw-meta-table {
    border-collapse: collapse;
}
.gw-meta-table td {
    padding: 6px 15px 6px 0;
    color: #111827;
}

.gw-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.gw-table th {
    background-color: #d1d5db;
    color: #111827;
    padding: 12px;
    border: 1px solid #9ca3af;
    font-weight: bold;
}

.gw-table td {
    padding: 12px;
    border: 1px solid #d1d5db;
    color: #111827;
}

.gw-table tbody tr:nth-child(even) {
    background-color: #f3f4f6;
}

.gw-bottom-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 40px;
}

.gw-payment-info {
    font-size: 0.85rem;
    color: #111827;
    padding-right: 20px;
}
.gw-payment-info ol {
    margin: 10px 0 0 0;
    padding-left: 20px;
}
.gw-payment-info li {
    margin-bottom: 5px;
}

.gw-summary-table {
    width: 100%;
    border-collapse: collapse;
}
.gw-summary-table td {
    padding: 10px;
    border: 1px solid #e5e7eb;
    color: #111827;
}

.gw-grand-total {
    background-color: #f3f4f6;
    font-size: 1.1rem;
}

.gw-footer-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    font-size: 0.9rem;
    margin-bottom: 0; 
}

.gw-bank-info {
    color: #111827;
}

.gw-signature {
    text-align: right;
    padding-right: 50px;
}
.gw-signature p {
    margin: 0;
    color: #111827;
}

/* Force backgrounds to print */
@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* --- Mobile Specific Fixes --- */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
    #sync-status-indicator {
        font-size: 0 !important;
        padding: 6px !important;
        width: 32px;
        height: 32px;
        border-radius: 50% !important;
        justify-content: center;
        gap: 0 !important;
    }
    #sync-status-indicator i {
        font-size: 0.9rem;
        margin: 0 !important;
    }
    #btn-push-cloud {
        font-size: 0 !important;
        padding: 6px !important;
        width: 32px;
        height: 32px;
        border-radius: 50% !important;
        justify-content: center;
        gap: 0 !important;
    }
    #btn-push-cloud i {
        font-size: 0.9rem;
        margin: 0 !important;
    }
}

@media (max-width: 900px) {
    /* Fix Invoice Builder Mobile Layout */
    .invoice-builder-layout {
        flex-direction: column;
    }
    .invoice-controls {
        flex: 1 1 100%;
        max-width: 100%;
        position: relative;
        max-height: none;
    }
    .invoice-preview-container {
        width: 100%;
        padding: 10px;
    }
}

/* BKM Mode Form Toggles */
form#invoice-form.bkm-mode .hide-on-bkm {
    display: none !important;
}

/* Hide save-settings footer when backup tab is active */
#tab-backup.active ~ .tab-save-footer,
#tab-backup.active + .tab-save-footer {
    display: none !important;
}
/* Hide save footer when on backup tab (sibling check via JS class on form) */
.settings-form-backup-mode .tab-save-footer {
    display: none !important;
}

