.chat-container,
.tools-container {
      flex: 1;
      display: flex;
      flex-direction: column;
      min-width: 0;
    }


    /* This targets the input area specifically when tools are hidden */
      .chat-container.centered-chat .chat-input-area {
        width: 90%; /* YOUR REQUESTED WIDTH */
        max-width: none;
        margin-left: auto;
        margin-right: auto;
        /* Remove the side margin that was in the chat-container */
        margin-right: auto;
      }

      .chat-container.centered-chat .chat-message.ai {
      padding-bottom: 10px;
      margin-bottom: 10px;
    }

    /* This is now the BASE rule for larger screens */
    .chat-container.centered-chat .chat-messages {
      display: grid;
      grid-template-columns: 1fr minmax(0, 55%) 1fr;
      align-content: start;
    }

     .chat-container.centered-chat .chat-messages > * {
        grid-column: 2;
    }

    /* This rule will hide the chat history when the parent container has the 'voice-mode-active' class */
.chat-container.voice-mode-active .chat-messages {
    display: none;
}

.tools-toggle-bar {
      display: flex;
      background: rgba(255, 255, 255, 0.05);
      backdrop-filter: blur(10px);
      border: 1px solid rgba(255, 255, 255, 0.1);
      border-radius: 30px;
      padding: 8px;
      margin-bottom: 20px;
      position: relative;
      flex-shrink: 0;
    }

     .pane-toggle {
      position: absolute;
      top: 50%;
      left: 0;
      transform: translateY(-50%);
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 0px;
      opacity: 0;
      transition: opacity 0.3s ease;
      pointer-events: auto;
    }

    .pane-toggle i {
      color: #fff;
      font-size: 24px;
      cursor: pointer;
      user-select: none;
    }

    .pane-toggle i:hover {
      opacity: 0.8;
    }

    
    .pane-toggle-hover {
      position: absolute;
      left: 0;
      top: 0;
      width: 40px;
      height: 100%;
      pointer-events: auto;
    }

    .pane-toggle-hover:hover+.pane-toggle,
    .pane-toggle-wrapper:hover .pane-toggle {
      opacity: 1;
    }

    .pane-toggle-wrapper {
      position: fixed;
      top: 50%;
      left: 0px;
      transform: translateY(-50%);
      width: 40px;
      height: 80px;
      z-index: 100;
    }

     .toggle-button {
      flex: 1;
      text-align: center;
      cursor: pointer;
      user-select: none;
      z-index: 1;
      color: #f0f0f0;
      transition: color 0.2s ease-in-out;
      padding: 8px 0;
      font-weight: 500;
    }

    .toggle-button.active {
      color: #fff;
      font-weight: 600;
    }

    .toggle-indicator {
      position: absolute;
      top: 4px;
      bottom: 4px;
      background: rgba(255, 255, 255, 0.1);
      border-radius: 30px;
      transition: transform 0.3s ease-in-out, width 0.3s ease-in-out;
      z-index: 0;
    }



.chat-header {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      height: 60px;
      display: flex;
      align-items: center;
      padding: 0 20px;
      z-index: 5;
      background: linear-gradient(to bottom,
          rgba(57, 53, 136, 0.9),
          rgba(57, 53, 136, 0));
      backdrop-filter: blur(5px);
    }


    .chat-header-actions {
    /* This div is already styled inline with flex and gap,
       but you could move those styles here if preferred:
       display: flex;
       align-items: center;
       gap: 10px;
    */
}


.chat-input {
      width: 100%;
      font-size: 18px;
      background: transparent;
      border: none;
      outline: none;
      max-height: 150px;
      overflow-y: auto;
      color: #f0f0f0;
      padding: 5px;
      margin-bottom: 5px;
    }


   .chat-input-area {
      background: rgba(255, 255, 255, 0.05);
      backdrop-filter: blur(10px);
      
      /* Base state: 10% opacity (Very subtle gray) */
      border: 1px solid rgba(255, 255, 255, 0.1);
      
      border-radius: 30px;
      padding: 15px 20px;
      margin-right: 20px;
      flex-shrink: 0;
      position: relative;
      
      /* Smooth transition */
      transition: border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out, background-color 0.2s ease-in-out;
    }

    /* 
       Hover state ONLY.
       Removed :focus-within so it stays dark while typing unless you hover.
    */
    .chat-container .chat-input-area:hover {
      border-color: rgba(255, 255, 255, 0.22) !important;
    }

    .chat-input-area.drag-over {
      border-color: #a18cd1;
      border-style: dashed;
      border-width: 2px;
      box-shadow: 0 0 15px rgba(161, 140, 209, 0.3);
    }


    /* ADD THIS NEW CSS RULE */
.chat-input-area.is-locked > *:not(.chat-lockout-overlay) {
    opacity: 0.3;
    pointer-events: none;
    transition: opacity 0.3s ease-out;
}

 /* In index.html, inside the main <style> tag */
/* REPLACE your old .chat-input-row rule with this one */
.chat-input-row {
    display: flex;
    align-items: center; /* Vertically centers items */
    justify-content: space-between;
    padding-top: 8px; /* Add some top padding to lower the entire row */
}

.chat-input:empty::before {
      content: attr(placeholder);
      color: var(--chat-placeholder-color, rgba(190, 180, 210, 0.65)); /* Use variable */
      font-style: normal;
      cursor: text;
      pointer-events: none;
      display: block;
    }

/* --- Chat Input Lockout Overlay --- */
.chat-lockout-overlay {
    position: absolute;
    inset: 0; /* Shorthand for top: 0; right: 0; bottom: 0; left: 0; */
    
    background-color: rgba(36, 37, 38, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    
    border-radius: 30px; /* This should match the parent's border-radius */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    
    opacity: 0;
    transition: opacity 0.3s ease-out;
    pointer-events: none;
}

.chat-lockout-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto; /* Make it interactive when visible */
}

.lockout-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    text-align: center;
}

#lockout-timer-text {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary, #E4E6EB);
    margin: 0;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

#lockout-upgrade-btn {
    background: #A78BFA;
    color: #1C1B22;
    padding: 12px 28px;
    font-size: 1rem;
    border-radius: 25px;
    border: none;
}
#lockout-upgrade-btn:hover {
    background: #B99CFB;
}

.calcgpt-btn {
      position: relative;
      background: linear-gradient(145deg,
          rgba(234, 228, 250, 0.9),
          rgba(214, 201, 242, 0.9));
      border: none;
      border-radius: 8px;
      padding: 8px 12px;
      color: #393588;
      font-size: 18px;
      font-weight: bold;
      display: flex;
      align-items: center;
      cursor: pointer;
      transition: transform 0.2s ease, box-shadow 0.2s ease;
    }

    .calcgpt-btn i {
      margin-right: 8px;
      font-size: 22px;
    }

    .calcgpt-btn:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    }

    .calcgpt-dropdown {
      position: absolute;
      top: 100%;
      left: 20px;
      background: linear-gradient(135deg,
          rgb(250, 244, 250),
          rgba(200, 180, 240, 0.95));
      backdrop-filter: blur(12px);
      border-radius: 12px;
      margin-top: 4px;
      padding: 12px 0;
      min-width: 220px;
      box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
      opacity: 0;
      visibility: hidden;
      transform: translateY(-10px);
      transition: opacity 0.3s ease, transform 0.3s ease;
      border: 1px solid rgba(255, 255, 255, 0.2);
      z-index: 2000;
    }

    .calcgpt-dropdown.show {
      opacity: 1;
      visibility: visible;
      transform: translateY(0);
    }

    .calcgpt-dropdown a {
      display: flex;
      align-items: center;
      padding: 10px 16px;
      text-decoration: none;
      color: #393588;
      font-size: 16px;
      font-weight: 500;
      transition: background 0.2s ease, transform 0.2s ease;
      border-radius: 8px;
    }

    .calcgpt-dropdown a i {
      margin-right: 10px;
      font-size: 20px;
      color: #4a3e9e;
    }

    .calcgpt-dropdown a:hover {
      background: rgba(150, 120, 220, 0.15);
      transform: translateX(4px);
    }

    .calcgpt-dropdown a:hover i {
      color: #6a50d0;
    }

    /* --- Chat Header Action Buttons --- */
.header-action-btn {
    background: rgba(255, 255, 255, 0.07); /* Slightly more subtle */
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #B0B0BE; /* Softer icon color */
    border-radius: 10px; /* Circular buttons */
    width: 38px;   /* Consistent size */
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px; /* Adjusted icon size */
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.15s ease-out, box-shadow 0.2s ease, color 0.2s ease;
    backdrop-filter: blur(8px); /* Slightly more blur */
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.header-action-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #FFFFFF;
    transform: scale(1.005); /* More subtle hover scale */
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2), 0 0 15px rgba(107, 138, 255, 0.1); /* Subtle glow */
}

.header-action-btn:active {
    transform: scale(0.98);
    background: rgba(255, 255, 255, 0.09);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.chat-icon-btn {
      background: transparent;
      border: none;
      color: #f0f0f0;
      font-size: 24px;
      cursor: pointer;
      opacity: 0.7;
      transition: opacity 0.2s, transform 0.2s;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .chat-icon-btn:hover {
      opacity: 1;
      transform: scale(1.01);
    }

    /* ADD this new rule to your stylesheet */
.input-buttons {
    display: flex;
    align-items: center; /* Ensures vertical alignment of items within the button group */
    gap: 8px; /* Maintain consistent gap */
}


.send-section-to-chat-btn {
      background: linear-gradient(145deg, #4b476b 0%, #5e5a80 100%);
      color: #EFEBF5;
      border: 1px solid rgba(179, 157, 219, 0.15);
      border-radius: 25px;

      padding: 11px 28px;
      font-size: 1.0rem;
      font-weight: 500;
      letter-spacing: 0.1px;

      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      margin-top: 10px;
      margin-left: auto;
      margin-right: auto;

      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25),
        inset 0 1px 0px rgba(255, 255, 255, 0.04);
      text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);

      transition: all 0.25s cubic-bezier(0.25, 0.8, 0.25, 1);
      cursor: pointer;
    }

    .send-section-to-chat-btn:hover {
      background: linear-gradient(145deg, #5a567a 0%, #6d6990 100%);
      border-color: rgba(179, 157, 219, 0.3);
      color: #FFFFFF;
      transform: translateY(-2px) scale(1.015);
      box-shadow: 0 7px 18px rgba(0, 0, 0, 0.35),
        0 0 15px rgba(179, 157, 219, 0.2);
    }

    .send-section-to-chat-btn i {
      font-size: 1.2em;
    }


    .send-section-to-chat-btn:hover {
      background: linear-gradient(145deg, #5a567a 0%, #6d6990 100%);
      border-color: rgba(179, 157, 219, 0.3);
      color: #FFFFFF;
      transform: translateY(-2px) scale(1.015);
      box-shadow: 0 7px 18px rgba(0, 0, 0, 0.35),
        0 0 15px rgba(179, 157, 219, 0.2);
    }

    #sendBtn .bx-loader-alt.bx-spin {
            font-size: 24px;
            line-height: 1;
            vertical-align: middle;
            animation: spin 1s linear infinite;
          }


          .chat-mode-option {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px 14px; /* Give icons a bit more breathing room */
    position: relative;
    z-index: 1;
    transition: color 0.3s ease; /* Smoother color transition */
    /* A softer, more thematic inactive color */
    color: #b0a8c9;
    font-size: 22px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-mode-option:hover:not(.active) {
    color: #FFFFFF; /* Bright white on hover for clarity */
}

.chat-mode-option.active {
    /* Active icon is bright white for maximum contrast and visibility */
    color: #FFFFFF;
    transition-delay: 0.05s;
}

.chat-mode-slider {
    position: absolute;
    top: 3px; /* Matches parent padding */
    left: 3px; /* Matches parent padding */
    height: calc(100% - 6px);
    /* A semi-transparent white for a "frosted glass" slider effect */
    background-color: rgba(255, 255, 255, 0.15);
    border-radius: 22px; /* Pill shape to match the container */
    /* A very subtle shadow to give the slider depth without being overpowering */
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 0;
}

/* --- Chat Mode Toggle (Elegant Sliding Design) --- */
.chat-mode-toggle {
    position: relative;
    display: flex;
    align-items: center;
    /* A dark, glassy container that forms a "pill" */
    background-color: rgba(0, 0, 0, 0.25);
    border-radius: 25px; /* Pill shape */
    padding: 3px; /* Tighter padding around the elements */
    border: 1px solid rgba(255, 255, 255, 0.1); /* Subtle edge highlight */
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

          #toolInsertBtn i.bx-customize {}

          .tool-insert-item {
            display: flex;
            align-items: center;
            padding: 10px 12px;
            border-radius: 8px;
            cursor: pointer;
            transition: background-color 0.15s ease;
            color: #e0e0e0;
          }


          .tool-insert-item .tool-item-description {
            font-size: 12px;
            color: #908aab;
            margin-top: 2px;
            line-height: 1.3;
          }

          .tool-insert-item .tool-item-text {
            font-size: 15px;
            font-weight: 500;
          }

          

          .tool-insert-item div {
            display: flex;
            flex-direction: column;
          }


          .tool-insert-item:hover {
            background-color: #404060;
          }

          .tool-insert-item i {
            font-size: 20px;
            margin-right: 12px;
            color: #b5a7d8;
          }


          .tool-insert-popover {
            position: absolute;
            background: #2f2f4f;
            border: 1px solid #4a4a70;
            border-radius: 12px;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
            z-index: 1060;
            width: 280px;
            padding: 10px;

            opacity: 0;
            transform: translateY(10px) scale(0.95);
            transition: opacity 0.2s ease-out, transform 0.2s ease-out;
            pointer-events: none;
          }

          .tool-insert-popover.hidden {
            display: none !important;
          }

          .tool-insert-popover:not(.hidden) {
            opacity: 1;
            transform: translateY(0) scale(1);
            pointer-events: auto;
          }

          .tool-tag {
            display: inline;
            color: #c084fc;
            font-weight: 600;
            padding: 0 1px;
            margin: 0;
            cursor: default;
            user-select: none;
            white-space: nowrap;

            background: none;
            border: none;
            border-radius: 0;
            box-shadow: none;
          }

          .tool-tag i {
            margin-right: 3px;
            vertical-align: baseline;
            font-size: 0.9em;
            color: inherit;
          }


          /* Messages & Math */
.chat-messages {
      flex: 1;
      overflow-y: auto;
      overflow-x: hidden;
      padding-top: 60px;
      margin-top: 0px;
      margin-bottom: 1px;
      padding-right: 20px;
      min-width: 0;
    }

     .chat-messages::-webkit-scrollbar {
      width: 8px;
    }

    .chat-messages::-webkit-scrollbar-thumb {
      background: rgba(255, 255, 255, 0.2);
      border-radius: 4px;
    }

    .chat-message {
      display: flex;
      align-items: center;
      margin-bottom: 20px;
      position: relative;
      min-width: 0;
    }

    .chat-message .avatar {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      margin: 0px 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      background-color: #6a0dad;
      color: white;
      font-size: 18px;
    }

    .chat-message img,
    #screenshotUpdatesArea img {
      max-width: 100%;
      max-height: 100%;
      object-fit: cover;
    }

    .chat-message.ai {
      display: flex;
      align-items: flex-start;
      position: relative;
      padding-bottom: 10px;
    }


    /* Default state (The PFP image) */
    .chat-message.ai .avatar {
      content: url("https://lh3.googleusercontent.com/pw/AP1GczNdDnYo-ZWZ9xAOVxQvXn1llk2UawIZ4YrQToZhW_HpcIGjwMPI55040QK8Rd6mzn6GN1c3s3ywkYKGuRdSR8ldZ844tZ3RV7p-M4XSer-ZDgo9LX3PnCT673hCr1USFRSiduWROgL2F9eOhyRZBVZA=w913-h913-s-no-gm?authuser=0");
      background-color: transparent;
      /* Ensure exact sizing matches the loading state */
      width: 32px;
      height: 32px;
      object-fit: cover;
      border-radius: 50%;
      transition: transform 0.3s ease, background-color 0.3s ease;
    }

    /* Loading State (Spinning Logo) */
    .chat-message.ai .avatar.loading {
      /* Override the content to use the SVG loader */
      content: url("/static/images/loader.svg");
      /* Exact purple background from PFP */
      background-color: #7b1fa2;
      /* Ensure circular shape */
      border-radius: 50%;
      /* Exact dimensions to match PFP */
      width: 32px !important;
      height: 32px !important;
      /* Padding controls the size of the inner spinner relative to the purple circle */
      padding: 5px; 
      box-sizing: border-box;
      /* Animation */
      animation: spin 1s linear infinite;
      box-shadow: none; /* Removed shadow to match flat design of PFP */
    }

    /* Reset the left offset for the icon container to align it with the text */
    .chat-message.ai .icon-container {
      left: 0;
    }

    .chat-message.ai .icon-container i {
      cursor: pointer;
      font-size: 17px;
      color: #909296;
      padding: 7px;
      border-radius: 50%;
      transition: color 0.2s ease, background-color 0.2s ease;
      line-height: 1;
    }

    .chat-message.ai .icon-container i.bx-check {
      color: #40c057;
      background-color: transparent !important;
    }

     .chat-message.ai .icon-container i.tts-button.speaking::before {
      color: #339af0;
    }

    .chat-message.ai .icon-container i.tts-button.speaking:hover::before {
      background-color: rgba(51, 154, 240, 0.1);
    }

    .chat-message.ai .icon-container i:hover {
      color: #e9ecef;
      background-color: rgba(255, 255, 255, 0.08);
    }

    .chat-message.ai .message-content {
      max-width: 65%;
      padding-left: 10px;
      margin-top: -10px;
    }

     .chat-message.ai .message-content+.icon-container {
      max-width: 100%;
    }

    .chat-message.ai .message-content .inline-math math-field[read-only],
    .chat-message.ai .message-content .block-math-wrapper>math-field[read-only] {
      font-size: inherit !important;
    }

    .chat-message.ai .message-content .inline-math math-field[read-only] .ML__container {
      padding: 0px !important;
      border: 1px dashed red !important;
    }

    .chat-message.ai .message-content .inline-math math-field[read-only] .ML__container .ML__content {
      padding: 0 0px !important;
      border: 1px dashed blue !important;
    }

    .chat-message.ai .message-content img {
        border-radius: 12px; /* This is the key property for rounded corners */
        max-width: 100%;     /* Ensure the image is responsive */
        height: auto;        /* Maintain aspect ratio */
        display: block;      /* Ensures margin is applied correctly */
        margin-top: 10px;    /* Add some space above the image */
        margin-bottom: 10px; /* Add some space below the image */
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); /* Optional: add a subtle shadow for depth */
    }

    .chat-message.ai .message-content li {
      margin-bottom: 0.6em;
    }

    .chat-message.ai .message-content math-field[read-only] {
      margin: 12px auto;
    }

    .chat-message.ai .message-content ul,
    .chat-message.ai .message-content ol {
      padding-left: 1.8em;
      margin-top: 0.5em;
      margin-bottom: 0.8em;
    }

    /* Style for the container of the code/output block */
.chat-message.ai .message-content pre {
    background-color: rgba(0, 0, 0, 0.25); /* A dark, slightly transparent background */
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 16px;
    margin: 1em 0;
    overflow-x: auto; /* This is the key property for the horizontal scrollbar */
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

/* Style for the text content itself inside the block */
.chat-message.ai .message-content pre code.language-output {
    font-family: 'SF Mono', Menlo, Monaco, Consolas, "Courier New", monospace;
    font-size: 0.9em;
    color: #E0E0E5; /* A bright but not harsh color for the text */
    white-space: pre; /* Prevents text from wrapping, allowing the scrollbar to appear */
    background-color: transparent; /* The parent <pre> handles the background */
    padding: 0; /* Remove any default padding from the code tag itself */
}

/* Custom scrollbar styling for the output block to match the app's theme */
.chat-message.ai .message-content pre::-webkit-scrollbar {
    height: 8px;
    cursor: grab;
}

.chat-message.ai .message-content pre::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.chat-message.ai .message-content pre::-webkit-scrollbar-thumb {
    background-color: rgba(170, 102, 255, 0.5);
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.3);
}

.chat-message.ai .message-content pre::-webkit-scrollbar-thumb:hover {
    background-color: rgba(170, 102, 255, 0.7);
}

.chat-message.ai.no-avatar {
      margin-top: -10px;
      margin-bottom: 20px;
    }

    .chat-message.ai.no-avatar .avatar {
      display: none;
    }

    .chat-message.ai:hover .icon-container {
      opacity: 0.7;
      visibility: visible;
      transform: translateY(0);
      transition: opacity 0.2s ease-in-out,
        transform 0.2s ease-in-out,
        visibility 0s linear 0s;
    }

     .chat-message.ai:hover .response-timer {
      display: inline-block;
    }

    .chat-message.user {
      flex-direction: row-reverse;
    }

    .chat-message.user .avatar {
      background-color: #6a0dad;
    }

    .chat-message.user .message-content {
      background: rgba(170, 102, 255, 0.2);
      backdrop-filter: blur(10px);
      border: 1px solid rgba(255, 255, 255, 0.2);
      border-radius: 16px;
      padding: 10px;
      max-width: 60%;
      text-align: left;
    }

    .chat-message:hover .icon-container {
      opacity: 1;
    }

    .ai .icon-container {
      top: 100%;
      right: 40px;
      transform: translateY(0%);
    }

    .ai-message-main-block {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      flex-grow: 1;
      min-width: 0;
      margin-bottom: 20px;
    }

    .user .icon-container {
      top: 50%;
      transform: translateY(-50%);
    }

    .block-math-wrapper {
      display: flex;
      justify-content: center;
      width: 100%;
      margin: 12px 0;
      padding: 0;
      overflow-x: auto; /* For very long equations */
      background-color: transparent;
      border-radius: 4px;
      box-sizing: border-box;
      scrollbar-width: thin;
      scrollbar-color: rgba(170, 102, 255, 0.6) rgba(0, 0, 0, 0.2);
    }

    .block-math-wrapper>math-field[read-only] {
      width: max-content;
      padding: 0 0px;
      margin: 0;
      text-align: left;
      box-sizing: border-box;
      background-color: transparent !important;
      border: none !important;
      color: white;
      font-size: inherit;
      line-height: inherit;
      vertical-align: baseline;
    }

    .block-math-wrapper::-webkit-scrollbar {
      height: 8px;
      cursor: grab;
    }

    .block-math-wrapper::-webkit-scrollbar-thumb {
      background-color: rgba(170, 102, 255, 0.6);
      border-radius: 4px;
      border: 1px solid rgba(0, 0, 0, 0.3);
    }

    .block-math-wrapper::-webkit-scrollbar-thumb:hover {
      background-color: rgba(170, 102, 255, 0.8);
    }

    .block-math-wrapper::-webkit-scrollbar-track {
      background: rgba(0, 0, 0, 0.2);
      border-radius: 4px;
    }

    .block-math-wrapper::-webkit-scrollbar:horizontal:active {
      cursor: grabbing;
    }

    .inline-math {
      display: inline-block;
      vertical-align: middle;
      margin: 0 1px;
      line-height: inherit;
    }

    .inline-math math-field[read-only] {
      display: inline !important;
      margin: 0 !important;
      padding: 0 !important;
      border: none !important;
      background: transparent !important;
      font-size: inherit !important;
      vertical-align: baseline;
      max-width: none !important;
      overflow-x: visible !important;
      scrollbar-width: auto !important;
    }

    .inline-math math-field[read-only] .ML__container {
      padding: 0px !important;
    }

    .inline-math math-field[read-only] .ML__container .ML__content {
      padding: 0 1px !important;
    }

    .inline-math math-field[read-only]::-webkit-scrollbar {
      display: none !important;
    }

    
    .inline-math:focus-within math-field {
      background: transparent !important;
    }


    math-field {
      --contains-highlight-background-color: rgba(255, 255, 0, 0.3);
    }

    math-field[read-only] {
      border: none;
      color: white;
    }

    .ML__container {
      padding: 1px !important;
    }

    /* FIX: Ensure the MathLive virtual keyboard appears above the modal backdrop */
.ML__keyboard, .ML__keyboard-host {
    z-index: 1101 !important;
}

.math-input-modal {
  position: fixed;
  left: 50%;
  bottom: 400px;
  transform: translateX(-50%);
  background: rgba(30, 30, 30, 0.95);
  /* backdrop-filter removed from here */
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 20px;
  border-radius: 16px;
  z-index: 1100;
  display: none;
  width: 90%;
  max-width: 600px;
}

.math-input-modal .done-button {
      background: rgba(57, 53, 136, 0.9);
      border: none;
      border-radius: 4px;
      padding: 10px 20px;
      color: #fff;
      font-size: 16px;
      cursor: pointer;
      width: 100%;
    }

    .math-input-modal .math-field-container {
      background: #1e1e1e;
      border-radius: 4px;
      padding: 10px;
      margin-bottom: 10px;
    }

    .math-input-modal header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 10px;
    }

    .math-input-modal header h3 {
      margin: 0;
      font-size: 18px;
      color: #f0f0f0;
    }

    .math-input-modal header button {
      background: transparent;
      border: none;
      color: #f0f0f0;
      font-size: 18px;
      cursor: pointer;
    }

     .math-input-modal math-field {
      width: 100%;
      font-size: 20px;
      color: #f0f0f0;
      background: #1e1e1e;
      border: none;
      outline: none;
    }

    #mathInputModalBackdrop {
    display: block; /* Override the default flex display */
    z-index: 1050;  /* Position it just below the math modal */
}


/* Apple/Streaming UI */

.apple-loading-buttons {
            display: flex;
            align-items: center;
            gap: 8px;
            flex-shrink: 0;
          }


          .apple-loading-container::before {
            content: '';
            position: absolute;
            inset: -100%;
            z-index: -1;
            border-radius: 50%;
            background: radial-gradient(circle at 30% 30%,
                rgba(161, 140, 209, 0.18) 0%,
                rgba(130, 190, 210, 0.12) 45%,
                rgba(0, 0, 0, 0) 75%);
            animation: subtleRotate 30s linear infinite;
          }

          .apple-loading-stop-btn,
          .apple-loading-dropdown-btn {
            background: rgba(255, 255, 255, 0.15);
            border: none;
            color: rgba(255, 255, 255, 0.8);
            border-radius: 50%;
            width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            padding: 0;
            line-height: 1;
            transition: background-color 0.2s ease, color 0.2s ease, transform 0.3s ease-out;
          }

          .apple-loading-dropdown-btn i {
            font-size: 26px;
          }

          .apple-loading-dropdown-btn.open {
            transform: rotate(180deg);
          }

          .apple-loading-stop-btn:hover,
          .apple-loading-dropdown-btn:hover {
            background: rgba(255, 255, 255, 0.25);
            color: rgba(255, 255, 255, 1);
          }

          .apple-loading-main-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 12px;
            min-height: 32px;
          }

          .apple-loading-progress-bar {
            height: 100%;
            width: 0%;
            background: linear-gradient(90deg, #a18cd1 0%, #fbc2eb 100%);
            border-radius: 3px;
            transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
          }

          .apple-loading-progress-bar.animate-timed {
            transition: width 60s linear;
            width: 100%;
          }

          .apple-loading-progress-bar.complete-zoop {
            transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
            width: 100%;
          }

          .apple-loading-progress-track {
            width: 100%;
            height: 6px;
            background-color: rgba(255, 255, 255, 0.18);
            border-radius: 3px;
            overflow: hidden;
          }

          .apple-loading-status-text {
            flex-grow: 1;
            font-size: 15px;
            color: #f0f0f0;
            font-weight: 500;
            transition: opacity 0.3s ease-in-out;
          }

          .apple-loading-stop-btn i {
            font-size: 18px;
          }

          .apple-loading-stream-content {
            background-color: rgba(0, 0, 0, 0.3);
            border-radius: 10px;
            padding: 12px;
            max-height: 180px;
            overflow-y: auto;
            font-family: "SF Mono", Menlo, Monaco, Consolas, "Courier New", monospace;
            font-size: 12.5px;
            color: #c5c5c5;
            white-space: pre-wrap;
            word-break: break-all;
            border: 1px solid rgba(255, 255, 255, 0.15);
            visibility: visible;
            opacity: 1;
            transition: max-height 0.35s ease-in-out, opacity 0.3s ease-in-out 0.05s,
              padding-top 0.35s ease-in-out, padding-bottom 0.35s ease-in-out,
              border-color 0.3s ease-in-out,
              visibility 0s linear 0s;
          }

          .apple-loading-stream-content.collapsed {
            max-height: 0;
            opacity: 0;
            padding-top: 0;
            padding-bottom: 0;
            border-color: transparent;
            overflow: hidden;
            visibility: hidden;
            transition: max-height 0.35s ease-in-out, opacity 0.2s ease-in-out,
              padding-top 0.35s ease-in-out, padding-bottom 0.35s ease-in-out,
              border-color 0.1s linear,
              visibility 0s linear 0.35s;
          }

           .apple-loading-stream-content::-webkit-scrollbar {
            width: 7px;
          }

          .apple-loading-stream-content::-webkit-scrollbar-track {
            background: rgba(0, 0, 0, 0.15);
            border-radius: 3.5px;
          }

          .apple-loading-stream-content::-webkit-scrollbar-thumb {
            background-color: rgba(255, 255, 255, 0.4);
            border-radius: 3.5px;
            border: 1px solid rgba(0, 0, 0, 0.1);
          }

          .apple-loading-stream-content::-webkit-scrollbar-thumb:hover {
            background-color: rgba(255, 255, 255, 0.6);
          }

          
    /* Loading State: Aligns timer with PFP */
    .message-content.is-loading {
        display: flex;
        align-items: center;
        height: 32px; /* Matches exact height of PFP */
        margin: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        line-height: 1;
    }
    
    /* Timer Style */
    .message-content.is-loading .loading-timer {
        font-size: 14px;
        color: #B0B3B8;
        font-weight: 500;
        margin: 0;
        padding: 0;
    }

    .loading-content.extended-loading .animated-thinking-container {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      justify-content: flex-start;
      width: 100%;
      min-height: 1.5em;
      box-sizing: border-box;
    }

    .loading-content.extended-loading .loading-spinner {
      display: none;
    }

    .loading-content.extended-loading .loading-timer {
      display: block;
      position: relative;
      width: 100%;
      text-align: left;
      font-size: 12px;
      color: #aaa;
      margin-top: 2px;
      padding-left: 0;
    }

    .response-timer {
      display: none;
      font-size: 12px;
      color: #aaa;
      margin-left: 10px;
    }

    .thinking-content-area {
    display: none; /* Hidden by default */
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.9em;
    color: #b0a8c9;
    line-height: 1.6;
    word-wrap: break-word;
}

.thinking-message {
      position: absolute;
      left: 0;
      top: 0;
      opacity: 0;
      white-space: nowrap;
      width: auto;
      font-size: 16px;
      font-weight: 400;
      color: transparent;
      text-align: left;
      background: linear-gradient(90deg, #8a8a8a 30%, #d0d0d0 50%, #8a8a8a 70%);
      background-size: 300% 100%;
      background-position: 150% 0;
      -webkit-background-clip: text;
      background-clip: text;
      animation: cycleMessages 12s linear infinite,
        shimmerText 2.5s ease-in-out infinite;
    }

    .thinking-message:nth-child(1) {
      animation-delay: 0s, 0s;
    }

    .thinking-message:nth-child(2) {
      animation-delay: 4s, 0s;
    }

    .thinking-message:nth-child(3) {
      animation-delay: 8s, 0s;
    }


    .thinking-messages-wrapper {
      position: relative;
      height: 1.4em;
      width: 100%;
      display: flex;
      align-items: center;
      margin-bottom: 5px;
      overflow: visible;
    }

    .thinking-shimmer-text {
    font-family: "Rubik", sans-serif;
    font-size: 15px;
    font-weight: 500;
    /* Gradient for shimmer effect */
    background: linear-gradient(to right, #a0a0b0 0%, #ffffff 50%, #a0a0b0 100%);
    background-size: 200% auto;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmerFlash 3s linear infinite;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Ensure it handles clicks */
    pointer-events: none; /* Let parent handle click */
}

/* --- New Shimmering Thinking UI --- */
.thinking-ui-container {
    /* Layout & Alignment */
    display: flex; 
    align-items: center;
    min-height: 32px; /* Matches the exact height of the PFP */
    
    /* Spacing: 10px top margin counteracts the -10px margin on .message-content */
    margin: 10px 0 15px 0; 
    
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    cursor: pointer;
    
    /* Default Style */
    background: transparent;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 0; 
    overflow: hidden;
    width: fit-content;
    max-width: 100%;
}

/* Expanded State: Becomes a rectangle */
.thinking-ui-container.expanded {
    display: block; /* Switch to block to let content flow vertically */
    height: auto;
    background: rgba(30, 30, 40, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 15px 20px;
    width: 100%; 
    margin-top: 5px; /* Slight adjustment when expanded for aesthetics */
}

.thinking-ui-container.expanded .thinking-content-area {
    display: block; /* Show when expanded */
    animation: fadeInContent 0.3s ease-out;
}

.inline-tool-loader {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 10px 14px;
    margin: 12px 0;
    width: fit-content;
}
.inline-loader-spinner {
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(255, 255, 255, 0.25);
    border-top-color: #A78BFA; /* Use an accent color */
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.inline-loader-text {
    font-size: 0.9em;
    color: #b0b3b8;
    font-weight: 500;
    font-family: 'Rubik', sans-serif;
}

.voice-ctrl-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #E4E6EB;
    border-radius: 50%;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 28px; /* Icon size */
    transition: all 0.25s ease;
}

.voice-ctrl-btn.mic-btn {
    background: #A78BFA;
    color: #1C1B22;
    border-color: #A78BFA;
    width: 80px; /* Make the central button larger */
    height: 80px;
    font-size: 36px;
}

.voice-ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.voice-input-area {
    display: none; /* Hidden by default, enabled by JS */
    justify-content: center;
    align-items: center;
    gap: 25px;
    padding: 10px 20px;
    margin-right: 20px;
    flex-shrink: 0;
    height: 148px; 
    box-sizing: border-box;
    margin-top: auto; /* FIX: This pushes the controls to the bottom */
}

   #micBtn {}

    #micBtn.listening i {
      color: #ff6868;
      animation: pulseMic 1.5s infinite ease-in-out;
    }

    @keyframes pulseMic {
      0% {
        transform: scale(1);
        opacity: 1;
      }

      50% {
        transform: scale(1.2);
        opacity: 0.7;
      }

      100% {
        transform: scale(1);
        opacity: 1;
      }
    }

    #voice-visualizer-container {
    position: absolute;
    top: 45%; /* Adjusted from 50% to better center visually */
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1; /* Below the welcome header but above the chat background */
    display: none; /* Controlled by JavaScript */
    pointer-events: none;
}
#voiceVisualizer {
    width: 150px;
    height: 150px;
    background-color: #A78BFA;
    border-radius: 50%;
    box-shadow: 0 0 50px rgba(167, 139, 250, 0.6);
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    animation: pulseVisualizer 2.5s infinite ease-in-out;
}