/* ====================================================
   SMART Docs — Master Stylesheet (Clean Build)
   ==================================================== */

/* ==== CSS VARIABLES ==== */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #10b981;
    --secondary-hover: #059669;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;
    --dark-bg: #111827;
    --light-bg: #f3f4f6;
    --white: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --sidebar-width: 260px;
    --header-height: 70px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    --transition: all 0.3s ease;
}

/* ==== RESET ==== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
html, body {
    overflow-x: hidden;
    max-width: 100%;
}

/* ==== HIDE NUMBER SPINNERS ==== */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    -moz-appearance: textfield;
}

/* ==== GLOBAL FONT ==== */
body {
    background-color: var(--light-bg);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    font-family: 'Inter', 'Roboto', 'Poppins', 'Noto Sans Lao Looped', 'Phetsarath', sans-serif;
}
/* Force font on form elements (they don't inherit from body by default) */
input, select, textarea, button, option, optgroup,
table, th, td, label, a, span, p, div, h1, h2, h3, h4, h5, h6, li, ul, ol {
    font-family: inherit;
}

/* ====================================================
   SIDEBAR
   ==================================================== */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--white);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    border-right: 1px solid var(--border-color);
    z-index: 100;
    display: flex;
    flex-direction: column;
}
.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
}
.sidebar-header h2 {
    color: var(--primary-color);
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.025em;
}
.sidebar-header i {
    margin-right: 10px;
    font-size: 1.3rem;
}
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
}
.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 24px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: var(--transition);
    gap: 12px;
}
.nav-link i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}
.nav-link:hover, .nav-link.active {
    background-color: #eef2ff;
    color: var(--primary-color);
}
.nav-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
    margin: 20px 0 10px 16px;
    letter-spacing: 0.05em;
}
.sidebar-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100vh;
    background: rgba(0,0,0,0.5); z-index: 99; display: none;
}
.sidebar-overlay.active { display: block; }
.sidebar .close-btn { display: none; }

/* ====================================================
   MAIN CONTENT
   ==================================================== */
.main-content {
    min-width: 0;
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

/* ==== TOP HEADER ==== */
.top-header {
    max-width: 100%;
    height: var(--header-height);
    background-color: var(--white);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 90;
}
.search-bar {
    display: flex;
    align-items: center;
    background-color: var(--light-bg);
    border-radius: 20px;
    padding: 8px 16px;
    width: 300px;
}
.search-bar i {
    color: var(--text-muted);
    margin-right: 8px;
}
.search-bar input {
    border: none;
    background: transparent;
    outline: none;
    width: 100%;
    font-size: 0.9rem;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}
.notification-btn {
    position: relative;
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-muted);
    cursor: pointer;
}
.notification-btn .badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: var(--danger-color);
    color: white;
    font-size: 0.6rem;
    padding: 2px 5px;
    border-radius: 10px;
    font-weight: bold;
}
.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* ====================================================
   PAGE CONTENT
   ==================================================== */
.page-content {
    max-width: 100%;
    overflow-x: hidden;
    min-width: 0;
    padding: 32px;
    flex: 1;
}
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}
.page-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
}
.page-subtitle {
    color: var(--text-muted);
    margin-top: 5px;
    font-size: 0.95rem;
}

/* ====================================================
   BUTTONS
   ==================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 24px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    border: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    letter-spacing: 0.02em;
    position: relative;
    overflow: hidden;
}
.btn i {
    font-size: 1.1rem;
}
.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2), 0 2px 4px -1px rgba(79, 70, 229, 0.1);
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-hover) 0%, #312e81 100%);
    box-shadow: 0 10px 15px -3px rgba(79, 70, 229, 0.3), 0 4px 6px -2px rgba(79, 70, 229, 0.15);
    transform: translateY(-2px);
}

.btn-secondary {
    background-color: var(--white);
    color: var(--text-main);
    border: 1px solid #d1d5db;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}
.btn-secondary:hover {
    background-color: #f9fafb;
    border-color: #9ca3af;
    color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger-color) 0%, #b91c1c 100%);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(239, 68, 68, 0.2);
}
.btn-danger:hover {
    background: linear-gradient(135deg, #b91c1c 0%, #991b1b 100%);
    box-shadow: 0 10px 15px -3px rgba(239, 68, 68, 0.3);
    transform: translateY(-2px);
}

.btn-success {
    background: linear-gradient(135deg, var(--secondary-color) 0%, #047857 100%);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2);
}
.btn-success:hover {
    background: linear-gradient(135deg, #047857 0%, #065f46 100%);
    box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.3);
    transform: translateY(-2px);
}

.btn-warning {
    background: linear-gradient(135deg, var(--warning-color) 0%, #d97706 100%);
    color: white;
}
.btn-info {
    background: linear-gradient(135deg, var(--info-color) 0%, #2563eb 100%);
    color: white;
}

.btn-submit {
    font-size: 1.05rem;
    padding: 12px 32px;
}
.btn-block {
    width: 100%;
    padding: 14px;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: var(--white);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1.1rem;
    box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05);
}
.btn-icon:hover {
    color: var(--primary-color);
    border-color: #d1d5db;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}
.btn-icon.danger { color: var(--danger-color); }
.btn-icon.danger:hover { 
    background-color: #fef2f2; 
    border-color: #fecaca;
    box-shadow: 0 4px 6px -1px rgba(239,68,68,0.2);
}

/* ====================================================
   DASHBOARD CARDS
   ==================================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}
.stat-card {
    background: var(--white);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: var(--transition);
    border: 1px solid var(--border-color);
}
.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
}
.stat-icon.quo { background-color: #e0e7ff; color: #4f46e5; }
.stat-icon.inv { background-color: #dcfce7; color: #10b981; }
.stat-icon.due { background-color: #fee2e2; color: #ef4444; }
.stat-icon.rev { background-color: #fef3c7; color: #d97706; }
.stat-details h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
}
.stat-details p {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

/* ====================================================
   CARDS & TABLES
   ==================================================== */
.card {
    min-width: 0;
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    overflow: hidden;
}
.card + .card, .card.mb { margin-bottom: 20px; }
.card-narrow { max-width: 800px; }
.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-title {
    font-weight: 600;
    font-size: 1.1rem;
}
.card-body {
    padding: 24px;
}
.card-search {
    width: 250px;
    background: var(--white);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    border-radius: 20px;
    padding: 8px 16px;
}
.card-search i {
    color: var(--text-muted);
    margin-right: 8px;
}
.card-search input {
    border: none;
    background: transparent;
    outline: none;
    width: 100%;
    font-size: 0.9rem;
}
.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table-responsive table {
    min-width: 800px;
}
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    padding: 16px 24px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
th {
    background-color: #f9fafb;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
td { font-size: 0.95rem; }
tbody tr:hover { background-color: #f9fafb; }

/* Status Badges */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-draft { background-color: #f3f4f6; color: #4b5563; }
.badge-sent { background-color: #dbeafe; color: #2563eb; }
.badge-paid { background-color: #dcfce7; color: #166534; }
.badge-overdue { background-color: #fee2e2; color: #991b1b; }

/* ====================================================
   FORMS
   ==================================================== */
.form-group { margin-bottom: 20px; }
.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-main);
    font-size: 0.95rem;
}
.form-control, .form-select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    transition: var(--transition);
    outline: none;
    background-color: var(--white);
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
textarea.form-control {
    resize: vertical;
    min-height: 100px;
}
.form-row {
    display: flex;
    gap: 20px;
}
.form-col { flex: 1; }
.form-col-wide { flex: 2; }
.form-col-narrow { flex: 0.4; }
.form-actions {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}
.form-check {
    display: flex;
    align-items: center;
    gap: 10px;
}
.form-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary-color);
    cursor: pointer;
}
.form-check label { margin-bottom: 0; cursor: pointer; }

/* ==== REQUIRED ASTERISK ==== */
.text-required { color: var(--danger-color); font-weight: bold; }

/* ====================================================
   TABLE INPUTS (items table)
   ==================================================== */
.table-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
    background-color: transparent;
    color: var(--text-main);
    font-family: inherit;
}
.table-input:focus {
    border-color: var(--primary-color);
    background-color: var(--white);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.table-input[readonly] {
    background-color: transparent;
    font-weight: 600;
}
.table-input:hover:not([readonly]) {
    border-color: var(--border-color);
}
.items-toolbar {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.items-toolbar .form-select {
    width: 300px;
    max-width: 100%;
}
.items-table th:nth-child(1) { width: 40%; }
.items-table th:nth-child(2) { width: 15%; }
.items-table th:nth-child(3) { width: 20%; }
.items-table th:nth-child(4) { width: 20%; }
.items-table th:nth-child(5) { width: 5%; }

/* ====================================================
   SUMMARY BOX (Subtotal, Discount, VAT, Grand Total)
   ==================================================== */
.summary-container {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 30px;
    margin-top: 30px;
}
.notes-container {
    flex: 1;
    min-width: 250px;
    max-width: 50%;
}
.summary-box {
    width: 420px;
    max-width: 100%;
}
.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px dashed var(--border-color);
    gap: 15px;
}
.summary-row:last-child { border-bottom: none; }
.summary-row.total {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary-color);
    padding-top: 15px;
    border-top: 2px solid var(--primary-color);
    border-bottom: none;
}
.summary-row span {
    white-space: nowrap;
    color: var(--text-main);
    font-weight: 500;
    flex-shrink: 0;
}
.summary-input {
    width: 140px;
    min-width: 140px;
    text-align: right;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    font-size: 1rem;
    outline: none;
    transition: var(--transition);
    background-color: var(--white);
    font-family: inherit;
}
.summary-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.summary-vat-input {
    width: 70px;
    min-width: 70px;
    text-align: center;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px;
    font-size: 1rem;
    outline: none;
    transition: var(--transition);
    background-color: var(--white);
    font-family: inherit;
}
.summary-vat-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.summary-value {
    width: 140px;
    min-width: 140px;
    text-align: right;
    font-size: 1.05rem;
    font-weight: 600;
    border: none;
    background: transparent;
    color: var(--text-main);
    font-family: inherit;
}
.summary-row.total .summary-value {
    color: var(--primary-color);
    font-size: 1.25rem;
}
.vat-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* ====================================================
   ALERTS
   ==================================================== */
.alert-error {
    background: var(--danger-color);
    color: white;
    padding: 15px 20px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
}
.alert-error-inline {
    background: var(--danger-color);
    color: white;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: var(--radius-md);
}
.alert-success {
    background: #dcfce7;
    color: #166534;
    padding: 15px 20px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
}

/* ====================================================
   ACTION LINKS (table row actions)
   ==================================================== */
.action-link {
    text-decoration: none;
    margin-right: 10px;
    font-size: 1rem;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.action-link:hover { opacity: 0.7; }
.action-link.edit { color: var(--info-color); }
.action-link.convert { color: var(--secondary-color); }
.action-link.print { color: var(--text-muted); }
.action-link.delete { color: var(--danger-color); }

/* ====================================================
   INVOICE SELECT TABLE (Billing/Collection)
   ==================================================== */
.invoice-select-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid var(--border-color);
}
.invoice-select-table thead { background: #f9fafb; }
.invoice-select-table.danger thead { background: #fee2e2; }
.invoice-select-table th,
.invoice-select-table td {
    padding: 10px;
    border: 1px solid var(--border-color);
}
.invoice-select-table th.check-col { width: 5%; }
.invoice-select-total { text-align: right; font-weight: bold; padding: 15px; }
.invoice-select-value { text-align: right; font-weight: bold; padding: 15px; font-size: 1.2rem; }
.invoice-select-value.primary { color: var(--primary-color); }
.invoice-select-value.danger { color: var(--danger-color); }

/* ====================================================
   MISC UTILITIES
   ==================================================== */
.table-empty { text-align: center; color: var(--text-muted); padding: 40px; }
.text-muted-col { color: var(--text-muted); }
.text-danger { color: var(--danger-color); }
.text-primary { color: var(--primary-color); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-bold { font-weight: bold; }
.text-primary-bold { color: var(--primary-color); font-weight: bold; }
.text-danger-bold { color: var(--danger-color); font-weight: bold; }
.text-overdue { color: var(--danger-color); font-weight: bold; }
.text-help { color: var(--text-muted); font-size: 0.85rem; }
.icon-receipt { color: var(--secondary-color); }
.link-invoice { color: var(--info-color); text-decoration: none; }
.link-invoice:hover { text-decoration: underline; }
.js-hidden { display: none; }
.mt-20 { margin-top: 20px; }
.mb-50 { margin-bottom: 50px; }
.input-amount { font-weight: bold; color: var(--primary-color); font-size: 1.1rem; }
.section-title { margin-bottom: 10px; color: var(--text-main); }
.section-title.danger { color: var(--danger-color); }
.empty-state { display: none; text-align: center; padding: 30px; color: var(--text-muted); }
.empty-state-icon { font-size: 3rem; margin-bottom: 10px; }
.empty-state-icon.success { color: var(--secondary-color); }

/* ====================================================
   RESPONSIVE (Mobile ≤ 992px)
   ==================================================== */
@media (max-width: 992px) {
    .page-content {
        max-width: 100%;
        overflow-x: hidden;
        padding: 15px;
    }
    .card-header {
        padding: 15px;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .card-search { width: 100%; margin-top: 10px; }
    .stat-card { padding: 15px; gap: 10px; }
    .stat-icon { width: 45px; height: 45px; font-size: 1.2rem; }
    #mobileMenuBtn { display: inline-block !important; }
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        position: fixed;
        height: 100vh;
        z-index: 1000;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        background: white;
    }
    .sidebar.active { transform: translateX(0); }
    .sidebar .close-btn {
        display: block;
        position: absolute;
        right: 15px;
        top: 20px;
        font-size: 1.5rem;
        background: none;
        border: none;
        color: var(--text-muted);
        cursor: pointer;
    }
    .main-content { min-width: 0; margin-left: 0; }
    .form-row { flex-direction: column; }
    .form-col { width: 100%; flex: none !important; }
    .top-header { max-width: 100%; padding: 15px 20px; gap: 10px; }
    .search-bar { display: flex; flex: 1; min-width: 0; margin: 0 10px; padding: 6px 12px; }
    .user-info { display: none; }
    .search-bar input { width: 100%; min-width: 0; font-size: 0.85rem; }
    .stats-grid { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 15px; }
    .header-actions { width: 100%; text-align: left; }
    .items-toolbar { flex-direction: column; align-items: stretch; }
    .items-toolbar .form-select { width: 100%; }
    .notes-container { max-width: 100%; min-width: auto; }
    .summary-box { width: 100%; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; justify-content: center; }
}
