/* ==============================
   1?? Global Styles
   ============================== */
body {
    font-family: 'Segoe UI', Roboto, Arial, sans-serif;
    background: #181818;            /* VS Code dark */
    margin: 0;
    padding: 0;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: stretch;
    color: #d4d4d4;                 /* VS Code text colour */
}

/* ==============================
   2?? App Container
   ============================== */
.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* ==============================
   3?? Sidebar
   ============================== */
.sidebar {
    width: 280px;
    background: #252526;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #3c3c3c;
    padding: 15px;
    box-sizing: border-box;
    transition: all 0.3s ease;
}
.sidebar-header {
    margin-bottom: 12px;
    font-size: 18px;
    font-weight: 600;
    color: #ffffff;
}
.new-chat-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.new-chat-row button {
    flex: 1;
    padding: 12px;
    background: #007acc; /* VS Code blue */
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}
.new-chat-row button:hover {
    background: #005f9e;
    transform: translateY(-1px);
}
.new-chat-row select {
    background-color: #3c3c3c;
    color: white;
    border: none;
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s ease;
}
.new-chat-row select:hover {
    background-color: #505050;
}
.sidebar-label {
    font-size: 12px;
    text-transform: uppercase;
    color: #9e9e9e;
    margin: 14px 0 8px 0;
}
.chat-history {
    flex-grow: 1;
    overflow-y: auto;
    font-size: 14px;
    scrollbar-width: thin;
    scrollbar-color: #3c3c3c transparent;
}
.chat-history::-webkit-scrollbar {
    width: 6px;
}
.chat-history::-webkit-scrollbar-thumb {
    background-color: #3c3c3c;
    border-radius: 3px;
}
.chat-item {
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    background-color: transparent;
    transition: background 0.2s ease, transform 0.1s ease;
    opacity: 0;
    transform: translateX(-20px);
    animation: slideIn 0.3s forwards;
}
.chat-item:hover {
    background-color: #2d2d2d;
    transform: translateX(0);
}

/* ==============================
   4?? Main Chat Area
   ============================== */
.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    flex: 1;
    background: #181818;
}
.chatbox {
    flex-grow: 1;
    overflow-y: auto;
    padding: 24px;
    scrollbar-width: thin;
    scrollbar-color: #3c3c3c transparent;
}
.message {
    display: flex;
    margin-bottom: 20px;
    opacity: 0;
    transform: translateY(20px);
    animation: messageIn 0.4s forwards;
}
.message.user {
    justify-content: flex-end;
}
.message.assistant {
    justify-content: flex-start;
}
.message p {
    padding: 14px 18px;
    border-radius: 14px;
    max-width: 70%;
    line-height: 1.5;
    white-space: pre-wrap;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    transition: background 0.2s ease;
}
.message.user p {
    background: #0e639c; /* dark VS Code blue */
    color: white;
}
.message.assistant p {
    background: #252526;
    color: #d4d4d4;
}
.message.assistant p.error {
    background-color: #f44747;
    color: white;
    font-weight: bold;
    border: 1px solid #e51400;
}
.typing {
    display: inline-block;
    font-weight: bold;
    letter-spacing: 2px;
    animation: pulseDots 1s infinite;
}
@keyframes pulseDots {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* ==============================
   5?? Input Area
   ============================== */
.input-area {
    display: flex;
    padding: 12px;
    border-top: 1px solid #3c3c3c;
    background: #181818;
}
textarea {
    flex: 1;
    resize: none;
    padding: 14px;
    border: none;
    border-radius: 12px;
    background-color: #252526;
    color: #d4d4d4;
    font-size: 14px;
    outline: none;
    overflow: hidden;
    transition: background 0.2s ease;
}
textarea:focus {
    background-color: #3c3c3c;
}
#sendBtn {
    margin-left: 12px;
    background: #007acc;
    color: white;
    border: none;
    border-radius: 12px;
    padding: 0 18px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}
#sendBtn:hover {
    background: #005f9e;
    transform: translateY(-1px);
}

/* ==============================
   6?? Animations
   ============================== */
@keyframes slideIn {
    to { opacity: 1; transform: translateX(0); }
}
@keyframes messageIn {
    to { opacity: 1; transform: translateY(0); }
}
.generated-image {
    max-width: 80%;         /* at most 80% of chat container width */
    max-height: 400px;
    width: auto;
    height: auto;
    border-radius: 8px;
    margin-top: 5px;
    display: block;
}

/* ==============================
   7?? Footer
   ============================== */
.footer {
    padding: 10px 15px;
    font-size: 0.9em;
    color: #fff;
    background-color: #2c2c2c;
    position: fixed;
    bottom: 0;
    width: 100%;
    display: flex;
    justify-content: center; /* centers text block */
    align-items: center;
}
.footer-content {
    flex-grow: 1;
    text-align: center;
}
.footer a {
    color: #66aaff;
    text-decoration: none;
}
.footer a:hover {
    text-decoration: underline;
}
.footer-close {
    background: none;
    border: none;
    color: #aaa;
    font-size: 1.2em;
    cursor: pointer;
    margin-left: auto; /* pushes X to the far right */
}
.footer-close:hover {
    color: #fff;
}

/* ==============================
   8?? Modal Overlay
   ============================== */
.model-modal .content {
    max-width: 900px;
    margin: 0 auto;
    background: #252526 !important;   /* VS-Code dark – keep it dark */
    background-color: #252526 !important;
    border-radius: 8px;
    padding: 1.5rem;
    position: relative;
    box-shadow: 0 4px 12px rgba(0,0,0,0.35);
    color: #fff;
    max-height: 85vh;           /* stays within the viewport */
    display: flex;
    flex-direction: column;
}
.model-modal .close-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.4rem;
    color: #fff;
    cursor: pointer;
    transition: color 0.2s ease;
}
.model-modal .close-btn:hover { color: #fff; }

/* ==============================
   9?? Search Input
   ============================== */
.model-search {
    width: 100%;
    padding: 0.55rem 1rem;
    font-size: 1rem;
    border: 1px solid #555;
    border-radius: 4px;
    margin-bottom: 1.25rem;
    background: #252526;   /* VS-Code surface */
    color: #d4d4d4;
    box-sizing: border-box;
}
.model-search::placeholder { color: #fff; }

/* ==============================
   ?? Grid & Cards
   ============================== */
.model-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
    overflow-y: auto;
    padding-right: 6px;         /* avoid scrollbar overlap */
    max-height: calc(85vh - 160px);
}
.model-grid::-webkit-scrollbar {
    width: 6px;
}
.model-grid::-webkit-scrollbar-thumb {
    background: #3c3c3c;
    border-radius: 3px;
}
.model-card {
    background: #252526;   /* same as sidebar background */
    border: 1px solid #3c3c3c;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    display: flex;
    flex-direction: column;
    height: 100%;
}
.model-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}
.model-card img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    background: #444;   /* fallback while image loads */
}
.model-card h4 {
    margin: 0.75rem 0.5rem 0.25rem;
    font-size: 1rem;
    color: #fff;
}
.model-card p {
    margin: 0 0.5rem 0.75rem;
    font-size: 0.85rem;
    color: #fff;
    flex-grow: 1;      /* push content to bottom */
}

/* ==============================
   11?? Change Model button
   ============================== */
#changeModelBtn {
    flex: 1;
    padding: 12px;
    background: #007acc;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
#changeModelBtn:hover {
    background: #005f9e;
    transform: translateY(-1px);
}

/* ==============================
   12?? Responsive tweaks
   ============================== */
@media (max-width: 480px) {
    .model-modal .content {
        padding: 1rem;
        width: 100%;
        margin: 0;
    }
    .model-search { margin-bottom: 1rem; }
}

/* ==============================
   13?? New focus-outline fix
   ============================== */
/* 1??  Remove the browser-default focus ring on the card itself */
.model-card:focus,
.model-card:active,
.model-card:focus-visible {
    outline: none;
    border: 1px solid #3c3c3c;   /* keep the dark border */
}

/* 2??  If the card contains a link or button, hide its focus ring */
.model-card a:focus,
.model-card button:focus {
    outline: none;
}

/* 3??  (Optional) – Show a nicer focus ring for keyboard users */
.model-card:focus-visible {
    outline: 2px solid #3c3c3c;   /* or any colour that fits your palette */
    outline-offset: 2px;          /* keeps the outline a little away from the border */
}

/* 3?? Bolded words (the default `<strong>` tag) */
.message strong {
  color: #d63384;      /* a nice magenta – change it to whatever you like */
  font-weight: 600;
}

/* 4?? Typing animation (optional) */
.typing::after {
  content: '';
  display: inline-block;
  width: .8em;
  height: .8em;
  margin-left: .2em;
  background: #ddd;
  border-radius: 50%;
  animation: pulse 1.2s infinite ease-in-out;
}

@keyframes pulse {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}
/* ================= CODE BLOCKS ================= */

.code-block {
  position: relative;
  background-color: #1f2937; /* dark gray */
  color: #e5e7eb;
  padding: 14px 16px;
  border-radius: 10px;

  /* SCROLL FIX */
  overflow-x: auto;
  max-width: 100%;

  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 14px;
  line-height: 1.5;

  margin: 10px 0;
}

/* Ensure the <code> does NOT override background */
.code-block code {
  display: block;
  background: transparent !important;
  color: inherit;
  white-space: pre;        /* Preserve formatting */
  min-width: max-content;  /* Forces horizontal scroll */
}

/* Copy button */
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;

  background: #374151;
  color: #f9fafb;
  border: none;
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
}

.copy-btn:hover {
  background: #4b5563;
}

/* Inline code */
.inline-code {
  background: #374151;
  color: #f9fafb;
  padding: 2px 6px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 0.95em;
}

.code-block {
  position: relative;
  background-color: #1f2937;
  color: #e5e7eb;
  padding: 14px 16px 12px;
  border-radius: 10px;
  margin: 10px 0;
}

/* Scrollable inner area */
.code-scroll {
  overflow-x: auto;
  max-width: 100%;
  padding-top: 8px;
}

/* Code text */
.code-scroll code {
  display: block;
  white-space: pre;
  min-width: max-content;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 14px;
  line-height: 1.5;
  background: transparent;
  color: inherit;
}

/* Copy button (pinned to visible edge) */
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;

  background: #374151;
  color: #f9fafb;
  border: none;
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
}

.copy-btn:hover {
  background: #4b5563;
}

/* Outer code container (never scrolls) */
.code-block {
  position: relative;
  background-color: #1f2937;
  color: #e5e7eb;
  padding: 14px 16px 12px;
  border-radius: 10px;
  margin: 10px 0;
  max-width: 100%;
}

/* Scroll container (ONLY this scrolls) */
.code-scroll {
  overflow-x: auto;
  max-width: 100%;
}

/* Kill pre defaults */
.code-scroll pre {
  margin: 0;
  background: transparent;
  overflow: visible; /* IMPORTANT */
}

/* Code text */
.code-scroll code {
  display: block;
  white-space: pre;
  min-width: max-content;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 14px;
  line-height: 1.5;
  color: inherit;
}

/* Copy button NEVER scrolls */
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;

  background: #374151;
  color: #f9fafb;
  border: none;
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
}

.copy-btn:hover {
  background: #4b5563;
}