/* =============================================================
   Crackbill — Custom Styles
   Crackers/Fireworks billing theme — primary #e63946
   Tamil font support via Noto Sans Tamil
   ============================================================= */

/* ── Google Font import (fallback if link tag fails) ─────────── */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Tamil:wght@400;500;600;700&family=Inter:wght@400;500;600;700&display=swap');

/* ── CSS Variables ───────────────────────────────────────────── */
:root {
    --cb-primary:       #e63946;
    --cb-primary-dark:  #c1121f;
    --cb-primary-light: #ff6b6b;
    --cb-sidebar-bg:    #1d3557;
    --cb-sidebar-width: 250px;
    --cb-navbar-height: 56px;
    --cb-font-base:     16px;
    --cb-border-radius: 0.5rem;
    --cb-shadow:        0 2px 8px rgba(0,0,0,.12);
}

/* ── Base Reset / Body ───────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', 'Noto Sans Tamil', 'Segoe UI', sans-serif;
    font-size: var(--cb-font-base);
    line-height: 1.6;
    background-color: #f4f6fb;
    color: #212529;
}

/* Tamil text nodes */
.tamil,
[lang="ta"] {
    font-family: 'Noto Sans Tamil', 'Latha', 'Vijaya', sans-serif;
}

/* ── Bootstrap overrides ─────────────────────────────────────── */
.btn {
    font-size: 1rem;
    padding: 0.5rem 1.2rem;
    border-radius: var(--cb-border-radius);
}

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

.btn-lg {
    font-size: 1.1rem;
    padding: 0.7rem 1.8rem;
}

/* Form controls — larger for easy use */
.form-control,
.form-select {
    font-size: 1rem;
    padding: 0.55rem 0.9rem;
    border-radius: var(--cb-border-radius);
}
.form-control:focus,
.form-select:focus {
    border-color: var(--cb-primary);
    box-shadow: 0 0 0 0.2rem rgba(230,57,70,.2);
}

label {
    font-weight: 500;
    margin-bottom: 0.3rem;
}

/* ── Top Navbar ──────────────────────────────────────────────── */
.cb-navbar {
    background-color: var(--cb-primary) !important;
    height: var(--cb-navbar-height);
    box-shadow: var(--cb-shadow);
    z-index: 1040;
}

.cb-navbar .navbar-brand {
    font-size: 1.3rem;
    letter-spacing: 0.5px;
}

.avatar-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background-color: rgba(255,255,255,.25);
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.9rem;
    color: #fff;
    flex-shrink: 0;
}

/* ── Layout Wrapper ──────────────────────────────────────────── */
#wrapper {
    display: flex;
    min-height: 100vh;
    padding-top: var(--cb-navbar-height);
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.cb-sidebar {
    width: var(--cb-sidebar-width);
    min-height: calc(100vh - var(--cb-navbar-height));
    background-color: var(--cb-sidebar-bg);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: var(--cb-navbar-height);
    left: 0;
    bottom: 0;
    overflow-y: auto;
    transition: transform 0.25s ease;
    z-index: 1035;
}

.cb-sidebar.collapsed {
    transform: translateX(calc(-1 * var(--cb-sidebar-width)));
}

.sidebar-header {
    background-color: rgba(0,0,0,.2);
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-section-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,.45);
    padding: 0.8rem 0.75rem 0.2rem;
    font-weight: 600;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--cb-border-radius);
    color: rgba(255,255,255,.8);
    text-decoration: none;
    font-size: 0.95rem;
    transition: background .15s ease, color .15s ease;
    margin-bottom: 2px;
}

.sidebar-link:hover {
    background-color: rgba(255,255,255,.1);
    color: #fff;
}

.sidebar-link.active {
    background-color: var(--cb-primary);
    color: #fff;
    font-weight: 600;
}

.sidebar-link i {
    width: 18px;
    text-align: center;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,.1);
    margin-top: auto;
}

/* ── Main Content Area ───────────────────────────────────────── */
#page-content-wrapper {
    flex: 1;
    margin-left: var(--cb-sidebar-width);
    transition: margin-left 0.25s ease;
    min-width: 0;
}

#page-content-wrapper.full-width {
    margin-left: 0;
}

main.content-area {
    padding: 1.5rem;
}

/* ── Page header ─────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.page-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: #1d3557;
    margin: 0;
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
    border: none;
    border-radius: var(--cb-border-radius);
    box-shadow: var(--cb-shadow);
}

.card-header {
    background-color: #fff;
    border-bottom: 2px solid #f0f0f0;
    font-weight: 600;
    font-size: 1rem;
    padding: 0.9rem 1.25rem;
}

/* Stat / KPI cards */
.stat-card {
    border-left: 4px solid var(--cb-primary);
}
.stat-card .stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--cb-primary);
}
.stat-card .stat-label {
    font-size: 0.85rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── Tables ──────────────────────────────────────────────────── */
.table {
    font-size: 0.95rem;
}

.table thead th {
    background-color: #1d3557;
    color: #fff;
    font-weight: 600;
    border: none;
    padding: 0.75rem 1rem;
    white-space: nowrap;
}

.table tbody tr:hover {
    background-color: #f8f9ff;
}

/* ── POS / Billing styles ────────────────────────────────────── */
.pos-wrapper {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 1rem;
    height: calc(100vh - var(--cb-navbar-height) - 2rem);
}

.pos-left {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pos-right {
    background: #fff;
    border-radius: var(--cb-border-radius);
    box-shadow: var(--cb-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Product search bar */
.pos-search-bar {
    position: relative;
}

.pos-search-bar .form-control {
    font-size: 1.1rem;
    padding: 0.7rem 1rem;
    border: 2px solid var(--cb-primary);
}

.pos-search-bar .form-control:focus {
    border-color: var(--cb-primary-dark);
    box-shadow: 0 0 0 0.2rem rgba(230,57,70,.2);
}

/* Autocomplete dropdown */
.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #dee2e6;
    border-top: none;
    border-radius: 0 0 var(--cb-border-radius) var(--cb-border-radius);
    max-height: 320px;
    overflow-y: auto;
    z-index: 1050;
    box-shadow: 0 6px 20px rgba(0,0,0,.15);
}

.autocomplete-item {
    display: flex;
    align-items: center;
    padding: 0.6rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #f5f5f5;
    gap: 0.75rem;
    transition: background .1s;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background-color: #fff5f5;
}

.autocomplete-item .ac-name {
    flex: 1;
}

.autocomplete-item .ac-name-en {
    font-weight: 600;
    font-size: 0.95rem;
    color: #1d3557;
    display: block;
}

.autocomplete-item .ac-name-ta {
    font-size: 0.85rem;
    color: #6c757d;
    font-family: 'Noto Sans Tamil', sans-serif;
    display: block;
}

.autocomplete-item .ac-price {
    text-align: right;
    flex-shrink: 0;
}

.autocomplete-item .ac-price-val {
    font-weight: 700;
    color: var(--cb-primary);
    font-size: 0.95rem;
    display: block;
}

.autocomplete-item .ac-stock {
    font-size: 0.75rem;
    color: #6c757d;
    display: block;
}

.autocomplete-item .ac-code {
    font-size: 0.75rem;
    color: #adb5bd;
    flex-shrink: 0;
}

/* POS billing table */
.pos-items-table {
    flex: 1;
    overflow-y: auto;
}

.pos-product-row td {
    padding: 0.45rem 0.5rem;
    vertical-align: middle;
}

.pos-product-row .item-name-en {
    font-weight: 600;
    font-size: 0.9rem;
}

.pos-product-row .item-name-ta {
    font-size: 0.8rem;
    color: #6c757d;
    font-family: 'Noto Sans Tamil', sans-serif;
}

.pos-qty-input,
.pos-rate-input,
.pos-discount-input {
    width: 80px;
    text-align: center;
    padding: 0.3rem 0.4rem;
    font-size: 0.9rem;
}

.pos-amount {
    font-weight: 700;
    color: #1d3557;
}

.pos-remove-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.85rem;
}

/* POS right panel - totals */
.pos-totals {
    padding: 1rem;
    border-top: 2px solid #f0f0f0;
}

.pos-total-row {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    font-size: 0.95rem;
}

.pos-grand-total {
    display: flex;
    justify-content: space-between;
    padding: 0.6rem 0;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--cb-primary);
    border-top: 2px solid #dee2e6;
    margin-top: 0.3rem;
}

.pos-action-btns {
    padding: 0.75rem 1rem;
    display: flex;
    gap: 0.5rem;
}

.pos-action-btns .btn {
    flex: 1;
    font-size: 1rem;
    font-weight: 600;
}

/* ── Badge / Status ──────────────────────────────────────────── */
.badge {
    font-size: 0.78rem;
    padding: 0.35em 0.65em;
}

/* ── Alerts / Flash ──────────────────────────────────────────── */
.alert {
    border-left: 4px solid currentColor;
    border-radius: var(--cb-border-radius);
}

/* ── Login Page ──────────────────────────────────────────────── */
.login-wrapper {
    min-height: 100vh;
    background: linear-gradient(135deg, #1d3557 0%, #457b9d 50%, var(--cb-primary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    width: 100%;
    max-width: 420px;
    border-radius: 1rem;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-logo {
    font-size: 2.5rem;
    color: var(--cb-primary);
}

/* ── Responsive: Mobile Sidebar ──────────────────────────────── */
@media (max-width: 992px) {
    .cb-sidebar {
        transform: translateX(calc(-1 * var(--cb-sidebar-width)));
        z-index: 1045;
    }

    .cb-sidebar.open {
        transform: translateX(0);
    }

    #page-content-wrapper {
        margin-left: 0;
    }

    /* Overlay when sidebar open on mobile */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.45);
        z-index: 1044;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* POS in single column on mobile */
    .pos-wrapper {
        grid-template-columns: 1fr;
        height: auto;
    }
}

@media (max-width: 576px) {
    main.content-area {
        padding: 1rem 0.75rem;
    }

    .page-title {
        font-size: 1.1rem;
    }
}

/* ── Print Styles ────────────────────────────────────────────── */
@media print {
    /* Hide everything except the invoice */
    .cb-navbar,
    .cb-sidebar,
    #sidebarToggleBtn,
    .no-print,
    .pos-wrapper .pos-right,
    .pos-action-btns {
        display: none !important;
    }

    #page-content-wrapper {
        margin-left: 0 !important;
    }

    body {
        background: #fff;
        font-size: 12pt;
    }

    .invoice-print-area {
        display: block !important;
        width: 100%;
    }

    .card {
        box-shadow: none;
        border: 1px solid #dee2e6;
    }

    a[href]::after {
        content: none !important;
    }

    .table {
        font-size: 10pt;
    }

    .invoice-header h2,
    .invoice-header h3 {
        font-size: 14pt;
    }
}

/* ── 80mm Thermal Printer Styles ─────────────────────────────── */
@media print and (max-width: 80mm) {
    @page {
        size: 80mm auto;
        margin: 0;
    }

    body {
        font-size: 9pt;
        width: 80mm;
    }

    .thermal-invoice {
        width: 76mm;
        margin: 0 auto;
        font-family: 'Noto Sans Tamil', monospace, sans-serif;
    }

    .thermal-invoice .th-header {
        text-align: center;
        font-size: 11pt;
        font-weight: bold;
        border-bottom: 1px dashed #000;
        padding-bottom: 4px;
        margin-bottom: 6px;
    }

    .thermal-invoice .th-company-ta {
        font-family: 'Noto Sans Tamil', sans-serif;
        font-size: 10pt;
        text-align: center;
    }

    .thermal-invoice table {
        width: 100%;
        border-collapse: collapse;
        font-size: 8pt;
    }

    .thermal-invoice table td,
    .thermal-invoice table th {
        padding: 2px 1px;
        vertical-align: top;
    }

    .thermal-invoice .th-total {
        border-top: 1px dashed #000;
        font-weight: bold;
        font-size: 10pt;
        text-align: right;
        padding-top: 4px;
        margin-top: 4px;
    }

    .thermal-invoice .th-footer {
        text-align: center;
        font-size: 8pt;
        border-top: 1px dashed #000;
        margin-top: 6px;
        padding-top: 4px;
    }
}
