/* ============================================
   Sasi Sales & Stock Management - Main Stylesheet
   Primary: #267568 | Secondary: #FFBD4A
   Font: Barlow
   ============================================ */

:root {
    --primary: #267568;
    --primary-rgb: 38, 117, 104;
    --primary-dark: #1a5249;
    --primary-light: #3aad95;
    --secondary: #FFBD4A;
    --secondary-rgb: 255, 189, 74;
    --secondary-dark: #e8a63a;
    --secondary-light: #ffd06f;
    --dark: #1a1a2e;
    --body-bg: #f0f2f5;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #17a2b8;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.25s ease;
}

* {
    font-family: 'Barlow', sans-serif;
}

body {
    background: var(--body-bg);
    color: #333;
    font-size: 15px;
    min-height: 100vh;
}

/* ---- Sidebar Layout ---- */
.app-body {
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1030;
    width: 260px;
    height: 100vh;
    background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-dark) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    transition: width 0.25s ease, transform 0.3s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.12);
    overflow: hidden;
}

.sidebar-header {
    flex-shrink: 0;
    padding: 1.25rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    min-height: 72px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.25rem;
}

.sidebar-brand i {
    font-size: 1.75rem;
    flex-shrink: 0;
}

.sidebar-brand-logo {
    height: 38px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
}
.sidebar-brand-logo-collapsed {
    display: none;
}
body.sidebar-collapsed .sidebar-brand-logo-expanded {
    display: none;
}
body.sidebar-collapsed .sidebar-brand-logo-collapsed {
    display: block;
    height: 32px;
}

.sidebar-brand-text {
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.2s;
}

.sidebar-toggle {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: #fff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.sidebar-toggle:hover {
    background: rgba(255,255,255,0.2);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 0.75rem;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.sidebar-nav::-webkit-scrollbar {
    display: none;
}

.nav-section {
    margin-bottom: 1.25rem;
}

.nav-section-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.5);
    padding: 0 0.75rem;
    margin-bottom: 0.5rem;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.65rem 0.75rem;
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.95rem;
    transition: var(--transition);
    margin-bottom: 2px;
}

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

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

.sidebar-nav .nav-link.active {
    background: var(--secondary);
    color: var(--primary-dark);
}

.sidebar-nav .nav-link.active:hover {
    background: var(--secondary-light);
    color: var(--primary-dark);
}

.sidebar-footer {
    flex-shrink: 0;
    padding: 1rem 0.75rem;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
}

.sidebar-user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--secondary);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.sidebar-user-info {
    overflow: hidden;
}

.sidebar-user-name {
    display: block;
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.6);
}

.nav-link-logout {
    color: rgba(255,255,255,0.7) !important;
}

.nav-link-logout:hover {
    background: rgba(220, 53, 69, 0.3) !important;
    color: #fff !important;
}

/* Sidebar collapsed */
body.sidebar-collapsed .sidebar {
    width: 72px;
}

body.sidebar-collapsed .sidebar-brand-text,
body.sidebar-collapsed .nav-section-label,
body.sidebar-collapsed .sidebar-nav .nav-link span,
body.sidebar-collapsed .sidebar-user-info,
body.sidebar-collapsed .nav-link-logout span {
    opacity: 0;
    visibility: hidden;
    width: 0;
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
}

body.sidebar-collapsed .sidebar-nav .nav-link {
    justify-content: center;
    padding: 0.65rem;
}

body.sidebar-collapsed .sidebar-toggle i {
    transform: rotate(180deg);
}

body.sidebar-collapsed .sidebar-user {
    justify-content: center;
    padding: 0.5rem;
}

body.sidebar-collapsed .nav-link-logout {
    justify-content: center;
    padding: 0.65rem;
}

/* App main content */
.app-main {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.25s ease;
    background: var(--body-bg);
}

body.sidebar-collapsed .app-main {
    margin-left: 72px;
}

.app-topbar {
    flex-shrink: 0;
    height: 64px;
    min-height: 64px;
    background: #fff;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
@media (min-width: 576px) {
    .app-topbar { padding: 0 1.5rem; }
}

.sidebar-toggle-mobile {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--primary);
    font-size: 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle-mobile:hover {
    background: rgba(var(--primary-rgb), 0.08);
}

.admin-access-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0.75rem 1rem;
    background: #fff8e5;
    border-bottom: 1px solid rgba(var(--secondary-rgb), 0.45);
    color: #5d4308;
}

.admin-access-banner-text {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-weight: 600;
}

.admin-access-banner-text span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 575.98px) {
    .admin-access-banner {
        align-items: flex-start;
        flex-direction: column;
    }
}

/* Mobile sidebar overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1029;
    opacity: 0;
    transition: opacity 0.3s ease;
}

body.sidebar-open .sidebar-overlay {
    display: block;
    opacity: 1;
}

@media (max-width: 991.98px) {
    .app-topbar {
        height: calc(72px + env(safe-area-inset-top));
        min-height: calc(72px + env(safe-area-inset-top));
        align-items: flex-end;
        padding: max(1rem, env(safe-area-inset-top)) 1rem 0.5rem;
    }

    .sidebar {
        transform: translateX(-100%);
    }

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

    .app-main {
        margin-left: 0 !important;
    }

    .sidebar-toggle {
        display: none !important;
    }
}

/* Legacy - keep for auth pages */
.user-avatar-sm {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--secondary);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

/* ---- Page Wrapper ---- */
.page-wrapper {
    flex: 1;
    padding: 1rem;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}
@media (min-width: 576px) {
    .page-wrapper { padding: 1.25rem 1.5rem; }
}
@media (min-width: 768px) {
    .page-wrapper { padding: 2rem 2.5rem; }
}

/* ---- Page Header ---- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 1.25rem;
}
.page-header .btn-group {
    flex-shrink: 0;
}
.page-header h4 {
    font-weight: 700;
    color: var(--dark);
    margin: 0;
    font-size: 1.3rem;
}

/* ---- Cards ---- */
.card {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: var(--transition);
}
.card:hover {
    box-shadow: var(--shadow-lg);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid #eee;
    font-weight: 600;
    padding: 1rem 1.25rem;
}

/* ---- Stat Cards ---- */
@media (max-width: 575.98px) {
    .row.g-3 .col-6, .row.g-4 .col-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}
.stat-card {
    border-radius: var(--radius);
    padding: 1.25rem;
    position: relative;
    overflow: hidden;
    color: #fff;
    min-height: 100px;
	background: #000000;
}
.stat-card .stat-icon {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 2.5rem;
    opacity: 0.2;
}
.stat-card .stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1.2;
}
.stat-card .stat-label {
    font-size: 0.85rem;
    opacity: 0.9;
    margin-top: 4px;
}
.stat-primary { background: linear-gradient(135deg, var(--primary), var(--primary-light)); }
.stat-secondary { background: linear-gradient(135deg, #e0a800, var(--warning)); color: var(--dark); }
.stat-success { background: linear-gradient(135deg, #1e7e34, var(--success)); }
.stat-info { background: linear-gradient(135deg, #117a8b, var(--info)); }
.stat-danger { background: linear-gradient(135deg, #bd2130, var(--danger)); }
.stat-card-clickable { cursor: pointer; transition: transform 0.2s ease, box-shadow 0.2s ease; }
.stat-card-clickable:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.15); }

a.stat-card-wrap {
    display: block;
    text-decoration: none !important;
    color: inherit;
}
a.stat-card-wrap:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
    border-radius: var(--radius);
}

.dashboard-financial-tile {
    border-radius: var(--radius);
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
}
a.dashboard-financial-tile:hover {
    background-color: rgba(0, 0, 0, 0.04);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.dashboard-date-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.dashboard-date-presets {
    display: inline-flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 100%;
    border: 1px solid var(--primary);
    border-radius: 4px;
    background: #fff;
}
.dashboard-date-preset {
    border: 0;
    border-right: 1px solid var(--primary);
    background: #fff;
    color: var(--primary);
    min-height: 36px;
    padding: 0.45rem 0.75rem;
    font-size: 0.9rem;
    line-height: 1;
    white-space: nowrap;
}
.dashboard-date-preset:last-child {
    border-right: 0;
}
.dashboard-date-preset:hover,
.dashboard-date-preset:focus {
    background: rgba(var(--primary-rgb), 0.08);
    outline: 0;
}
.dashboard-date-preset.active {
    background: var(--primary);
    color: #fff;
}
.dashboard-date-range {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
}
.dashboard-date-range .form-control {
    width: 150px;
    min-height: 36px;
}
.dashboard-date-to {
    color: var(--muted);
    font-weight: 600;
}
.dashboard-date-apply {
    min-height: 36px;
    white-space: nowrap;
}
.warrant-filter-toolbar {
    align-items: stretch;
}
.warrant-filter-toolbar .dashboard-date-presets,
.warrant-filter-toolbar .dashboard-date-range {
    flex: 0 1 auto;
}
.warrant-filter-toolbar .dashboard-date-preset,
.warrant-filter-toolbar .dashboard-date-apply,
.warrant-filter-toolbar .form-control,
.warrant-filter-toolbar .form-select {
    min-height: 32px;
    height: 32px;
}
.warrant-filter-toolbar .dashboard-date-preset {
    padding: 0.35rem 0.62rem;
    font-size: 0.82rem;
}
.warrant-filter-toolbar .dashboard-date-range .form-control {
    width: 132px;
}
.warrant-filter-toolbar .form-select {
    width: 170px;
    min-width: 150px;
}

@media (max-width: 767.98px) {
    .dashboard-date-toolbar,
    .dashboard-date-range {
        width: 100%;
    }
    .dashboard-date-presets {
        width: 100%;
    }
    .dashboard-date-range {
        flex-wrap: wrap;
    }
    .dashboard-date-range .form-control {
        flex: 1 1 135px;
        width: auto;
    }
    .dashboard-date-apply {
        flex: 1 1 100%;
    }
    .warrant-filter-toolbar .dashboard-date-range .form-control,
    .warrant-filter-toolbar .form-select {
        flex: 1 1 140px;
        width: auto;
    }
}

.analytics-bar-row {
    padding: 0.55rem 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
.analytics-bar-row:last-child {
    border-bottom: 0;
}
.analytics-bar-track {
    width: 100%;
    height: 8px;
    background: #edf1f4;
    border-radius: 999px;
    overflow: hidden;
}
.analytics-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--success));
    border-radius: inherit;
}

/* ---- Buttons ---- */
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}
.btn-secondary {
    background: var(--secondary);
    border-color: var(--secondary);
    color: var(--dark);
}
.btn-secondary:hover {
    background: var(--secondary-dark);
    border-color: var(--secondary-dark);
    color: var(--dark);
}
.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}
.btn-outline-primary:hover {
    background: var(--primary);
    color: #fff;
}

/* ---- Forms ---- */
.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.15rem rgba(var(--primary-rgb), 0.2);
}
.form-label {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

/* ---- Mobile Form Ergonomics ---- */
.commerce-modal .modal-body {
    background: #f8fafc;
}
.commerce-line-items {
    overflow: visible;
}
.commerce-line-items .form-control,
.commerce-line-items .form-select {
    min-width: 92px;
}
.commerce-line-items textarea {
    resize: vertical;
}
.commerce-actions {
    gap: 0.75rem;
}
.commerce-add-line {
    width: auto;
}
.import-preview-table {
    max-height: 320px;
    overflow: auto;
}
.import-preview-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f8fafc;
    white-space: nowrap;
}
.import-preview-table td {
    min-width: 120px;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.import-error-details {
    background: #fff;
}

@media (max-width: 767.98px) {
    input.form-control,
    select.form-select,
    textarea.form-control,
    .input-group > .form-control,
    .input-group > .form-select {
        min-height: 48px;
        font-size: 16px;
    }
    textarea.form-control {
        min-height: 88px;
    }
    .btn {
        min-height: 44px;
        padding: 0.6rem 0.9rem;
    }
    .btn-sm {
        min-height: 42px;
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }
    .btn-close {
        min-width: 44px;
        min-height: 44px;
        padding: 0.75rem;
        background-size: 0.9rem;
    }
    .form-check-input {
        width: 1.35rem;
        height: 1.35rem;
    }
    .form-switch .form-check-input {
        width: 2.7rem;
    }
    .form-check-label {
        padding-top: 0.15rem;
        padding-left: 0.25rem;
    }
    .page-header {
        align-items: stretch;
    }
    .page-header > div:first-child {
        width: 100%;
    }
    .page-header > .btn,
    .page-header > .btn-group {
        width: 100%;
    }
    .page-header > .btn-group .btn {
        flex: 1 1 auto;
    }
    .commerce-modal {
        margin: 0;
        width: 100%;
        max-width: none;
        height: 100%;
    }
    .commerce-modal .modal-content {
        min-height: 100%;
        border: 0;
        border-radius: 0;
    }
    .commerce-modal .modal-header {
        position: sticky;
        top: 0;
        z-index: 30;
        background: #fff;
        padding: 0.75rem 1rem;
    }
    .commerce-modal .modal-body {
        padding: 1rem;
    }
    .commerce-modal .modal-footer,
    .commerce-actions {
        position: sticky;
        bottom: 0;
        z-index: 30;
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
        padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, 0.98);
        box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.1);
    }
    .commerce-modal .modal-footer .btn,
    .commerce-actions .btn {
        width: 100%;
        min-height: 50px;
    }
    .commerce-line-items table,
    .commerce-line-items thead,
    .commerce-line-items tbody,
    .commerce-line-items tr,
    .commerce-line-items td {
        display: block;
        width: 100%;
    }
    .commerce-line-items thead {
        display: none;
    }
    .commerce-line-items tr {
        padding: 0.85rem;
        margin-bottom: 1rem;
        border: 1px solid #dbe3ea;
        border-radius: 12px;
        background: #fff;
        box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
    }
    .commerce-line-items td {
        padding: 0.4rem 0;
        border: 0;
    }
    .commerce-line-items td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 0.3rem;
        color: #64748b;
        font-size: 0.78rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.02em;
    }
    .commerce-line-items td[data-label=""]::before {
        display: none;
    }
    .commerce-line-items td[data-label="Remove"] {
        padding-top: 0.75rem;
    }
    .commerce-line-items td[data-label="Remove"] .btn {
        width: 100%;
    }
    .commerce-line-items .input-group .btn {
        min-width: 52px;
    }
    .commerce-add-line {
        width: 100%;
    }
    .approval-row,
    .expense-row {
        margin-left: 0;
        margin-right: 0;
        padding: 0.85rem;
        border: 1px solid #dbe3ea;
        border-radius: 12px;
        background: #fff;
    }
    .expense-row > [class*="col-"] {
        width: 100%;
    }
    .expense-row .btn {
        width: 100%;
    }
    .mobile-form-actions {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.75rem;
        margin-top: 1rem;
    }
    .mobile-form-actions .btn {
        width: 100%;
    }
}

/* ---- Material-Style Form Field (outlined) ---- */
.form-field {
    position: relative;
}

.form-field .form-control,
.form-field .form-select {
    border: 2px solid #ced4da;
    border-radius: 10px;
    padding: 1.1rem 0.875rem 0.45rem;
    min-height: 54px;
    height: auto;
    background: #fff;
    font-size: 0.95rem;
    line-height: 1.4;
    box-shadow: none !important;
    transition: border-color 0.2s ease;
}

.form-field .form-control:focus,
.form-field .form-select:focus {
    border-color: var(--primary);
    box-shadow: none !important;
}

.form-field .form-label {
    position: absolute;
    top: -0.55rem;
    left: 0.75rem;
    padding: 0 4px;
    margin: 0;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1;
    color: #6b7280;
    background: #fff;
    pointer-events: none;
    z-index: 2;
    white-space: nowrap;
    max-width: calc(100% - 1.5rem);
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s ease;
}

.form-field:focus-within .form-label {
    color: var(--primary);
}

.form-field textarea.form-control {
    padding-top: 1.4rem;
    min-height: 80px;
    resize: vertical;
}

.form-field .form-control[readonly],
.form-field .form-control:disabled {
    background: #f3f4f6;
    border-color: #e5e7eb;
    color: #9ca3af;
    cursor: default;
}

.form-field .form-select {
    padding-right: 2.5rem;
}

.form-field + small {
    display: block;
    margin-top: 0.35rem;
    padding-left: 0.25rem;
}

.form-field .form-control.is-invalid,
.form-field .form-select.is-invalid {
    border-color: var(--danger);
}

.form-field:has(.is-invalid) .form-label {
    color: var(--danger);
}

.region-select-wrap {
    position: relative;
}
.region-select-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 230px;
    overflow-y: auto;
    z-index: 1060;
    border-radius: 8px;
}
.region-select-menu .list-group-item {
    cursor: pointer;
}
.region-select-menu .list-group-item:hover,
.region-select-menu .list-group-item:focus {
    background: rgba(0, 100, 84, 0.08);
    color: var(--primary);
}
.ew-autocomplete-menu {
    position: fixed;
    z-index: 3000;
    max-height: min(320px, 45vh);
    overflow-y: auto;
    border-radius: 8px;
    background: #fff;
    border: 1px solid #dbe3ea;
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.18);
}
.ew-autocomplete-menu .list-group-item {
    border-left: 0;
    border-right: 0;
}
.ew-autocomplete-menu .list-group-item:first-child {
    border-top: 0;
}
.ew-autocomplete-menu .list-group-item:last-child {
    border-bottom: 0;
}
.ew-autocomplete-menu .list-group-item:hover,
.ew-autocomplete-menu .list-group-item:focus {
    background: rgba(0, 100, 84, 0.08);
    color: var(--primary);
}

/* ---- Invoice Builder ---- */
.invoice-builder {
    position: relative;
}
.invoice-builder .invoice-section {
    padding: 1rem 0;
    border-top: 1px solid #e5e7eb;
}
.invoice-builder .invoice-section:first-of-type {
    border-top: 0;
    padding-top: 0;
}
.invoice-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}
.invoice-section-title h6 {
    margin: 0;
    font-weight: 800;
    color: #111827;
}
.invoice-item-table {
    overflow: visible;
}
.invoice-item-table .table {
    margin-bottom: 0;
}
.invoice-item-table td {
    vertical-align: top;
}
.invoice-total-panel {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.9rem 1rem;
}
.invoice-total-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.25rem 0;
}
.invoice-total-row strong {
    white-space: nowrap;
}
.invoice-total-row.grand {
    margin-top: 0.35rem;
    padding-top: 0.7rem;
    border-top: 1px solid #dbe3ea;
    font-size: 1.08rem;
}
.invoice-submit-bar {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    align-items: center;
    padding-top: 1rem;
    border-top: 1px solid #e5e7eb;
}

/* ---- Warrant Product Builder ---- */
.warrant-product-table {
    overflow: visible;
}
.warrant-product-table .unit-price {
    min-width: 120px;
}

@media (max-width: 767.98px) {
    .invoice-builder .card-body {
        padding: 1rem;
    }
    .invoice-section-title {
        align-items: flex-start;
        flex-direction: column;
    }
    .invoice-item-table {
        overflow: visible;
    }
    .invoice-item-table table,
    .invoice-item-table thead,
    .invoice-item-table tbody,
    .invoice-item-table tr,
    .invoice-item-table td {
        display: block;
        width: 100%;
    }
    .invoice-item-table thead {
        display: none;
    }
    .invoice-item-table tr {
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        padding: 0.75rem;
        margin-bottom: 0.85rem;
        background: #fff;
    }
    .invoice-item-table td {
        border: 0;
        padding: 0.35rem 0;
    }
    .invoice-item-table td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 0.25rem;
        color: #64748b;
        font-size: 0.78rem;
        font-weight: 700;
    }
    .invoice-item-table td[data-label=""]::before {
        display: none;
    }
    .invoice-submit-bar {
        position: sticky;
        bottom: calc(70px + env(safe-area-inset-bottom));
        z-index: 20;
        margin: 1rem -1rem -1rem;
        padding: 0.75rem 1rem;
        background: rgba(255, 255, 255, 0.96);
        box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.08);
    }
    .invoice-submit-bar .btn {
        width: 100%;
    }
    .warrant-product-table {
        overflow: visible;
    }
    .warrant-product-table table,
    .warrant-product-table thead,
    .warrant-product-table tbody,
    .warrant-product-table tr,
    .warrant-product-table td {
        display: block;
        width: 100%;
    }
    .warrant-product-table thead {
        display: none;
    }
    .warrant-product-table tr {
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        padding: 0.75rem;
        margin-bottom: 0.85rem;
        background: #fff;
    }
    .warrant-product-table td {
        border: 0;
        padding: 0.35rem 0;
    }
    .warrant-product-table td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 0.25rem;
        color: #64748b;
        font-size: 0.78rem;
        font-weight: 700;
    }
    .warrant-product-table td[data-label=""]::before {
        display: none;
    }
    .warrant-product-table .unit-price {
        min-width: 0;
        width: 100%;
    }
}

/* ---- Password Toggle ---- */
.password-wrapper {
    position: relative;
}
.password-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: #6c757d;
    background: none;
    border: none;
    padding: 0;
    z-index: 5;
}
.password-toggle:hover {
    color: var(--primary);
}

/* ---- Auth Pages ---- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 1rem;
}
.auth-card {
    width: 100%;
    max-width: 440px;
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
}
.auth-header {
    background: var(--primary);
    color: #fff;
    padding: 1.5rem;
    text-align: center;
}
.auth-header h3 {
    font-weight: 700;
    margin: 0;
}
.auth-logo {
    max-height: 48px;
    width: auto;
    margin-bottom: 8px;
}
.auth-header .subtitle {
    opacity: 0.8;
    font-size: 0.9rem;
}
.auth-body {
    padding: 1.5rem;
    background: #fff;
}

/* ---- Data Table ---- */
.ew-table-container {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.ew-table-toolbar {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    border-bottom: 1px solid #eee;
}
.ew-table-search {
    max-width: 280px;
}
.ew-table-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.ew-table-sort {
    width: 250px;
}
.ew-table-sort .sort-direction {
    min-width: 42px;
}
.ew-table table {
    margin: 0;
}
.ew-table th {
    background: #f8f9fa;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    color: #555;
    letter-spacing: 0.3px;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    border-bottom: 2px solid #dee2e6;
}
.ew-table th:hover {
    background: #e9ecef;
}
.ew-table th .sort-icon {
    margin-left: 4px;
    opacity: 0.4;
}
.ew-table th.sorted .sort-icon {
    opacity: 1;
    color: var(--primary);
}
.ew-table td {
    vertical-align: middle;
    font-size: 0.95rem;
}
.ew-table-footer {
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    border-top: 1px solid #eee;
    font-size: 0.9rem;
}
.ew-pagination .page-link {
    color: var(--primary);
    border-radius: 6px;
    margin: 0 2px;
    font-size: 0.85rem;
}
.ew-pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* ---- Mobile Card Layout ---- */
.mobile-card {
    display: none;
}
.ew-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
@media (max-width: 767.98px) {
    .ew-table-toolbar {
        align-items: stretch;
    }
    .ew-table-toolbar > .d-flex,
    .ew-table-controls,
    .ew-table-search,
    .ew-table-sort {
        width: 100%;
        max-width: none;
    }
    .ew-table-controls {
        flex-wrap: wrap;
    }
    .ew-table-controls > .dropdown {
        flex: 1 1 auto;
    }
    .ew-table-controls > .dropdown > .btn {
        width: 100%;
    }
    .ew-table .desktop-table {
        display: none;
    }
    .mobile-card {
        display: block;
    }
    .mobile-card-item {
        background: #fff;
        border-radius: var(--radius-sm);
        padding: 1rem;
        margin-bottom: 0.75rem;
        box-shadow: 0 1px 4px rgba(0,0,0,0.06);
        border-left: 4px solid var(--primary);
    }
    .mobile-card-item .card-row {
        display: flex;
        justify-content: space-between;
        padding: 4px 0;
        font-size: 0.9rem;
    }
    .mobile-card-item .card-row .label {
        color: #888;
        font-weight: 600;
        font-size: 0.8rem;
        text-transform: uppercase;
    }
    .mobile-card-item .card-row .value {
        font-weight: 500;
        text-align: right;
    }
    .mobile-card-item .card-actions {
        display: flex;
        gap: 8px;
        margin-top: 8px;
        padding-top: 8px;
        border-top: 1px solid #eee;
    }
    .mobile-card-item .card-title {
        font-weight: 700;
        font-size: 1rem;
        margin-bottom: 6px;
        color: var(--dark);
    }
}

/* ---- Bulk Actions Bar ---- */
.bulk-actions-bar {
    background: var(--primary);
    color: #fff;
    padding: 8px 16px;
    display: none;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
}
.bulk-actions-bar.active {
    display: flex;
}

/* ---- Badges ---- */
.badge-active { background: var(--success); }
.badge-inactive { background: var(--danger); }
.badge-pending { background: var(--warning); color: #333; }
.badge-expired { background: #6c757d; }

/* ---- Toast ---- */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
}
.toast {
    border: none;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
}

/* ---- PWA Install UI ---- */
.pwa-install-button {
    position: fixed;
    right: calc(16px + env(safe-area-inset-right));
    bottom: calc(18px + env(safe-area-inset-bottom));
    z-index: 1080;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 14px;
    border: 0;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
    box-shadow: 0 14px 34px rgba(var(--primary-rgb), 0.32);
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.pwa-install-button:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 18px 42px rgba(var(--primary-rgb), 0.38);
}
.pwa-install-button:active { transform: translateY(1px); }
.pwa-install-button[hidden] { display: none; }
.pwa-install-button i { font-size: 1.05rem; }
body.has-bottom-nav .pwa-install-button {
    bottom: calc(82px + env(safe-area-inset-bottom));
}

.pwa-ios-modal .modal-content {
    border: 0;
    border-radius: 16px;
    overflow: hidden;
}
.ios-guide-svg {
    width: min(100%, 300px);
    height: auto;
    margin: 6px auto 16px;
}
.ios-phone { fill: #102a43; }
.ios-screen { fill: #f8fafc; }
.ios-home { fill: #cbd5e1; }
.ios-menu {
    fill: #fff;
    stroke: #dbe3ea;
    stroke-width: 2;
}
.ios-menu-line,
.ios-tray,
.ios-share-box {
    fill: none;
    stroke: var(--primary);
    stroke-width: 5;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.ios-arrow,
.ios-arrow-head,
.ios-share-stem,
.ios-share-head {
    fill: none;
    stroke: var(--secondary);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.ios-arrow {
    stroke-dasharray: 70;
    animation: iosArrow 1.4s ease-in-out infinite;
}
.ios-tap {
    fill: rgba(var(--primary-rgb), 0.15);
    stroke: var(--primary);
    stroke-width: 2;
    transform-origin: center;
}
.ios-tap-one { animation: iosTap 1.8s ease-in-out infinite; }
.ios-tap-two { animation: iosTap 1.8s ease-in-out 0.75s infinite; }
.pwa-ios-steps {
    display: grid;
    gap: 10px;
    text-align: left;
    margin-top: 8px;
}
.pwa-ios-steps div {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    color: #334155;
    background: #f8fafc;
}
.pwa-ios-steps span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 0.8rem;
    flex: 0 0 auto;
}
@keyframes iosArrow {
    0%, 100% { opacity: 0.35; transform: translateY(8px); }
    45% { opacity: 1; transform: translateY(-4px); }
}
@keyframes iosTap {
    0%, 65%, 100% { opacity: 0; transform: scale(0.65); }
    20% { opacity: 1; transform: scale(1); }
    45% { opacity: 0; transform: scale(1.35); }
}

/* ---- Rich Text Editor ---- */
.ql-toolbar {
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    border-color: #dee2e6;
}
.ql-container {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    border-color: #dee2e6;
    min-height: 200px;
    font-family: 'Barlow', sans-serif;
}

/* ---- Column Toggle Dropdown ---- */
.column-toggle-dropdown {
    min-width: 200px;
    padding: 0.5rem;
}
.column-toggle-dropdown .form-check {
    padding: 4px 8px 4px 28px;
}

/* ---- Loading Spinner ---- */
.ew-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}
.ew-loading .spinner-border {
    color: var(--primary);
}

/* ---- Warranty Card (Premium) ---- */
.wc {
    max-width: 680px;
    margin: 0 auto;
    background: #fff;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 16px 56px rgba(28,47,96,0.18), 0 2px 8px rgba(0,0,0,0.06);
}

/* Header */
.wc-header { background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 70%, var(--primary-light) 100%); padding: 28px 36px 18px; }
.wc-header-row { display: flex; justify-content: space-between; align-items: flex-start; }
.wc-header-brand { flex: 1; min-width: 0; }
.wc-header-status { flex-shrink: 0; padding-left: 16px; padding-top: 2px; }
.wc-logo-wrap { margin-bottom: 10px; }
.wc-logo-wrap img { height: 44px; width: auto; object-fit: contain; }
.wc-biz { color: #fff; font-size: 20px; font-weight: 700; letter-spacing: 0.2px; line-height: 1.25; }
.wc-biz-info { color: rgba(255,255,255,0.6); font-size: 11px; margin-top: 3px; }
.wc-status { display: inline-block; padding: 5px 14px; border-radius: 20px; font-size: 10px; font-weight: 700; letter-spacing: 1px; border: 1.5px solid rgba(255,255,255,0.4); background: rgba(255,255,255,0.15); color: #fff; }
.wc-status-expired { background: rgba(239,68,68,0.2); border-color: rgba(239,68,68,0.55); color: #fca5a5; }

/* Certificate title band */
.wc-cert-band { display: flex; align-items: center; gap: 14px; margin-top: 20px; }
.wc-cert-line-l, .wc-cert-line-r { flex: 1; }
.wc-cert-line-inner { height: 1px; background: rgba(255,255,255,0.2); }
.wc-cert-label { color: var(--secondary); font-size: 9px; font-weight: 700; letter-spacing: 3.5px; text-transform: uppercase; white-space: nowrap; }
.wc-id-row { margin-top: 10px; }
.wc-id-num { color: rgba(255,255,255,0.7); font-size: 12px; font-weight: 600; letter-spacing: 0.3px; }
.wc-id-num strong { color: #fff; }

/* Gold accent stripe */
.wc-accent-bar { height: 4px; background: var(--secondary); }

/* Body */
.wc-body { padding: 24px 36px 12px; }

/* Product card */
.wc-product-card { background: #ecf6f4; border-radius: 12px; padding: 18px 20px; margin-bottom: 20px; border: 1px solid rgba(38,117,104,0.08); }
.wc-product-row { display: flex; align-items: flex-start; }
.wc-product-main-cell { flex: 1; min-width: 0; padding-right: 16px; }
.wc-product-qty-cell { flex-shrink: 0; text-align: right; }
.wc-label { font-size: 9px; text-transform: uppercase; letter-spacing: 1px; color: #94a3b8; font-weight: 700; margin-bottom: 5px; }
.wc-product-name { font-size: 18px; font-weight: 700; color: var(--primary); line-height: 1.2; }
.wc-qty-val { font-size: 24px; font-weight: 700; color: var(--primary); line-height: 1; }
.wc-serial-section { margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(38,117,104,0.12); }
.wc-serial-val { font-size: 13px; font-weight: 600; color: #1e293b; font-family: 'Courier New', monospace; margin-top: 4px; margin-bottom: 8px; }
.wc-barcode-wrap { margin-top: 6px; }
.wc-barcode { display: block; max-width: 100%; height: auto; }

/* Customer info */
.wc-info-row { display: flex; flex-wrap: wrap; gap: 12px 0; margin-bottom: 16px; }
.wc-info-cell { flex: 1; min-width: 0; padding-right: 10px; }
.wc-val { font-size: 14px; font-weight: 600; color: #1e293b; margin-top: 4px; }

/* Dashed divider */
.wc-divider { border: none; border-top: 1px dashed #cbd5e1; margin: 0 0 16px; }

/* Dates */
.wc-dates-row { display: flex; margin-bottom: 20px; border-radius: 10px; overflow: hidden; border: 1px solid #cfe8e2; }
.wc-date-cell { flex: 1; padding: 12px 14px; background: #f4faf9; }
.wc-date-cell + .wc-date-cell { border-left: 1px solid #cfe8e2; }
.wc-date-val { font-size: 13px; font-weight: 700; color: #1e293b; margin-top: 5px; }

/* Terms */
.wc-note-block { margin-bottom: 16px; padding: 12px 14px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; }
.wc-note-body { font-size: 12px; color: #475569; line-height: 1.5; }
.wc-terms-row { display: flex; align-items: flex-end; margin-bottom: 20px; gap: 16px; }
.wc-terms-col { flex: 1; min-width: 0; }
.wc-stamp-col { flex-shrink: 0; }
.wc-terms h4 { font-size: 10px; color: var(--primary); text-transform: uppercase; letter-spacing: 1px; font-weight: 700; margin: 0 0 6px; }
.wc-terms-body { font-size: 11px; color: #64748b; line-height: 1.6; }

/* QR section */
.wc-qr-section { background: var(--primary-dark); padding: 22px 36px; }
.wc-qr-row { display: flex; align-items: center; gap: 24px; }
.wc-qr-img-cell { flex-shrink: 0; }
.wc-qr-img-inner { background: #fff; border-radius: 10px; padding: 8px; display: inline-block; line-height: 0; }
.wc-qr-img-inner img { display: block; border-radius: 4px; }
.wc-qr-text-cell { flex: 1; min-width: 0; }
.wc-scan-label { font-size: 9px; font-weight: 700; letter-spacing: 2.5px; color: var(--secondary); text-transform: uppercase; margin-bottom: 8px; }
.wc-warrant-ref { font-size: 18px; font-weight: 700; color: #fff; margin-bottom: 6px; }
.wc-verify-url { font-size: 11px; color: rgba(255,255,255,0.55); word-break: break-all; }

/* Gold footer bar */
.wc-footer-bar { background: var(--secondary); padding: 10px 36px; display: flex; justify-content: space-between; align-items: center; }
.wc-footer-left { font-size: 10px; color: #5c4510; font-weight: 700; letter-spacing: 0.3px; }
.wc-footer-right { text-align: right; }
.wc-footer-biz { font-size: 11px; font-weight: 700; color: #3b2a08; line-height: 1.3; }
.wc-footer-contact { font-size: 10px; color: #5c4510; font-weight: 500; margin-top: 2px; }

/* Mobile */
@media (max-width: 575.98px) {
    .wc-header, .wc-body, .wc-qr-section, .wc-footer-bar { padding-left: 20px; padding-right: 20px; }
    .wc-product-card { padding: 14px 16px; }
    .wc-dates-row { flex-direction: column; border-radius: 10px; }
    .wc-date-cell + .wc-date-cell { border-left: none; border-top: 1px solid #cfe8e2; }
    .wc-qr-row { flex-direction: column; text-align: center; }
    .wc-qr-text-cell { text-align: center; }
    .wc-footer-bar { flex-direction: column; gap: 2px; text-align: center; }
}

/* ---- Verification Page ---- */
.verify-page {
    min-height: 100vh;
    background: var(--body-bg);
    padding: 1rem;
}
.verify-card {
    max-width: 500px;
    margin: 2rem auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.verify-header {
    background: var(--primary);
    color: #fff;
    padding: 1.5rem;
    text-align: center;
}
.verify-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.95rem;
}
.verify-badge.valid {
    background: var(--success);
    color: #fff;
}
.verify-badge.expired {
    background: var(--danger);
    color: #fff;
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #999;
}
.empty-state i {
    font-size: 3rem;
    opacity: 0.4;
    margin-bottom: 1rem;
}
.empty-state h5 {
    font-weight: 600;
}

/* ---- Utility ---- */
.text-primary { color: var(--primary) !important; }
.bg-primary { background-color: var(--primary) !important; }
.border-primary { border-color: var(--primary) !important; }
.fw-700 { font-weight: 700; }
.fs-sm { font-size: 0.85rem; }
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Animations ---- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.fade-in {
    animation: fadeIn 0.3s ease;
}

/* ---- Bottom Nav (mobile) ---- */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1020;
    background: #fff;
    border-top: 1px solid #eee;
    padding: 0.5rem 0;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0.5rem 0.25rem;
    color: #64748b;
    text-decoration: none;
    font-size: 0.7rem;
    font-weight: 500;
    transition: var(--transition);
}

.bottom-nav-item i {
    font-size: 1.25rem;
}

.bottom-nav-item:hover {
    color: var(--primary);
}

.bottom-nav-item.active {
    color: var(--primary);
}

.bottom-nav-item.active i {
    color: var(--primary);
}

@media (max-width: 991.98px) {
    .bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: stretch;
    }

    .app-main {
        padding-bottom: 5rem;
    }
}

@media (min-width: 992px) {
    .app-main {
        padding-bottom: 0;
    }
}

/* ---- Footer ---- */
.footer-ew {
    background: #fff;
    border-top: 1px solid #eee;
    padding: 1rem 1.5rem;
    text-align: center;
    font-size: 0.85rem;
    color: #888;
    margin-top: auto;
}
