/* Invoicing System - Main Stylesheet */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

:root {
    --primary: #1a56db;
    --primary-light: #ebf0ff;
    --primary-dark: #1341b0;
    --success: #0e9f6e;
    --success-light: #e3faf3;
    --warning: #c27803;
    --warning-light: #fef3c7;
    --danger: #e02424;
    --danger-light: #fde8e8;
    --info: #0694a2;
    --info-light: #e3fafc;
    --dark: #111827;
    --gray-900: #1f2937;
    --gray-700: #374151;
    --gray-500: #6b7280;
    --gray-400: #9ca3af;
    --gray-300: #d1d5db;
    --gray-200: #e5e7eb;
    --gray-100: #f3f4f6;
    --gray-50: #f9fafb;
    --white: #ffffff;
    --sidebar-width: 240px;
    --header-height: 60px;
    --border-radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --font: 'DM Sans', sans-serif;
    --font-mono: 'DM Mono', monospace;
}

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

html { font-size: 15px; -webkit-font-smoothing: antialiased; }

body {
    font-family: var(--font);
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.6;
}

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

/* ===== LAYOUT ===== */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--white);
    border-right: 1px solid var(--gray-200);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-logo {
    padding: 14px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    overflow: hidden;
}

.sidebar-logo img {
    width: 160px;
    max-width: 100%;
    height: auto;
    display: block;
    flex-shrink: 0;
}

.sidebar-logo .logo-icon {
    width: 32px; height: 32px;
    background: var(--primary);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 16px; font-weight: 700;
}

.sidebar-logo span {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-900);
    line-height: 1.2;
}

.sidebar-logo small {
    display: block;
    font-size: 10px;
    color: var(--gray-500);
    font-weight: 400;
}

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }

.nav-section-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--gray-400);
    padding: 12px 20px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    color: var(--gray-600, #4b5563);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    border-left: 3px solid transparent;
    text-decoration: none;
}

.nav-item:hover {
    background: var(--gray-50);
    color: var(--gray-900);
    text-decoration: none;
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    border-left-color: var(--primary);
}

.nav-item svg { width: 17px; height: 17px; opacity: 0.8; flex-shrink: 0; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--gray-200);
}

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

.user-avatar {
    width: 32px; height: 32px;
    background: var(--primary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 13px; font-weight: 600;
    flex-shrink: 0;
}

.user-name { font-size: 13px; font-weight: 500; color: var(--gray-900); }
.user-role { font-size: 11px; color: var(--gray-500); }

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.top-header {
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-title { font-size: 16px; font-weight: 600; color: var(--gray-900); }

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

.page-content { padding: 24px; flex: 1; }

/* ===== CARDS ===== */
.card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title { font-size: 14px; font-weight: 600; color: var(--gray-900); }
.card-body { padding: 20px; }

/* ===== STAT CARDS ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}

.stat-label { font-size: 12px; color: var(--gray-500); font-weight: 500; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--gray-900); font-family: var(--font-mono); }
.stat-sub { font-size: 12px; color: var(--gray-500); margin-top: 4px; }
.stat-icon { font-size: 20px; margin-bottom: 10px; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13.5px;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover { text-decoration: none; }
.btn svg { width: 15px; height: 15px; }

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

.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-success:hover { background: #087f5b; color: white; }

.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #c81e1e; color: white; }

.btn-outline { background: white; color: var(--gray-700); border-color: var(--gray-300); }
.btn-outline:hover { background: var(--gray-50); color: var(--gray-900); }

.btn-ghost { background: transparent; color: var(--gray-600); border-color: transparent; }
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-900); }

.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; gap: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 5px;
}

label .required { color: var(--danger); margin-left: 2px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="tel"], input[type="url"], textarea, select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 13.5px;
    font-family: var(--font);
    color: var(--gray-900);
    background: white;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}

textarea { resize: vertical; min-height: 80px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; background-size: 16px; padding-right: 32px; }

.form-hint { font-size: 12px; color: var(--gray-500); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--danger); margin-top: 4px; }

/* ===== TABLES ===== */
.table-wrapper { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

thead th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
    vertical-align: middle;
}

tbody tr:hover { background: var(--gray-50); }
tbody tr:last-child td { border-bottom: none; }

.table-actions { display: flex; gap: 6px; align-items: center; }

/* ===== BADGES ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
}

.badge-paid { background: var(--success-light); color: var(--success); }
.badge-pending { background: var(--warning-light); color: var(--warning); }
.badge-overdue { background: var(--danger-light); color: var(--danger); }
.badge-draft { background: var(--gray-100); color: var(--gray-500); }
.badge-cancelled { background: var(--gray-100); color: var(--gray-500); }

/* ===== ALERTS ===== */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 13.5px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success { background: var(--success-light); color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger { background: var(--danger-light); color: #9b1c1c; border: 1px solid #f8b4b4; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fcd34d; }
.alert-info { background: var(--info-light); color: #164e63; border: 1px solid #a5f3fc; }

/* ===== SEARCH & FILTER BAR ===== */
.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.search-input-wrap { position: relative; flex: 1; min-width: 200px; max-width: 320px; }
.search-input-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--gray-400); }
.search-input-wrap input { padding-left: 34px; }

/* ===== PAGINATION ===== */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
    justify-content: flex-end;
}

.page-btn {
    padding: 5px 10px;
    border: 1px solid var(--gray-300);
    background: white;
    border-radius: 5px;
    font-size: 13px;
    cursor: pointer;
    color: var(--gray-700);
    font-family: var(--font);
    transition: all 0.15s;
}

.page-btn:hover { background: var(--gray-50); }
.page-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== MODALS ===== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}

.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
    background: white;
    border-radius: 10px;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: translateY(-20px);
    transition: transform 0.2s;
}

.modal-overlay.active .modal { transform: translateY(0); }
.modal-lg { max-width: 800px; }
.modal-xl { max-width: 1100px; }

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

.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--gray-400); font-size: 20px; line-height: 1; padding: 2px; }
.modal-close:hover { color: var(--gray-700); }
.modal-body { padding: 20px; }
.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ===== TABS ===== */
.tabs { display: flex; border-bottom: 1px solid var(--gray-200); margin-bottom: 20px; }
.tab {
    padding: 10px 18px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--gray-500);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.15s;
}
.tab:hover { color: var(--gray-900); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== INVOICE ITEMS TABLE ===== */
.items-table-wrap { overflow-x: auto; }
.items-table { width: 100%; border-collapse: collapse; }
.items-table th {
    padding: 8px 10px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-500);
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
}
.items-table td {
    padding: 8px 10px;
    border: 1px solid var(--gray-200);
    vertical-align: top;
}
.items-table input, .items-table select { border: none; padding: 4px; background: transparent; font-size: 13.5px; }
.items-table input:focus, .items-table select:focus { outline: none; background: var(--primary-light); border-radius: 3px; }

.amount-col { text-align: right; font-family: var(--font-mono); }

/* ===== TOTALS BOX ===== */
.totals-box {
    margin-left: auto;
    width: 300px;
    margin-top: 16px;
}
.totals-row {
    display: flex;
    justify-content: space-between;
    padding: 7px 0;
    font-size: 13.5px;
    border-bottom: 1px solid var(--gray-100);
}
.totals-row:last-child { border-bottom: none; font-weight: 700; font-size: 15px; }
.totals-row span:last-child { font-family: var(--font-mono); }

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--gray-500);
}
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 16px; opacity: 0.3; }
.empty-state h3 { font-size: 15px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
.empty-state p { font-size: 13.5px; }

/* ===== HAMBURGER ===== */
.hamburger { display: none; background: none; border: none; cursor: pointer; padding: 4px; }
.hamburger svg { width: 22px; height: 22px; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 99; }

/* ===== PRINT STYLES ===== */
@media print {
    .sidebar, .top-header, .no-print { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page-content { padding: 0 !important; }
    .card { border: none !important; box-shadow: none !important; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .hide-mobile { display: none !important; }

    /* Prevent any horizontal scroll on mobile */
    html, body { overflow-x: hidden; max-width: 100vw; }

    /* Sidebar */
    .sidebar {
        transform: translateX(-100%);
        bottom: 0;
        overflow: hidden; /* sidebar itself never scrolls — logo stays pinned */
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-logo {
        flex: 0 0 auto;
        background: var(--white);
        padding: 16px 20px;
    }
    .sidebar-nav {
        flex: 1 1 auto;
        min-height: 0; /* allows the nav to shrink and scroll inside flex column */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .sidebar-footer {
        flex: 0 0 auto;
        max-height: 40vh;
        overflow-y: auto;
    }
    .sidebar-overlay.active { display: block; }
    .main-content { margin-left: 0; overflow-x: hidden; }
    .hamburger { display: flex; }

    /* Stats cards */
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-card { min-width: 0; overflow: hidden; }
    .stat-card .stat-value { font-size: 18px; white-space: nowrap; overflow: visible; }

    /* Forms */
    .form-row.cols-2, .form-row.cols-3, .form-row.cols-4 { grid-template-columns: 1fr; }
    .page-content { padding: 16px; }
    .top-header { padding: 0 16px; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .search-input-wrap { max-width: 100%; }
    .totals-box { width: 100%; }

    /* Tables — horizontal scroll */
    .table-wrap, .data-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .data-table { min-width: 600px; }
    .data-table td, .data-table th { white-space: nowrap; }

    /* Filter tabs — horizontal scroll instead of stacking */
    .filter-tabs { display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; gap: 6px; padding-bottom: 4px; }
    .filter-tabs::-webkit-scrollbar { display: none; }
    .filter-tab, .tab { white-space: nowrap; flex-shrink: 0; }

    /* Bulk action bar */
    .bulk-actions { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .bulk-actions-inner { white-space: nowrap; min-width: max-content; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-card .stat-value { font-size: 16px; overflow: visible; }
}

/* ===== LOGIN PAGE ===== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-50);
    padding: 20px;
}

.login-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo img {
    width: 210px;
    height: auto;
    display: block;
    margin: 0 auto 16px;
}

.login-logo .logo-icon {
    width: 48px; height: 48px;
    background: var(--primary);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 22px; font-weight: 700;
    margin: 0 auto 12px;
}

.login-logo h1 { font-size: 20px; font-weight: 700; color: var(--gray-900); }
.login-logo p { font-size: 13px; color: var(--gray-500); margin-top: 2px; }

/* ===== LOADING ===== */
.loading { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3); border-top-color: white; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn .loading { margin-right: 4px; }

/* ===== DROPDOWN ===== */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
    position: absolute;
    right: 0; top: calc(100% + 4px);
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    z-index: 200;
    display: none;
    padding: 4px 0;
}
.dropdown-menu.open { display: block; }
.dropdown-item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 14px;
    font-size: 13.5px;
    color: var(--gray-700);
    cursor: pointer;
    transition: background 0.1s;
}
.dropdown-item:hover { background: var(--gray-50); }
.dropdown-item svg { width: 15px; height: 15px; opacity: 0.7; }
.dropdown-divider { height: 1px; background: var(--gray-200); margin: 4px 0; }
