:root {
    --bg-base: #0b1020;
    --surface: #11162b;
    --surface-elevated: #1b2240;
    --border: #1e2540;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-2: #22d3ee;
    --accent-3: #f472b6;
    --text: #e8ecff;
    --text-muted: #94a3c7;
    --error: #f15c6d;
    --bubble-me: #4f46e5;
    --bubble-ai: #1b2240;
}

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

body {
    font-family: 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background-color: var(--bg-base);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* Utilities */
.hidden { display: none !important; }
.active { display: flex !important; }

/* Login Screen */
#login-screen {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-base);
}

.login-box {
    background: linear-gradient(160deg, #151b34, #11152a);
    border: 1px solid var(--border);
    padding: 40px;
    border-radius: 14px;
    text-align: center;
    box-shadow: 0 8px 30px rgba(0,0,0,0.45);
    width: 350px;
}

.login-box h2 {
    margin-bottom: 10px;
    font-weight: 500;
}

.login-box p {
    color: var(--text-muted);
    margin-bottom: 20px;
    font-size: 14px;
}

.login-box input {
    width: 100%;
    padding: 12px;
    background-color: var(--surface-elevated);
    border: none;
    border-radius: 8px;
    color: var(--text);
    font-size: 15px;
    margin-bottom: 15px;
    outline: none;
}

.login-box button {
    width: 100%;
    padding: 12px;
    background-color: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.login-box button:hover {
    background-color: var(--accent-hover);
}

#login-error {
    color: var(--error);
    margin-top: 15px;
    font-size: 13px;
    margin-bottom: 0;
}

/* App Screen */
#app-screen {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Top Navbar */
.top-navbar {
    height: 60px;
    background: linear-gradient(180deg, #151b34, #0f1429);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
}

.navbar-logo {
    font-size: 18px;
    font-weight: bold;
    color: var(--text);
}

.navbar-tabs {
    display: flex;
    gap: 15px;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 8px 15px;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-weight: 500;
}

.tab-btn:hover {
    background-color: var(--surface-elevated);
    color: var(--text);
}

.active-tab {
    background-color: var(--surface-elevated);
    color: var(--accent);
}

.navbar-user {
    font-size: 15px;
    color: var(--text-muted);
}

/* Views Container */
.views-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

.view {
    width: 100%;
    height: 100%;
}

.view.hidden { display: none !important; }
.view.active-view { display: flex !important; }

/* Sidebar */
.sidebar {
    width: 30%;
    min-width: 300px;
    max-width: 400px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background-color: var(--bg-base);
}

.sidebar-header {
    background-color: var(--surface);
    height: 59px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.sidebar-header button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
}

.sidebar-search {
    padding: 10px;
    border-bottom: 1px solid var(--border);
}

.sidebar-search input {
    width: 100%;
    background-color: var(--surface);
    border: none;
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--text);
    outline: none;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-list::-webkit-scrollbar, .chat-history::-webkit-scrollbar {
    width: 6px;
}
.chat-list::-webkit-scrollbar-thumb, .chat-history::-webkit-scrollbar-thumb {
    background-color: var(--surface-elevated);
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

.chat-item:hover {
    background-color: var(--surface);
}

.chat-item.active-chat {
    background-color: var(--surface-elevated);
}

.chat-item .avatar {
    width: 49px;
    height: 49px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-right: 15px;
    flex-shrink: 0;
    color: #fff;
}

.chat-item-info {
    flex: 1;
    overflow: hidden;
}

.chat-item-title {
    font-size: 17px;
    color: var(--text);
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-time {
    margin-left: 8px;
    align-self: flex-start;
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
    white-space: nowrap;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-base);
    position: relative;
}

.chat-header {
    padding: 15px 20px;
    background-color: var(--surface);
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--border);
    z-index: 10;
}

.chat-header-main {
    display: flex;
    align-items: center;
}

.chat-header-title {
    display: flex;
    flex-direction: column;
}

.chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
}

.chat-phone {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.chat-header-actions {
    margin-left: auto;
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-badge {
    background-color: var(--surface-elevated);
    color: var(--text);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 5px;
}

.badge-msg { background-color: var(--accent-hover); color: var(--text); }
.badge-dept { background-color: var(--accent-2); color: #06121f; }
.badge-intent { background-color: var(--accent-3); color: #2a0f1f; }

.chat-header-details {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
}

.chat-header-details.hidden {
    display: none;
}

.chat-summary-box {
    background-color: var(--bg-base);
    border-radius: 8px;
    padding: 10px 15px;
    margin-top: 5px;
}

.chat-summary-text {
    margin-top: 5px;
    font-size: 13px;
    color: var(--text-muted);
    max-height: 80px;
    overflow-y: auto;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chat-summary-text::-webkit-scrollbar {
    width: 6px;
}

.chat-summary-text::-webkit-scrollbar-thumb {
    background: var(--surface-elevated);
    border-radius: 3px;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-base);
}

.empty-state {
    margin: auto;
    color: var(--text-muted);
    font-size: 14px;
    background-color: var(--surface);
    padding: 10px 20px;
    border-radius: 15px;
}

.message {
    max-width: 65%;
    padding: 8px 10px;
    border-radius: 7.5px;
    margin-bottom: 8px;
    font-size: 14.2px;
    line-height: 19px;
    position: relative;
    word-wrap: break-word;
}

.message.human {
    background-color: var(--bubble-me);
    color: var(--text);
    align-self: flex-end;
    border-top-right-radius: 0;
}

.message.ai {
    background-color: var(--bubble-ai);
    align-self: flex-start;
    border-top-left-radius: 0;
}

/* Emails View */
#view-emails {
    flex-direction: column;
    background-color: var(--bg-base);
    width: 100%;
}

.emails-header {
    padding: 20px 30px;
    background-color: var(--bg-base);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.emails-header h2 {
    font-weight: 500;
}

.refresh-email-btn {
    background-color: var(--surface);
    color: var(--accent);
    border: 1px solid var(--border);
    padding: 8px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

.refresh-email-btn:hover {
    background-color: var(--surface-elevated);
}

.emails-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.emails-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.emails-table th {
    text-align: left;
    padding: 12px 15px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    background-color: var(--bg-base);
}

.emails-table td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: top;
}

.emails-table tr:hover td {
    background-color: var(--surface);
}

.td-resumen {
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Emails Select Filter */
.filter-dropdown {
    background-color: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 15px;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    cursor: pointer;
}

.filter-dropdown:focus {
    border-color: var(--accent);
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(7, 11, 26, 0.85);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: var(--surface);
    width: 90%;
    max-width: 600px;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.modal-header {
    padding: 15px 20px;
    background-color: var(--surface-elevated);
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    margin: 0;
    color: var(--text);
    font-size: 18px;
    font-weight: 500;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

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

.modal-body {
    padding: 20px;
    overflow-y: auto;
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}

.detail-row {
    margin-bottom: 15px;
}

.detail-label {
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 5px;
    font-size: 14px;
    text-transform: uppercase;
}

.detail-value {
    background-color: var(--bg-base);
    padding: 10px;
    border-radius: 5px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* KPIs View */
.kpi-container {
    padding: 30px;
    color: var(--text);
}

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

.kpi-card {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    background: linear-gradient(160deg, #151b34, #11152a);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}

.kpi-glow {
    position: absolute;
    z-index: 0;
    right: -30px;
    top: -30px;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    filter: blur(30px);
    opacity: 0.35;
}

.kpi-badge, .kpi-title, .kpi-value, .kpi-sub {
    position: relative;
    z-index: 1;
}

.kpi-badge {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    margin-bottom: 14px;
}

.kpi-card[data-accent="indigo"] .kpi-glow { background: var(--accent); }
.kpi-card[data-accent="indigo"] .kpi-badge { background: rgba(99,102,241,0.16); color: #a5b4fc; }
.kpi-card[data-accent="cyan"] .kpi-glow { background: var(--accent-2); }
.kpi-card[data-accent="cyan"] .kpi-badge { background: rgba(34,211,238,0.16); color: #67e8f9; }
.kpi-card[data-accent="pink"] .kpi-glow { background: var(--accent-3); }
.kpi-card[data-accent="pink"] .kpi-badge { background: rgba(244,114,182,0.16); color: #f9a8d4; }

.kpi-title {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    margin-bottom: 6px;
}

.kpi-value {
    font-size: 34px;
    color: var(--text);
    font-weight: 700;
    line-height: 1;
}

.kpi-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
}

.kpi-section {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.kpi-section h3 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 18px;
    color: var(--text);
}

.kpi-table-container {
    background-color: var(--bg-base);
    border-radius: 8px;
    overflow: hidden;
}

/* Ionicons */
ion-icon {
    vertical-align: middle;
    font-size: 1.15em;
}
.tab-btn ion-icon, .navbar-user ion-icon {
    margin-right: 4px;
}
.avatar ion-icon {
    font-size: 26px;
    color: #fff;
}
.chat-badge ion-icon {
    font-size: 14px;
}
.sidebar-header button ion-icon,
.refresh-email-btn ion-icon {
    font-size: 18px;
}

/* Barras de intenciones */
.intent-bar-cell {
    min-width: 180px;
}
.intent-bar-track {
    background: var(--surface-elevated);
    border-radius: 6px;
    height: 8px;
    width: 100%;
    overflow: hidden;
    margin-top: 6px;
}
.intent-bar-fill {
    height: 100%;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

/* Home / Inicio View */
.home-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 4px;
}

.home-container {
    padding: 30px;
    color: var(--text);
}

.home-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.home-card {
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.home-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.home-card .kpi-title {
    font-size: 15px;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text);
    margin-top: 6px;
}

.home-card-link {
    position: relative;
    z-index: 1;
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.home-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.home-panel {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
}

.home-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.home-panel-link {
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.home-list {
    display: flex;
    flex-direction: column;
}

.home-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 13px;
}

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

.home-row:hover {
    color: var(--accent);
}

.home-row-main {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.home-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 15px;
    flex-shrink: 0;
}

.home-row-sub {
    color: var(--text-muted);
    font-size: 12px;
    flex-shrink: 0;
    margin-left: 10px;
}

.home-intent {
    margin-bottom: 14px;
}

.home-intent:last-child {
    margin-bottom: 0;
}

.home-intent-label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text);
    margin-bottom: 2px;
}

.home-empty {
    color: var(--text-muted);
    font-size: 13px;
    padding: 8px 0;
}

@media (max-width: 900px) {
    .home-cards, .home-panels {
        grid-template-columns: 1fr;
    }
}
