/**
 * Invoice Manager - Mobile First
 */

:root {
    --bg-dark: #0d0d14;
    --bg-card: #161622;
    --bg-input: #1e1e2d;
    --text-white: #ffffff;
    --text-gray: #9ca3af;
    --text-muted: #6b7280;
    --accent: #00d4ff;
    --accent-purple: #a855f7;
    --green: #22c55e;
    --red: #ef4444;
    --yellow: #f59e0b;
    --blue: #3b82f6;
    --border: #2a2a3d;
    --radius: 12px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    overflow-x: hidden;
    width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text-white);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
}

a { color: inherit; text-decoration: none; }

/* ===== APP LAYOUT ===== */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ===== SIDEBAR (Desktop Only) ===== */
.sidebar {
    width: 250px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 200;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 18px;
}

.logo i {
    color: var(--accent);
    font-size: 22px;
}

.sidebar-nav {
    flex: 1;
    padding: 15px 10px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    border-radius: 10px;
    color: var(--text-gray);
    margin-bottom: 4px;
    transition: all 0.2s;
}

.nav-item i { width: 20px; text-align: center; }
.nav-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav-item.active { background: linear-gradient(135deg, var(--accent), var(--accent-purple)); color: #000; font-weight: 600; }

.sidebar-footer {
    padding: 15px;
    border-top: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent), var(--accent-purple));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #000;
}

.user-details { flex: 1; min-width: 0; }
.user-name { font-size: 14px; font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 12px; color: var(--text-muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn-logout {
    width: 100%;
    padding: 10px;
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.3);
    border-radius: 8px;
    color: var(--red);
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    margin-left: 250px;
    padding: 25px;
    min-height: 100vh;
    width: calc(100% - 250px);
}

/* ===== MOBILE HEADER ===== */
.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    margin: -16px -16px 16px -16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.mobile-header .logo { font-size: 16px; }
.mobile-header .logo i { font-size: 20px; }

.menu-toggle {
    width: 40px;
    height: 40px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.btn-add-mobile {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent), var(--accent-purple));
    border-radius: 10px;
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== MOBILE OVERLAY ===== */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 199;
    opacity: 0;
    transition: opacity 0.3s;
}
.mobile-menu-overlay.active { opacity: 1; }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 8px 0;
    padding-bottom: calc(8px + var(--safe-bottom));
    z-index: 100;
}

.bottom-nav-items {
    display: flex;
    justify-content: space-around;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    color: var(--text-muted);
    font-size: 10px;
    border-radius: 8px;
}

.bottom-nav-item i { font-size: 20px; }
.bottom-nav-item.active { color: var(--accent); }

/* ===== FAB ===== */
.fab {
    display: none;
    position: fixed;
    bottom: 80px;
    right: 16px;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--accent), var(--accent-purple));
    border-radius: 50%;
    color: #000;
    font-size: 22px;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0,212,255,0.4);
    z-index: 99;
}

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    gap: 15px;
    flex-wrap: wrap;
}

.page-title h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.page-title h1 i { color: var(--accent); margin-right: 8px; }
.page-title p { color: var(--text-muted); font-size: 14px; }

.page-actions { display: flex; gap: 10px; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    font-family: inherit;
    white-space: nowrap;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #00b4d8);
    color: #000;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 15px rgba(0,212,255,0.3); }

.btn-secondary {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: #fff;
}

.btn-danger {
    background: rgba(239,68,68,0.15);
    color: var(--red);
}

.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-gray);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-icon:hover { color: #fff; background: rgba(255,255,255,0.1); }
.btn-icon.btn-danger { border-color: rgba(239,68,68,0.3); }
.btn-icon.btn-danger:hover { background: rgba(239,68,68,0.2); color: var(--red); }

/* ===== STATS ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    margin-bottom: 12px;
}

.stat-icon.blue { background: rgba(59,130,246,0.15); color: var(--blue); }
.stat-icon.green { background: rgba(34,197,94,0.15); color: var(--green); }
.stat-icon.purple { background: rgba(168,85,247,0.15); color: var(--accent-purple); }
.stat-icon.cyan { background: rgba(0,212,255,0.15); color: var(--accent); }

.stat-value { font-size: 20px; font-weight: 700; display: block; }
.stat-label { font-size: 12px; color: var(--text-muted); }

/* ===== CARDS ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-wrap: wrap;
}

.card-header h2 {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-header h2 i { color: var(--accent); }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card-body { padding: 16px; }

/* ===== FORMS ===== */
.form-grid {
    display: grid;
    gap: 16px;
}

.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-gray);
    margin-bottom: 8px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: #fff;
    font-size: 16px;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.form-group input::placeholder { color: var(--text-muted); }

.form-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%239ca3af' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 24px;
    padding-right: 40px;
}

.form-group select option { background: var(--bg-card); }
.form-group textarea { min-height: 100px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.search-input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: #fff;
    font-size: 14px;
    font-family: inherit;
}

.search-input:focus { outline: none; border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

/* ===== TABLE ===== */
.table-responsive { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th,
.data-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    background: rgba(255,255,255,0.02);
}

.data-table tbody tr:hover { background: rgba(255,255,255,0.02); }
.action-buttons { display: flex; gap: 6px; }

/* ===== MOBILE INVOICE CARDS ===== */
.invoice-cards { display: none; }

.invoice-card-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.invoice-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.invoice-card-number {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent);
}

.invoice-card-company {
    font-size: 13px;
    color: var(--text-gray);
    margin-top: 2px;
}

.invoice-card-amount { text-align: right; }
.invoice-card-amount .amount { font-size: 18px; font-weight: 700; }
.invoice-card-amount .date { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.invoice-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.invoice-card-actions { display: flex; gap: 6px; }
.invoice-card-actions .btn-icon { width: 36px; height: 36px; }

/* ===== STATUS BADGES ===== */
.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.status-draft { background: rgba(245,158,11,0.15); color: var(--yellow); }
.status-sent { background: rgba(59,130,246,0.15); color: var(--blue); }
.status-paid { background: rgba(34,197,94,0.15); color: var(--green); }
.status-cancelled { background: rgba(239,68,68,0.15); color: var(--red); }

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
}

.empty-state i { font-size: 48px; color: var(--text-muted); margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { font-size: 18px; margin-bottom: 8px; }
.empty-state p { color: var(--text-muted); margin-bottom: 20px; font-size: 14px; }

/* ===== ALERTS ===== */
.alert {
    padding: 14px 16px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success { background: rgba(34,197,94,0.15); border: 1px solid rgba(34,197,94,0.3); color: #4ade80; }
.alert-error { background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.3); color: #f87171; }
.alert-warning { background: rgba(245,158,11,0.15); border: 1px solid rgba(245,158,11,0.3); color: #fbbf24; }
.alert-info { background: rgba(59,130,246,0.15); border: 1px solid rgba(59,130,246,0.3); color: #93c5fd; }

/* ===== MODAL ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.modal.active { display: flex; }

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; display: flex; align-items: center; gap: 10px; }
.modal-header h3 i { color: var(--yellow); }
.modal-body { padding: 20px; }
.modal-body p { color: var(--text-gray); font-size: 14px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ===== INVOICE ITEMS ===== */
.invoice-items { margin-top: 16px; }

.item-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 16px;
    padding: 16px;
    background: var(--bg-input);
    border-radius: 10px;
}

.item-row input {
    width: 100%;
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
}

.item-row input:focus { outline: none; border-color: var(--accent); }

.btn-remove-item {
    width: 100%;
    padding: 10px;
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.3);
    border-radius: 8px;
    color: var(--red);
    cursor: pointer;
}

.btn-add-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    background: rgba(0,212,255,0.1);
    border: 1px dashed rgba(0,212,255,0.3);
    border-radius: 10px;
    color: var(--accent);
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
}

/* ===== INVOICE TOTALS ===== */
.invoice-totals {
    margin-top: 20px;
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 16px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.total-row:last-child {
    border-bottom: none;
    font-size: 18px;
    font-weight: 700;
    padding-top: 14px;
    color: var(--accent);
}

/* ===== TABS ===== */
.tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-input);
    padding: 4px;
    border-radius: 10px;
    margin-bottom: 20px;
    overflow-x: auto;
}

.tab {
    flex: 1;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-gray);
    border: none;
    background: transparent;
    font-family: inherit;
    white-space: nowrap;
    text-align: center;
}

.tab:hover { color: #fff; }
.tab.active { background: var(--accent); color: #000; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== CHARTS ===== */
.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.chart-header h3 { font-size: 15px; font-weight: 600; }

.date-range-picker {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.date-range-picker input {
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: #fff;
    font-size: 13px;
}

/* ===== INVOICE PREVIEW ===== */
.invoice-preview {
    background: #fff;
    color: #1a1a2e;
    max-width: 100%;
    margin: 0 auto;
    padding: 24px;
    border-radius: var(--radius);
}

.invoice-preview-container {
    background: var(--bg-input);
    padding: 16px;
    min-height: calc(100vh - 100px);
}

.preview-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

.preview-actions .btn { padding: 10px 14px; font-size: 13px; }

/* ===== CHECKBOX ===== */
.checkbox-group {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin: 16px 0;
}

.checkbox-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent);
    flex-shrink: 0;
}

.checkbox-group label { font-size: 14px; cursor: pointer; }

/* ========================================
   RESPONSIVE - TABLET
======================================== */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.active { transform: translateX(0); }
    .main-content { margin-left: 0; width: 100%; padding: 16px; }
    .mobile-header { display: flex; }
    .mobile-menu-overlay { display: block; }
}

/* ========================================
   RESPONSIVE - MOBILE
======================================== */
@media (max-width: 768px) {
    .main-content {
        padding: 16px;
        padding-bottom: 100px;
    }
    
    .mobile-header {
        margin: -16px -16px 16px -16px;
    }
    
    .bottom-nav { display: block; }
    .fab { display: flex; bottom: calc(70px + var(--safe-bottom)); }
    
    .page-header { margin-bottom: 16px; }
    .page-title h1 { font-size: 20px; }
    .page-title h1 i { display: none; }
    .page-actions .btn-primary { display: none; }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    
    .stat-card { padding: 14px; }
    .stat-icon { width: 36px; height: 36px; font-size: 16px; margin-bottom: 10px; }
    .stat-value { font-size: 18px; }
    .stat-label { font-size: 11px; }
    
    .card-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 14px;
    }
    
    .card-header h2 { font-size: 14px; }
    .card-actions { width: 100%; }
    .card-body { padding: 14px; }
    
    .table-responsive { display: none; }
    .invoice-cards { display: block; }
    
    .form-row { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    
    .tabs { flex-wrap: nowrap; }
    .tab { padding: 10px 8px; font-size: 12px; }
    
    .preview-actions .btn span { display: none; }
    
    .invoice-preview { padding: 16px; font-size: 14px; }
}

/* ========================================
   RESPONSIVE - SMALL PHONE
======================================== */
@media (max-width: 380px) {
    .main-content { padding: 12px; padding-bottom: 100px; }
    .mobile-header { margin: -12px -12px 12px -12px; padding: 10px 12px; }
    
    .stats-grid { gap: 8px; }
    .stat-card { padding: 12px; }
    .stat-value { font-size: 16px; }
    
    .bottom-nav-item { padding: 6px 8px; }
    .bottom-nav-item i { font-size: 18px; }
    .bottom-nav-item span { font-size: 9px; }
    
    .invoice-card-item { padding: 14px; }
    .invoice-card-number { font-size: 15px; }
    .invoice-card-amount .amount { font-size: 16px; }
}

/* ===== PRINT ===== */
@media print {
    body * { visibility: hidden; }
    .invoice-preview, .invoice-preview * { visibility: visible; }
    .invoice-preview { position: absolute; left: 0; top: 0; width: 100%; box-shadow: none; }
    .preview-actions, .sidebar, .mobile-header, .bottom-nav, .fab { display: none !important; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
