/* ==========================================================================
   LAK TRACTOR SPARE PARTS & AUTO CENTER - Point of Sale & Inventory System
   Designed for Tractor Spare Parts Counter POS, Warehouse Shelving & Credit Accounting
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=Noto+Sans+Sinhala:wght@400;500;600;700&display=swap');

:root {
    /* Color Palette */
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    
    --success: #10b981;
    --success-hover: #059669;
    --success-light: #ecfdf5;
    
    --warning: #f59e0b;
    --warning-hover: #d97706;
    --warning-light: #fffbeb;
    --warning-dark: #b45309;

    --danger: #ef4444;
    --danger-hover: #dc2626;
    --danger-light: #fef2f2;

    --info: #0284c7;
    --info-light: #f0f9ff;

    --dark-900: #0f172a;
    --dark-800: #1e293b;
    --dark-700: #334155;
    --dark-600: #475569;
    --gray-400: #94a3b8;
    --gray-300: #cbd5e1;
    --gray-200: #e2e8f0;
    --gray-100: #f1f5f9;
    --gray-50:  #f8fafc;
    --white:    #ffffff;

    /* Typography */
    --font-main: 'Plus Jakarta Sans', 'Noto Sans Sinhala', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    
    /* Layout */
    --sidebar-width: 260px;
    --header-height: 64px;
    --bottom-nav-height: 64px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 9999px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    font-family: var(--font-main);
    background-color: #f1f5f9;
    color: var(--dark-800);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding-bottom: calc(var(--bottom-nav-height) + 16px);
    overflow-x: hidden;
    max-width: 100vw;
}

@media (min-width: 1024px) {
    body {
        padding-bottom: 0;
    }
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: all 0.2s;
}

/* ==========================================================================
   App Layout
   ========================================================================== */

.app-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

/* Sidebar for Desktop & Mobile Off-Canvas Drawer */
.sidebar {
    width: var(--sidebar-width);
    background: var(--dark-900);
    color: var(--white);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1050;
    box-shadow: var(--shadow-lg);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Mobile & Tablet (< 1024px): Slide-out drawer */
@media (max-width: 1023px) {
    .sidebar {
        transform: translateX(-100%);
        width: 290px;
        max-width: 86vw;
        z-index: 1050;
    }
    
    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 10px 0 50px rgba(0, 0, 0, 0.5);
    }
    
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* Desktop (>= 1024px): Fixed static sidebar */
@media (min-width: 1024px) {
    .sidebar {
        transform: none !important;
        z-index: 100;
    }
    .main-content {
        margin-left: var(--sidebar-width);
        width: calc(100% - var(--sidebar-width));
        max-width: calc(100% - var(--sidebar-width));
        min-width: 0;
    }
}

/* Backdrop Overlay for Mobile Drawer */
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.sidebar-brand {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-close-btn {
    display: none;
    margin-left: auto;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: var(--white);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    cursor: pointer;
    transition: background 0.2s;
}

.sidebar-close-btn:hover, .sidebar-close-btn:active {
    background: rgba(255, 255, 255, 0.25);
}

@media (max-width: 1023px) {
    .sidebar-close-btn {
        display: inline-flex;
    }
}

.brand-icon {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--primary), #818cf8);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: var(--white);
}

.brand-text h2 {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--white);
    line-height: 1.2;
}

.brand-text span {
    font-size: 0.72rem;
    color: var(--gray-400);
    font-weight: 500;
}

.sidebar-menu {
    list-style: none;
    padding: 16px 12px;
    flex: 1;
    overflow-y: auto;
}

.menu-category {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-400);
    padding: 12px 12px 6px;
    font-weight: 700;
}

.menu-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: #cbd5e1;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 4px;
    transition: all 0.2s;
}

.menu-item a:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--white);
    transform: translateX(3px);
}

.menu-item.active a {
    background: var(--primary);
    color: var(--white);
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

.menu-item .menu-badge {
    margin-left: auto;
    font-size: 0.72rem;
    padding: 2px 7px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.15);
}

/* User Card in Sidebar */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 38px;
    height: 38px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--white);
}

.user-info {
    flex: 1;
    overflow: hidden;
}

.user-info .name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--white);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.user-info .role {
    font-size: 0.72rem;
    color: var(--gray-400);
}

/* Main Content Area */
.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    max-width: 100%;
}

/* Header */
.top-header {
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 90;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Mobile Hamburger Toggle Button */
.btn-mobile-menu {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    background: #f1f5f9;
    color: var(--dark-900);
    border: 1px solid var(--gray-300);
    font-size: 1.35rem;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-mobile-menu:hover, .btn-mobile-menu:active {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

@media (min-width: 1024px) {
    .btn-mobile-menu {
        display: none !important;
    }
}

.mobile-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--dark-900);
}

@media (min-width: 1024px) {
    .mobile-logo {
        display: none;
    }
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Mobile Quick POS Shortcut Button */
.btn-quick-pos {
    background: linear-gradient(135deg, #4f46e5, #4338ca);
    color: var(--white);
    font-weight: 700;
    font-size: 0.88rem;
    padding: 8px 14px;
    border-radius: var(--radius-full);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
    animation: pulse-soft 2s infinite;
}

@keyframes pulse-soft {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* Bottom Navigation Bar for Mobile */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 100;
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.05);
}

@media (min-width: 1024px) {
    .bottom-nav {
        display: none;
    }
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--dark-600);
    font-size: 0.68rem;
    font-weight: 600;
    text-align: center;
    padding: 6px 4px;
    width: 20%;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s ease;
}

.bottom-nav-item .icon {
    font-size: 1.25rem;
    margin-bottom: 2px;
}

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

.bottom-nav-item.pos-highlight {
    color: var(--white);
    background: linear-gradient(135deg, var(--primary), #6366f1);
    border-radius: var(--radius-lg);
    padding: 8px 6px;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
    margin: 0 2px;
    transform: translateY(-8px);
}

/* ==========================================================================
   Page Container & Cards
   ========================================================================== */

.page-container {
    padding: 16px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

@media (min-width: 768px) {
    .page-container {
        padding: 24px;
    }
}

.page-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

@media (min-width: 640px) {
    .page-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

.page-title {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--dark-900);
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-subtitle {
    font-size: 0.82rem;
    color: var(--dark-600);
}

/* Card Component */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 20px;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--dark-900);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body {
    padding: 20px;
}

/* ==========================================================================
   KPI Stats Grid (Executive Dashboard)
   ========================================================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 14px;
    margin-bottom: 24px;
}

@media (min-width: 480px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 18px;
    border: 1px solid var(--gray-200);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
}

.stat-card.primary::before { background: var(--primary); }
.stat-card.success::before { background: var(--success); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.danger::before  { background: var(--danger); }
.stat-card.info::before    { background: var(--info); }

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--dark-600);
    margin-bottom: 6px;
}

.stat-value {
    font-size: 1.45rem;
    font-weight: 800;
    color: var(--dark-900);
    line-height: 1.2;
    margin-bottom: 4px;
}

.stat-subtext {
    font-size: 0.75rem;
    color: var(--gray-400);
}

.stat-icon {
    width: 46px;
    height: 46px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.stat-icon.primary { background: var(--primary-light); color: var(--primary); }
.stat-icon.success { background: var(--success-light); color: var(--success); }
.stat-icon.warning { background: var(--warning-light); color: var(--warning-dark); }
.stat-icon.danger  { background: var(--danger-light); color: var(--danger); }
.stat-icon.info    { background: var(--info-light); color: var(--info); }

/* Warning Banner for Previous Debt in POS */
.debt-warning-banner {
    background: linear-gradient(135deg, #fffbeb, #fef3c7);
    border: 2px solid #f59e0b;
    border-radius: var(--radius-md);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
    animation: shake 0.4s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-4px); }
    40%, 80% { transform: translateX(4px); }
}

.debt-warning-banner .icon {
    font-size: 26px;
    color: #b45309;
}

.debt-warning-banner .text {
    flex: 1;
}

.debt-warning-banner .title {
    font-weight: 700;
    color: #92400e;
    font-size: 0.95rem;
}

.debt-warning-banner .desc {
    font-size: 0.82rem;
    color: #b45309;
}

/* ==========================================================================
   Buttons & Forms
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-main);
    font-size: 0.88rem;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    line-height: 1.2;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}
.btn-primary:hover {
    background: var(--primary-hover);
    color: var(--white);
}

.btn-success {
    background: var(--success);
    color: var(--white);
}
.btn-success:hover {
    background: var(--success-hover);
    color: var(--white);
}

.btn-warning {
    background: var(--warning);
    color: var(--dark-900);
}
.btn-warning:hover {
    background: var(--warning-hover);
    color: var(--dark-900);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}
.btn-danger:hover {
    background: var(--danger-hover);
    color: var(--white);
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--dark-700);
    border-color: var(--gray-300);
}
.btn-secondary:hover {
    background: var(--gray-200);
    color: var(--dark-900);
}

.btn-outline {
    background: transparent;
    border-color: var(--gray-300);
    color: var(--dark-700);
}
.btn-outline:hover {
    background: var(--gray-100);
    border-color: var(--gray-400);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.78rem;
    border-radius: var(--radius-sm);
}

.btn-lg {
    padding: 14px 24px;
    font-size: 1rem;
    border-radius: var(--radius-lg);
}

.btn-block {
    width: 100%;
}

/* Form Controls */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--dark-700);
    margin-bottom: 6px;
}

.form-control, .form-select {
    width: 100%;
    padding: 10px 14px;
    font-family: var(--font-main);
    font-size: 0.9rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    background-color: var(--white);
    color: var(--dark-800);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.form-help {
    font-size: 0.72rem;
    color: var(--gray-400);
    margin-top: 4px;
}

/* Form Grid */
.form-row {
    display: flex;
    flex-wrap: wrap;
    margin: -8px;
}

.form-col {
    flex: 1 0 0%;
    padding: 8px;
    min-width: 240px;
}

/* ==========================================================================
   Tables & Lists
   ========================================================================== */

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    text-align: left;
}

.table th {
    background: var(--gray-50);
    color: var(--dark-600);
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

.table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--gray-200);
    color: var(--dark-800);
    vertical-align: middle;
}

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

/* Status Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 9px;
    font-size: 0.72rem;
    font-weight: 700;
    border-radius: var(--radius-full);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1;
}

.badge-success { background: var(--success-light); color: var(--success-hover); }
.badge-warning { background: var(--warning-light); color: var(--warning-dark); }
.badge-danger  { background: var(--danger-light); color: var(--danger-hover); }
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-gray    { background: var(--gray-100); color: var(--dark-600); }

/* Quick Action Cards */
.action-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

@media (min-width: 640px) {
    .action-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.action-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
    transition: all 0.2s;
    color: var(--dark-800);
}

.action-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
    color: var(--primary);
}

.action-card-icon {
    width: 50px;
    height: 50px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--white);
}

.action-card-title {
    font-size: 0.85rem;
    font-weight: 700;
}

/* Flash message alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.alert-success { background: var(--success-light); border: 1px solid #a7f3d0; color: #065f46; }
.alert-danger  { background: var(--danger-light); border: 1px solid #fecaca; color: #991b1b; }
.alert-warning { background: var(--warning-light); border: 1px solid #fde68a; color: #92400e; }
.alert-info    { background: var(--info-light); border: 1px solid #bae6fd; color: #075985; }

/* Modal Dialogs */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--white);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: modal-slide 0.25s ease-out;
}

@keyframes modal-slide {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--dark-900);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-400);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: var(--gray-50);
    border-bottom-left-radius: var(--radius-xl);
    border-bottom-right-radius: var(--radius-xl);
}
