:root {
    --brand-700: #0b3b6f;
    --brand-600: #025f9c;
    --brand-500: #1d7cc2;
    --brand-400: #60a5fa;
    --accent: #0ea5e9;
    --bg: #0a1524;
    --panel: #0f1e34;
    --muted: #94a3b8;
    --ink: #e6eef7;
    --line: #1f314d;
    --shadow: 0 20px 60px rgba(4, 12, 24, 0.35);
    --radius: 16px;
    --nav-h: 56px;
    --input-h: 68px;
    --safe: env(safe-area-inset-bottom, 0px);
}

/* === LOGOUT BUTTON === */
.logout-btn {
    background: linear-gradient(
        90deg,
        var(--brand-600) 60%,
        var(--brand-400) 100%
    );
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 18px;
    font-size: 1rem;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(2, 95, 156, 0.1);
    cursor: pointer;
    transition: background 0.18s, box-shadow 0.18s, transform 0.08s;
    margin: -2px 0 -2px 12px;
    outline: 0;
    float: left;
}
.logout-btn:hover,
.logout-btn:focus {
    background: var(--brand-500);
    box-shadow: 0 3px 12px rgba(14, 165, 233, 0.18);
    transform: translateY(-1px) scale(1.03);
}

/* === HISTORY BUTTONS (unificado) === */
.btn-history-clear-all,
.btn-hist-back,
.btn-hist-delete,
.btn-hist-resume {
    background: var(--brand-600);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 8px 14px;
    font-size: 0.98rem;
    font-weight: 700;
    margin: 0 4px;
    cursor: pointer;
    transition: background 0.18s, box-shadow 0.18s, transform 0.08s;
    box-shadow: 0 1px 4px rgba(2, 95, 156, 0.08);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    outline: 0;
}
.btn-history-clear-all:hover,
.btn-hist-back:hover,
.btn-hist-delete:hover,
.btn-hist-resume:hover,
.btn-history-clear-all:focus,
.btn-hist-back:focus,
.btn-hist-delete:focus,
.btn-hist-resume:focus {
    background: var(--brand-500);
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.13);
    transform: translateY(-1px) scale(1.04);
}
.btn-hist-delete {
    background: #e74c3c;
}
.btn-hist-delete:hover,
.btn-hist-delete:focus {
    background: #c0392b;
}

/* === Floating button === */
#ai-agents-chatbot-toggle {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 10000;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--brand-600);
    color: #fff;
    border: 0;
    font-size: 24px;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform 0.15s, background 0.2s;
}
#ai-agents-chatbot-toggle:hover {
    transform: translateY(-1px);
    background: var(--brand-500);
}

/* === Widget === */
#ai-agents-chatbot-widget {
    position: fixed;
    bottom: 98px;
    right: 28px;
    z-index: 9999;
    width: 420px;
    max-width: 92vw;
    display: none;
    overflow: hidden;
    background: #0b1a2e;
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow);
    color: var(--ink);
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
}
#ai-agents-chatbot-widget.open {
    display: flex;
    flex-direction: column;
    max-height: min(88dvh, 720px);
    border-radius: 18px;
}

/* === Header === */
.chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(160deg, #0b1b31 0%, #071325 100%);
    border-bottom: 1px solid var(--line);
}

/* === Content (single scroll) === */
.chat-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px 14px calc(var(--nav-h) + 16px + var(--safe));
    background: var(--bg);
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #2a5a8b transparent;
}
#ai-agents-chatbot-widget .chat-content::-webkit-scrollbar {
    width: 10px;
}
#ai-agents-chatbot-widget .chat-content::-webkit-scrollbar-track {
    background: transparent;
}
#ai-agents-chatbot-widget .chat-content::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #214066, #163046);
    border: 2px solid rgba(10, 21, 36, 0.6);
    border-radius: 10px;
}
#ai-agents-chatbot-widget .chat-content::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #2a5a8b, #1b4665);
}

/* === HOME === */
.home-screen {
    background: radial-gradient(
            1200px 600px at -10% -10%,
            #163055 0%,
            rgba(22, 48, 85, 0) 60%
        ),
        radial-gradient(
            900px 500px at 120% -10%,
            #0e406e 0%,
            rgba(14, 64, 110, 0) 60%
        ),
        var(--bg);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.home-greeting h2 {
    margin: 4px 2px 0;
    font-size: 22px;
    font-weight: 800;
    line-height: 1.1;
    color: #cfe7ff;
}
.home-greeting h1 {
    margin: 4px 2px 8px;
    font-size: 26px;
    font-weight: 800;
    color: #fff;
}

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    color: #e8f1fb;
    box-shadow: 0 8px 20px rgba(1, 9, 22, 0.35);
}
.card + .card {
    margin-top: 8px;
}
.card .label {
    font-size: 12px;
    color: #9fb3cc;
    margin-bottom: 6px;
    display: block;
}
.card .title {
    font-weight: 700;
}
.card .right {
    margin-left: auto;
    opacity: 0.8;
}
.card.row {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    justify-content: space-between;
    transition: background 0.12s, border-color 0.12s, transform 0.12s;
}
.card.row:hover {
    background: #112840;
    border-color: #2a4d6d;
    transform: translateY(-1px);
}

.home-screen .search {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #0f2336;
    border: 1px solid #1f3852;
    border-radius: 10px;
    padding: 10px 12px;
    margin: 12px 0 8px;
}
.home-screen .search .icon {
    opacity: 0.7;
}
.home-screen .search input {
    flex: 1;
    background: transparent;
    border: 0;
    outline: 0;
    color: #e6f0ff;
    font-size: 14px;
}

.faq-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 8px;
    background: transparent;
    border: 0;
    padding: 0;
}
@media (min-width: 420px) {
    .faq-list {
        grid-template-columns: 1fr 1fr;
    }
}
@media (min-width: 640px) {
    .faq-list {
        grid-template-columns: 1fr 1fr 1fr;
    }
}
.faq-item {
    display: block;
    width: 100%;
    text-align: left;
    background: #0e1e2f;
    border: 1px solid #1f3852;
    color: #cfe3ff;
    border-radius: 10px;
    padding: 10px 12px;
    cursor: pointer;
    transition: transform 0.12s, background 0.12s, border-color 0.12s;
    font-size: 13.5px;
    line-height: 1.35;
}
.faq-item:hover {
    background: #112840;
    border-color: #2a4d6d;
    transform: translateY(-1px);
}
.faq-item:active {
    transform: translateY(0);
}
.faq-item:focus-visible {
    outline: 2px solid #2d7ff9;
    outline-offset: 2px;
}
.faq-list .empty {
    color: #89a8c8;
    background: #0e1e2f;
    border: 1px dashed #1f3852;
    border-radius: 10px;
    padding: 12px;
    font-size: 13px;
}

/* === CHAT === */
.chat-scroll {
    display: none;
    background: #091524;
    padding: 0;
    flex: 1;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: #1f3852 transparent;
}
.chat-scroll::-webkit-scrollbar {
    width: 8px;
}
.chat-scroll::-webkit-scrollbar-thumb {
    background: #1f3852;
    border-radius: 8px;
}
.msg {
    max-width: 80%;
    margin: 6px 0;
    padding: 10px 12px;
    border-radius: 14px;
    line-height: 1.35;
    white-space: pre-wrap;
}
.msg b {
    display: block;
    font-size: 0.85rem;
    margin-bottom: 4px;
    opacity: 0.85;
}
.msg.user {
    margin-left: auto;
    background: #114a7a;
    color: #fff;
    border-top-right-radius: 6px;
}
.msg.bot {
    margin-right: auto;
    background: #10233d;
    color: #e7f3ff;
    border-top-left-radius: 6px;
    border: 1px solid #12365e;
}
.typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}
.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #6fb8ff;
    opacity: 0.35;
    animation: blip 1.2s infinite;
}
.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}
.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}
@keyframes blip {
    0% {
        opacity: 0.2;
        transform: translateY(0);
    }
    50% {
        opacity: 1;
        transform: translateY(-2px);
    }
    100% {
        opacity: 0.2;
        transform: translateY(0);
    }
}

/* === INPUT === */
.chat-input {
    display: flex;
    gap: 8px;
    padding: 8px 10px;
    border-top: 1px solid var(--line);
    background: #0c1b30;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
}
.chat-input textarea {
    flex: 1 1 auto;
    resize: none;
    min-height: 40px;
    max-height: 140px;
    line-height: 1.3;
    padding: 10px 12px;
    background: #0f223b;
    color: #e6eef7;
    border: 1px solid var(--line);
    border-radius: 10px;
    outline: 0;
    font-size: 0.96rem;
    width: 100%;
    box-sizing: border-box;
}
.chat-input textarea::placeholder {
    color: #97abc4;
}
.chat-input textarea:focus {
    border-color: #1e6fb0;
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}
.chat-input .send {
    height: 44px;
    min-width: 64px;
    border-radius: 10px;
    border: 0;
    padding: 0 16px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(14, 165, 233, 0.3);
    transition: background 0.2s, transform 0.05s, box-shadow 0.2s;
    margin-left: 0;
}
.chat-input .send:hover {
    background: var(--brand-500);
    box-shadow: 0 3px 8px rgba(14, 165, 233, 0.4);
}
.chat-input .send:active {
    transform: scale(0.98);
}

/* === CHAT HISTORY (refinado) === */
.chat-tab-history {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: transparent;
    padding: 4px 0 12px;
}

.chat-tab-history .history-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: linear-gradient(160deg, #0b1b31 0%, #071325 100%);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 4px 14px rgba(2, 12, 28, 0.35);
}
.chat-tab-history .history-toolbar strong {
    font-weight: 800;
    font-size: 1.05rem;
    color: #fff;
}
.chat-tab-history .history-toolbar .btn-history-clear-all {
    background: var(--brand-600);
    color: #fff;
    border-radius: 8px;
    padding: 6px 14px;
    font-weight: 600;
    transition: background 0.2s;
}
.chat-tab-history .history-toolbar .btn-history-clear-all:hover {
    background: var(--brand-500);
}

.chat-history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 2px 4px 6px;
}
.chat-history-list .empty {
    background: #0e1f36;
    border: 1px dashed #27466b;
    color: #a9c2de;
    padding: 16px;
    border-radius: 14px;
    text-align: center;
}

.hist-item {
    background: #0e1f36;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    color: #cfe1ff;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease,
        transform 0.1s ease;
    box-shadow: 0 4px 12px rgba(1, 9, 22, 0.25);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.hist-item:hover {
    background: #102742;
    border-color: #2a4d6d;
    transform: translateY(-1px);
}

.hist-item .hist-meta {
    font-size: 12px;
    color: #8fa9c8;
    margin-bottom: 2px;
}

.hist-item .hist-title {
    font-weight: 800;
    color: #e6f1ff;
    font-size: 1rem;
    line-height: 1.15;
    text-transform: lowercase;
}

.hist-item .hist-preview {
    color: #bcd3f5;
    font-size: 13.5px;
    opacity: 0.9;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}


.chat-history-detail {
    background: #0b1a2e;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    display: none;
    flex-direction: column;
    gap: 10px;
}
.chat-history-detail.active {
    display: flex;
}

.hist-detail-head {
  display: flex;
  flex-direction: column; 
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 5px 8px;
  margin-bottom: 10px;
  background: linear-gradient(160deg, #0b1b31 0%, #071325 100%);
  border-radius: 10px;
  border: 1px solid var(--line);
  box-shadow: 0 4px 16px rgba(2, 12, 28, 0.35);
  text-align: center;
}


.hist-detail-title {
  font-weight: 800;
  color: #e6f1ff;
  font-size: 1.1rem;
  line-height: 1.3;
  word-break: break-word;
  text-transform: capitalize;
}


.hist-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}


.btn-hist-back,
.btn-hist-resume,
.btn-hist-delete {
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  border: none;
  transition: transform 0.1s ease, background 0.2s ease, box-shadow 0.2s ease;
}


.btn-hist-back,
.btn-hist-resume {
  background: var(--brand-600);
  color: #fff;
}
.btn-hist-back:hover,
.btn-hist-resume:hover {
  background: var(--brand-500);
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(14, 165, 233, 0.3);
}
.btn-hist-delete {
  background: #e74c3c;
  color: #fff;
}
.btn-hist-delete:hover {
  background: #c0392b;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(255, 80, 80, 0.3);
}


/* === Bottom nav === */
.bottom-nav {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-h);
    background: #0c1b30;
    border-top: 1px solid var(--line);
    display: flex;
    align-items: stretch;
    gap: 2px;
    z-index: 99;
    box-sizing: border-box;
    padding: 0;
}
.nav-btn {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #c8d8ee;
    gap: 4px;
    font-size: 12px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s, color 0.15s;
    padding: 0 6px;
    height: 100%;
    box-sizing: border-box;
}
.nav-btn .ico {
    font-size: 15px;
    line-height: 15px;
}
.nav-btn .label {
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.nav-btn.active {
    color: #fff;
    background: #0e233d;
}
.nav-btn:hover {
    background: #10243e;
}

#ai-agents-chatbot-widget #ai-chatbot-bottom-nav,
#ai-agents-chatbot-widget #ai-chatbot-bottom-nav * {
    box-sizing: border-box !important;
}
#ai-agents-chatbot-widget #ai-chatbot-bottom-nav {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100% !important;
    height: var(--nav-h);
    background: #0c1b30;
    border-top: 1px solid var(--line);
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 2px;
    z-index: 9999;
    overflow: hidden;
    padding: 0;
}
#ai-agents-chatbot-widget #ai-chatbot-bottom-nav .nav-btn {
    all: unset;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-direction: column !important;
    padding: 0 8px;
    gap: 4px;
    cursor: pointer;
    color: #c8d8ee;
    font-size: 12px;
    line-height: 1.1;
    text-align: center;
    user-select: none;
    height: 100%;
    box-sizing: border-box;
}
#ai-agents-chatbot-widget #ai-chatbot-bottom-nav .nav-btn .ico {
    display: block;
    font-size: 16px;
    line-height: 16px;
}
#ai-agents-chatbot-bottom-nav .nav-btn .label {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
#ai-agents-chatbot-bottom-nav .nav-btn.active {
    color: #fff;
    background: #0e233d;
}
#ai-agets-chatbot-bottom-nav .nav-btn:hover {
    background: #10243e;
}

.nav-btn:focus-visible,
.logout-btn:focus-visible,
.send:focus-visible {
    outline: 2px solid #2d7ff9;
    outline-offset: 2px;
}

/* Responsive */
@media (max-width: 520px) {
    #ai-agents-chatbot-widget {
        right: 12px;
        left: 12px;
        width: auto;
        bottom: 84px;
        max-height: 78vh;
    }
    .chat-content {
        padding: 10px 10px calc(var(--nav-h) + 16px + var(--safe));
    }
}
@media (max-width: 380px) {
    #ai-agents-chatbot-bottom-nav .nav-btn .label {
        font-size: 11px;
    }
}

/* Safe area iOS */
@supports (padding: max(0px)) {
    .bottom-nav {
        padding-bottom: max(env(safe-area-inset-bottom), 0px);
    }
    .chat-content {
        padding-bottom: calc(
            var(--nav-h) + 16px + max(env(safe-area-inset-bottom), 0px)
        );
    }
}

#ai-agents-chatbot-widget .chat-messages div:nth-child(odd),
#ai-agents-chatbot-widget .chat-messages div:nth-child(even) {
    background: unset;
    color: unset;
    align-self: auto;
}
/* ===== LOGIN (restore design, scoped) ===== */
#ai-agents-chatbot-widget .chat-login-screen {
    background: linear-gradient(
        135deg,
        var(--brand-700) 60%,
        var(--brand-400) 100%
    );
    border-radius: 18px;
    box-shadow: 0 4px 32px rgba(11, 59, 111, 0.1);
    padding: 32px 24px 24px 24px !important;
    margin: 18px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

#ai-agents-chatbot-widget .chat-login-screen h2 {
    color: #fff;
    font-size: 1.5rem;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

#ai-agents-chatbot-widget .chat-login-screen input[type="text"],
#ai-agents-chatbot-widget .chat-login-screen input[type="password"] {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--brand-400);
    background: #f7fbff;
    color: #1d3557;
    font-size: 1rem;
    margin-bottom: 10px;
    outline: 0;
    transition: border 0.2s, background 0.2s;
}

#ai-agents-chatbot-widget .chat-login-screen input[type="text"]:focus,
#ai-agents-chatbot-widget .chat-login-screen input[type="password"]:focus {
    border: 1.5px solid var(--brand-600);
    background: #fff;
}

#ai-agents-chatbot-widget .chat-login-screen .login-btn {
    width: 100%;
    padding: 12px 0;
    border-radius: 10px;
    background: var(--brand-600);
    color: #fff;
    font-weight: 600;
    font-size: 1.1rem;
    border: none;
    box-shadow: 0 2px 8px rgba(2, 95, 156, 0.08);
    cursor: pointer;
    transition: background 0.18s;
    margin-top: 6px;
}
#ai-agents-chatbot-widget .chat-login-screen .login-btn:hover {
    background: var(--brand-500);
}

#ai-agents-chatbot-widget .chat-login-screen .login-error {
    background: #fff0f0;
    color: #e74c3c;
    border-radius: 8px;
    padding: 7px 12px;
    font-size: 0.98rem;
    margin-bottom: 0;
    width: 100%;
    text-align: center;
    border: 1px solid #ffd6d6;
}
