@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800;900&family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

:root {
    --bg-admin-primary: #fcfbf9; /* Soft warm ivory */
    --bg-admin-secondary: #f5f3ef; /* Sand beige */
    --bg-admin-card: rgba(255, 255, 255, 0.85); /* Pristine glass */
    --bg-admin-hover: rgba(243, 176, 4, 0.06);
    --text-primary: #292524; /* Deep bronze charcoal */
    --text-secondary: #57534e; /* Warm stone gray */
    --text-muted: #a8a29e;
    --primary: #f3b004; /* bright brand yellow-gold */
    --primary-hover: #ffc83b;
    --primary-gradient: linear-gradient(135deg, #ffc83b 0%, #f3b004 50%, #b38000 100%);
    --primary-glow: rgba(243, 176, 4, 0.15);
    --border-color: rgba(243, 176, 4, 0.15); /* Golden border */
    --success: #2c9b44;
    --warning: #d97706;
    --info: #2563eb;
    --danger: #dc2626;
    --font-sans: 'Plus Jakarta Sans', 'Outfit', sans-serif;
    --sidebar-width: 260px;
    --transition: all 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-admin-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 100;
    transition: var(--transition);
}

.sidebar-brand {
    padding: 2rem 1.5rem;
    font-weight: 800;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-menu {
    list-style: none;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
}

.sidebar-item a {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    transition: var(--transition);
    cursor: pointer;
}

.sidebar-item.active a, .sidebar-item a:hover {
    color: var(--text-primary);
    background-color: var(--bg-admin-hover);
}

.sidebar-item.active a {
    border-left: 3px solid var(--primary);
    border-radius: 4px 12px 12px 4px;
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: var(--text-muted);
}

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

/* Top Navigation Bar */
.topbar {
    height: 70px;
    background-color: var(--bg-admin-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 90;
}

.search-box {
    position: relative;
    width: 300px;
}

.search-box i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-input {
    width: 100%;
    padding: 0.6rem 1rem 0.6rem 2.5rem;
    background-color: var(--bg-admin-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    transition: var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.notifications-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    position: relative;
    padding: 0.5rem;
    border-radius: 50%;
    transition: var(--transition);
}

.notifications-btn:hover {
    background-color: var(--bg-admin-hover);
    color: var(--text-primary);
}

.notification-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 8px;
    height: 8px;
    background-color: var(--warning);
    border-radius: 50%;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-color);
}

/* Page Containers */
.page-container {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    flex-grow: 1;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.page-title h1 {
    font-size: 1.8rem;
    font-weight: 700;
}

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

/* KPIs Metric Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
}

.metric-card {
    background-color: var(--bg-admin-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 1.8rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: var(--transition);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.metric-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 15px 35px rgba(245, 196, 60, 0.08), 0 5px 15px rgba(0, 0, 0, 0.2);
}

.metric-info h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-value {
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0.5rem 0 0.25rem;
}

.metric-change {
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.metric-change.up {
    color: var(--success);
}

.metric-change.down {
    color: var(--danger);
}

.metric-icon {
    font-size: 1.5rem;
    color: var(--primary);
    background: rgba(212, 175, 55, 0.08);
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    border: 1px solid rgba(212, 175, 55, 0.1);
}

/* Dashboard Split Layout (Table & Details) */
.dashboard-layout {
    display: grid;
    grid-template-columns: 1.3fr 0.7fr;
    gap: 2rem;
    align-items: start;
}

.table-section {
    background-color: var(--bg-admin-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    overflow: hidden;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
}

.table-header-actions {
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.table-tabs {
    display: flex;
    gap: 0.5rem;
}

.tab-btn {
    background: none;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-admin-hover);
}

.tab-btn.active {
    color: #ffffff;
    background-color: var(--primary);
    box-shadow: 0 4px 15px var(--primary-glow);
}

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    padding: 1rem 1.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 1.2rem 1.5rem;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-color);
}

tr {
    cursor: pointer;
    transition: var(--transition);
}

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

tr.selected {
    background-color: rgba(212, 175, 55, 0.04);
}

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

.badge-pendiente {
    background-color: rgba(255, 159, 10, 0.1);
    color: var(--warning);
}

.badge-cotizado {
    background-color: rgba(10, 132, 255, 0.1);
    color: var(--info);
}

.badge-confirmado {
    background-color: rgba(48, 209, 88, 0.1);
    color: var(--success);
}

/* Details Panel (AI Workspace) */
.details-section {
    background-color: var(--bg-admin-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 1.8rem 1.5rem;
    position: sticky;
    top: 90px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

.details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.details-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
}

.empty-details {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.empty-details i {
    font-size: 3rem;
    color: var(--bg-admin-hover);
}

/* Detail UI Components */
.detail-block h4 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    letter-spacing: 0.5px;
}

.detail-block p {
    font-size: 0.95rem;
    color: var(--text-primary);
}

.detail-text-box {
    background-color: var(--bg-admin-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1rem;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary);
    max-height: 120px;
    overflow-y: auto;
}

/* AI Workspace Box */
.ai-workspace {
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.05) 0%, rgba(10, 132, 255, 0.03) 100%);
    border: 1px solid rgba(212, 175, 55, 0.15);
    border-radius: 12px;
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.ai-header-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
}

.ai-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary);
    font-weight: 600;
}

.ai-indicator i {
    animation: rotate 4s linear infinite;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.ai-results-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.ai-result-card {
    background-color: var(--bg-admin-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.6rem;
    text-align: center;
}

.ai-result-card span.label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.ai-result-card span.val {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary);
}

/* AI Logs Simulation */
.ai-logs-terminal {
    background-color: #020205;
    border: 1px solid #1f1f35;
    border-radius: 8px;
    padding: 0.8rem;
    font-family: monospace;
    font-size: 0.75rem;
    color: #4af626;
    height: 120px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.log-line {
    white-space: pre-wrap;
}

.log-system {
    color: #a1a1a6;
}

.log-ia {
    color: #0a84ff;
}

/* AI Extracted Items Table */
.ai-items-list {
    background-color: var(--bg-admin-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    max-height: 150px;
    overflow-y: auto;
    padding: 0.5rem;
}

.ai-item-row {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border-color);
}

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

.ai-item-qty {
    color: var(--primary);
    font-weight: 600;
}

/* Smart Email Box */
.smart-email-box {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.email-textarea {
    width: 100%;
    padding: 0.8rem;
    background-color: var(--bg-admin-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    min-height: 120px;
    resize: vertical;
}

.email-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    border-radius: 8px;
}

/* Calendar Section */
.calendar-section {
    background-color: var(--bg-admin-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    display: none; /* Controlled by admin.js */
}

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

.calendar-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.5rem;
}

.calendar-day-header {
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0.5rem 0;
    text-transform: uppercase;
}

.calendar-cell {
    min-height: 110px;
    background-color: var(--bg-admin-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    transition: var(--transition);
}

.calendar-cell:hover {
    border-color: rgba(255, 255, 255, 0.15);
}

.calendar-cell.other-month {
    opacity: 0.3;
}

.calendar-day-number {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.calendar-event {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    transition: var(--transition);
}

.calendar-event.event-pendiente {
    background-color: rgba(255, 159, 10, 0.15);
    color: var(--warning);
    border-left: 2px solid var(--warning);
}

.calendar-event.event-cotizado {
    background-color: rgba(10, 132, 255, 0.15);
    color: var(--info);
    border-left: 2px solid var(--info);
}

.calendar-event.event-confirmado {
    background-color: rgba(48, 209, 88, 0.15);
    color: var(--success);
    border-left: 2px solid var(--success);
}

.calendar-event:hover {
    transform: translateX(2px);
}

/* Animations */
@keyframes pulse {
    0% { transform: scale(1); opacity: 0.2; }
    50% { transform: scale(1.05); opacity: 0.4; }
    100% { transform: scale(1); opacity: 0.2; }
}

.pulse-glow {
    animation: pulse 2s ease-in-out infinite;
}

/* Responsive Admin */
@media (max-width: 1200px) {
    .dashboard-layout {
        grid-template-columns: 1fr;
    }
    
    .details-section {
        position: static;
        max-height: none;
    }
}

@media (max-width: 900px) {
    .sidebar {
        left: -100%;
    }
    
    .sidebar.active {
        left: 0;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .metrics-grid {
        grid-template-columns: 1fr;
    }
    
    .topbar {
        padding: 0 1rem;
    }
    
    .search-box {
        width: 180px;
    }
}
