:root {
    --primary: #2563EB;
    --secondary: #F59E0B;
    --success: #10B981;
    --danger: #EF4444;
    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --text: #1E293B;
    --border: #E2E8F0;
    --whatsapp: #25D366;
    --ai-msg-bg: #E0F2FE;
    --user-msg-bg: #FFFFFF;
    --ai-avatar-color: #3B82F6;
}

/* Toast Notification */
.toast {
    position: fixed; bottom: 20px; right: 20px; background: #334155; color: white;
    padding: 12px 24px; border-radius: 12px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    transform: translateY(100px); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
    z-index: 5000; font-weight: 600; display: flex; align-items: center; gap: 10px;
    font-family: 'Outfit', sans-serif;
    opacity: 0; visibility: hidden;
}
.toast.show { transform: translateY(0); opacity: 1; visibility: visible; }
.toast.success { background: #10B981; }
.toast.error { background: #EF4444; }

@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.4; } 100% { opacity: 1; } }

/* Dashboard Styles */
.dashboard-container { max-width: 1200px; margin: 0 auto; padding: 20px; font-family: 'Outfit', sans-serif; }
body { background-color: var(--bg); color: var(--text); margin: 0; }

header { margin-bottom: 30px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 15px; }
h1 { font-size: 1.8rem; font-weight: 800; color: var(--text); margin: 0; }

.header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.metrics-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; margin-bottom: 30px;
}

.metric-card {
    background: var(--surface); padding: 20px; border-radius: 12px; border: 1px solid var(--border);
    display: flex; align-items: center; gap: 15px; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.metric-icon {
    width: 50px; height: 50px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; color: white;
}
.bg-blue { background: var(--primary); }
.bg-green { background: var(--success); }
.bg-orange { background: var(--secondary); }
.bg-red { background: var(--danger); }

.metric-info h3 { font-size: 0.9rem; color: #64748B; margin: 0 0 5px 0; }
.metric-info p { font-size: 1.5rem; font-weight: 800; margin: 0; }

.charts-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 30px;
}
.chart-card {
    background: var(--surface); padding: 20px; border-radius: 12px; border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.chart-card h3 { margin-top: 0; }

@media (max-width: 768px) {
    .charts-grid { grid-template-columns: 1fr; }
}

.orders-section { background: var(--surface); padding: 20px; border-radius: 12px; border: 1px solid var(--border); box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.orders-header { display: flex; justify-content: space-between; margin-bottom: 15px; }
.orders-header h2 { margin: 0; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { font-weight: 600; color: #64748B; background: #F1F5F9; }
tr:hover { background: #F8FAFC; }

.status-badge {
    padding: 4px 8px; border-radius: 20px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
}
.status-new { background: #DBEAFE; color: var(--primary); }
.status-urgent { background: #FEE2E2; color: var(--danger); }

.btn-icon {
    border: none; background: none; cursor: pointer; padding: 5px; font-size: 1rem; transition: transform 0.1s;
}
.btn-icon:hover { transform: scale(1.1); }

.refresh-btn {
    background: var(--primary); color: white; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer;
    font-weight: 600; display: flex; align-items: center; gap: 8px;
}
.refresh-btn:hover { background: #1E40AF; }

.logout-btn {
    background: #EF4444; color: white; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer;
    font-weight: 600; display: flex; align-items: center; gap: 8px;
}
.logout-btn:hover { background: #B91C1C; }

/* Modal Styles */
.modal {
    display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%;
    overflow: auto; background-color: rgba(0,0,0,0.5); /* Simple overlay */
}
.modal-content {
    background-color: var(--surface); margin: 5% auto; padding: 25px; border-radius: 8px;
    width: 95%; max-width: 700px; position: relative; border: 1px solid #CBD5E1;
}
.close {
    color: #94A3B8; float: right; font-size: 24px; font-weight: bold; cursor: pointer; transition: color 0.2s;
    background: #F1F5F9; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.close:hover { color: var(--danger); background: #FEE2E2; }

.modal-body-section { margin-bottom: 20px; }
.modal-body-section h4 { margin: 0 0 10px 0; color: #64748B; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.5px; }
.modal-info-row { display: flex; justify-content: space-between; margin-bottom: 8px; border-bottom: 1px dashed var(--border); padding-bottom: 8px; }
.modal-info-label { font-weight: 500; color: #64748B; }
.modal-info-value { font-weight: 600; }

.item-list { list-style: none; padding: 0; margin: 0; }
.item-list li { padding: 10px; background: #F8FAFC; border-radius: 8px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.item-badge { background: var(--primary); color: white; padding: 2px 8px; border-radius: 12px; font-size: 0.7rem; }

.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }
.btn-action { padding: 10px 20px; border-radius: 8px; border: none; cursor: pointer; font-weight: 600; color: white; }

/* Settings Form */
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 500; }
.form-group input[type="number"] { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--border); box-sizing: border-box; }
.form-group input[type="checkbox"] { transform: scale(1.2); margin-right: 8px; }

/* Professional/Fast PDV Styles */
.pdv-header {
    margin-bottom: 15px; border-bottom: 2px solid var(--border); padding-bottom: 10px;
    display: flex; justify-content: space-between; align-items: center;
}
.pdv-header h3 { font-size: 1.2rem; margin: 0; color: var(--text); }

.pdv-row { display: flex; gap: 10px; margin-bottom: 15px; }
.pdv-col { flex: 1; }

.pdv-input {
    width: 100%; padding: 8px; border: 1px solid #CBD5E1; border-radius: 4px;
    font-size: 0.9rem; background: white;
}
.pdv-input:focus { border-color: var(--primary); outline: none; }

.pdv-btn {
    padding: 0 15px; height: 100%; min-height: 35px; border: none; border-radius: 4px; cursor: pointer;
    font-weight: 600; color: white;
}
.pdv-btn-primary { background: var(--primary); }
.pdv-btn-secondary { background: #64748B; }

/* Table Layout */
.pdv-table-container {
    max-height: 300px; overflow-y: auto; margin: 10px 0; border: 1px solid #E2E8F0;
}
.pdv-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.pdv-table th { position: sticky; top: 0; background: #F1F5F9; text-align: left; padding: 8px; border-bottom: 1px solid #CBD5E1; font-size: 0.8rem; text-transform: uppercase; color: #475569; }
.pdv-table td { padding: 8px; border-bottom: 1px solid #F1F5F9; }
.pdv-table tr:last-child td { border-bottom: none; }

.pdv-qty-input { width: 50px; padding: 4px; text-align: center; border: 1px solid #CBD5E1; border-radius: 4px; }
.pdv-price-input { width: 80px; padding: 4px; text-align: right; border: 1px solid #CBD5E1; border-radius: 4px; }

.pdv-footer {
    display: flex; justify-content: space-between; align-items: center; margin-top: 15px;
    padding-top: 15px; border-top: 2px solid var(--border);
}
.pdv-total-box { text-align: right; }
.pdv-total-label { font-size: 0.9rem; color: #64748B; }
.pdv-total-val { font-size: 1.5rem; font-weight: 800; color: var(--text); }

.pdv-actions { display: flex; gap: 10px; }
.pdv-btn-action { padding: 10px 20px; border-radius: 4px; cursor: pointer; font-weight: 700; border: none; color: white; }
.pdv-btn-whatsapp { background: var(--whatsapp); }
.pdv-btn-back { background: white; border: 1px solid #CBD5E1; color: #475569; }

/* AI Chat Interface */
.ai-chat-wrapper {
    display: flex; flex-direction: column; height: 65vh; max-height: 600px;
    background: #F1F5F9; border-radius: 16px; overflow: hidden;
    position: relative;
}

.ai-chat-header {
    background: #FFFFFF; padding: 15px; border-bottom: 1px solid #E2E8F0;
    display: flex; align-items: center; gap: 15px;
}
.ai-avatar {
    width: 42px; height: 42px; background: var(--ai-avatar-color); color: white;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; flex-shrink: 0;
}
.ai-header-info h3 { margin: 0; font-size: 1rem; color: var(--text); font-weight: 700; }
.ai-header-info p { margin: 0; font-size: 0.75rem; color: var(--success); font-weight: 600; display: flex; align-items: center; gap: 5px; }
.ai-header-info p::before { content: ''; display: block; width: 6px; height: 6px; background: var(--success); border-radius: 50%; }

.ai-chat-messages {
    flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 15px;
}

.chat-msg { display: flex; flex-direction: column; max-width: 85%; animation: fadeIn 0.3s ease; }
.chat-msg.assistant { align-self: flex-start; }
.chat-msg.user { align-self: flex-end; align-items: flex-end; }

.chat-msg .msg-bubble {
    padding: 12px 16px; border-radius: 18px; font-size: 0.95rem; line-height: 1.5;
    position: relative; box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.chat-msg.assistant .msg-bubble {
    background: var(--surface); color: var(--text); border-top-left-radius: 4px;
    border: 1px solid #E2E8F0;
}
.chat-msg.user .msg-bubble {
    background: var(--primary); color: white; border-top-right-radius: 4px;
}

.ai-chat-input-area {
    padding: 15px; background: #FFFFFF; border-top: 1px solid #E2E8F0;
    display: flex; gap: 10px; align-items: center;
}
.ai-chat-input-area input {
    flex: 1; padding: 12px 16px; border: 1px solid #CBD5E1; border-radius: 24px;
    outline: none; transition: border-color 0.2s; font-size: 1rem;
}
.ai-chat-input-area input:focus { border-color: var(--primary); }
.ai-chat-input-area button {
    width: 42px; height: 42px; border-radius: 50%; background: var(--primary); color: white;
    border: none; cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; transition: transform 0.1s;
}
.ai-chat-input-area button:active { transform: scale(0.9); }

/* Typing Indicator */
.typing-indicator .msg-bubble { padding: 15px; display: flex; gap: 5px; align-items: center; }
.typing-indicator .dot {
    width: 6px; height: 6px; background: #94A3B8; border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.typing-indicator .dot:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator .dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Mobile Optimization */
@media (max-width: 600px) {
    .modal-content {
        margin: 0; width: 100%; height: 100%; max-width: 100%; border-radius: 0;
        display: flex; flex-direction: column; padding: 15px;
        overflow-y: auto;
    }
    .pdv-table-container { max-height: none; flex: 1; border: none; }

    /* Turn Table into Cards */
    .pdv-table, .pdv-table tbody, .pdv-table tr, .pdv-table td { display: block; width: 100%; }
    .pdv-table thead { display: none; } /* Hide Header */

    .pdv-table tr {
        background: #F8FAFC; border: 1px solid #E2E8F0; border-radius: 8px;
        margin-bottom: 15px; padding: 15px; position: relative;
    }

    .pdv-table td {
        padding: 5px 0; border: none; text-align: left !important;
        display: flex; justify-content: space-between; align-items: center;
    }

    /* Item Title - Make it look like a header */
    .pdv-table td:nth-child(1) {
        font-weight: 800; color: var(--primary); font-size: 1.1rem; margin-bottom: 10px;
        border-bottom: 1px dashed #CBD5E1; padding-bottom: 10px; display: block;
    }

    /* Labels for mobile clarity */
    .pdv-table td:nth-child(2)::before { content: "Qtd:"; font-size: 0.85rem; color: #64748B; font-weight: 600; margin-right: 10px; }
    .pdv-table td:nth-child(3)::before { content: "Unit:"; font-size: 0.85rem; color: #64748B; font-weight: 600; margin-right: 10px; }
    .pdv-table td:nth-child(4)::before { content: "Total:"; font-size: 0.85rem; color: #64748B; font-weight: 600; margin-right: 10px; }

    /* Actions - Position Delete Button */
    .pdv-table td:nth-child(5) {
        position: absolute; top: 10px; right: 10px; width: auto; padding: 0;
    }

    /* Inputs Bigger for Touch */
    .pdv-qty-input, .pdv-price-input {
        padding: 8px; font-size: 1rem; width: 100px;
    }

    /* Footer Stack */
    .pdv-footer { flex-direction: column-reverse; gap: 20px; align-items: stretch; text-align: center; }
    .pdv-total-box { text-align: center; }
    .pdv-actions { flex-direction: column; }
    .pdv-btn-action { padding: 15px; font-size: 1.1rem; }

    .ai-chat-wrapper { height: 100%; max-height: none; flex: 1; border-radius: 0; }
}
