@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --sidebar-bg: #1e293b;
    /* Slate 800 */
    --sidebar-text: #f8fafc;
    --sidebar-active: #374151;
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --text-color: #111827;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
}

body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(45deg, #ff9a9e, #fad0c4, #fad0c4, #ffd1ff, #a18cd1, #84fab0, #8fd3f4);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    color: var(--text-color);
    margin: 0;
    padding: 0;
    display: flex;
    min-height: 100vh;
}

@keyframes gradientBG {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

/* Sidebar Layout */
.app-container {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow: hidden;
}

.sidebar-header {
    padding: 1.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    border-bottom: 1px solid #334155;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-menu {
    padding: 0.25rem 0;
    list-style: none;
    margin: 0;
}

.sidebar-menu::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    padding: 0.5rem 1.25rem;
    color: #cbd5e1;
    text-decoration: none;
    transition: all 0.2s;
    font-weight: 500;
    font-size: 0.9rem;
}

.sidebar-menu li a:hover {
    background-color: #334155;
    color: white;
}

.sidebar-menu li a.active {
    background-color: var(--primary-color);
    color: white;
}

.sidebar-icon {
    margin-right: 0.75rem;
    width: 20px;
    text-align: center;
}

.sidebar-user {
    padding: 1.5rem;
    border-top: 1px solid #334155;
    font-size: 0.875rem;
    margin-top: auto;
}

.sidebar-user-name {
    font-weight: 600;
    color: white;
    margin-bottom: 0.25rem;
}

.sidebar-logout {
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.8rem;
}

.sidebar-logout:hover {
    color: white;
}

/* Main Content Area */
.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

/* Card & Table Styles (Reused/Updated) */
.card {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    padding: 2rem;
    border: 1px solid var(--border-color);
}

.card-header {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

th,
td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: #f9fafb;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Header & User Info */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-weight: 500;
    color: var(--text-color);
}

.user-avatar {
    width: 40px;
    height: 40px;
    background-color: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.img-thumbnail {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

/* Auth Pages (Center Layout Override) */
body.auth-body {
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #f3f4f6, #e0e7ff);
}

.auth-wrapper {
    padding: 0;
    height: auto;
}

/* Buttons */
.btn {
    display: inline-flex;
    padding: 0.5rem 1rem;
    background-color: var(--primary-color);
    color: white;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 500;
    border: none;
    cursor: pointer;
}

.btn:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: white;
    border: 1px solid var(--border-color);
    color: var(--text-color);
}

.btn-secondary:hover {
    background-color: #f9fafb;
}

.btn-danger {
    background-color: #ef4444;
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.alert-error {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-success {
    background-color: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-sizing: border-box;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 0;
    border: 1px solid #888;
    width: 90%;
    max-width: 600px;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
}

.close-modal {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close-modal:hover,
.close-modal:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.modal-body {
    padding: 1.5rem;
    text-align: center;
}

.modal-image {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.modal-details {
    text-align: left;
    margin-top: 1rem;
}

.modal-detail-row {
    display: flex;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f3f4f6;
}

.modal-detail-label {
    font-weight: 600;
    width: 120px;
    color: #4b5563;
}

/* POS Layout */
.pos-layout {
    display: flex;
    height: calc(100vh - 60px);
    /* Adjust based on sidebar/header */
    gap: 1rem;
    overflow: hidden;
}

.pos-products-area {
    flex: 2;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-right: 0.5rem;
}

.pos-cart-area {
    flex: 1;
    background: white;
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    min-width: 350px;
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.05);
}

/* POS Search Bar */
.pos-filters {
    padding: 1rem;
    background: white;
    border-radius: 8px;
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* POS Grid */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    overflow-y: auto;
    padding: 0.5rem;
    padding-bottom: 2rem;
}

.product-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
}

.product-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.product-card img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    margin-bottom: 0.5rem;
    border-radius: 4px;
}

.product-card h4 {
    margin: 0.5rem 0;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.2;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    height: 2.4em;
    /* fixed height for 2 lines */
}

.product-stock {
    font-size: 0.8rem;
    color: #059669;
    font-weight: 500;
    margin-top: auto;
}

/* POS Cart */
.pos-cart-header {
    padding: 1rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--border-color);
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.pos-cart-items {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.cart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f1f5f9;
}

.cart-item:hover {
    background-color: #f8fafc;
}

.cart-item-info {
    flex: 1;
    padding-right: 1rem;
}

.cart-item-name {
    font-weight: 500;
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}

.cart-item-meta {
    font-size: 0.8rem;
    color: #64748b;
}

.cart-item-qty-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.qty-btn {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 1px solid #cbd5e1;
    background: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1;
}

.qty-btn:hover {
    background: #f1f5f9;
}

/* Editable Qty Input */
.qty-input {
    width: 60px;
    height: 30px;
    text-align: center;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 0 4px;
    font-weight: 600;
    font-size: 0.9rem;
    /* -moz-appearance: textfield;  Hide arrows in Firefox */
}

/* 
.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
} 
*/

/* Badge Styles */
.badge {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
}

.badge-success {
    background-color: #10b981 !important;
}

/* Green */
.badge-warning {
    background-color: #f59e0b !important;
}

/* Orange */
.badge-danger {
    background-color: #ef4444 !important;
}

/* Red */

.qty-display {
    min-width: 30px;
    text-align: center;
    font-weight: 600;
}

.pos-cart-footer {
    padding: 1rem;
    background: white;
    border-top: 1px solid var(--border-color);
}

/* Print Styles */
@media print {
    /* Hide non-printable elements */
    .sidebar,
    .form-input,
    .btn,
    .sidebar-user,
    form,
    .app-container::before,
    .card-header span

    /* Hide the default card title text to use our custom header, or keep both? Let's use custom */
        {
        display: none !important;
    }

    /* Show Print Header */
    .print-header {
        display: block !important;
        text-align: center;
        margin-bottom: 20px;
        border-bottom: 2px solid #000;
        padding-bottom: 10px;
    }

    .print-header h1 {
        font-size: 18pt;
        margin: 0;
        color: #000;
    }

    .print-header p {
        font-size: 12pt;
        margin: 5px 0 0 0;
        color: #666;
    }

    /* Date from card-header */
    .card-header {
        border: none;
        /* Remove border from old header */
        margin: 0;
        padding: 0;
        text-align: right;
        /* Move date to right */
    }

    .card-header::after {
        content: "วันที่พิมพ์: " attr(data-date);
        font-size: 10pt;
        color: #444;
        display: block;
        margin-bottom: 10px;
    }

    /* Layout Adjustments */
    .app-container {
        display: block;
        padding: 0;
    }

    .main-content {
        margin: 0;
        padding: 0;
        width: 100%;
        overflow: visible;
    }

    .card {
        box-shadow: none;
        border: none;
        padding: 0;
    }

    /* Hide images */
    th img,
    td img {
        display: none !important;
    }

    /* Table Typography */
    table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 10px;
    }

    th {
        background-color: #f3f4f6 !important;
        color: #000;
        font-weight: bold;
        font-size: 11pt;
        /* Professional Header Size */
        border: 1px solid #999;
        padding: 8px;
        text-align: center;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    td {
        border: 1px solid #ccc;
        padding: 6px 8px;
        /* Comfortable padding */
        color: #000;
        font-size: 10pt;
        /* Readable Body Size */
        vertical-align: middle;
    }

    /* Badge Plain Text */
    .badge {
        border: none !important;
        background: none !important;
        color: #000 !important;
        padding: 0 !important;
        font-weight: normal;
        font-size: 10pt;
    }

    body {
        overflow: visible !important;
        background: white;
    }
}

/* Dashboard Analytics Styles */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-5px);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.stat-title {
    color: #64748b;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-icon {
    font-size: 1.5rem;
    padding: 10px;
    border-radius: 10px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 0.5rem;
}

.stat-desc {
    font-size: 0.85rem;
    color: #94a3b8;
}

/* Colors for stats */
.bg-blue-light {
    background: #eff6ff;
    color: #3b82f6;
}

.bg-green-light {
    background: #f0fdf4;
    color: #22c55e;
}

.bg-orange-light {
    background: #fff7ed;
    color: #f97316;
}

.bg-red-light {
    background: #fef2f2;
    color: #ef4444;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-card {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    height: 400px;
    /* Fixed height for consistency */
    display: flex;
    flex-direction: column;
}

.chart-header {
    margin-bottom: 1.5rem;
    font-weight: 600;
    color: #334155;
    font-size: 1.1rem;
}

.chart-body {
    flex: 1;
    position: relative;
    width: 100%;
    min-height: 0;
}

/* Mobile Responsiveness */
.mobile-menu-toggle {
    display: none;
}

.sidebar-overlay {
    display: none;
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        width: 260px;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.2);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        padding: 1rem;
        width: 100%;
        margin-left: 0;
        overflow-x: hidden;
        /* Prevent horizontal scroll on body */
    }

    /* Hamburger Menu Button */
    .mobile-menu-toggle {
        display: flex !important;
        align-items: center;
        gap: 0.5rem;
        position: fixed;
        top: 10px;
        right: 10px;
        z-index: 1001;
        background: var(--primary-color);
        color: white;
        border: none;
        padding: 0.5rem 1rem;
        border-radius: 8px;
        cursor: pointer;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        font-family: 'Sarabun', sans-serif;
        font-weight: 600;
    }

    /* Wrap tables */
    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    /* Adjust Card Header */
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    /* Stack Layouts for Mobile */
    .pos-layout,
    .split-container {
        flex-direction: column !important;
        height: auto !important;
        overflow: visible !important;
    }

    .pos-products-area,
    .pos-cart-area,
    .left-panel,
    .right-panel {
        width: 100% !important;
        flex: none !important;
        overflow: visible;
    }

    .pos-cart-area {
        border-left: none;
        border-top: 1px solid var(--border-color);
        margin-top: 1rem;
    }

    /* Adjust Stats Grid */
    .dashboard-stats {
        grid-template-columns: 1fr;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    /* Overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Print adjustments for mobile */
    @media print {
        .mobile-menu-toggle {
            display: none !important;
        }

        .sidebar {
            display: none !important;
        }

        .main-content {
            margin: 0;
            padding: 0;
        }

        table {
            display: table;
            white-space: normal;
        }
    }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    /* Sidebar Mobile */
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    }

    .sidebar.active {
        left: 0;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .mobile-menu-toggle {
        display: block !important;
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 1001;
        background: var(--primary-color);
        color: white;
        border: none;
        padding: 1rem;
        border-radius: 50%;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        width: 60px;
        height: 60px;
        font-size: 1.5rem;
        cursor: pointer;
    }

    /* Layout stacking */
    .split-container {
        flex-direction: column;
        padding: 1rem;
        height: auto;
    }

    .left-panel,
    .right-panel {
        width: 100%;
    }

    /* Header adjustments */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .header-controls {
        width: 100%;
        flex-direction: column;
    }

    .header-controls input,
    .header-controls select,
    .form-control {
        width: 100% !important;
    }

    /* Grid/Table scrolling */
    .grid-wrapper {
        overflow-x: auto;
    }

    .data-table {
        min-width: 800px;
    }

    body {
        overflow-x: hidden;
    }

    .auth-wrapper {
        width: 90%;
        margin: 2rem auto;
    }
}

/* Default state for toggle button (hidden on desktop) */
.mobile-menu-toggle {
    display: none;
}