/* IBM i BI Chatbot — Styles
   AIonthei brand: Navy #004987, Blue #0082CA, Green #93D500
*/

:root {
    --navy: #004987;
    --blue: #0082CA;
    --green: #93D500;
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-light: #6b7280;
    --border: #e5e7eb;
    --danger: #ef4444;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    color: var(--text);
    background: var(--bg);
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
}

@media (min-width: 768px) {
    #app { max-width: 800px; }
}

/* --- Header ------------------------------------------------- */

#header {
    background: var(--navy);
    color: white;
    padding: 12px 16px;
    flex-shrink: 0;
}

#header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#header h1 {
    font-size: 20px;
    font-weight: 600;
}

#subtitle {
    font-size: 13px;
    opacity: 0.7;
    margin-top: 2px;
}

#clear-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.3);
    background: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

#clear-btn:active {
    background: rgba(255,255,255,0.15);
}

/* --- Examples Panel ----------------------------------------- */

#examples-btn {
    height: 32px;
    padding: 0 12px;
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.4);
    background: rgba(255,255,255,0.1);
    color: white;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    white-space: nowrap;
    transition: background 0.2s;
}

#examples-btn:active,
#examples-btn.active {
    background: rgba(255,255,255,0.25);
}

#examples-panel {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    max-height: 50vh;
    overflow-y: auto;
    padding: 12px 16px;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
}

#examples-panel.hidden {
    display: none;
}

.examples-category {
    margin-bottom: 12px;
}

.examples-category:last-child {
    margin-bottom: 0;
}

.examples-category h3 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-light);
    margin-bottom: 6px;
    padding-left: 2px;
}

.example-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    margin-bottom: 4px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
}

.example-item:active {
    background: var(--blue);
    color: white;
    border-color: var(--blue);
}

/* --- Chat Messages ------------------------------------------ */

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

.system-message {
    text-align: center;
    color: var(--text-light);
    font-size: 14px;
    padding: 20px 0;
}

.example-queries {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 16px;
}

.example-btn {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--card-bg);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.example-btn:active {
    background: var(--bg);
    border-color: var(--blue);
}

/* --- Chat Bubbles ------------------------------------------- */

.chat-bubble {
    max-width: 90%;
    padding: 10px 14px;
    border-radius: 16px;
    margin-bottom: 8px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-bubble.user {
    background: var(--blue);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.chat-bubble.assistant {
    background: var(--card-bg);
    border: 1px solid var(--border);
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

/* --- SQL Collapsible ---------------------------------------- */

.sql-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text-light);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.sql-toggle:active {
    background: var(--border);
}

.sql-toggle .arrow {
    transition: transform 0.2s;
    font-size: 10px;
}

.sql-toggle.open .arrow {
    transform: rotate(90deg);
}

.sql-block {
    display: none;
    margin-top: 6px;
    padding: 10px 12px;
    background: #1e293b;
    color: #e2e8f0;
    border-radius: 8px;
    font-family: "SF Mono", "Menlo", "Monaco", monospace;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    overflow-x: auto;
}

.sql-block.visible {
    display: block;
}

/* --- Typing Indicator --------------------------------------- */

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    max-width: 60px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    margin-bottom: 8px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--text-light);
    border-radius: 50%;
    animation: typing 1.4s infinite both;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* --- Error Bubble ------------------------------------------- */

.chat-bubble.error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

/* --- Input Bar ---------------------------------------------- */

#input-bar {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    line-height: 1.4;
    max-height: 100px;
    overflow-y: auto;
}

#chat-input:focus {
    outline: none;
    border-color: var(--blue);
}

#send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--blue);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

#send-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* --- Toast -------------------------------------------------- */

#toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--navy);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 1000;
    transition: opacity 0.3s;
    pointer-events: none;
}

#toast.hidden {
    opacity: 0;
}

/* --- Scrollbar (hidden on mobile) --------------------------- */

::-webkit-scrollbar {
    width: 0;
}

/* --- Standalone mode ---------------------------------------- */

@media (display-mode: standalone) {
    #header {
        padding-top: calc(var(--safe-top) + 12px);
    }
}

/* --- Markdown-like formatting in answers -------------------- */

.chat-bubble.assistant strong {
    font-weight: 600;
}

.chat-bubble.assistant table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 13px;
}

.chat-bubble.assistant th,
.chat-bubble.assistant td {
    padding: 4px 8px;
    border: 1px solid var(--border);
    text-align: left;
}

.chat-bubble.assistant th {
    background: var(--bg);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.chat-bubble.assistant ul,
.chat-bubble.assistant ol {
    padding-left: 20px;
    margin: 6px 0;
}

.chat-bubble.assistant li {
    margin-bottom: 2px;
}

.chat-bubble.assistant p + p {
    margin-top: 8px;
}
