/* SPVi Operations Audit Toolkit - Main Stylesheet */
/* This file contains all shared styles across the application */

/* Import Sarabun font - Thai-friendly font */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;500;700;900&display=swap');

/* ===== BASE STYLES ===== */
body {
    font-family: 'Sarabun', sans-serif;
    margin: 0;
    padding: 0;
}

/* ===== TOOL CARD STYLES ===== */
.tool-card {
    background-color: white;
    border-radius: 1rem;
    border: 1px solid #e2e8f0;
    text-decoration: none;
    transition: all 0.3s ease-in-out;
    box-shadow: 0 1px 3px 0 rgba(0,0,0,0.1), 0 1px 2px 0 rgba(0,0,0,0.06);
    display: block;
}

.tool-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

.icon-wrapper {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    border-radius: 0.75rem;
}

/* ===== CHAT CONTAINER STYLES ===== */
#chat-container {
    flex: 1 1 0%;
    padding: 1rem;
    overflow-y: auto;
    background: #f8fafc;
    min-height: 120px;
    max-height: 350px;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f8fafc;
}

#chat-container::-webkit-scrollbar {
    width: 8px;
}

#chat-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

#chat-container::-webkit-scrollbar-track {
    background: #f8fafc;
}

/* ===== TOAST NOTIFICATION STYLES ===== */
.spvi-toast {
    font-family: 'Sarabun', 'Noto Sans Thai', sans-serif !important;
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    max-width: 400px;
    padding: 16px 20px;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
}

.spvi-toast.show {
    transform: translateX(0);
}

.spvi-toast.success {
    background: #10b981;
    color: white;
}

.spvi-toast.error {
    background: #ef4444;
    color: white;
}

.spvi-toast.warning {
    background: #f59e0b;
    color: white;
}

.spvi-toast.info {
    background: #3b82f6;
    color: white;
}

/* ===== PRINT STYLES ===== */
@media print {
    body * {
        font-family: 'TH SarabunPSK', 'TH Sarabun New', 'Sarabun', 'Times New Roman', Times, serif !important;
    }
    
    .no-print {
        display: none !important;
    }
    
    .print-break {
        page-break-before: always;
    }

    .no-print {
        display: none !important;
    }
    
    #spvi-user-info {
        display: none !important;
    }
}

/* ===== USER INFO BAR STYLES ===== */
#spvi-user-info {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(90deg, #1e40af, #3b82f6);
    color: white;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    font-family: 'Sarabun', sans-serif;
    width: 100%;
}

.spvi-nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    position: relative;
}

.spvi-nav-links {
    display: flex;
    align-items: center;
    transition: all 0.3s ease;
}

.spvi-nav-link {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    font-weight: 500;
    border-radius: 0.25rem;
    transition: all 0.2s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.spvi-nav-link:hover {
    color: white;
    background-color: rgba(255,255,255,0.15);
}

.spvi-user-details {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    flex-shrink: 1;
    min-width: 0;
}

.spvi-user-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.spvi-user-actions button {
    font-size: 0.75rem !important;
    padding: 0.4rem 0.65rem !important;
    border-radius: 0.375rem !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    min-width: fit-content !important;
    font-weight: 500 !important;
}

.spvi-logout-btn {
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
    white-space: nowrap;
    padding: 0.4rem 0.65rem;
    flex-shrink: 0;
    min-width: fit-content;
}

.spvi-logout-btn:hover {
    background: rgba(255,255,255,0.3);
}

/* Mobile Navigation Toggle */
.spvi-nav-toggle {
    display: none;
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 0.5rem;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.spvi-nav-toggle:hover {
    background: rgba(255,255,255,0.3);
}

.spvi-nav-toggle svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Desktop View (>1420px) - Fixed one row, no wrapping */
@media (min-width: 1421px) {
    #spvi-user-info {
        padding: 0.75rem 1rem;
        height: 3.5rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .spvi-nav-container {
        display: contents;
    }
    
    .spvi-nav-links {
        gap: 0.25rem;
        flex-wrap: nowrap;
    }
    
    .spvi-nav-link {
        font-size: 0.75rem;
        padding: 0.375rem 0.5rem;
    }
    
    .spvi-user-details {
        font-size: 0.75rem;
        gap: 0.5rem;
    }
    
    .spvi-logout-btn {
        font-size: 0.75rem;
        padding: 0.4rem 0.65rem;
    }
    
    .spvi-nav-toggle {
        display: none !important;
    }
}

/* Mobile View (<=1420px) - Collapsible navigation */
@media (max-width: 1420px) {
    #spvi-user-info {
        padding: 0.75rem 0.75rem;
        min-height: 3rem;
        transition: min-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .spvi-nav-container {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        gap: 1rem;
    }
    
    .spvi-nav-toggle {
        display: block !important;
        order: -1;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .spvi-nav-toggle:hover {
        transform: scale(1.05);
    }
    
    .spvi-nav-links {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: linear-gradient(90deg, #1e40af, #3b82f6);
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), padding 0.4s cubic-bezier(0.4, 0, 0.2, 1), border-top 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        z-index: 999;
        border-top: 1px solid transparent;
    }
    
    .spvi-nav-links.open {
        max-height: 280px;
        padding: 0.1rem 0;
        border-top: 1px solid rgba(255,255,255,0.1);
    }
    
    .spvi-nav-link {
        padding: 0.3rem 1rem;
        font-size: 0.75rem;
        border-radius: 0;
        border-bottom: 1px solid rgba(255,255,255,0.1);
        justify-content: flex-start;
        line-height: 1.1;
        transition: background-color 0.2s ease, transform 0.2s ease;
    }
    
    .spvi-nav-link:last-child {
        border-bottom: none;
    }
    
    .spvi-nav-link:hover {
        background-color: rgba(255,255,255,0.15);
        transform: translateX(4px);
    }
    
    .spvi-nav-link svg {
        width: 0.875rem;
        height: 0.875rem;
        flex-shrink: 0;
        transition: transform 0.2s ease;
    }
    
    .spvi-nav-link:hover svg {
        transform: scale(1.1);
    }
    
    .spvi-user-actions {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        flex-wrap: nowrap;
        flex-shrink: 0;
    }
    
    .spvi-user-details {
        font-size: 0.75rem;
        gap: 0.25rem;
        flex-shrink: 1;
        min-width: 0;
    }
    
    .spvi-logout-btn {
        font-size: 0.75rem;
        padding: 0.4rem 0.65rem;
        flex-shrink: 0;
    }
}

/* Small Mobile adjustments (<=768px) */
@media (max-width: 768px) {
    #spvi-user-info {
        padding: 0.625rem 0.75rem;
        min-height: 2.75rem;
    }
    
    .spvi-user-details {
        font-size: 0.7rem;
        gap: 0.2rem;
    }
    
    .spvi-user-details .opacity-75:not(:last-child) {
        display: none;
    }
    
    .spvi-logout-btn {
        font-size: 0.7rem;
        padding: 0.35rem 0.6rem;
    }
    
    .spvi-nav-link {
        font-size: 0.7rem;
        padding: 0.35rem 0.875rem;
    }
    
    .spvi-nav-link svg {
        width: 0.8rem;
        height: 0.8rem;
    }
    
    .spvi-nav-links.open {
        max-height: 260px;
        padding: 0.1rem 0;
    }
}

/* Very Small Mobile (<=480px) */
@media (max-width: 480px) {
    #spvi-user-info {
        padding: 0.5rem 0.625rem;
        min-height: 2.5rem;
    }
    
    .spvi-user-details {
        font-size: 0.65rem;
        gap: 0.15rem;
    }
    
    .spvi-logout-btn {
        font-size: 0.65rem;
        padding: 0.3rem 0.5rem;
    }
    
    .spvi-user-actions {
        gap: 0.4rem;
    }
    
    .spvi-nav-link {
        font-size: 0.65rem;
        padding: 0.3rem 0.75rem;
    }
    
    .spvi-nav-link svg {
        width: 0.75rem;
        height: 0.75rem;
    }
    
    .spvi-nav-links.open {
        max-height: 240px;
        padding: 0.05rem 0;
    }
}

/* Adjust body padding when user info bar is present */
body.logged-in {
    padding-top: 4rem !important;
    transition: padding-top 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Adjust body padding when mobile nav is expanded */
body.logged-in.nav-expanded {
    padding-top: calc(4rem + 160px) !important;
}

/* ===== FORM STYLES ===== */
.spvi-form-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    font-family: 'Sarabun', sans-serif;
    transition: border-color 0.2s;
}

.spvi-form-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.spvi-btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-family: 'Sarabun', sans-serif;
    font-weight: 500;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    transition: all 0.2s;
    cursor: pointer;
    border: none;
}

.spvi-btn-primary {
    background: #3b82f6;
    color: white;
}

.spvi-btn-primary:hover {
    background: #2563eb;
}

.spvi-btn-secondary {
    background: #6b7280;
    color: white;
}

.spvi-btn-secondary:hover {
    background: #4b5563;
}

.spvi-btn-success {
    background: #10b981;
    color: white;
}

.spvi-btn-success:hover {
    background: #059669;
}

.spvi-btn-danger {
    background: #ef4444;
    color: white;
}

.spvi-btn-danger:hover {
    background: #dc2626;
}

/* ===== LOGIN PAGE STYLES ===== */
.auth-card {
    background: white;
    border-radius: 1.5rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    border: 1px solid #e2e8f0;
}

.input-field {
    transition: all 0.2s ease-in-out;
}

.input-field:focus {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* ===== USER MANAGEMENT STYLES ===== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 50;
    align-items: center;
    justify-content: center;
}

.modal.show { 
    display: flex; 
}

.user-card {
    transition: all 0.2s ease-in-out;
}

.user-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-pending { 
    background: #fef3c7; 
    color: #92400e; 
}

.status-approved { 
    background: #d1fae5; 
    color: #065f46; 
}

.status-rejected { 
    background: #fee2e2; 
    color: #991b1b; 
}

.role-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.role-admin { 
    background: #dc2626; 
    color: white; 
}

.role-user { 
    background: #3b82f6; 
    color: white; 
}

/* ===== RESPONSIVE UTILITIES ===== */
@media (max-width: 768px) {
    .tool-card {
        margin-bottom: 1rem;
    }
    
    #spvi-user-info {
        flex-direction: column;
        padding: 0.75rem 1rem;
    }
    
    #spvi-user-info .user-details {
        margin-bottom: 0.5rem;
    }
}

/* ===== ANIMATION UTILITIES ===== */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

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

.bounce-in {
    animation: bounceIn 0.6s ease-out;
}

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

/* ===== LOADING SPINNER ===== */
.spvi-spinner {
    border: 3px solid #f3f4f6;
    border-top: 3px solid #3b82f6;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
    display: inline-block;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== TOOL-SPECIFIC STYLES ===== */
.currency-input { 
    text-align: right; 
}

.summary-value { 
    font-weight: 700; 
    font-size: 1.125rem; 
}

.result-positive { 
    color: #16a34a; 
}

.result-negative { 
    color: #dc2626; 
}

.result-zero { 
    color: #374151; 
}

.dynamic-row { 
    transition: all 0.3s ease-in-out; 
    overflow: hidden; 
}

.dynamic-row.removing { 
    transform: translateX(100%); 
    max-height: 0; 
    opacity: 0; 
    padding-top: 0; 
    padding-bottom: 0; 
    margin-top: 0; 
    margin-bottom: 0; 
}

.attachment-thumbnail {
    width: 2.5rem;
    height: 2.5rem;
    object-fit: cover;
    border-radius: 0.375rem;
    cursor: pointer;
    border: 1px solid #e5e7eb;
}

#image-modal {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
}

#modal-img {
    max-height: 80vh;
    max-width: 90vw;
}

/* ===== REPORT COMPARISON STYLES ===== */
.comparison-added { 
    background-color: #dcfce7; 
}

.comparison-removed { 
    background-color: #fee2e2; 
}

.comparison-changed { 
    background-color: #fef3c7; 
}

/* ===== RISK ANALYZER STYLES ===== */
.table-container { 
    max-height: 70vh; 
    overflow-y: auto; 
}

.table-container th { 
    position: sticky; 
    top: 0; 
    background-color: #f1f5f9; 
    z-index: 10; 
    cursor: pointer; 
    user-select: none; 
}

.table-container th .sort-indicator { 
    display: inline-block; 
    margin-left: 5px; 
    opacity: 0.5; 
    font-size: 0.9em; 
}

.risk-high { 
    background-color: #fee2e2; 
}

.risk-medium { 
    background-color: #fef3c7; 
}

.risk-low { 
    background-color: #dcfce7; 
}

/* ===== TAB AND SCANNER STYLES ===== */
.tab-button {
    transition: all 0.2s ease-in-out;
    border-bottom: 2px solid transparent;
}

.tab-button.active {
    border-color: #3b82f6;
    color: #3b82f6;
}

.scanner-tab-button {
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    background-color: #e5e7eb;
    color: #374151;
    transition: all 0.2s;
    user-select: none;
}

.scanner-tab-button:hover {
    background-color: #d1d5db;
    transform: translateY(-1px);
}

.scanner-tab-button.active {
    background-color: #3b82f6;
    color: white;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.overlay { 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background: rgba(255,255,255,0.8); 
    backdrop-filter: blur(4px); 
    z-index: 999; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
}

#save-status { 
    transition: opacity 0.5s ease-in-out; 
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
