/* =============================================
   INVOICE MANAGEMENT SYSTEM - MAIN STYLES
   ============================================= */

:root {
    --primary: #1a56db;
    --primary-dark: #1342a8;
    --primary-light: #e8f0fe;
    --secondary: #64748b;
    --success: #059669;
    --success-light: #d1fae5;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-hover: #1e293b;
    --sidebar-active: #1a56db;
    --bg: #f8fafc;
    --white: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-light: #64748b;
    --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --radius: 8px;
    --sidebar-w: 240px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

/* ---- APP LAYOUT ---- */
.app-wrapper { display: flex; height: 100vh; overflow: hidden; }

/* ---- SIDEBAR ---- */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex; flex-direction: column;
    overflow: hidden;
    transition: width 0.3s ease;
    flex-shrink: 0;
    height: 100vh;
}
.sidebar.collapsed { width: 60px; }
.sidebar.collapsed .brand-name, .sidebar.collapsed span,
.sidebar.collapsed .nav-section, .sidebar.collapsed .user-details { display: none; }
.sidebar.collapsed .nav-link { justify-content: center; padding: 12px; }
.sidebar.collapsed .nav-link i { margin-right: 0; }

.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 20px 16px; border-bottom: 1px solid #1e293b;
    color: #fff; font-weight: 700; font-size: 16px;
}
.brand-icon { width: 32px; height: 32px; background: var(--primary); border-radius: 8px;
    display: flex; align-items: center; justify-content: center; color: #fff; flex-shrink: 0; }
.brand-logo { width: 36px; height: 36px; object-fit: contain; border-radius: 6px; flex-shrink: 0; }
.brand-name { white-space: nowrap; overflow: hidden; }

.sidebar-nav { list-style: none; padding: 12px 0; flex: 1; overflow-y: auto; overflow-x: hidden; }
.sidebar-nav li { }
.nav-section {
    font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em;
    color: #475569; padding: 16px 16px 4px; white-space: nowrap; overflow: hidden;
}
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px; color: var(--sidebar-text);
    text-decoration: none; transition: all 0.2s;
    border-left: 3px solid transparent;
}
.nav-link:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-link.active { background: var(--sidebar-hover); color: #fff; border-left-color: var(--primary); }
.nav-link i { width: 18px; text-align: center; flex-shrink: 0; }

.sidebar-footer {
    padding: 12px 16px; border-top: 1px solid #1e293b;
    display: flex; align-items: center; gap: 10px;
    flex-shrink: 0;
}
.user-info { display: flex; align-items: center; gap: 8px; flex: 1; overflow: hidden; }
.user-avatar { font-size: 28px; color: var(--sidebar-text); flex-shrink: 0; }
.user-details { overflow: hidden; }
.user-name { color: #e2e8f0; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: var(--sidebar-text); font-size: 11px; }
.btn-logout { color: var(--sidebar-text); text-decoration: none; padding: 6px; border-radius: 6px;
    transition: all 0.2s; flex-shrink: 0; }
.btn-logout:hover { color: var(--danger); background: rgba(220,38,38,0.1); }

/* ---- MAIN CONTENT ---- */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
    height: 56px; background: var(--white); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; padding: 0 24px; gap: 16px;
    flex-shrink: 0; box-shadow: var(--shadow);
}
.sidebar-toggle { display: none; background: none; border: none; cursor: pointer; color: var(--text-light);
    font-size: 18px; padding: 6px; border-radius: 6px; transition: all 0.2s; }
.sidebar-toggle:hover { background: var(--bg); color: var(--text); }
.page-breadcrumb { font-weight: 600; font-size: 15px; flex: 1; }
.company-name-badge { font-size: 12px; color: var(--text-light); display: flex; align-items: center; gap: 6px;
    background: var(--bg); padding: 4px 10px; border-radius: 20px; }

.content-area { flex: 1; overflow-y: auto; padding: 24px; }

/* ---- ALERTS ---- */
.alert {
    padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px;
    display: flex; align-items: center; gap: 10px; font-size: 14px;
}
.alert-success { background: var(--success-light); color: var(--success); }
.alert-danger { background: var(--danger-light); color: var(--danger); }
.alert-warning { background: var(--warning-light); color: var(--warning); }

/* ---- CARDS ---- */
.card {
    background: var(--white); border-radius: var(--radius);
    border: 1px solid var(--border); box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.card-header {
    padding: 16px 20px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* ---- STATS CARDS ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--white); border-radius: var(--radius);
    border: 1px solid var(--border); padding: 20px;
    display: flex; align-items: center; gap: 16px;
    box-shadow: var(--shadow);
}
.stat-icon { width: 48px; height: 48px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0; }
.stat-icon.blue { background: #dbeafe; color: var(--primary); }
.stat-icon.green { background: #d1fae5; color: var(--success); }
.stat-icon.orange { background: #ffedd5; color: #f97316; }
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }
.stat-info .stat-value { font-size: 24px; font-weight: 700; }
.stat-info .stat-label { font-size: 12px; color: var(--text-light); margin-top: 2px; }

/* ---- FORMS ---- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.span-2 { grid-column: span 2; }
.form-group.span-3 { grid-column: span 3; }
label { font-size: 12px; font-weight: 500; color: var(--text-light); }
label .required { color: var(--danger); margin-left: 2px; }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=password],
select, textarea {
    padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 14px; color: var(--text); font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--white); width: 100%;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}
input[readonly] { background: #f8fafc; cursor: not-allowed; }

/* ---- BUTTONS ---- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 500;
    cursor: pointer; border: none; text-decoration: none; transition: all 0.2s;
    font-family: inherit; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: 6px; justify-content: center; }

/* ---- TABLES ---- */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { background: #f8fafc; }
th { padding: 10px 12px; text-align: left; font-weight: 600; color: var(--text-light);
    border-bottom: 2px solid var(--border); white-space: nowrap; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: #f8fafc; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-light); }

/* ---- BADGES ---- */
.badge {
    display: inline-flex; padding: 2px 8px; border-radius: 12px;
    font-size: 11px; font-weight: 500;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--primary-light); color: var(--primary); }

/* ---- SECTION HEADER ---- */
.section-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; flex-wrap: wrap; gap: 10px;
}
.section-title { font-size: 18px; font-weight: 700; }

/* ---- SEARCH BAR ---- */
.search-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search-input-wrap { position: relative; }
.search-input-wrap input { padding-left: 36px; min-width: 220px; }
.search-input-wrap i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-light); }

/* ---- LOGIN PAGE ---- */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}
.login-box {
    background: var(--white); border-radius: 16px; padding: 40px;
    width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .icon { font-size: 48px; color: var(--primary); }
.login-logo h1 { font-size: 24px; font-weight: 700; margin-top: 8px; }
.login-logo p { color: var(--text-light); font-size: 13px; }

/* ---- INVOICE DETAIL TABLE ---- */
.inv-detail-table { width: 100%; border-collapse: collapse; margin-bottom: 0; }
.inv-detail-table th { background: #1a56db; color: #fff; padding: 8px 10px; font-size: 12px; }
.inv-detail-table td { padding: 4px 6px; }
.inv-detail-table td input, .inv-detail-table td select {
    padding: 5px 8px; border: 1px solid var(--border); border-radius: 4px;
    font-size: 13px; width: 100%;
}
.inv-detail-table tr.item-row:hover td { background: #f0f7ff; }
.inv-detail-table tr.item-desc-row td { background: #fafbfc; border-bottom: 1px solid #f0f0f0; padding: 0 6px 5px; vertical-align: top; }
.inv-detail-table tr.item-desc-row textarea { font-family: inherit; font-size: 11.5px; color: #64748b; border: 1px solid #e8edf2; border-radius: 4px; padding: 3px 8px; width: 100%; resize: vertical; min-height: 26px; background: #fff; line-height: 1.4; }
.inv-detail-table tr.item-desc-row textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(26,86,219,.1); }
.inv-detail-table .del-btn { background: none; border: none; color: var(--danger);
    cursor: pointer; font-size: 14px; padding: 4px 8px; border-radius: 4px; }
.inv-detail-table .del-btn:hover { background: var(--danger-light); }

/* Disabled nav links when no FY selected */
.nav-link-disabled {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px; border-radius: 8px; margin: 1px 8px;
    color: var(--text-muted); opacity: 0.38;
    cursor: not-allowed; pointer-events: none;
    font-size: 14px; font-weight: 500; text-decoration: none;
    user-select: none;
}
.nav-link-disabled i { width: 18px; text-align: center; font-size: 15px; }

/* FY warning banner inside sidebar */
.nav-fy-warning { list-style: none; margin: 8px; background: #fef3cd;
    border: 1px solid #ffc107; border-radius: 8px; padding: 10px 12px; }
.nav-fy-msg { display: flex; align-items: flex-start; gap: 8px;
    font-size: 12px; color: #856404; font-weight: 500; line-height: 1.4; }
.nav-fy-msg i { color: #f59e0b; flex-shrink: 0; margin-top: 2px; }

/* ---- INVOICE SUMMARY ---- */
.invoice-summary { max-width: 350px; margin-left: auto; }
.summary-row { display: flex; justify-content: space-between; padding: 6px 0;
    border-bottom: 1px solid var(--border); font-size: 13px; }
.summary-row.total { font-weight: 700; font-size: 16px; border-top: 2px solid var(--text);
    border-bottom: none; padding-top: 10px; margin-top: 4px; }

/* ---- TABS ---- */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; gap: 2px; }
.tab-btn { padding: 10px 20px; border: none; background: none; cursor: pointer;
    font-family: inherit; font-size: 14px; color: var(--text-light);
    border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.2s; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {

    /* Show hamburger only on mobile */
    .sidebar-toggle { display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

    /* App wrapper: single column, sidebar out of flow */
    .app-wrapper { display: block; height: 100vh; overflow: hidden; position: relative; }

    /* Main content: full width, full height */
    .main-content {
        width: 100%;
        height: 100vh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* Sidebar: fixed overlay, slides in from left */
    .sidebar {
        position: fixed !important;
        top: 0;
        left: -260px;
        width: 240px !important;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    .sidebar.open { left: 0 !important; }

    /* Cancel desktop icon-only collapsed mode on mobile */
    .sidebar.collapsed { left: -260px; width: 240px !important; }
    .sidebar.collapsed .brand-name,
    .sidebar.collapsed span,
    .sidebar.collapsed .nav-section,
    .sidebar.collapsed .user-details { display: revert !important; }
    .sidebar.collapsed .nav-link { justify-content: flex-start !important; padding: 10px 16px !important; }
    .sidebar.collapsed .nav-link i { margin-right: unset !important; }
    .sidebar.open.collapsed { left: 0 !important; }

    /* Nav scrolls, footer stays frozen */
    .sidebar-nav { overflow-y: auto; flex: 1; }
    .sidebar-footer { flex-shrink: 0; }

    /* Topbar */
    .topbar { padding: 0 12px; gap: 8px; }
    .company-name-badge { display: none; }

    /* Forms: single column */
    .form-grid-3, .form-grid-4 { grid-template-columns: 1fr; }
    .form-group.span-2, .form-group.span-3 { grid-column: span 1; }

    /* Stats: 2-col on tablet */
    .stats-grid { grid-template-columns: 1fr 1fr; }

    /* Tables: horizontal scroll */
    .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Content */
    .content-area { padding: 12px; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .section-header { flex-direction: column; align-items: flex-start; }
    .search-bar { flex-direction: column; align-items: stretch; }
    .search-input-wrap { width: 100%; }
    .search-input-wrap input { min-width: unset; width: 100%; }
    .topbar-right { display: none; }
}

/* ---- PRINT ---- */
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .content-area { padding: 0; }
    body { background: white; }
}

/* ---- UTILS ---- */
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-3 { margin-bottom: 12px; }
.fw-bold { font-weight: 700; }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.rupee::before { content: 'Rs. '; font-size: 0.85em; }
