/* Google Fonts: Prompt (for Thai) and Inter (for UI/Numbers) */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Prompt:wght@300;400;500;600;700&display=swap');

:root {
    /* Color Palette */
    --bg-darkest: #0b0f19;
    --bg-dark: #111827;
    --bg-card: rgba(31, 41, 55, 0.75);
    --bg-card-hover: rgba(37, 99, 235, 0.08);
    --primary: #06b6d4;      /* Teal */
    --primary-hover: #0891b2;
    --accent: #6366f1;       /* Indigo */
    --accent-hover: #4f46e5;
    --success: #10b981;      /* Emerald */
    --warning: #f59e0b;      /* Amber */
    --danger: #ef4444;       /* Rose */
    
    /* Text Colors */
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --text-inverse: #ffffff;
    
    /* Layout */
    --sidebar-width: 70px;
    --sidebar-width-expanded: 260px;
    --border-color: rgba(255, 255, 255, 0.08);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Prompt', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-darkest);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-darkest);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* App Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar State Toggle (CSS Custom Property update) */
.sidebar-expanded {
    --sidebar-width: var(--sidebar-width-expanded);
}

/* Sidebar Navigation */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--bg-dark) 0%, var(--bg-darkest) 100%);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 100;
    padding: 1.5rem 0.5rem;
    box-shadow: var(--shadow-lg);
    transition: var(--transition);
}

.sidebar-expanded .sidebar {
    padding: 1.5rem 1rem;
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
    width: 100%;
}

.sidebar-expanded .sidebar-header {
    flex-direction: row;
    justify-content: space-between;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-inverse);
    text-decoration: none;
    transition: var(--transition);
}

.sidebar-expanded .brand {
    justify-content: flex-start;
    gap: 0.75rem;
}

.brand-icon {
    width: 2.25rem;
    height: 2.25rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.25rem;
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.4);
    flex-shrink: 0;
}

.brand-name {
    font-weight: 600;
    font-size: 1.15rem;
    letter-spacing: 0.5px;
    background: linear-gradient(to right, #ffffff, var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: none;
    opacity: 0;
    transition: var(--transition);
}

.sidebar-expanded .brand-name {
    display: block;
    opacity: 1;
    animation: fadeIn 0.25s ease-out forwards;
}

.sidebar-toggle-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    width: 2.25rem;
    height: 2.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    outline: none;
}

.sidebar-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--primary);
    border-color: var(--primary);
}

.sidebar-toggle-btn svg {
    width: 1.2rem;
    height: 1.2rem;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-expanded .sidebar-toggle-btn svg {
    transform: rotate(180deg);
}

.menu-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.menu-item a {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.95rem;
    transition: var(--transition);
    border: 1px solid transparent;
}

.sidebar-expanded .menu-item a {
    justify-content: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
}

.menu-item a:hover, .menu-item.active a {
    color: var(--text-inverse);
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.05);
}

.menu-item.active a {
    background: linear-gradient(90deg, rgba(6, 182, 212, 0.15) 0%, rgba(99, 102, 241, 0.05) 100%);
    border-left: 3px solid var(--primary);
    color: var(--primary);
}

.menu-item a svg {
    width: 1.25rem;
    height: 1.25rem;
    transition: var(--transition);
    flex-shrink: 0;
}

.menu-item a:hover svg, .menu-item.active a svg {
    transform: scale(1.1);
    stroke: var(--primary);
}

.menu-text {
    display: none;
    opacity: 0;
    transition: var(--transition);
}

.sidebar-expanded .menu-text {
    display: block;
    opacity: 1;
    animation: fadeIn 0.25s ease-out forwards;
}

.user-profile {
    margin-top: auto;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    width: 100%;
}

.sidebar-expanded .user-profile {
    padding: 1rem;
    justify-content: flex-start;
    gap: 0.75rem;
}

.user-avatar {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

.user-info {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: none;
    opacity: 0;
    transition: var(--transition);
}

.sidebar-expanded .user-info {
    display: block;
    opacity: 1;
    animation: fadeIn 0.25s ease-out forwards;
}

.user-name {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-main);
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Main Content Layout */
.main-content {
    margin-left: var(--sidebar-width);
    flex-grow: 1;
    min-height: 100vh;
    background-color: var(--bg-darkest);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    transition: var(--transition);
}

/* Typography & Headers */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1.5rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-inverse);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.page-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Cards & Glassmorphism */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    transition: var(--transition);
}

.card:hover {
    border-color: rgba(6, 182, 212, 0.2);
}

.card-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--text-inverse);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
}

/* Forms & Inputs */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    background-color: rgba(17, 24, 39, 0.8);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.65rem 1rem;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-main);
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.15);
}

.form-control::placeholder {
    color: #4b5563;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    color: var(--text-inverse);
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.2);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(6, 182, 212, 0.35);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-inverse);
}

.btn-danger {
    background-color: var(--danger);
    color: var(--text-inverse);
}

.btn-danger:hover {
    background-color: #e11d48;
}

.btn-warning {
    background-color: var(--warning);
    color: var(--bg-darkest);
    font-weight: 600;
}

.btn-warning:hover {
    background-color: #d97706;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
}

/* Tables */
.table-responsive {
    overflow-x: auto;
    width: 100%;
}

.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
    text-align: left;
}

.table th {
    background-color: rgba(17, 24, 39, 0.4);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
    color: var(--text-main);
}

.table tbody tr {
    transition: var(--transition);
}

.table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Requisition dynamic rows */
.req-item-row {
    animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Alerts / Badges */
.alert {
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-success {
    background-color: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.alert-danger {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 50px;
}

.badge-primary {
    background-color: rgba(6, 182, 212, 0.15);
    color: var(--primary);
}

.badge-success {
    background-color: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

/* Summary Grid */
.summary-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.summary-card {
    background: linear-gradient(135deg, rgba(31, 41, 55, 0.7) 0%, rgba(17, 24, 39, 0.7) 100%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.summary-card:hover {
    transform: translateY(-2px);
    border-color: rgba(99, 102, 241, 0.2);
}

.summary-card-icon {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.summary-card-icon.blue {
    background-color: rgba(6, 182, 212, 0.1);
    color: var(--primary);
}

.summary-card-icon.purple {
    background-color: rgba(99, 102, 241, 0.1);
    color: var(--accent);
}

.summary-card-icon.green {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.summary-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-inverse);
    line-height: 1.2;
}

.summary-card-label {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Login Page Styling */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.15), transparent 40%),
                radial-gradient(circle at bottom left, rgba(6, 182, 212, 0.15), transparent 40%),
                var(--bg-darkest);
    padding: 1rem;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 2.5rem 2rem;
    background: rgba(31, 41, 55, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.login-brand-icon {
    width: 3.5rem;
    height: 3.5rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.75rem;
    color: white;
    box-shadow: 0 0 25px rgba(6, 182, 212, 0.3);
}

.login-brand-title {
    font-size: 1.4rem;
    font-weight: 600;
    background: linear-gradient(to right, #ffffff, var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-align: center;
}

.login-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: -0.5rem;
    margin-bottom: 1.5rem;
}

/* POS Layout styling */
.pos-container {
    display: flex;
    gap: 1.5rem;
    align-items: stretch;
}

.pos-left-col {
    flex: 1.3;
    min-width: 0;
    display: flex;
}

.pos-left-col .card {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.pos-right-col {
    flex: 0.9;
    position: sticky;
    top: 2rem;
    display: flex;
    flex-direction: column;
    align-self: stretch;
}

.pos-right-col .card {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.catalog-container {
    overflow-y: auto;
    flex-grow: 1;
    padding-right: 0.25rem;
    margin-top: 0.5rem;
}

.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.75rem;
}

.catalog-card {
    background: rgba(17, 24, 39, 0.6);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

.catalog-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.15);
    background: rgba(17, 24, 39, 0.8);
}

.catalog-card-image {
    width: 100%;
    height: 90px;
    object-fit: cover;
    background-color: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border-color);
}

.catalog-card-image-fallback {
    width: 100%;
    height: 90px;
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.1) 0%, rgba(99, 102, 241, 0.1) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    border-bottom: 1px solid var(--border-color);
}

.catalog-card-body {
    padding: 0.65rem;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.catalog-card-code {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 0.15rem;
}

.catalog-card-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-inverse);
    line-height: 1.3;
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.catalog-card-footer {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.75rem;
}

.catalog-card-price {
    font-weight: 700;
    color: var(--success);
}

.catalog-card-unit {
    color: var(--text-muted);
}

/* Animations for active item rows adding */
@keyframes highlightRow {
    0% { background-color: rgba(16, 185, 129, 0.25); }
    100% { background-color: transparent; }
}

.row-highlight {
    animation: highlightRow 0.8s ease-out forwards;
}

@media (max-width: 1024px) {
    .pos-container {
        flex-direction: column;
    }
    .pos-right-col {
        position: static;
        width: 100%;
        height: auto;
    }
}

/* Customer Select Buttons styling */
.customer-buttons-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-top: 0.5rem;
}

.customer-btn {
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    transition: var(--transition);
}

.customer-btn:hover {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: var(--primary);
    color: var(--text-inverse);
}

.customer-btn.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    color: var(--text-inverse);
    border-color: transparent;
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.35);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar-toggle-btn {
        display: none !important;
    }
    
    .sidebar, .sidebar-expanded .sidebar {
        width: 70px !important;
        padding: 1.5rem 0.5rem !important;
    }
    
    .brand-name, .user-info, .menu-text,
    .sidebar-expanded .brand-name, .sidebar-expanded .user-info, .sidebar-expanded .menu-text {
        display: none !important;
    }
    
    .brand, .sidebar-expanded .brand {
        justify-content: center !important;
        padding: 0.5rem 0 !important;
    }
    
    .user-profile, .sidebar-expanded .user-profile {
        justify-content: center !important;
        padding: 0.5rem !important;
    }
    
    .main-content, .sidebar-expanded .main-content {
        margin-left: 70px !important;
        padding: 1.5rem 1rem !important;
    }
    
    .menu-item a, .sidebar-expanded .menu-item a {
        justify-content: center !important;
        gap: 0 !important;
        padding: 0.75rem !important;
    }
}

/* Print Styling */
@media print {
    .sidebar, .no-print, .btn, .form-group, .page-header {
        display: none !important;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    
    .card {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
    }
    
    .table th {
        background-color: #f3f4f6 !important;
        color: black !important;
        border-bottom: 2px solid black !important;
    }
    
    .table td {
        border-bottom: 1px solid #e5e7eb !important;
        color: black !important;
    }
    
    .summary-card {
        border: 1px solid #ccc !important;
        background: transparent !important;
        color: black !important;
    }
    
    .summary-card-value, .summary-card-label {
        color: black !important;
    }
}
