/* =========================================================
   ECDA LLM — FULL CSS (LIGHT + DARK + SWEETALERT2)
   Toggle by setting: <html data-theme="dark"> or "light"
   ========================================================= */

/* =========================
   THEME VARIABLES
   ========================= */

/* LIGHT MODE (default) */


:root {
    color-scheme: light;

    --border: #e5e7eb;
    --text: #111827;
    --muted: #6b7280;
    --bg: #ffffff;
    --page-bg: #ddd;

    --surface: rgba(255, 255, 255, 0.92);
    --surface-soft: rgba(255, 255, 255, 0.65);

    --primary: #16a34a;
    --primary-hover: #15803d;

    --input-bg: rgba(255, 255, 255, 0.9);
    --input-text: #111827;
    --placeholder: rgba(17, 24, 39, 0.45);
    --field-border: #ccc;
    /* LIGHT MODE */
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

/* DARK MODE */
:root[data-theme="dark"] {
    color-scheme: dark;

    --border: rgba(255, 255, 255, 0.12);
    --text: rgba(255, 255, 255, 0.92);
    --muted: rgba(255, 255, 255, 0.65);
    --bg: #0b1220;
    --page-bg: #0b1220;

    --surface: rgba(17, 24, 39, 0.78);
    --surface-soft: rgba(17, 24, 39, 0.55);

    --input-bg: rgba(31, 41, 55, 0.85);
    --input-text: rgba(255, 255, 255, 0.92);
    --placeholder: rgba(255, 255, 255, 0.40);

    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}


/* =========================
     BASE / LAYOUT
     ========================= */

html,
body {
    height: auto;
    margin: 0;
    overflow-y: auto;
    /* allow page scroll */
}

body {
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    margin: 0;
    position: relative;
    background-color: var(--page-bg);
    color: var(--text);
}

/* GLOBAL watermark background */
body::before {
    content: "";
    position: fixed;
    inset: 0;

    background-image: url("/static/images/ecda-bg.png");
    background-repeat: no-repeat;
    background-position: top;
    background-size: 45%;

    opacity: 0.2;
    z-index: -1;
}

:root[data-theme="dark"] body::before {
    background-image: url("/static/images/ecda-bg-white.png");
    opacity: 0.35;
    /* optional: usually looks better in dark mode */
}

/* Fixed top navbar */
.top-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100000;

    /* layout */
    display: flex;
    justify-content: center;
    align-items: center;

    /* spacing */
    padding: 10px 0;

    /* background + border (works for both themes) */
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(6px);
}

/* inner container */
.nav-inner {
    display: flex;
    gap: 15px;
    align-items: center;
}




/* Move content a bit upward */
.wrap {
    min-height: 50vh;
    display: grid;
    justify-items: center;
    align-content: start;
    padding-top: 30vh;
    padding-left: 16px;
    padding-right: 16px;
}


.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.table-wrap table {
    width: 100%;
    border-collapse: collapse;
}

/* =========================
     CARD
     ========================= */

.card {
    width: 60%;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    background: var(--surface);
    backdrop-filter: blur(6px);
    box-shadow: var(--shadow);
}

.card-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.card-col {
    display: grid;
    gap: 14px;
}

h1 {
    font-size: 2rem;
    margin: 0;
}

.meta {
    font-size: 0.95rem;
    color: var(--muted);
}


/* =========================
     BUTTONS
     ========================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 12px 22px;

    font-size: 1rem;
    font-weight: 700;
    text-decoration: none;

    transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    user-select: none;
    cursor: pointer !important;
}

.btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-proceed {
    background: rgba(255, 255, 255, 0.55);
    color: var(--text);
    border: 1px solid var(--border);
    cursor: pointer;
}

.btn-proceed:hover {
    background: rgba(255, 255, 255, 0.7);
}

:root[data-theme="dark"] .btn-proceed {
    background: rgba(255, 255, 255, 0.08);
}

:root[data-theme="dark"] .btn-proceed:hover {
    background: rgba(255, 255, 255, 0.12);
}

.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.06);
}

:root[data-theme="dark"] .btn-ghost:hover {
    background: rgba(255, 255, 255, 0.08);
}


.btn-base {
    background: #fff;
    /* light mode default */
    color: var(--text);
    border: 1px solid var(--border);
    transition: background 0.2s ease;
}

.btn-base:hover {
    background: rgba(0, 0, 0, 0.05);
}

:root[data-theme="dark"] .btn-base {
    background: transparent;
}

:root[data-theme="dark"] .btn-base:hover {
    background: rgba(255, 255, 255, 0.08);
}


/* =========================
     CHAT UI
     ========================= */

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
    margin-bottom: 10px;
}



.msg {
    max-width: 80%;
    padding: 10px 12px;
    border-radius: 12px;
    margin: 8px 0;
    line-height: 1.35;
    overflow-x: auto;
    /* allow horizontal scroll if needed */
    word-break: break-word;
    /* break long words/urls */
    overflow-wrap: anywhere;
    /* modern wrap for long tokens */
}

.msg-user {
    margin-left: auto;
    background: rgba(22, 163, 74, 0.13);
    border: 1px solid rgba(22, 163, 74, 0.28);
}

.msg-bot {
    margin-right: auto;
    background: rgb(226 217 217 / 35%);
    border: 1px solid var(--border);
    color: var(--text);
}


/* Tables inside assistant messages */
.msg-bot table {
    width: 100%;
    border-collapse: collapse;
    display: block;
    /* ✅ makes table respect overflow */
    overflow-x: auto;
    /* ✅ horizontal scroll for wide tables */
    max-width: 100%;
}

/* Keep table cells readable and prevent layout explosion */
.msg-bot th,
.msg-bot td {
    padding: 6px 8px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    vertical-align: top;

    /* ✅ allow wrapping inside cells */
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Optional: avoid huge rows by forcing wrapping */
.msg-bot td {
    white-space: normal;
}

/* Optional: make code/long strings not break layout */
.msg-bot pre,
.msg-bot code {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}

:root[data-theme="dark"] .msg-bot {
    background: rgba(255, 255, 255, 0.06);
}


.chat-container {
    padding-bottom: 30px;
    /* height of fixed form */
    margin-bottom: 100px;
}

.messages:empty {
    display: none;
}

.messages {
    flex: 1 1 auto;
    min-height: 0;

    overflow-y: auto;
    overflow-x: hidden;

    border: 1px solid var(--border);
    border-radius: 12px;

    padding: 18px;
    background: var(--surface-soft);

    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-form {
    position: fixed;
    text-align: center !important;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--surface);
    z-index: 1000;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: 16px;

}

.chat-form-wrapper {
    position: fixed;
    bottom: 1%;
    width: 60%;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    background: var(--surface);
}

@media (max-width: 768px) {
    .chat-container {
        height: 100dvh;
        padding-bottom: 100px;
    }
}


.msg-bot p,
.msg-bot ul,
.msg-bot ul li,
.msg-bot ol {
    margin: 0;
}

.msg-bot ul,
.msg-bot ol {
    padding-left: 1.2rem;
}

.msg-bot {
    white-space: normal;
}


/* =========================
     INPUTS
     ========================= */

.input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 1rem;
    outline: none;

    background: var(--input-bg);
    color: var(--input-text);
}

.input::placeholder {
    color: var(--placeholder);
    opacity: 1;
}

.input:focus {
    border-color: #86efac;
    box-shadow: 0 0 0 3px rgba(134, 239, 172, 0.35);
}


/* Only messages scroll */
body.chat .messages {
    flex: 1;
    overflow-y: auto;
}


/* =========================
     "THINKING" + DOTS
     ========================= */

.msg-bot.thinking {
    color: var(--muted);
    font-style: italic;
}

/* 3 bouncing dots */
.dots {
    display: inline-flex;
    gap: 3px;
    margin-left: 6px;
    vertical-align: middle;
}

.dots span {
    width: 4px;
    height: 4px;
    background: currentColor;
    border-radius: 50%;
    animation: bounce 1.2s infinite;
    opacity: 0.7;
}

.dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: translateY(0);
        opacity: 0.5;
    }

    40% {
        transform: translateY(-4px);
        opacity: 1;
    }
}


/* =========================
     UPLOAD UI
     ========================= */

.upload-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 30px;
}

.uploaded-list {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.60);
}

:root[data-theme="dark"] .uploaded-list {
    background: rgba(255, 255, 255, 0.06);
}

.uploaded-ul {
    margin: 0;
    padding-left: 18px;
}

.uploaded-ul li {
    margin: 6px 0;
    color: var(--text);
}

.files-meta {
    font-size: 0.9rem;
    color: var(--muted);
}

.header-actions {
    display: flex;
    gap: 10px;
}


/* =========================
     FILE UPLOAD
     ========================= */

.file-upload {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Hide default input */
.file-upload input[type="file"] {
    display: none;
}

/* Custom button */
.file-upload-label {
    width: 40%;
    display: inline-block;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.55);
    cursor: pointer;
    font-weight: 600;
    text-align: center;
    transition: all 0.15s ease;
    color: var(--text);
}

.file-upload-label:hover {
    background: rgba(255, 255, 255, 0.75);
    border-color: rgba(0, 0, 0, 0.12);
}

:root[data-theme="dark"] .file-upload-label {
    background: rgba(255, 255, 255, 0.08);
}

:root[data-theme="dark"] .file-upload-label:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.18);
}

/* File list text */
.file-names {
    font-size: 0.9rem;
    color: var(--muted);
}


/* =========================
     LIST + ICON BUTTONS
     ========================= */

.uploaded-li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
}

.icon-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 8px;
    color: var(--text);
}

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

:root[data-theme="dark"] .icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.delete-filename {
    cursor: pointer !important;
    color: #900 !important;
}


/* =========================
     TOOLTIP
     ========================= */

.tooltip-container {
    display: inline-block;
    position: relative;
}

.tooltip {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    background-color: #333;
    color: white;
    font-size: 12px;
    padding: 8px 12px;
    border-radius: 5px;
    white-space: nowrap;
    bottom: 105%;
    left: 50%;
    transform: translateX(-50%);
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 100;
}

.tooltip-container:hover .tooltip {
    visibility: visible;
    opacity: 1;
}


/* =========================
   SweetAlert2 — ONLY in DARK MODE
   (Light mode stays default)
   ========================= */

:root[data-theme="dark"] .swal2-popup {
    background: rgba(17, 24, 39, 0.99) !important;
    color: rgba(255, 255, 255, 0.92) !important;
    border: 1px solid rgba(255, 255, 255, 0.92) !important;
}

:root[data-theme="dark"] .swal2-title,
:root[data-theme="dark"] .swal2-html-container {
    color: rgba(255, 255, 255, 0.92) !important;
}

:root[data-theme="dark"] .swal2-input {
    background: rgba(31, 41, 55, 0.85) !important;
    color: rgba(255, 255, 255, 0.92) !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
}

:root[data-theme="dark"] .swal2-input::placeholder {
    color: rgba(255, 255, 255, 0.10) !important;
    opacity: 0.1 !important;
}

:root[data-theme="dark"] .swal2-input:focus {
    border-color: #86efac !important;
    box-shadow: 0 0 0 3px rgba(134, 239, 172, 0.25) !important;
}


:root[data-theme="dark"] .delete-filename {
    color: #ff6b6b !important;
    cursor: pointer !important;

}

.swal2-container.swal2-backdrop-show {
    background: rgba(0, 0, 0, 0.45) !important;
}

.swal2-container.swal2-backdrop-show {
    backdrop-filter: blur(2px);
}

:root[data-theme="dark"] .swal2-container.swal2-backdrop-show {
    background: rgba(0, 0, 0, 0.70) !important;
}

:root[data-theme="dark"] .swal2-container.swal2-backdrop-show {
    background: rgba(0, 0, 0, 0.7) !important;
    backdrop-filter: blur(2px);
}



.settings-form {
    display: grid;
    gap: 14px;
    margin-top: 14px;
}

.field {
    border: 1px solid var(--field-border);
    border-radius: 16px;
    padding: 12px;
    background: var(--surface);
}

.field-label {
    font-size: 13px;
    opacity: .75;
    margin-bottom: 8px;
}

.field-hint {
    font-size: 12px;
    opacity: .7;
    margin-top: 6px;
    line-height: 1.35;
}

.control {
    width: 100%;
    height: 44px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, .14);
    background: rgba(0, 0, 0, .25);
    color: var(--text);
    outline: none;
    box-sizing: border-box;
}

.control:focus {
    border-color: rgba(120, 180, 255, .55);
    box-shadow: 0 0 0 4px rgba(120, 180, 255, .25);
}

.settings-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 6px;
}

.status {
    font-size: 13px;
    opacity: .8;
    padding-left: 4px;
}


.input-wrap {
    position: relative;
    flex: 1;
}

.fake-placeholder {
    position: absolute;
    left: 7%;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.6;
    pointer-events: none;
    white-space: nowrap;
}


.input-wrap .input {
    width: 90%;
}

.voice-preview {
    position: absolute;
    right: 6%;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
}

.voice-chip {
    font-size: 0.9em;
    opacity: 0.85;
    white-space: nowrap;
}

/* optional: make overlay feel "inside" the input */
.voice-preview button {
    border: none;
    background: transparent;
    cursor: pointer;
}

/* Voice message container */
.msg-voice-user {
    display: flex;
    justify-content: flex-end;
    /* RIGHT SIDE */
    margin: 6px 0;
}

/* remove all bubble feeling */
.msg-voice-user audio {
    padding: 0;
    margin: 0;
    background: none;
    width: 260px;
    max-width: 100%;
}

[data-theme="dark"] {
    --field-border: rgba(255, 255, 255, .12);
}



.file-names {
    display: flex;
    flex-direction: column;
    /* stack content vertically */
    gap: 4px;
}

.file-names button {
    align-self: flex-start;
    /* keep toggle aligned left */
    padding: 8px;
    font-size: 13px;
}

.files-meta {
    display: flex;
    flex-direction: column;
    /* stack vertically */
    gap: 4px;
}

.files-meta button {
    align-self: flex-start;
    padding: 8px;
    font-size: 13px;
}


textarea.input {
    width: 100%;
    box-sizing: border-box;
    resize: none;
    overflow: hidden;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    height: calc(2.0em + 16px);
    min-height: calc(2.0em + 16px);
    max-height: 120px;
    padding: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}