/* CSS Reset & Display Fix for Hidden Elements */
[hidden],
.modal-backdrop[hidden],
.banner-warning[hidden],
#modal-settings[hidden],
#backend-warning[hidden],
.is-hidden {
    display: none !important;
}

:root {
    --ict-navy: #192f88;
    --ict-navy-dark: #122263;
    --ict-yellow: #ffdf00;
    --ict-yellow-hover: #faea38;
    --bg-surface: #f4f6fa;
    --panel-bg: #ffffff;
    --ink: #172b46;
    --ink-muted: #64748b;
    --border-line: #e2e8f0;
    --bubble-sunny: #ffffff;
    --bubble-user: #192f88;
    --bubble-user-text: #ffffff;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 14px rgba(16, 32, 76, 0.08);
}

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

body, html {
    width: 100%;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--ink);
    background-color: var(--bg-surface);
    overflow: hidden;
    font-size: 14px;
}

.sunny-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 100%;
    background-color: var(--bg-surface);
    position: relative;
}

/* Header */
.sunny-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--ict-navy);
    color: #ffffff;
    border-bottom: 3px solid var(--ict-yellow);
    box-shadow: 0 2px 10px rgba(16, 32, 76, 0.15);
    flex-shrink: 0;
}

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

.sunny-avatar {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
}

.sunny-avatar svg {
    width: 100%;
    height: 100%;
}

.header-titles .brand-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--ict-yellow);
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.2;
}

.tag-ai {
    font-size: 10px;
    background: rgba(255, 223, 0, 0.2);
    color: var(--ict-yellow);
    padding: 1px 5px;
    border-radius: 4px;
    border: 1px solid var(--ict-yellow);
    font-weight: 800;
}

.header-titles .brand-sub {
    font-size: 11px;
    color: #cbd5e1;
    font-weight: 400;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.12);
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 11px;
    font-weight: 500;
    cursor: default;
    transition: all 0.2s ease;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
}

.status-online .status-dot {
    background: #10b981;
    box-shadow: 0 0 8px #10b981;
}

.status-warning .status-dot {
    background: #f59e0b;
    box-shadow: 0 0 8px #f59e0b;
}

.status-offline .status-dot {
    background: #ef4444;
}

.status-loading .status-dot {
    background: #e2e8f0;
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    0% { opacity: 0.4; }
    100% { opacity: 1; }
}

.btn-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-icon svg {
    width: 17px;
    height: 17px;
}

/* Warning Banner */
.banner-warning {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #fffbeb;
    border-bottom: 1px solid #fde68a;
    color: #92400e;
    font-size: 12px;
    flex-shrink: 0;
}

.banner-warning[hidden] {
    display: none !important;
}

.banner-icon {
    font-size: 18px;
}

.banner-content {
    flex: 1;
}

.banner-content strong {
    display: block;
    margin-bottom: 2px;
}

.banner-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
}

.btn-sm {
    padding: 5px 10px;
    background: #f59e0b;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

/* Chat Messages */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.message-row {
    display: flex;
    gap: 10px;
    max-width: 90%;
    animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.sunny-row {
    align-self: flex-start;
}

.user-row {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--ict-navy);
    border: 2px solid var(--ict-yellow);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}

.msg-bubble {
    padding: 12px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
    box-shadow: var(--shadow-sm);
}

.sunny-row .msg-bubble {
    background: var(--bubble-sunny);
    color: var(--ink);
    border: 1px solid var(--border-line);
    border-top-left-radius: 4px;
}

.user-row .msg-bubble {
    background: var(--bubble-user);
    color: var(--bubble-user-text);
    border-top-right-radius: 4px;
}

.msg-sender {
    font-size: 11px;
    font-weight: 700;
    color: var(--ict-navy);
    margin-bottom: 4px;
}

.user-row .msg-sender {
    display: none;
}

.msg-body p {
    margin-bottom: 8px;
}

.msg-body p:last-child {
    margin-bottom: 0;
}

.msg-body strong {
    font-weight: 600;
}

.msg-body ul, .msg-body ol {
    margin-left: 20px;
    margin-bottom: 8px;
}

.msg-body li {
    margin-bottom: 4px;
}

.msg-body a {
    color: #1d4ed8;
    text-decoration: underline;
    word-break: break-all;
}

.msg-body a:hover {
    color: #1e40af;
}

/* Database Table Formatting */
.msg-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 12px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    overflow: hidden;
}

.msg-body th {
    background: #f1f5f9;
    color: var(--ict-navy);
    font-weight: 600;
    text-align: left;
    padding: 6px 10px;
    border-bottom: 2px solid #cbd5e1;
}

.msg-body td {
    padding: 6px 10px;
    border-bottom: 1px solid #e2e8f0;
}

.msg-body tr:last-child td {
    border-bottom: none;
}

.msg-body tr:nth-child(even) {
    background: #f8fafc;
}

/* Code Blocks */
.msg-body pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
    margin: 8px 0;
}

.msg-body code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
}

.user-row .msg-body code {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.msg-body pre code {
    background: transparent;
    padding: 0;
    color: #38bdf8;
}

/* Query Tag */
.query-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #e0e7ff;
    color: #3730a3;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 6px;
    margin-bottom: 6px;
    font-weight: 600;
}

/* Suggestions Bar */
.suggestions-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: -6px;
    margin-bottom: 10px;
    padding-left: 42px;
}

.chip {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: var(--ict-navy);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.chip:hover {
    background: var(--ict-yellow);
    border-color: #d1b800;
    color: #0f172a;
    transform: translateY(-1px);
}

/* Typing Indicator */
.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #94a3b8;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* Chat Footer / Input */
.chat-footer {
    padding: 10px 14px 12px;
    background: var(--panel-bg);
    border-top: 1px solid var(--border-line);
    flex-shrink: 0;
}

.chat-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-surface);
    border: 1.5px solid var(--border-line);
    border-radius: 12px;
    padding: 6px 8px 6px 12px;
    transition: border-color 0.2s;
}

.chat-form:focus-within {
    border-color: var(--ict-navy);
    box-shadow: 0 0 0 3px rgba(25, 47, 136, 0.1);
}

#user-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    resize: none;
    max-height: 110px;
    min-height: 22px;
    font-family: inherit;
    font-size: 13.5px;
    color: var(--ink);
    line-height: 1.4;
    padding: 4px 0;
}

.btn-send {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: var(--ict-navy);
    color: var(--ict-yellow);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-send:hover {
    background: var(--ict-navy-dark);
    transform: scale(1.04);
}

.btn-send:disabled {
    background: #cbd5e1;
    color: #94a3b8;
    cursor: not-allowed;
    transform: none;
}

.btn-send svg {
    width: 17px;
    height: 17px;
}

.input-hint {
    font-size: 10.5px;
    color: var(--ink-muted);
    text-align: center;
    margin-top: 6px;
}

.input-hint span {
    font-weight: 600;
}

/* Settings Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.modal-backdrop[hidden],
.modal-backdrop.is-hidden {
    display: none !important;
}

.modal-card {
    background: #ffffff;
    border-radius: 14px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    animation: modalIn 0.2s ease-out;
    position: relative;
    z-index: 1001;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--ict-navy);
    color: #ffffff;
}

.modal-header h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--ict-yellow);
}

.btn-close {
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    border-radius: 4px;
    transition: background 0.15s;
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.modal-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-size: 13px;
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-line);
}

.setting-label {
    font-weight: 600;
    color: var(--ink);
}

.setting-val {
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
}

.badge-neutral { background: #f1f5f9; color: #475569; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger  { background: #fee2e2; color: #b91c1c; }

.setting-desc {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    padding: 10px;
    border-radius: 8px;
    font-size: 12px;
    color: var(--ink-muted);
}

.setting-desc p {
    margin-bottom: 4px;
    color: var(--ink);
}

.setting-desc code {
    display: block;
    background: #1e293b;
    color: #38bdf8;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 11px;
    margin-bottom: 4px;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    background: #f8fafc;
    border-top: 1px solid var(--border-line);
}

.btn-primary {
    background: var(--ict-navy);
    color: #ffffff;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-primary:hover {
    background: var(--ict-navy-dark);
}

.btn-secondary {
    background: #e2e8f0;
    color: #1e293b;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-secondary:hover {
    background: #cbd5e1;
}
