/* ============================================================
   Hamro Sanchar Kendra — Main Stylesheet
   Clean, professional, IRD-compliant invoice UI
   ============================================================ */

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

:root {
    --primary:        #1a56db;
    --primary-dark:   #1143b0;
    --primary-light:  #e8f0fe;
    --accent:         #e3342f;
    --success:        #0d9f6e;
    --success-light:  #d1fae5;
    --warning:        #d97706;
    --warning-light:  #fef3c7;
    --danger:         #dc2626;
    --danger-light:   #fee2e2;
    --info:           #0891b2;

    --bg:             #f3f4f8;
    --surface:        #ffffff;
    --border:         #e2e5eb;
    --border-light:   #f0f2f5;
    --text:           #111827;
    --text-muted:     #6b7280;
    --text-light:     #9ca3af;

    --sidebar-bg:     #0f172a;
    --sidebar-text:   #cbd5e1;
    --sidebar-hover:  #1e293b;
    --sidebar-active: #1a56db;
    --sidebar-width:  240px;

    --radius-sm:  4px;
    --radius:     8px;
    --radius-lg:  12px;
    --radius-xl:  16px;

    --shadow-sm:  0 1px 3px rgba(0,0,0,.08);
    --shadow:     0 4px 12px rgba(0,0,0,.10);
    --shadow-lg:  0 8px 24px rgba(0,0,0,.12);

    --font:       'Inter', sans-serif;
    --font-np:    'Noto Sans Devanagari', 'Inter', sans-serif;

    --topbar-h:   58px;
}

html { font-size: 14px; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

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

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform 0.26s ease;
    overflow-y: auto;
    scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px 18px;
    border-bottom: 1px solid rgba(255,255,255,.07);
}
.logo-icon { font-size: 24px; }
.logo-text { display: flex; flex-direction: column; line-height: 1.2; }
.logo-main { color: #fff; font-weight: 700; font-size: 13px; letter-spacing: .3px; }
.logo-sub { color: var(--sidebar-text); font-size: 11px; }

.sidebar-nav { padding: 12px 0 24px; flex: 1; }
.nav-group { margin-bottom: 4px; }
.nav-label {
    display: block;
    padding: 12px 18px 4px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: #475569;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 18px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13px;
    font-weight: 450;
    border-radius: 0;
    transition: background .15s, color .15s;
    border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active {
    background: rgba(26,86,219,.18);
    color: #93bbfd;
    border-left-color: var(--primary);
}
.nav-item--danger:hover { background: rgba(220,38,38,.12); color: #f87171; }
.nav-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; }

/* MAIN AREA */
.main-area {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* TOPBAR */
.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}
.sidebar-toggle {
    background: none; border: none; cursor: pointer;
    font-size: 18px; color: var(--text-muted);
    display: none;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
}
.sidebar-toggle:hover { background: var(--bg); }
.topbar-info { flex: 1; display: flex; align-items: center; gap: 16px; font-size: 12px; color: var(--text-muted); }
.topbar-fy {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
}
.topbar-user { display: flex; align-items: center; gap: 8px; }
.user-avatar {
    width: 32px; height: 32px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px;
}
.user-name { font-weight: 500; font-size: 13px; }

/* PAGE CONTENT */
.page-content { padding: 24px; flex: 1; }
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap; gap: 12px;
}
.page-title {
    font-size: 20px; font-weight: 700; color: var(--text);
}
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

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

/* STAT CARDS */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    display: flex; align-items: flex-start; gap: 14px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: var(--shadow); }
.stat-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0;
}
.stat-icon.blue   { background: #e8f0fe; }
.stat-icon.green  { background: #d1fae5; }
.stat-icon.amber  { background: #fef3c7; }
.stat-icon.red    { background: #fee2e2; }
.stat-icon.purple { background: #ede9fe; }
.stat-info { flex: 1; min-width: 0; }
.stat-label { font-size: 11px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase; color: var(--text-muted); }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.2; margin-top: 2px; }
.stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap { overflow-x: auto; }
table {
    width: 100%; border-collapse: collapse;
    font-size: 13px;
}
thead th {
    background: var(--bg);
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbff; }
tfoot td {
    padding: 10px 14px;
    font-weight: 600;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 180px; }

label {
    display: block;
    font-size: 12px; font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 5px;
    letter-spacing: .2px;
}
label .required { color: var(--danger); }

input[type=text], input[type=number], input[type=email],
input[type=date], input[type=tel], input[type=search],
select, textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: var(--font);
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
    outline: none;
    -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,.1);
}
input[readonly] { background: var(--bg); color: var(--text-muted); }
select { cursor: pointer; }
textarea { resize: vertical; min-height: 80px; }
.form-text { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.input-group { position: relative; display: flex; }
.input-group-text {
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-right: none;
    border-radius: var(--radius) 0 0 var(--radius);
    font-size: 12px; color: var(--text-muted); font-weight: 600;
    display: flex; align-items: center;
    white-space: nowrap;
}
.input-group input {
    border-radius: 0 var(--radius) var(--radius) 0;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px; font-weight: 600;
    font-family: var(--font);
    border: 1px solid transparent;
    cursor: pointer; text-decoration: none;
    transition: all .15s;
    white-space: nowrap;
    line-height: 1.4;
}
.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { background: #0a8a60; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-outline   { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-sm  { padding: 5px 10px; font-size: 12px; }
.btn-lg  { padding: 11px 22px; font-size: 14px; }
.btn-icon { padding: 6px 9px; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    display: inline-flex; align-items: center;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px; font-weight: 600;
    letter-spacing: .2px;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.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-muted   { background: var(--bg); color: var(--text-muted); }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    padding: 12px 18px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px; font-weight: 500;
    display: flex; align-items: center; gap: 8px;
}
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid #86efac; }
.alert-error   { background: var(--danger-light); color: var(--danger); border: 1px solid #fca5a5; }
.alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid #fde68a; }
.alert-info    { background: #e0f2fe; color: var(--info); border: 1px solid #93c5fd; }

/* ============================================================
   INVOICE BUILDER
   ============================================================ */
.invoice-builder { display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start; }
@media (max-width: 1024px) { .invoice-builder { grid-template-columns: 1fr; } }

.invoice-items-table { width: 100%; border-collapse: collapse; }
.invoice-items-table th {
    background: #f8faff;
    padding: 9px 10px;
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    text-align: left;
}
.invoice-items-table td { padding: 6px 6px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.invoice-items-table tbody tr:hover { background: #fafbff; }
.invoice-items-table input, .invoice-items-table select {
    padding: 6px 8px; font-size: 12px;
    border-radius: var(--radius-sm);
}
.col-sn    { width: 36px; text-align: center; }
.col-item  { min-width: 200px; }
.col-qty   { width: 80px; }
.col-unit  { width: 70px; }
.col-rate  { width: 100px; }
.col-disc  { width: 80px; }
.col-amt   { width: 100px; text-align: right; }
.col-tax   { width: 80px; text-align: center; }
.col-del   { width: 36px; text-align: center; }

.total-panel { background: var(--bg); border-radius: var(--radius-lg); padding: 18px; border: 1px solid var(--border); }
.total-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 7px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
}
.total-row:last-child { border-bottom: none; }
.total-row.total-final {
    font-size: 16px; font-weight: 700;
    color: var(--primary);
    border-top: 2px solid var(--border);
    padding-top: 12px; margin-top: 4px;
}
.total-label { color: var(--text-muted); font-size: 12px; }
.total-value { font-weight: 600; font-size: 13px; }

/* ============================================================
   INVOICE PRINT LAYOUT (A5: 148mm × 210mm)
   ============================================================ */
.invoice-print-page {
    width: 148mm;
    min-height: 210mm;
    background: #fff;
    margin: 0 auto;
    padding: 8mm 10mm;
    font-family: 'Inter', Arial, sans-serif;
    font-size: 9pt;
    color: #111;
    position: relative;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

.inv-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid #1a56db;
    padding-bottom: 8px;
    margin-bottom: 10px;
}
.inv-company-name {
    font-size: 14pt;
    font-weight: 800;
    color: #1a56db;
    line-height: 1.2;
}
.inv-company-name-np {
    font-family: var(--font-np);
    font-size: 11pt;
    color: #1a56db;
}
.inv-company-meta { font-size: 7.5pt; color: #555; line-height: 1.6; margin-top: 2px; }
.inv-meta-right { text-align: right; min-width: 90px; }
.inv-bill-label { font-size: 8.5pt; font-weight: 700; color: #888; text-transform: uppercase; letter-spacing: .5px; }
.inv-bill-no { font-size: 13pt; font-weight: 800; color: #1a56db; }
.inv-bill-date { font-size: 8pt; color: #555; margin-top: 2px; }

.inv-party-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 8px;
}
.inv-party-box {
    background: #f8faff;
    border: 1px solid #dde3f0;
    border-radius: 4px;
    padding: 6px 8px;
}
.inv-party-label { font-size: 7pt; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: #888; margin-bottom: 2px; }
.inv-party-name { font-size: 9.5pt; font-weight: 700; }
.inv-party-meta { font-size: 7.5pt; color: #555; }

.inv-table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.inv-table th {
    background: #1a56db;
    color: #fff;
    padding: 5px 6px;
    font-size: 7.5pt;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    text-align: left;
}
.inv-table th.text-right, .inv-table td.text-right { text-align: right; }
.inv-table th.text-center, .inv-table td.text-center { text-align: center; }
.inv-table td {
    padding: 5px 6px;
    font-size: 8.5pt;
    border-bottom: 1px solid #eef1f8;
    vertical-align: top;
}
.inv-table tbody tr:nth-child(even) td { background: #f8faff; }
.inv-table tfoot td {
    font-weight: 700;
    border-top: 1px solid #ccd5e8;
    padding: 5px 6px;
    font-size: 8.5pt;
    background: transparent;
}

.inv-totals {
    display: grid;
    grid-template-columns: 1fr 160px;
    gap: 10px;
    align-items: start;
}
.inv-totals-left { font-size: 7.5pt; }
.inv-amount-words {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 4px;
    padding: 5px 7px;
    font-size: 7.5pt;
    font-weight: 600;
    color: #92400e;
    margin-bottom: 8px;
}
.inv-payment-info { font-size: 7.5pt; color: #555; }

.inv-totals-right table { width: 100%; }
.inv-totals-right td { padding: 3px 5px; font-size: 8pt; }
.inv-totals-right td:last-child { text-align: right; font-weight: 600; }
.inv-grand-total {
    background: #1a56db; color: #fff;
    border-radius: 4px;
}
.inv-grand-total td { padding: 5px; font-size: 9pt; font-weight: 800; }

.inv-footer {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #dde3f0;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}
.inv-note { font-size: 7.5pt; color: #777; max-width: 60%; }
.inv-sign { text-align: right; }
.inv-sign-line { border-top: 1px solid #999; width: 100px; margin-bottom: 3px; }
.inv-sign-label { font-size: 7pt; color: #888; font-style: italic; }

.inv-ird-note {
    text-align: center;
    font-size: 7pt;
    color: #999;
    margin-top: 6px;
    border-top: 1px dashed #ddd;
    padding-top: 5px;
}
.vat-tag {
    background: #dc2626; color: #fff;
    font-size: 7pt; font-weight: 700;
    padding: 1px 5px; border-radius: 3px;
    display: inline-block;
}

/* ============================================================
   SEARCH / FILTER BAR
   ============================================================ */
.filter-bar {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
    margin-bottom: 16px;
    padding: 14px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.filter-bar .form-group { margin-bottom: 0; flex: 1; min-width: 140px; max-width: 220px; }
.filter-bar .form-group label { font-size: 11px; }

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 200;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    opacity: 0; pointer-events: none;
    transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
    background: var(--surface);
    border-radius: var(--radius-xl);
    max-width: 500px; width: 100%;
    box-shadow: var(--shadow-lg);
    transform: scale(.95); transition: transform .2s;
}
.modal-overlay.open .modal { transform: scale(1); }
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination { display: flex; gap: 4px; align-items: center; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.page-link {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 34px; height: 34px;
    padding: 0 8px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    color: var(--text); text-decoration: none;
    font-size: 12px; font-weight: 500;
    background: var(--surface);
    transition: all .15s;
}
.page-link:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-link.disabled { opacity: .4; pointer-events: none; }

/* ============================================================
   PRODUCT SEARCH DROPDOWN
   ============================================================ */
.product-dropdown {
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 100;
    max-height: 220px; overflow-y: auto;
    display: none;
}
.product-dropdown.open { display: block; }
.product-option {
    padding: 9px 12px;
    cursor: pointer;
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
    transition: background .12s;
}
.product-option:last-child { border-bottom: none; }
.product-option:hover { background: var(--primary-light); }
.product-option .prod-price { font-weight: 700; color: var(--primary); }
.product-option .prod-stock { font-size: 11px; color: var(--text-muted); }

/* ============================================================
   UTILITY
   ============================================================ */
.d-flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-primary { color: var(--primary); }
.text-warning { color: var(--warning); }
.fw-bold { font-weight: 700; }
.fw-600 { font-weight: 600; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.ms-auto { margin-left: auto; }
.w-100 { width: 100%; }
.small { font-size: 11px; }
.np { font-family: var(--font-np); }
.hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.loading { opacity: .5; pointer-events: none; }

/* Stock alert */
.stock-low { color: var(--danger); font-weight: 600; }
.stock-ok { color: var(--success); }

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
    body { background: #fff !important; }
    .sidebar, .topbar, .no-print, .btn, .page-header { display: none !important; }
    .main-area { margin-left: 0 !important; }
    .page-content { padding: 0 !important; }
    .invoice-print-page {
        box-shadow: none;
        border: none;
        margin: 0;
        width: 148mm;
        min-height: 210mm;
    }
    @page {
        size: A5 portrait;
        margin: 6mm;
    }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
    :root { --sidebar-width: 0px; }
    .sidebar { transform: translateX(-240px); }
    .sidebar.open { transform: translateX(0); width: 240px; }
    .main-area { margin-left: 0; }
    .sidebar-toggle { display: inline-flex; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .stats-grid { grid-template-columns: 1fr; }
    .page-content { padding: 14px; }
    .topbar { padding: 0 14px; }
    .topbar-date { display: none; }
}
