/* CSS Reset & Variable Definitions */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
    --bg-gradient: radial-gradient(circle at 50% 50%, #1e2433, #0f121d);
    --card-bg: rgba(255, 255, 255, 0.03);
    --card-border: rgba(255, 255, 255, 0.06);
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --primary: #00e5ff;
    --primary-glow: rgba(0, 229, 255, 0.25);
    --secondary: #a855f7;
    --secondary-glow: rgba(168, 85, 247, 0.25);
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.2);
    --warning: #f59e0b;
    --warning-glow: rgba(245, 158, 11, 0.2);
    --danger: #ef4444;
    --danger-glow: rgba(239, 68, 68, 0.2);
    --sidebar-width: 280px;
    --font-heading: 'Outfit', 'Sarabun', sans-serif;
    --font-body: 'Inter', 'Sarabun', sans-serif;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Mode Toggle Override */
body.light-theme {
    --bg-gradient: radial-gradient(circle at 50% 50%, #f9fafb, #f3f4f6);
    --card-bg: rgba(255, 255, 255, 0.7);
    --card-border: rgba(0, 0, 0, 0.06);
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --primary: #0284c7;
    --primary-glow: rgba(2, 132, 199, 0.15);
    --secondary: #7c3aed;
    --secondary-glow: rgba(124, 58, 237, 0.15);
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--bg-gradient);
    color: var(--text-primary);
    font-family: var(--font-body);
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
}

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

/* Sidebar Navigation */
.sidebar {
    width: var(--sidebar-width);
    background: rgba(15, 18, 29, 0.4);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--card-border);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: var(--transition);
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 2.5rem;
    padding: 0 0.5rem;
}

.logo-img {
    height: 40px;
    object-fit: contain;
    border-radius: 8px;
}

.logo-text {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.95rem;
    transition: var(--transition);
}

.nav-item i {
    font-size: 1.2rem;
    transition: var(--transition);
}

.nav-item:hover, .nav-item.active {
    color: var(--text-primary);
    background: var(--card-bg);
    box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.02);
}

.nav-item.active {
    border: 1px solid rgba(0, 229, 255, 0.15);
    background: linear-gradient(135deg, rgba(0, 229, 255, 0.08), rgba(168, 85, 247, 0.03));
    color: var(--primary);
}

.nav-item.active i {
    color: var(--primary);
    filter: drop-shadow(0 0 5px var(--primary));
}

.theme-toggle-container {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--card-border);
}

.theme-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    color: var(--text-primary);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--transition);
}

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

/* Main Content Area */
.main-content {
    margin-left: var(--sidebar-width);
    flex-grow: 1;
    padding: 2.5rem;
    min-height: 100vh;
    transition: var(--transition);
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.page-title h1 {
    font-family: var(--font-heading);
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.page-title p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 4px;
}

.demo-badge {
    background: linear-gradient(135deg, var(--warning), var(--danger));
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: bold;
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.3);
    animation: pulse 2s infinite;
    display: flex;
    align-items: center;
    gap: 6px;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.05); opacity: 1; }
    100% { transform: scale(1); opacity: 0.9; }
}

/* Content Views */
.view-panel {
    display: none;
    animation: fadeIn 0.4s ease-out forwards;
}

.view-panel.active {
    display: block;
}

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

/* Dashboard View Styles */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-4px);
    border-color: rgba(0, 229, 255, 0.3);
    box-shadow: 0 10px 25px -5px rgba(0, 229, 255, 0.1);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.blue { background: rgba(0, 229, 255, 0.1); color: var(--primary); }
.stat-icon.purple { background: rgba(168, 85, 247, 0.1); color: var(--secondary); }
.stat-icon.green { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.stat-icon.orange { background: rgba(245, 158, 11, 0.1); color: var(--warning); }

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.65rem;
    font-weight: 700;
    font-family: var(--font-heading);
    margin-top: 2px;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Charts & Summary Row */
.summary-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-card, .recent-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 1.5rem;
    backdrop-filter: blur(10px);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.card-header h2 {
    font-size: 1.2rem;
    font-family: var(--font-heading);
    font-weight: 600;
}

.chart-placeholder {
    height: 250px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 1px dashed var(--card-border);
    border-radius: 12px;
    color: var(--text-secondary);
    gap: 10px;
}

/* Custom Chart/Progress Visualization */
.audit-progress-container {
    width: 100%;
    margin-top: 10px;
}

.progress-track {
    width: 100%;
    height: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    width: 0%;
    transition: width 1s ease-out;
}

/* Forms & UI Controls */
.form-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
    backdrop-filter: blur(10px);
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-control {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 8px var(--primary-glow);
    background: rgba(255, 255, 255, 0.06);
}

select.form-control option {
    background: #0f121d;
    color: #fff;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--primary), #00b8d4);
    color: #0f121d;
    border: none;
    border-radius: 10px;
    padding: 12px 24px;
    font-size: 0.95rem;
    font-weight: 650;
    cursor: pointer;
    transition: var(--transition);
    text-shadow: 0 0 1px rgba(255, 255, 255, 0.3);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--primary-glow);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    box-shadow: none;
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger), #b91c1c);
    color: white;
}

.btn-danger:hover {
    box-shadow: 0 5px 15px var(--danger-glow);
}

/* Custom Table for Reports */
.table-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 1.5rem;
    overflow: hidden;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.search-wrapper {
    position: relative;
    flex-grow: 1;
    min-width: 250px;
}

.search-wrapper i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.search-input {
    width: 100%;
    padding-left: 40px;
}

.filter-select {
    min-width: 150px;
}

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

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

.asset-table th {
    background: rgba(255, 255, 255, 0.02);
    padding: 16px;
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--card-border);
}

.asset-table td {
    padding: 16px;
    border-bottom: 1px solid var(--card-border);
}

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

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

/* Status Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge.active { background: rgba(16, 185, 129, 0.15); color: var(--success); border: 1px solid rgba(16, 185, 129, 0.2); }
.badge.inactive { background: rgba(245, 158, 11, 0.15); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.2); }
.badge.sold { background: rgba(239, 68, 68, 0.15); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.2); }

/* QR Scanning Screen styling */
.scan-container {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}

.scanner-view-box {
    width: 100%;
    max-width: 400px;
    aspect-ratio: 1;
    margin: 1.5rem auto;
    border: 3px solid var(--primary);
    border-radius: 24px;
    overflow: hidden;
    position: relative;
    background: #000;
    box-shadow: 0 0 30px var(--primary-glow);
}

.scanner-laser {
    position: absolute;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    animation: scanning 2.5s ease-in-out infinite;
    z-index: 5;
}

@keyframes scanning {
    0% { top: 0%; }
    50% { top: 100%; }
    100% { top: 0%; }
}

.asset-details-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 2rem;
    margin-top: 2rem;
    text-align: left;
    animation: fadeIn 0.4s ease-out forwards;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.detail-value {
    font-weight: 600;
}

/* History Logs timeline */
.timeline {
    margin-top: 1.5rem;
    position: relative;
    padding-left: 24px;
    border-left: 2px solid var(--card-border);
}

.timeline-item {
    position: relative;
    margin-bottom: 20px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -31px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid #0f121d;
    box-shadow: 0 0 8px var(--primary-glow);
}

.timeline-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.timeline-content {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Print Page Setup */
#print-area {
    display: none;
}

/* Double-column barcode sticker container for print preview */
.sticker-preview-container {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin: 2rem 0;
}

.sticker-preview-wrapper {
    background: white;
    color: black;
    width: 260px;
    height: 320px;
    padding: 20px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    border: 2px solid #ddd;
    text-align: center;
}

.sticker-preview-qr {
    width: 150px;
    height: 150px;
    margin-bottom: 15px;
}

.sticker-preview-info {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    font-family: var(--font-body);
}

.sticker-preview-id {
    font-weight: 700;
    font-size: 1.25rem;
    margin-bottom: 8px;
    word-break: break-all;
    color: black;
}

.sticker-preview-name {
    font-size: 0.95rem;
    word-break: break-word;
    color: #444;
}

/* Mobile Header Styles (Hidden on Desktop) */
.mobile-header {
    display: none;
    height: 60px;
    background: rgba(15, 18, 29, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--card-border);
    padding: 0 1.5rem;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
}

.logo-container-mobile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mobile-kebab-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: var(--transition);
}

.mobile-kebab-btn:hover {
    background: var(--card-bg);
    color: var(--primary);
}

/* Mobile Responsiveness Rules */
@media (max-width: 991px) {
    .sidebar {
        width: 70px;
        padding: 2rem 0.5rem;
        align-items: center;
    }
    
    .logo-text, .nav-item span, .theme-btn span {
        display: none;
    }
    
    .logo-container {
        justify-content: center;
    }

    .main-content {
        margin-left: 70px;
        padding: 1.5rem;
    }

    .summary-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    body {
        padding-top: 60px; /* Space for mobile top bar */
        padding-bottom: 0;
    }
    
    .mobile-header {
        display: flex;
    }

    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: calc(100vh - 60px);
        position: fixed;
        top: 60px;
        bottom: auto;
        left: 0;
        transform: translateX(100%);
        flex-direction: column;
        padding: 1.5rem;
        border-right: none;
        border-top: none;
        background: rgba(15, 18, 29, 0.98);
        backdrop-filter: blur(20px);
        box-shadow: -5px 0 25px rgba(0,0,0,0.5);
        z-index: 999;
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
    }

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

    .logo-container {
        display: none;
    }
    
    .theme-toggle-container {
        display: block;
        margin-top: 2rem;
        padding-top: 1rem;
        border-top: 1px solid var(--card-border);
    }

    .nav-links {
        flex-direction: column;
        width: 100%;
        height: auto;
        justify-content: flex-start;
        gap: 10px;
    }

    .nav-item {
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        width: 100%;
        height: auto;
        padding: 14px 20px;
        border-radius: 12px;
        font-size: 1rem;
        color: var(--text-secondary);
        border: 1px solid transparent;
        background: rgba(255,255,255,0.02);
    }

    .nav-item i {
        font-size: 1.25rem;
        width: 30px;
    }

    .nav-item span {
        display: block;
        margin-top: 0;
    }
    
    .nav-item.active {
        background: var(--card-bg);
        border: 1px solid rgba(0, 229, 255, 0.15);
        color: var(--primary);
    }

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

    .main-content {
        margin-left: 0;
        padding: 1.5rem;
    }
    
    .grid-2 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .top-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
}

/* Report Sub-tabs Styles */
.report-subtabs {
    display: flex;
    gap: 8px;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 2px;
}

.subtab-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 10px 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    position: relative;
    transition: var(--transition);
    border-bottom: 2px solid transparent;
}

.subtab-btn:hover {
    color: var(--text-primary);
}

.subtab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    text-shadow: 0 0 8px var(--primary-glow);
}

/* Hide inactive containers */
.report-section {
    display: none;
    animation: fadeIn 0.3s ease-out forwards;
}

.report-section.active {
    display: block;
}

/* Strict Print Directives */
@media print {
    body, html {
        background: white !important;
        color: black !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 82mm; /* Double column width */
    }

    body * {
        visibility: hidden;
    }

    #print-area, #print-area * {
        visibility: visible;
    }

    #print-area {
        position: absolute;
        left: 0;
        top: 0;
        width: 82mm;
        margin: 0;
        padding: 0;
        display: block !important;
    }

    .print-row {
        display: flex !important;
        flex-direction: row !important;
        width: 82mm;
        height: 30mm;
        page-break-inside: avoid;
        page-break-after: always;
        box-sizing: border-box;
        padding: 0;
        margin: 0;
    }

    .sticker {
        width: 40mm;
        height: 30mm;
        box-sizing: border-box;
        padding: 1.5mm;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: flex-start !important;
        background: white !important;
        color: black !important;
        overflow: hidden;
        text-align: center;
    }
    
    .sticker.left {
        margin-right: 2mm; /* Space between the two labels */
    }

    .sticker-qr {
        width: 17mm !important;
        height: 17mm !important;
        display: block !important;
        margin-bottom: 1mm !important;
    }

    .sticker-info {
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: flex-start !important;
        font-family: 'Inter', sans-serif !important;
        color: black !important;
        box-sizing: border-box;
    }

    .sticker-id {
        font-weight: bold !important;
        font-size: 7px !important;
        line-height: 1.1 !important;
        margin-bottom: 0.5mm !important;
        word-break: break-all !important;
    }

    .sticker-name {
        font-size: 6px !important;
        line-height: 1.1 !important;
        word-break: break-word !important;
        max-height: 8mm !important;
        overflow: hidden !important;
    }
}

/* Confirmation Modal Styles */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

.modal-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    padding: 2rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(-20px);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal-card {
    transform: translateY(0);
}

.modal-title {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 0.75rem;
}

.confirm-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 2rem;
}

.confirm-row {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px dashed rgba(255,255,255,0.05);
    padding-bottom: 6px;
}

.light-theme .confirm-row {
    border-bottom: 1px dashed rgba(0,0,0,0.05);
}

.confirm-label {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.confirm-value {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}
