/* =========================================================
    1) Reset / Base
    ========================================================= */

/* Reset box-sizing for everything */
*, *::before, *::after {
box-sizing: border-box;
}

/* Base styles */
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial,
sans-serif;
min-height: 95vh;
margin: 0;
padding: 0;
background:
  radial-gradient(circle at 18% 0%, rgba(0, 123, 255, 0.08), transparent 28%),
  linear-gradient(180deg, #f7f9fc 0%, #eef3f8 100%);
color: #2b3a49;
box-sizing: border-box;
overflow-x: hidden;
--surface: rgba(250, 251, 252, 0.68);
--surface-strong: rgba(255, 255, 255, 0.82);
--surface-soft: rgba(255, 255, 255, 0.54);
--stroke: rgba(0, 0, 0, 0.07);
--stroke-strong: rgba(0, 0, 0, 0.1);
--text: #2b3a49;
--muted: #5b6b7a;
--blue: #0066ff;
--blue-dark: #0052cc;
--danger: #b02a37;
--shadow-soft: 0 6px 18px rgba(0, 0, 0, 0.08);
--shadow-panel: 0 12px 40px rgba(0, 0, 0, 0.14);
--radius-pill: 999px;
--radius-panel: 20px;
--radius-control: 14px;
}

button,
input,
select,
textarea {
font: inherit;
}

/* =========================================================
    2) App shell layout (container + screens)
    ========================================================= */

/* Container: centered app look */
.container {
    background: rgba(255, 255, 255, 0.45);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.7);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.6);
    overflow: hidden;
    max-width: 800px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    margin: 0 auto;
    position: relative;
}

table {
    border-collapse: collapse;
    width: 100%;
    color: var(--text);
    background: var(--surface-soft);
    border-radius: var(--radius-control);
    overflow: hidden;
    box-shadow: var(--shadow-soft);
}

th {
    background: rgba(250, 251, 252, 0.78);
    text-align: left;
    color: var(--text);
    font-weight: 600;
}

td, th {
    border: 1px solid var(--stroke);
    padding: 10px;
}

tr:hover {
    background: rgba(0, 102, 255, 0.05);
}

.screen {
display: flex;
flex-direction: column;
flex: 1 1 auto;
min-height: 0;
}

.chat-screen {
    background: transparent;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.loading-screen {
    align-items: center;
    justify-content: center;
    gap: 14px;
    color: var(--muted);
}

.loading-indicator {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 4px solid rgba(0, 102, 255, 0.16);
    border-top-color: var(--blue);
    animation: loading-spin 0.85s linear infinite;
}

.loading-text {
    font-size: 14px;
    font-weight: 600;
}

@keyframes loading-spin {
    to {
        transform: rotate(360deg);
    }
}

/* When running inside Tableau (iframe), use all available space */
body.in-extension .container {
max-width: 100vw !important;
width: 100vw !important;
margin: 0 !important;
border-radius: 0;
height: 100vh;
min-height: 0;
}

/* =========================================================
    3) Header
    ========================================================= */

header {
  background: var(--surface);
  position: sticky;
  top: 8px;
  z-index: 20;
  color: var(--text);
  margin: 8px auto;

  height: 45px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative; /* важно для абсолютного logout */

  width: fit-content;
  padding: 0 20px;
  transition: all 0.25s ease;
  will-change: transform, box-shadow, background;
  border-radius: var(--radius-pill);
  transform-origin: center;
  /* glass effect */
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);

  /* softer border */
  border: 1px solid var(--stroke);

  /* lighter shadow */
  box-shadow: var(--shadow-soft);
}

header h1 {
  margin: 0;
  font-size: 1.2em;  /* было 2em — слишком большое */
  line-height: 1;
  font-weight: 500;
  letter-spacing: 0.3px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

header:hover {
  transform: translateY(-2px) scale(1.03);

  background: var(--surface-strong);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);

  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.12);

  border: 1px solid rgba(0, 0, 0, 0.08);
}
header:active {
  transform: translateY(0px) scale(0.99);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

header p {
  margin: 0;
  font-size: 0.8em;
  opacity: 0.8;
}

/* Logo */
.logo a {
display: flex;
align-items: center;
justify-content: center;
gap: 10px;

text-decoration: none;
color: inherit;
}

.logo img {
height: 35px;
filter: drop-shadow(0 0 5px #3498db)
        drop-shadow(0 0 10px #3498db);
}


/* =========================================================
    4) Chat: toolbar + model panel
    ========================================================= */

/* Chat toolbar */
.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}


.model-pill {
  cursor: pointer;
  user-select: none;

  display: flex;
  align-items: center;

  height: 32px;

  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);

  background: var(--surface);

  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);

  border: 1px solid var(--stroke);

  box-shadow: var(--shadow-soft);

  transition: all 0.2s ease;
}

.model-pill:hover {
  transform: scale(1.05);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.12);
}

.model-pill:active {
  transform: scale(0.95);
}

.model-pill span {
  font-size: 12px;
  opacity: 0.8;
}

.model-pill strong {
  font-weight: 600;
}

.model-pill img {
  width: 16px;
  height: 16px;
  object-fit: contain;
}

.model-pill::after {
  content: "";
  width: 5px;
  height: 5px;

  border-right: 2px solid var(--text);
  border-bottom: 2px solid var(--text);

  transform: rotate(45deg);
  margin-left: 4px;

  opacity: 0.6;
}

.model-pill::before {
  content: "";

  width: 6px;
  height: 6px;
  border-radius: 50%;

  background: #9ca3af;

  margin-right: 5px;
}

.model-pill.is-valid::before {
  background: #22c55e;
  box-shadow:
    0 0 4px rgba(34, 197, 94, 0.35),
    0 0 8px rgba(34, 197, 94, 0.15);
}

.model-pill.is-invalid::before {
  background: #ef4444;
  box-shadow:
    0 0 4px rgba(239, 68, 68, 0.35),
    0 0 8px rgba(239, 68, 68, 0.15);
}

.modelBtn {
  height: 40px;
  padding: 0 16px;

  border-radius: var(--radius-pill);

  font-size: 14px;
  font-weight: 600;
  color: var(--text);

  cursor: pointer;

  background: var(--surface);

  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);

  border: 1px solid var(--stroke);

  box-shadow: var(--shadow-soft);

  transition: all 0.25s ease;
  will-change: transform, box-shadow, background;
}

.modelBtn:hover {
  transform: translateY(-2px) scale(1.03);

  background: var(--surface-strong);

  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);

  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.12);

  border: 1px solid rgba(0, 0, 0, 0.08);
}

.modelBtn:active {
  transform: translateY(0px) scale(0.98);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
/* Model panel */
.model-panel {
  position: fixed;
  inset: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  background: rgba(250, 251, 252, 0.45);

  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);

  z-index: 1000;

  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.model-panel.active {
  opacity: 1;
  pointer-events: all;
}

.model-card {
  width: 100%;
  max-width: 480px;

  background: var(--surface);

  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);

  border-radius: var(--radius-panel);

  padding: 22px 22px;

  border: 1px solid var(--stroke);

  box-shadow: var(--shadow-panel);

  display: grid;
  gap: 12px;

  transform: scale(0.95) translateY(10px);
  transition: all 0.25s ease;
}

.model-panel.active .model-card {
  transform: scale(1) translateY(0);
}

.model-card h3 {
margin: 0 0 6px 0;
}

.model-card label {
font-weight: 600;
font-size: 0.9em;
}

.model-card select,
.model-card input {
  background: var(--surface-soft);

  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);

  border: 1px solid var(--stroke);

  border-radius: var(--radius-control);

  padding: 10px 12px;

  font-size: 14px;

  transition: all 0.2s ease;
}

.model-card select:focus,
.model-card input:focus {
  border-color: rgba(0, 123, 255, 0.4);
  background: var(--surface-strong);
  outline: none;
  box-shadow: 0 0 0 4px rgba(0, 102, 255, 0.1);
}

.model-note {
margin: 0;
font-size: 0.85em;
color: var(--muted);
}

.model-actions {
margin-top: 8px;
display: flex;
justify-content: flex-end;
gap: 8px;
}

#modelSaveBtn {
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  backdrop-filter: blur(10px);

  border-radius: var(--radius-pill);
  padding: 8px 16px;
  border: none;
  color: white;
  cursor: pointer;

  box-shadow: 0 6px 18px rgba(0, 102, 255, 0.3);
  transition: all 0.2s ease;
}

#modelSaveBtn:hover {
transform: translateY(-1px);
box-shadow: 0 10px 22px rgba(0, 102, 255, 0.36);
}

#modelCancelBtn.ghost {
padding: 8px 14px;
background: var(--surface-soft);
border: 1px solid var(--stroke);
color: var(--text);
cursor: pointer;
font-size: 14px;
border-radius: var(--radius-pill);
box-shadow: var(--shadow-soft);
transition: all 0.2s ease;
}

#modelCancelBtn.ghost:hover {
background: var(--surface-strong);
transform: translateY(-1px);
}

/* =========================================================
    5) Auth screen
    ========================================================= */

.auth-screen {
flex: 1 1 auto;
background: transparent;
padding: 30px;
overflow-y: auto;
}

.auth-card {
max-width: 520px;
margin: 0 auto;
background: var(--surface);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
border: 1px solid var(--stroke);
border-radius: var(--radius-panel);
padding: 26px 26px;
box-shadow: var(--shadow-panel);
color: var(--text);
}

.auth-card h2 {
margin: 0 0 8px 0;
font-size: 1.5em;
}

.auth-card p {
margin: 0 0 18px 0;
color: var(--muted);
}

.auth-form {
display: grid;
gap: 10px;
}

.auth-form label {
font-weight: 600;
font-size: 0.9em;
}

.auth-form input {
padding: 10px 12px;
border: 1px solid var(--stroke);
border-radius: var(--radius-control);
font-size: 15px;
outline: none;
transition: all 0.2s ease;
background: var(--surface-soft);
color: var(--text);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.auth-form input:focus {
border-color: rgba(0, 102, 255, 0.42);
background: var(--surface-strong);
box-shadow:
  0 0 0 4px rgba(0, 102, 255, 0.1),
  inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.auth-actions {
margin-top: 18px;
display: flex;
justify-content: flex-end;
}

.primary-btn {
padding: 10px 22px;
background: linear-gradient(135deg, var(--blue), var(--blue-dark));
color: white;
border: none;
border-radius: var(--radius-pill);
cursor: pointer;
font-size: 15px;
font-weight: 600;
transition: all 0.2s ease;
box-shadow:
  0 6px 16px rgba(0, 102, 255, 0.32),
  inset 0 1px 0 rgba(255,255,255,0.35);
}

.primary-btn:hover {
transform: translateY(-1px);
box-shadow:
  0 10px 22px rgba(0, 102, 255, 0.4),
  inset 0 1px 0 rgba(255,255,255,0.45);
}

.primary-btn:active {
transform: translateY(0) scale(0.98);
}

.auth-error {
margin-top: 12px;
color: var(--danger);
min-height: 18px;
font-size: 0.95em;
}

/* =========================================================
    6) Datasource screen
   ========================================================= */

#datasourceScreen {
padding: 30px;
background: transparent;
}

#datasourceScreen .auth-card {
width: 100%;
max-width: 580px;
max-height: 80vh;
display: flex;
flex-direction: column;
min-height: 0;
padding: 24px 26px;
}

#datasourceList {
flex: 1 1 auto;
min-height: 0;
overflow-y: auto;
padding: 5px 3px 5px 0;
}

.datasource-item {
display: flex;
gap: 10px;
align-items: flex-start;
padding: 12px;
border: 1px solid var(--stroke);
border-radius: var(--radius-control);
margin-bottom: 8px;
cursor: pointer;
background: var(--surface-soft);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
transition: all 0.2s ease;
}

.datasource-item:hover {
background: var(--surface-strong);
transform: translateY(-1px);
box-shadow: var(--shadow-soft);
border-color: rgba(0, 102, 255, 0.18);
}

.datasource-item small,
.datasource-text small {
color: var(--muted);
}

#datasourceList .primary-btn {
margin-top: 8px;
width: 100%;
}

.datasource-item input[type="radio"],
.datasource-item input[type="checkbox"] {
accent-color: var(--blue);
margin-top: 2px;
}

/* =========================================================
    7) Chat: messages + box + input
    ========================================================= */

/* Chat box should flex and scroll as needed */
.chat-box {
  flex: 1 1 auto;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 14px 6px 14px;
  background: transparent;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;

  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0px,
    rgba(0,0,0,0.9) 20px,
    black 40px,
    black calc(100% - 40px),
    rgba(0,0,0,0.9) calc(100% - 20px),
    transparent 100%
  );

  mask-image: linear-gradient(
    to bottom,
    transparent 0px,
    rgba(0,0,0,0.6) 12px,
    black 28px,

    black calc(100% - 6px),
    rgba(0,0,0,0.4) calc(100% - 3px),
    transparent 100%
  );
}
.chat-box::-webkit-scrollbar {
  width: 6px;
}

.chat-box::-webkit-scrollbar-track {
  background: transparent;
}

.chat-box::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
  border-radius: 10px;
}

.chat-box::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.25);
}

/* Chat message styles */
.message {
    display: block;
    width: 100%;
    max-width: 100%;
    padding: 5px 10px;
    word-break: break-word;
}

.message.user {
    background: rgba(0, 123, 255, 0.75); /* синий, но с прозрачностью */

    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.2); /* легкая подсветка */
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 8px 24px rgba(0, 123, 255, 0.25);
    width: fit-content;
    max-width: 100%;
    align-self: flex-end;
    margin-left: auto;
    color: white;
}
.message.user p {
  margin: 10px 0px;
}

.message.user:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 32px rgba(0, 123, 255, 0.35);
}

.message.bot {
    background: var(--surface);
    max-width: 100%;
    width: fit-content;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);

    box-shadow: 0 8px 24px rgba(0, 123, 255, 0.25);

    border-radius: 16px 16px 16px 4px;

    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.55);
}

.message.bot.thinking {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-width: 46px;
    min-height: 30px;
    padding: 9px 12px;
}

.thinking-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #6b7785;
    opacity: 0.35;
    animation: thinkingPulse 1.2s ease-in-out infinite;
}

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

.thinking-dot:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes thinkingPulse {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.35;
    }
    40% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

.message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    width: fit-content;
}
.message-wrapper.user {
    align-self: flex-end;
    align-items: flex-end;
}

.message-wrapper.bot {
    width: 100%;
    max-width: 100%;
    align-items: flex-start;
}
/* чтобы кнопка была под сообщением */
.copy-btn {
    width: 34px;
    height: 34px;

    display: flex;
    align-items: center;
    justify-content: center;

    border: none;
    background: transparent;

    cursor: pointer;

    opacity: 0;
    transition: 0.2s ease;

    color: rgba(60, 60, 60, 0.7);

    border-radius: 10px; /* 👈 важно */
}


.copy-btn svg {
    width: 16px;
    height: 16px;
}

.message-wrapper:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    background: rgba(0, 0, 0, 0.06);

    border-radius: 10px; /* дублируем для стабильности */

    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12); /* 👈 добавили тень */

    color: rgba(0, 0, 0, 0.9);
    transform: scale(1.08);
}

.copy-btn:active {
    transform: scale(0.92);
}
.message-wrapper .copy-btn {
    margin-top: 5px;
}

.message-wrapper.user .copy-btn {
    align-self: flex-end;
}

/* BOT — кнопка слева */
.message-wrapper.bot .copy-btn {
    align-self: flex-start;
}
/* Input area at the bottom */
.input-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 12px 12px;
    background: transparent; /* важно */
    border-top: none; /* убрать линию */
    flex-shrink: 0;
    margin-top: 0;
}
.input-area .model-pill {
    align-self: flex-start;
    width: fit-content;
    padding: 4px 10px;
    font-size: 0.8em;
    margin-right: 4px;
}
.input-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--surface-strong);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--stroke);
    border-radius: 24px;
    box-shadow: var(--shadow-soft);
    padding: 8px;
    transition: box-shadow 0.2s ease;
}
.input-wrapper:focus-within {
    border-color: rgba(0, 102, 255, 0.22);
    box-shadow:
      0 8px 24px rgba(0,0,0,0.12),
      0 0 0 4px rgba(0, 102, 255, 0.08);
}

/* textarea вместо input */
#messageInput {
    width: 100%;
    resize: none;
    border: none; /* убрать рамку */
    outline: none;

    border-radius: 20px;
    padding: 10px 48px 10px 16px;
    min-height: 40px;

    font-size: 15px;
    line-height: 1.4;

    max-height: 200px;
    overflow-y: auto;

    background: transparent;
    color: var(--text);
}

#messageInput::placeholder {
    color: rgba(43, 58, 73, 0.48);
}

#messageInput:focus {
    outline: none;
    border: none;
}

#sendBtn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);

    width: 38px;
    height: 38px;
    border-radius: 50%;

    display: flex;
    align-items: center;
    justify-content: center;

    background: linear-gradient(135deg, var(--blue), var(--blue-dark));
    color: white;
    border: none;
    cursor: pointer;
    z-index: 4;

    box-shadow:
        0 6px 16px rgba(0, 102, 255, 0.35),
        inset 0 1px 0 rgba(255,255,255,0.4);

    transition: all 0.25s ease;
}

#sendBtn:hover:not(:disabled) {
    transform: translateY(-50%) scale(1.08);
    box-shadow:
        0 10px 22px rgba(0, 102, 255, 0.45),
        inset 0 1px 0 rgba(255,255,255,0.5);
}

#sendBtn:active {
    transform: translateY(-50%) scale(0.94);
}

#sendBtn svg {
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
}

#sendBtn:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    opacity: 0.7;
}

#sendBtn.loading {
    opacity: 0.7;
    pointer-events: none;
}

#sendBtn.cancel-mode {
    gap: 8px;
}

#sendBtn.cancel-mode svg {
    width: 18px;
    height: 18px;
}

/* =========================================================
    8) Controls / utilities
    ========================================================= */

.hidden {
display: none;
}

#logoutBtn.logout-glass {
  position: fixed;

  /* выравнивание по верхней линии header */
  top: 18px;

  /* справа контейнера */
  right: 12px;

  width: 40px;
  height: 40px;

  border-radius: var(--radius-pill);

  background-color: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);

  border: 1px solid var(--stroke);
  box-shadow: var(--shadow-soft);

  background-image: url('/static/LogOut_black.png');
  background-size: 55%;
  background-position: center;
  background-repeat: no-repeat;

  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 1000;
}

#logoutBtn.logout-glass:hover {
  transform: scale(1.05);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.12);
}

#logoutBtn.logout-glass:active {
  transform: scale(0.95);
}


/* =========================================================
    9) Responsive
    ========================================================= */

/* Responsive for smaller screens */
@media (max-width: 600px) {
.container {
    max-width: 100vw;
    width: 100vw;
    margin: 0;
    border-radius: 0;
    height: 100vh;
}

body {
    padding: 0;
}

header {
    height: 42px;
    padding: 0 16px;
    margin-top: 8px;
}

header h1 {
    font-size: 1.05em;
}

.logo img {
    height: 30px;
}

.chat-box {
    padding: 15px;
}

.input-area {
    flex-direction: column;
}

#sendBtn {
    padding: 12px;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

#modelBtn {
    padding: 8px 10px;
}

.auth-screen {
    padding: 20px;
}

.auth-card {
    padding: 18px 16px;
}
}

.app-version {
  position: absolute;
  right: 10px;
  bottom: 6px;
  z-index: 30;
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  opacity: 0.28;
  pointer-events: none;
  user-select: none;
}