/* ===== RESET & BASE ===== */
:root { --primary: #7c3aed; --primary-hover: #6d28d9; --primary-light: #f3e8ff; --primary-bg: #f9f5ff; }
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: #f5f6fa; color: #333; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; font-family: inherit; }
input, select { font-family: inherit; }

/* ===== INDUSTRY SELECTION SCREEN ===== */
.industry-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    display: flex; align-items: center; justify-content: center;
    overflow-y: auto; padding: 40px 20px;
}
.industry-overlay.hidden { display: none; }
.industry-container {
    max-width: 900px; width: 100%; text-align: center;
    animation: fadeInUp 0.6s ease-out;
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}
.industry-header { margin-bottom: 48px; }
.industry-logo {
    width: 80px; height: 80px; border-radius: 20px; margin: 0 auto 24px;
    background: linear-gradient(135deg, #7c3aed, #3b82f6);
    display: flex; align-items: center; justify-content: center;
    font-size: 36px; color: #fff;
    box-shadow: 0 12px 40px rgba(124,58,237,0.3);
}
.industry-header h1 { font-size: 32px; font-weight: 800; color: #fff; margin-bottom: 12px; }
.industry-header p { font-size: 16px; color: #94a3b8; }
.industry-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px; margin-bottom: 32px;
}
.industry-card {
    background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px; padding: 32px 24px; cursor: pointer;
    transition: all 0.3s ease; position: relative; overflow: hidden;
}
.industry-card:hover {
    background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.25);
    transform: translateY(-4px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
}
.industry-card .ind-icon {
    width: 60px; height: 60px; border-radius: 14px; margin: 0 auto 16px;
    display: flex; align-items: center; justify-content: center;
    font-size: 26px; color: #fff;
}
.industry-card h3 { font-size: 18px; font-weight: 700; color: #fff; margin-bottom: 8px; }
.industry-card p { font-size: 13px; color: #94a3b8; line-height: 1.5; }
.industry-card .ind-arrow {
    position: absolute; top: 16px; right: 16px;
    color: rgba(255,255,255,0.2); font-size: 14px;
    transition: all 0.3s;
}
.industry-card:hover .ind-arrow { color: rgba(255,255,255,0.6); transform: translateX(4px); }
.industry-footer-text { font-size: 13px; color: #475569; }

/* ===== CRM APP WRAPPER ===== */
.crm-app { display: flex; min-height: 100vh; width: 100%; }

/* ===== SIDEBAR ===== */
.sidebar {
    width: 220px;
    min-height: 100vh;
    background: #fff;
    border-right: 1px solid #e8e8ef;
    display: flex;
    flex-direction: column;
    transition: width 0.3s;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
}
.sidebar.collapsed { width: 68px; }
.sidebar.collapsed .sidebar-brand,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .sidebar-toggle span { display: none; }
.sidebar.collapsed .sidebar-header { justify-content: center; }
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px 10px;
}
.sidebar-logo { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.sidebar-logo-fallback {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 16px; flex-shrink: 0;
}
.sidebar-brand { font-weight: 700; font-size: 15px; color: var(--primary); white-space: nowrap; }
.sidebar-toggle {
    background: none; color: #888; font-size: 13px; padding: 8px 16px;
    text-align: left; display: flex; align-items: center; gap: 6px;
}
.sidebar-toggle:hover { color: var(--primary); }
.sidebar-nav { flex: 1; display: flex; flex-direction: column; padding: 8px 0; }
.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 12px 20px;
    font-size: 14px; color: #555; border-left: 3px solid transparent; transition: all 0.2s;
}
.nav-item:hover { background: var(--primary-light); color: var(--primary); }
.nav-item.active {
    background: var(--primary); color: #fff;
    border-radius: 0 8px 8px 0; margin-right: 12px; border-left-color: transparent;
}
.nav-item i { width: 20px; text-align: center; font-size: 15px; }
.sidebar-footer { border-top: 1px solid #e8e8ef; padding: 8px 0; }
.admin-link { color: var(--primary) !important; font-weight: 600; }

/* ===== MAIN CONTENT ===== */
.main-content {
    margin-left: 220px; flex: 1; padding: 24px 32px;
    min-height: 100vh; transition: margin-left 0.3s; width: calc(100% - 220px);
}
.sidebar.collapsed ~ .main-content { margin-left: 68px; width: calc(100% - 68px); }
.content-section { display: none; }
.content-section.active { display: block; }

/* ===== SECTION HEADER ===== */
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.section-title { display: flex; align-items: center; gap: 14px; }
.section-title h1 { font-size: 22px; font-weight: 700; }
.section-title p { font-size: 13px; color: #888; }
.section-icon {
    width: 44px; height: 44px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center; font-size: 18px; color: #fff;
}
.section-icon.purple { background: var(--primary); }
.section-icon.green { background: #22c55e; }

/* ===== PERIOD TABS ===== */
.period-tabs { display: flex; gap: 4px; background: #f1f1f5; border-radius: 8px; padding: 3px; }
.period-tab {
    padding: 7px 16px; border-radius: 6px; font-size: 13px;
    background: transparent; color: #666; font-weight: 500;
}
.period-tab.active { background: var(--primary); color: #fff; }
.period-tab:hover:not(.active) { background: #e0e0e5; }

/* ===== DASHBOARD WIDGETS ===== */
.dashboard-widgets {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 12px;
}
.widget {
    background: #fff; border-radius: 12px; border: 1px solid #e8e8ef;
    position: relative; transition: box-shadow 0.2s, transform 0.15s;
    cursor: grab;
}
.widget:hover { box-shadow: 0 4px 15px rgba(0,0,0,0.07); }
.widget.dragging { opacity: 0.5; transform: scale(0.97); }
.widget.drag-over { border: 2px dashed var(--primary); }
.widget-stat { padding: 20px; display: flex; align-items: center; gap: 16px; }
.widget-chart { padding: 18px; grid-column: span 2; }
.widget-chart canvas { width: 100% !important; height: 180px !important; }
.widget-chart h4 { font-size: 13px; color: #888; font-weight: 500; margin-bottom: 10px; }
.widget .card-icon {
    width: 40px; height: 40px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0;
}
.widget .card-icon.blue { background: #dbeafe; color: #3b82f6; }
.widget .card-icon.green { background: #dcfce7; color: #22c55e; }
.widget .card-icon.orange { background: #ffedd5; color: #f97316; }
.widget .card-icon.purple { background: var(--primary-light); color: var(--primary); }
.widget .card-icon.red { background: #fee2e2; color: #ef4444; }
.widget .card-icon.teal { background: #ccfbf1; color: #14b8a6; }
.widget .card-info h4 { font-size: 13px; color: #888; font-weight: 500; }
.widget .card-info .card-value { font-size: 28px; font-weight: 700; color: #222; }
.widget .card-info .card-subtitle { font-size: 11px; color: #aaa; }
.widget .btn-remove-card {
    position: absolute; top: 8px; right: 8px; background: none;
    color: #ccc; font-size: 14px; opacity: 0; transition: opacity 0.2s; z-index: 2;
}
.widget:hover .btn-remove-card { opacity: 1; }
.widget .btn-remove-card:hover { color: #ef4444; }
.widget .drag-handle {
    position: absolute; top: 8px; left: 8px; color: #d1d5db;
    font-size: 12px; opacity: 0; transition: opacity 0.2s; cursor: grab;
}
.widget:hover .drag-handle { opacity: 1; }

.add-card-container { margin-bottom: 24px; display: flex; gap: 10px; }
.btn-add-card {
    background: #fff; border: 2px dashed #d1d5db; border-radius: 12px;
    padding: 12px 24px; color: #888; font-size: 13px; transition: all 0.2s;
}
.btn-add-card:hover { border-color: var(--primary); color: var(--primary); }

/* ===== MAIN CHART ===== */
.chart-container {
    background: #fff; border-radius: 12px; padding: 24px; border: 1px solid #e8e8ef;
}
.chart-container h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; color: #444; }

/* ===== CHATS ===== */
.chats-layout { display: flex; height: calc(100vh - 48px); margin: -24px -32px; }
.chats-sidebar {
    width: 340px; border-right: 1px solid #e8e8ef; background: #fff;
    display: flex; flex-direction: column;
}
.chats-header { padding: 20px; }
.chats-header h2 { font-size: 20px; font-weight: 700; }
.chats-search { padding: 0 16px 12px; position: relative; }
.chats-search i { position: absolute; left: 28px; top: 10px; color: #aaa; font-size: 13px; }
.chats-search input {
    width: 100%; padding: 10px 12px 10px 36px; border: 1px solid #e0e0e5;
    border-radius: 8px; font-size: 13px; outline: none;
}
.chats-search input:focus { border-color: var(--primary); }
.chats-list { flex: 1; overflow-y: auto; }
.chat-item {
    display: flex; align-items: center; gap: 12px; padding: 14px 16px;
    cursor: pointer; border-left: 3px solid transparent; transition: background 0.15s;
}
.chat-item:hover { background: #f9fafb; }
.chat-item.active { background: var(--primary-light); border-left-color: var(--primary); }
.chat-item.needs-attention { border-left-color: #f59e0b; }
.avatar {
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; color: #fff; flex-shrink: 0;
}
.chat-item-info { flex: 1; min-width: 0; }
.chat-item-info h4 { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.chat-item-info p { font-size: 12px; color: #888; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-meta { text-align: right; flex-shrink: 0; }
.chat-item-meta .time { font-size: 11px; color: #aaa; display: block; margin-bottom: 4px; }
.chat-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 22px; height: 22px; border-radius: 11px;
    background: #22c55e; color: #fff; font-size: 11px; font-weight: 700; padding: 0 6px;
}
.tag-attention {
    background: #fff0f0; color: #ef4444; font-size: 10px; padding: 2px 8px;
    border-radius: 4px; font-weight: 600; border: 1px solid #fecaca;
}
.chats-main { flex: 1; display: flex; flex-direction: column; background: #fafafa; }
.chat-header {
    padding: 16px 24px; background: #fff; border-bottom: 1px solid #e8e8ef; display: flex; align-items: center;
}
.chat-contact-info { display: flex; align-items: center; gap: 12px; }
.chat-contact-info h3 { font-size: 15px; }
.chat-contact-info span { font-size: 12px; color: #888; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px 24px; }
.chat-empty {
    height: 100%; display: flex; flex-direction: column;
    align-items: center; justify-content: center; color: #bbb;
}
.chat-empty i { font-size: 48px; margin-bottom: 12px; }
.chat-empty p { font-size: 14px; }
.message {
    max-width: 65%; padding: 10px 16px; border-radius: 12px;
    margin-bottom: 8px; font-size: 13px; line-height: 1.5; position: relative;
}
.message.incoming { background: #fff; border: 1px solid #e8e8ef; align-self: flex-start; border-bottom-left-radius: 4px; }
.message.outgoing { background: #dcfce7; margin-left: auto; border-bottom-right-radius: 4px; }
.message .msg-time { font-size: 10px; color: #aaa; margin-top: 4px; display: block; }
.chat-input-area {
    padding: 12px 24px; background: #fff; border-top: 1px solid #e8e8ef; display: flex; gap: 10px;
}
.chat-input-area input {
    flex: 1; padding: 10px 16px; border: 1px solid #e0e0e5;
    border-radius: 8px; font-size: 13px; outline: none;
}
.chat-input-area input:focus { border-color: var(--primary); }
.btn-send {
    background: var(--primary); color: #fff; width: 40px; height: 40px;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.btn-send:hover { background: var(--primary-hover); }

/* ===== PEDIDOS ===== */
.pedidos-header { margin-bottom: 20px; }
.pedidos-summary {
    display: flex; gap: 20px; margin-bottom: 20px; flex-wrap: wrap;
}
.summary-card {
    background: #fff; border-radius: 12px; padding: 20px 28px;
    border: 1px solid #e8e8ef; display: flex; align-items: center; gap: 16px;
    flex: 1; min-width: 200px;
}
.summary-card .s-icon {
    width: 48px; height: 48px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.summary-card .s-icon.green { background: #dcfce7; color: #22c55e; }
.summary-card .s-icon.blue { background: #dbeafe; color: #3b82f6; }
.summary-card .s-icon.purple { background: var(--primary-light); color: var(--primary); }
.summary-card .s-value { font-size: 26px; font-weight: 700; color: #222; }
.summary-card .s-label { font-size: 13px; color: #888; }
.pedidos-filters { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.search-box { position: relative; }
.search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #aaa; font-size: 13px; }
.search-box input {
    padding: 10px 12px 10px 36px; border: 1px solid #e0e0e5;
    border-radius: 8px; font-size: 13px; width: 260px; outline: none;
}
.search-box input:focus { border-color: var(--primary); }
.date-filters { display: flex; align-items: center; gap: 8px; }
.date-filters label { font-size: 13px; color: #666; display: flex; align-items: center; gap: 4px; }
.date-filters input { padding: 8px 12px; border: 1px solid #e0e0e5; border-radius: 8px; font-size: 13px; outline: none; }
.btn-primary {
    background: var(--primary); color: #fff; padding: 10px 24px;
    border-radius: 8px; font-size: 14px; font-weight: 600;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
    background: #f1f1f5; color: #555; padding: 10px 24px;
    border-radius: 8px; font-size: 14px; font-weight: 500;
}
.btn-secondary:hover { background: #e0e0e5; }
.table-container { overflow-x: auto; }
.orders-table {
    width: 100%; border-collapse: collapse; background: #fff;
    border-radius: 12px; overflow: hidden; border: 1px solid #e8e8ef;
}
.orders-table thead { background: var(--primary-bg); }
.orders-table th {
    padding: 14px 18px; font-size: 12px; text-transform: uppercase;
    font-weight: 700; color: var(--primary); text-align: left; letter-spacing: 0.5px;
}
.orders-table td { padding: 14px 18px; font-size: 13px; border-top: 1px solid #f0f0f5; }
.orders-table tr:hover { background: #fafafa; }
.orders-table .client-cell { display: flex; align-items: center; gap: 10px; }
.orders-table .avatar { width: 32px; height: 32px; font-size: 12px; }
.btn-view {
    background: var(--primary); color: #fff; padding: 6px 16px;
    border-radius: 6px; font-size: 12px; font-weight: 600;
}
.btn-view:hover { background: var(--primary-hover); }
.pagination {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 0; font-size: 13px; color: #666;
}
.pagination-buttons { display: flex; gap: 8px; }
.btn-page {
    padding: 8px 16px; border: 1px solid #e0e0e5; border-radius: 6px;
    background: #fff; font-size: 13px; color: #555;
}
.btn-page:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-page:disabled { opacity: 0.4; cursor: default; }

/* ===== CONOCIMIENTO ===== */
.kb-guide {
    background: #fff; border: 1px solid #e8e8ef; border-radius: 10px;
    padding: 14px 18px; margin-bottom: 16px; font-size: 13px; color: #666;
}
.kb-sections { display: flex; flex-direction: column; gap: 12px; }
.kb-section { background: #fff; border: 1px solid #e8e8ef; border-radius: 10px; overflow: hidden; }
.kb-section-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; cursor: pointer; transition: background 0.15s;
}
.kb-section-header:hover { background: #f9fafb; }
.kb-section-header h3 { font-size: 15px; font-weight: 600; }
.kb-section-header p { font-size: 12px; color: #888; }
.kb-section-header i { color: #aaa; transition: transform 0.2s; }
.kb-section-header.open i { transform: rotate(180deg); }
.kb-section-content { padding: 0 20px 16px; }
.kb-items { display: flex; flex-direction: column; gap: 8px; }
.kb-item {
    display: flex; align-items: center; gap: 12px; padding: 14px 16px;
    background: #f9fafb; border-radius: 8px; border: 1px solid #f0f0f5;
}
.kb-item-icon {
    width: 36px; height: 36px; border-radius: 8px; background: var(--primary-light);
    color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.kb-item h4 { font-size: 14px; font-weight: 600; }
.kb-item p { font-size: 12px; color: #888; }
.btn-expand { margin-left: auto; background: none; color: #aaa; font-size: 12px; }
.kb-item-detail { padding: 0 16px 8px; }
.kb-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.kb-table th {
    padding: 8px 12px; background: var(--primary-light); font-size: 12px;
    text-align: left; color: var(--primary); font-weight: 600;
}
.kb-table td { padding: 8px 12px; font-size: 13px; border-top: 1px solid #f0f0f5; }

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal {
    background: #fff; border-radius: 14px; width: 480px;
    max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.modal-lg { width: 620px; }
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px 24px; border-bottom: 1px solid #e8e8ef;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; font-size: 22px; color: #aaa; }
.modal-close:hover { color: #333; }
.modal-body { padding: 20px 24px; }
.modal-footer {
    padding: 14px 24px; border-top: 1px solid #e8e8ef;
    display: flex; justify-content: flex-end; gap: 10px;
}
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #555; }
.form-group input, .form-group select {
    width: 100%; padding: 10px 14px; border: 1px solid #e0e0e5;
    border-radius: 8px; font-size: 13px; outline: none;
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary); }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.type-toggle { display: flex; gap: 8px; margin-bottom: 16px; }
.type-toggle button {
    flex: 1; padding: 10px; border: 2px solid #e0e0e5; border-radius: 8px;
    background: #fff; font-size: 13px; font-weight: 600; color: #666; transition: all 0.2s;
}
.type-toggle button.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.chart-fields { display: none; }
.chart-fields.visible { display: block; }

/* ===== ORDER DETAIL ===== */
.order-detail-grid { display: flex; flex-direction: column; gap: 12px; }
.order-detail-row { display: flex; gap: 16px; }
.order-detail-row .label { font-size: 13px; color: #888; width: 100px; flex-shrink: 0; }
.order-detail-row .value { font-size: 13px; font-weight: 600; }
.order-items-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.order-items-table th { padding: 8px 10px; background: var(--primary-bg); font-size: 12px; text-align: left; color: var(--primary); }
.order-items-table td { padding: 8px 10px; font-size: 13px; border-top: 1px solid #f0f0f5; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .sidebar { width: 68px; }
    .sidebar .sidebar-brand, .sidebar .nav-item span, .sidebar .sidebar-toggle span { display: none; }
    .main-content { margin-left: 68px; width: calc(100% - 68px); padding: 16px; }
    .chats-sidebar { width: 100%; }
    .dashboard-widgets { grid-template-columns: 1fr 1fr; }
    .pedidos-filters { flex-direction: column; align-items: stretch; }
    .search-box input { width: 100%; }
    .industry-grid { grid-template-columns: 1fr 1fr; }
    .industry-header h1 { font-size: 24px; }
}
@media (max-width: 480px) {
    .industry-grid { grid-template-columns: 1fr; }
}
