/**
 * Multi-AI Chat Interface Styles
 * v2.4 - Re-added Model Label styles
 */

/* =================================================================== */
/* === 1. COLLAPSED BAR STYLES (Default View) === */
/* =================================================================== */

#mac-wrapper-main {
  width: 100%;
  max-width: 600px; /* Max width of the collapsed bar */
  margin: 30px auto;
  position: relative;
  z-index: 1000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

#mac-logo {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 40px;
  padding: 0 15px;
  margin-bottom: 5px;
  opacity: 1;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#mac-chat-container {
  width: 100%;
  position: relative;
  background: #121212;
  border: 1px solid #2b2b2b;
  border-radius: 30px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  height: 60px;
  overflow: hidden;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#mac-chat-container .mac-input-area {
  position: relative;
  height: 100%;
  background: transparent;
  display: flex;
  align-items: center;
}

#mac-prompt-input-collapsed {
  width: 100%;
  height: 60px;
  font-size: 16px;
  border: none;
  background: transparent;
  color: #eee;
  padding: 19px 115px 19px 25px; /* Make space for 2 buttons */
  border-radius: 30px;
  box-sizing: border-box;
  outline: none !important;
  line-height: 1.4;
  resize: none;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#mac-prompt-input-collapsed::-webkit-scrollbar {
  width: 0px;
  background: transparent;
}
#mac-prompt-input-collapsed::placeholder {
  color: #9aa0a6;
}

#mac-send-button-collapsed {
  position: absolute;
  right: 6px;
  top: 5px;
  bottom: 5px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  font-size: 22px;
  background: linear-gradient(145deg, #0073e6, #005bb5);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, opacity 0.2s ease, background 0.3s ease;
}
#mac-send-button-collapsed:hover {
  background: linear-gradient(145deg, #3399ff, #0073e6);
}
#mac-send-button-collapsed:active {
  transform: scale(0.96);
}
#mac-send-button-collapsed::before {
  content: "⮝";
  font-weight: 700;
  line-height: 1;
}

/* Collapsed History Toggle Button */
.mac-history-toggle-btn {
  position: absolute;
  right: 62px; /* 50px for send + 6px padding + 6px */
  top: 5px;
  bottom: 5px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: #333;
  color: #ccc;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.mac-history-toggle-btn:hover {
  background: #444;
  color: #fff;
}
.mac-history-toggle-btn svg {
  transition: transform 0.2s ease;
}
.mac-history-toggle-btn:hover svg {
  transform: scale(1.1);
}


/* --- Modern Auth Modal --- */
.mac-auth-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(10, 10, 10, 0.8);
    backdrop-filter: blur(12px);
    z-index: 9999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    font-family: 'Inter', -apple-system, sans-serif;
}

.mac-auth-container {
    width: 100%;
    max-width: 960px;
    height: 640px;
    background: #ffffff;
    display: flex;
    position: relative;
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.mac-auth-close {
    position: absolute;
    top: 20px; right: 20px;
    background: #f3f4f6; border: none; color: #4b5563;
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; z-index: 10; transition: all 0.2s;
}
.mac-auth-close:hover { background: #e5e7eb; color: #111; }

/* Left Side Content */
.mac-auth-left {
    flex: 1.1;
    position: relative;
    background: #000 url('https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe?q=80&w=1000&auto=format&fit=crop') no-repeat center center;
    background-size: cover;
    padding: 60px;
    display: flex;
    align-items: flex-end;
    color: #fff;
}

.mac-auth-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.2) 100%);
}

.mac-auth-left-content { position: relative; z-index: 2; }

.mac-auth-badge {
    display: inline-block;
    padding: 4px 12px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 100px;
    font-size: 12px;
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.mac-auth-left h2 { font-size: 32px; font-weight: 700; line-height: 1.2; margin-bottom: 15px; color: white; }
.mac-auth-left p { color: rgba(255,255,255,0.7); line-height: 1.6; margin-bottom: 25px; }

.mac-auth-features { list-style: none; padding: 0; margin: 0; }
.mac-auth-features li { margin-bottom: 12px; font-size: 15px; display: flex; align-items: center; gap: 10px; }

/* Right Side Content */
.mac-auth-right {
    flex: 1;
    background: #fff;
    padding: 60px 50px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.mac-view-header { margin-bottom: 35px; }
.mac-view-header h3 { font-size: 24px; color: #111; margin: 0 0 8px 0; }
.mac-view-header p { color: #6b7280; font-size: 15px; }

.mac-input-group { margin-bottom: 20px; }
.mac-input-group label { display: block; font-size: 13px; font-weight: 600; color: #374151; margin-bottom: 6px; }
.mac-input-group input {
    width: 100%; padding: 12px 16px; border: 1px solid #d1d5db;
    border-radius: 10px; font-size: 15px; transition: border 0.2s;
}
.mac-input-group input:focus { outline: none; border-color: #0073e6; ring: 2px rgba(0,115,230,0.1); }

.mac-auth-primary-btn {
    width: 100%; padding: 14px; background: #111; color: #fff;
    border: none; border-radius: 10px; font-weight: 600; cursor: pointer;
    transition: background 0.2s; margin-top: 10px;
}
.mac-auth-primary-btn:hover { background: #333; }

.mac-auth-divider {
    text-align: center; margin: 25px 0; position: relative;
}
.mac-auth-divider:before { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: #eee; z-index: 1; }
.mac-auth-divider span { background: #fff; padding: 0 15px; position: relative; z-index: 2; color: #999; font-size: 13px; }

/* Plan Cards Grid */
.mac-plans-grid { display: flex; gap: 15px; margin-bottom: 25px; }
.mac-plan-card {
    flex: 1; border: 1px solid #e5e7eb; border-radius: 16px; padding: 20px;
    position: relative; transition: all 0.2s;
}
.mac-plan-card:hover { border-color: #0073e6; transform: translateY(-2px); }
.mac-plan-card.pro { border: 2px solid #0073e6; background: #f0f7ff; }

.plan-tag {
    font-size: 9px; text-transform: uppercase; font-weight: 800;
    color: #0073e6; margin-bottom: 10px;
}
.mac-plan-card h4 { font-size: 16px; margin: 0 0 10px 0; color: #111; }
.plan-price { font-size: 24px; font-weight: 700; color: #111; }
.plan-price span { font-size: 14px; font-weight: 400; color: #6b7280; }

.plan-features { list-style: none; padding: 0; margin: 15px 0; font-size: 12px; color: #4b5563; }
.plan-features li { margin-bottom: 6px; }

.mac-plan-btn {
    width: 100%; padding: 8px; border: 1px solid #111; background: transparent;
    border-radius: 8px; font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.pro .mac-plan-btn { background: #111; color: #fff; }
.mac-plan-btn:hover { background: #111; color: #fff; }

.mac-toggle-auth a { color: #0073e6; text-decoration: none; font-weight: 600; }
.mac-toggle-auth a:hover { text-decoration: underline; }

/* Responsive Mobile */
@media (max-width: 768px) {
    .mac-auth-container { flex-direction: column; height: auto; max-height: 90vh; }
    .mac-auth-left { display: none; }
    .mac-plans-grid { flex-direction: column; }
}

/* =================================================================== */
/* === 2. MODAL WRAPPER STYLES (Hidden by default) === */
/* =================================================================== */

#mac-modal-wrapper {
  display: none; /* Hidden by default */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2147483645;
  opacity: 0;
  transition: opacity 0.3s ease;
  align-items: center;
  justify-content: center;
}

.mac-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1;
}

.mac-modal-content {
  display: flex;
  position: relative;
  z-index: 2;
  width: 90vw;
  max-width: 1200px; /* Max width of sidebar + chat */
  height: 85vh;
  max-height: 900px;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  transition: all 0.3s ease-out;
}


.mac-auth-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.mac-auth-container {
    width: 900px;
    height: 600px;
    background: #1a1a1a;
    display: flex;
    position: relative;
    border-radius: 15px;
    overflow: hidden;
}
.mac-auth-close {
    position: absolute;
    top: 15px; right: 20px;
    background: none; border: none; color: #fff; font-size: 30px; cursor: pointer; z-index: 10;
}
.mac-auth-left {
    flex: 1;
    background: linear-gradient(rgba(0,0,0,0.6), rgba(0,0,0,0.6)), url('https://your-image-url.com/bg.jpg'); /* Update this URL */
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center;
    padding: 40px;
    color: #fff;
}
.mac-auth-right {
    flex: 1;
    padding: 40px;
    background: #fff;
    color: #333;
    overflow-y: auto;
}
.mac-auth-right h3 { margin-bottom: 20px; color: #111; }
.mac-auth-right input {
    width: 100%; padding: 12px; margin-bottom: 15px;
    border: 1px solid #ddd; border-radius: 5px;
}
.mac-primary-btn, .mac-plan-btn {
    width: 100%; padding: 12px; background: #0073e6; color: #fff;
    border: none; border-radius: 5px; cursor: pointer; font-weight: bold;
}
.mac-plan-card {
    border: 1px solid #eee; padding: 15px; margin-bottom: 15px; border-radius: 8px;
}
.mac-toggle-auth { margin-top: 20px; font-size: 14px; text-align: center; }

/* =================================================================== */
/* === 3. EXPANDED MODAL STATES (JS-driven) === */
/* =================================================================== */

/* --- Main "Modal Open" State --- */
body.mac-modal-open #mac-logo {
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
}
body.mac-modal-open #mac-chat-container {
  opacity: 0;
  transform: scale(0.95);
  pointer-events: none;
}
body.mac-modal-open #mac-modal-wrapper {
  display: flex; /* Use flex to center the content */
  opacity: 1;
}

/* --- State 1: Chat-Only View (Default Expanded) --- */
#mac-modal-wrapper:not(.sidebar-visible) .mac-sidebar {
  width: 0;
  padding: 0;
  border-right: none;
  overflow: hidden;
}
#mac-modal-wrapper:not(.sidebar-visible) .mac-sidebar > * {
  display: none;
}
#mac-modal-wrapper:not(.sidebar-visible) #mac-desktop-history-btn {
  display: flex;
}

/* --- State 2: History View (Sidebar Visible) --- */
#mac-modal-wrapper.sidebar-visible .mac-sidebar {
  width: 280px;
  border-right: 1px solid #333;
}
#mac-modal-wrapper.sidebar-visible .mac-sidebar > * {
  display: flex; /* or block, as needed */
}
#mac-modal-wrapper.sidebar-visible .mac-sidebar-actions {
  display: flex;
  flex-direction: column;
}
#mac-modal-wrapper.sidebar-visible .mac-sidebar-header,
#mac-modal-wrapper.sidebar-visible .mac-history-search-wrapper,
#mac-modal-wrapper.sidebar-visible .mac-session-list {
  display: block;
}
#mac-modal-wrapper.sidebar-visible #mac-desktop-history-btn {
  display: none;
}

/* =================================================================== */
/* === 4. SIDEBAR STYLES === */
/* =================================================================== */

.mac-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: #1e1e1e;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.3s ease, padding 0.3s ease, border 0.3s ease;
}

.mac-sidebar-header {
  padding: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

.mac-sidebar-logo {
  max-height: 40px;
  width: auto;
  max-width: 150px;
  filter: brightness(0) invert(1);
}
.mac-sidebar-actions {
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}
.mac-sidebar-btn {
  display: block;
  width: 100%;
  padding: 10px 15px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95em;
  font-weight: 600;
  text-align: center;
  transition: background-color 0.2s ease;
}
.mac-new-chat-btn {
  background-color: #0073e6;
  color: #ffffff;
}
.mac-new-chat-btn:hover {
  background-color: #005bb5;
}
.mac-voice-mode-btn {
  background-color: #495057;
  color: #f8f9fa;
}
.mac-voice-mode-btn:hover {
  background-color: #6c757d;
}
.mac-history-search-wrapper {
  position: relative;
  padding: 0 15px 15px 15px;
  flex-shrink: 0;
}
.mac-history-search-wrapper .search-icon {
  position: absolute;
  top: 50%;
  left: 27px;
  transform: translateY(-50%);
  color: #999;
  width: 16px;
  height: 16px;
}
.mac-history-search-input {
  width: 100%;
  padding: 8px 12px 8px 35px;
  border-radius: 20px;
  border: 1px solid #333;
  background-color: #1a1a1a;
  color: #eee;
  box-sizing: border-box;
  font-size: 0.9em;
}
.mac-history-search-input:focus {
  outline: none;
  border-color: #0073e6;
}
.mac-session-list {
  list-style: none;
  padding: 0 15px;
  margin: 0;
  flex-grow: 1;
  overflow-y: auto;
}
.mac-session-list li {
  position: relative;
  margin-bottom: 5px;
}
.mac-session-list li a {
  display: block;
  padding: 12px;
  border-radius: 8px;
  text-decoration: none;
  color: #eee;
  cursor: pointer;
  transition: background-color 0.2s;
  padding-right: 38px;
}
.mac-session-list li a:hover {
  background-color: #2a2a2a;
}
.mac-session-list li a.active {
  background-color: #0073e6;
  color: #fff;
  font-weight: 600;
}
.mac-session-list .session-title {
  font-weight: 500;
  font-size: 0.95em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mac-session-list .session-date {
  font-size: 0.8em;
  color: #999;
  margin-top: 4px;
}
.mac-session-list li a.active .session-date {
  color: rgba(255, 255, 255, 0.7);
}
.mac-list-placeholder p {
  text-align: center;
  color: #888;
  padding: 20px 0;
}
.udap-delete-session-btn {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  padding: 0;
  background-color: transparent;
  color: #999;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  opacity: 0;
  transition: all 0.2s;
  z-index: 5;
}
.mac-session-list li:hover .udap-delete-session-btn {
  opacity: 0.6;
}
.udap-delete-session-btn:hover {
  opacity: 1;
  color: #dc3545;
  transform: translateY(-50%) scale(1.1);
}

/* =================================================================== */
/* === 5. CHAT PANEL STYLES (Modal Right) === */
/* =================================================================== */

.mac-chat-panel {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  min-width: 0;
  background: #1a1a1a;
}
.mac-chat-panel .mac-header-controls {
  flex-shrink: 0;
  border-bottom: 1px solid #333;
  background: #1e1e1e;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  display: flex;
  flex-direction: column;
  position: relative;
}

.mac-header-top-row {
  display: flex;
  align-items: center;
  padding: 10px 15px;
  border-bottom: 1px solid #2b2b2b;
}

.mac-chat-panel .mac-toolbar {
  padding: 0;
  border-bottom: none;
  display: flex;
  align-items: center;
  flex-grow: 1;
  justify-content: flex-start;
  margin-left: 10px;
}
.mac-chat-panel .mac-toolbar label {
  font-size: 13px;
  font-weight: 600;
  color: #aaa;
  margin-right: 6px;
}
#mac-default-model-select {
  background: #222;
  color: #eee;
  border: 1px solid #444;
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 12px;
}
#mac-default-model-select option {
  background: #1a1a1a;
  color: #eee;
}

.mac-chat-panel .mac-tabs {
  display: flex;
  flex-wrap: wrap;
  padding: 5px 10px 0 10px;
  background: #1e1e1e;
}
.mac-chat-panel .mac-tab {
  padding: 10px 15px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: #aaa;
  border-bottom: 3px solid transparent;
  margin-right: 8px;
  transition: all .2s ease;
}
.mac-chat-panel .mac-tab:hover { color: #fff; }
.mac-chat-panel .mac-tab.active { color: #4aa3ff; border-bottom-color: #4aa3ff; }
.mac-chat-panel .mac-tab .spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 6px;
  vertical-align: middle;
  border: 2px solid rgba(255,255,255,.2);
  border-top-color: #4aa3ff;
  border-radius: 50%;
  animation: mac-spin 1s linear infinite;
}
@keyframes mac-spin { to { transform: rotate(360deg); } }

.mac-chat-panel .mac-chat-area {
  flex-grow: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  background: #181818;
  color: #eee;
  width: 100%;
  box-sizing: border-box;
}
.mac-chat-panel .mac-chat-window { display: none; }
.mac-chat-panel .mac-chat-window.active { display: block; }

.mac-chat-panel .message {
  max-width: 80%;
  padding: 10px 16px;
  border-radius: 16px;
  margin-bottom: 12px;
  line-height: 1.45;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.mac-chat-panel .message.user {
  background: #0073e6;
  color: #fff;
  border-bottom-right-radius: 4px;
  margin-left: auto;
}
.mac-chat-panel .message.ai {
  background: #2a2a2a;
  color: #f1f1f1;
  border-bottom-left-radius: 4px;
  margin-right: auto;
  white-space: pre-wrap;
}
.mac-chat-panel .message.error { background: #442222; color: #ff8888; border: 1px solid #663333; }
.mac-chat-panel .message.pending { background: #2a2a2a; color: #aaa; font-style: italic; }

.mac-chat-panel .message.system-placeholder {
  background: #222;
  color: #999;
  text-align: center;
  font-style: italic;
  max-width: 100%;
  box-shadow: none;
}

/* Modal Chat Input Area */
.mac-chat-panel .mac-input-area {
  height: auto;
  border: none;
  border-radius: 0;
  border-top: 1px solid #333;
  background: #1e1e1e;
  padding: 15px;
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  max-width: 1000px;
  width: calc(100% - 30px);
  margin: 0 auto;
}
#mac-prompt-input-modal {
  flex-grow: 1;
  padding: 11px 18px;
  font-size: 14px;
  line-height: 1.4;
  margin-right: 10px;
  min-height: 42px;
  max-height: 150px;
  background: #2a2a2a;
  color: #eee;
  box-shadow: none;
  outline: none;
  width: 100%;
  height: auto;
  border: 1px solid #444;
  border-radius: 21px;
  resize: none;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#mac-prompt-input-modal::-webkit-scrollbar {
  width: 0px;
  background: transparent;
}
#mac-prompt-input-modal:focus {
  border-color: #0073e6;
}
#mac-send-button-modal {
  position: static;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 20px;
  flex-shrink: 0;
  background: linear-gradient(145deg, #0073e6, #005bb5);
  color: #fff;
  border: none;
  cursor: pointer;
}
#mac-send-button-modal:hover {
  background: linear-gradient(145deg, #3399ff, #0073e6);
}
#mac-send-button-modal::before {
  content: "⮝";
  font-weight: 700;
}

/* =================================================================== */
/* === 6. SHARED MODAL & MISC STYLES === */
/* =================================================================== */

.mac-modal-close-btn {
  font-size: 28px;
  color: #999;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  z-index: 10;
  margin-left: auto; /* Pushes it to the right */
  flex-shrink: 0;
}
.mac-modal-close-btn:hover {
  color: #fff;
}

/* Custom Scrollbars */
.mac-chat-area::-webkit-scrollbar,
.mac-session-list::-webkit-scrollbar {
  width: 0px !important;
  background: transparent !important;
}
.mac-chat-area,
.mac-session-list {
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}

/* Message Wrappers & Timestamps */
.user-wrapper,
.ai-wrapper,
.error-wrapper {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
  max-width: 80%;
  box-sizing: border-box;
}
.mac-chat-panel .message {
  margin-bottom: 2px;
}
.user-wrapper { align-items: flex-end; margin-left: auto; margin-right: 0; }
.ai-wrapper,
.error-wrapper { align-items: flex-start; margin-right: auto; margin-left: 0; }
.message-timestamp {
  font-size: 0.75em;
  color: #999;
  padding: 0 10px;
  margin-top: 2px;
  display: inline-block;
}

/* **NEW** Model Label */
.message-model-label {
  font-size: 0.7em;
  font-weight: 600;
  color: #aaa;
  margin-left: 12px;
  margin-bottom: 3px;
  opacity: 0.8;
}
body.is-light-mode .message-model-label { color: #777; }

/* Theme Toggle Button */
#mac-theme-toggle {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid #444;
  background: #1e1e1e;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 15px;
  flex-shrink: 0;
  overflow: hidden;
  padding: 0;
}
#mac-theme-toggle span {
  position: absolute;
  transition: opacity 0.3s ease, transform 0.3s ease;
  line-height: 1;
}
#mac-theme-toggle .icon-dark { opacity: 1; transform: rotate(0deg); }
#mac-theme-toggle .icon-light { opacity: 0; transform: rotate(90deg); }

body.is-light-mode #mac-theme-toggle .icon-dark {
  opacity: 0;
  transform: rotate(-90deg);
}
body.is-light-mode #mac-theme-toggle .icon-light {
  opacity: 1;
  transform: rotate(0deg);
}

/* Mobile Toggles (Hidden by default) */
.mac-mobile-menu-toggle {
  display: none; /* Hide toggles on desktop */
  background: none;
  border: none;
  color: #eee;
  font-size: 24px;
  cursor: pointer;
  padding: 5px;
  z-index: 10;
  flex-shrink: 0;
}
#mac-mobile-menu-open { margin-right: 10px; }
#mac-mobile-menu-close { font-size: 28px; }

/* Desktop History Button */
.mac-desktop-history-btn {
  display: flex; /* Show on desktop */
  align-items: center;
  background: #333;
  color: #eee;
  border: 1px solid #444;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-left: 5px; /* Give it space from the edge */
  margin-right: 10px;
  flex-shrink: 0;
  transition: all 0.2s ease;
}
.mac-desktop-history-btn:hover {
  background: #444;
  color: #fff;
}

/* =================================================================== */
/* === 7. LIGHT MODE OVERRIDES === */
/* =================================================================== */

/* --- Light Mode: Collapsed Bar --- */
body.is-light-mode #mac-wrapper-main #mac-logo { filter: none; }
body.is-light-mode #mac-chat-container {
  background: #fff;
  border-color: #ccc;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
}
body.is-light-mode #mac-prompt-input-collapsed { color: #333; }
body.is-light-mode #mac-prompt-input-collapsed::placeholder { color: #999; }
body.is-light-mode .mac-history-toggle-btn {
  background: #f0f0f0;
  color: #555;
}
body.is-light-mode .mac-history-toggle-btn:hover {
  background: #e0e0e0;
  color: #111;
}

/* --- Light Mode: Modal Wrapper --- */
body.is-light-mode .mac-modal-backdrop { background: rgba(0, 0, 0, 0.15); }
body.is-light-mode .mac-modal-content {
  background: #f8f8f8;
  border-color: #ddd;
}

/* --- Light Mode: Sidebar --- */
body.is-light-mode .mac-sidebar {
  background: #fdfdfd;
  border-right-color: #ddd;
}
body.is-light-mode .mac-sidebar-header { border-bottom-color: #ddd; }
body.is-light-mode .mac-sidebar-logo { filter: none; }
body.is-light-mode .mac-voice-mode-btn {
  background-color: #e9ecef;
  color: #495057;
}
body.is-light-mode .mac-voice-mode-btn:hover { background-color: #dde2e6; }
body.is-light-mode .mac-history-search-input {
  background-color: #f0f0f0;
  border-color: #ddd;
  color: #333;
}
body.is-light-mode .mac-history-search-input:focus { border-color: #0073e6; }
body.is-light-mode .mac-session-list li a { color: #333; }
body.is-light-mode .mac-session-list li a:hover { background-color: #f0f0f0; }
body.is-light-mode .mac-session-list li a.active {
  background-color: #e0e7ff;
  color: #0056b3;
}
body.is-light-mode .mac-session-list .session-date { color: #777; }
body.is-light-mode .mac-session-list li a.active .session-date { color: #0056b3; }
body.is-light-mode .udap-delete-session-btn { color: #888; }
body.is-light-mode .udap-delete-session-btn:hover { color: #dc3545; }
body.is-light-mode .mac-mobile-menu-toggle { color: #333; }

/* --- Light Mode: Chat Panel --- */
body.is-light-mode .mac-chat-panel { background-color: #fff; }
body.is-light-mode .mac-chat-panel .mac-header-controls {
  background: #f8f8f8;
  border-bottom-color: #ddd;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
body.is-light-mode .mac-chat-panel .mac-header-top-row { border-bottom-color: #eee; }
body.is-light-mode .mac-chat-panel .mac-toolbar label { color: #666; }
body.is-light-mode #mac-default-model-select {
  background: #fff; color: #333; border-color: #ddd;
}
body.is-light-mode .mac-chat-panel .mac-tab { color: #777; }
body.is-light-mode .mac-chat-panel .mac-tab:hover { color: #333; }
body.is-light-mode .mac-chat-panel .mac-chat-area {
  background: #f3f3f3; color: #333;
}
body.is-light-mode .mac-chat-panel .message.ai,
body.is-light-mode .mac-chat-panel .message.pending {
  background: #e9e9e9; color: #333;
}
body.is-light-mode .mac-chat-panel .message.user {
  background: #0073e6; color: #fff;
}
body.is-light-mode .mac-chat-panel .message.system-placeholder {
  background: #ddd; color: #555;
}
body.is-light-mode .message-timestamp { color: #555; }
body.is-light-mode .mac-chat-panel .mac-input-area {
  background: #f8f8f8; border-top-color: #ddd;
}
body.is-light-mode #mac-prompt-input-modal {
  background: #ffffff; color: #333; border-color: #ddd;
}
body.is-light-mode #mac-prompt-input-modal:focus { border-color: #0073e6; }
body.is-light-mode #mac-prompt-input-modal::placeholder { color: #999; }
body.is-light-mode .mac-modal-close-btn { color: #777; }
body.is-light-mode .mac-modal-close-btn:hover { color: #111; }
body.is-light-mode .mac-desktop-history-btn {
  background: #f0f0f0; color: #555; border-color: #ddd;
}
body.is-light-mode .mac-desktop-history-btn:hover {
  background: #e0e0e0; color: #111;
}

/* =================================================================== */
/* === 8. RESPONSIVE & MOBILE TOGGLE STYLES === */
/* =================================================================== */

@media (max-width: 900px) { /* Tablet view */
  .mac-modal-content {
    width: 95vw;
    max-width: 95vw;
  }
}

@media (max-width: 768px) { /* Mobile view */
  #mac-wrapper-main {
    width: 100%;
    max-width: 100%;
    margin: 0;
    height: auto;
  }
  #mac-logo { padding-top: 20px; }

  #mac-modal-wrapper { align-items: stretch; }

  .mac-modal-content {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
    flex-direction: column;
    position: relative;
  }

  .mac-sidebar {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 300px;
    max-width: 90%;
    transform: translateX(-100%);
    z-index: 1001;
    transition: transform 0.3s ease-out;
    border-right: 1px solid #333;
  }

  .mac-chat-panel {
    width: 100%;
    flex-grow: 1;
    height: 100%;
  }

  #mac-modal-wrapper.sidebar-visible .mac-sidebar {
    transform: translateX(0);
    box-shadow: 5px 0 15px rgba(0,0,0,0.2);
  }

  .mac-mobile-menu-toggle { display: block; } /* Show mobile buttons */
  .mac-desktop-history-btn { display: none; } /* Hide desktop button */

  .mac-modal-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
  }
  #mac-modal-wrapper.sidebar-visible .mac-modal-backdrop { display: block; }

  .mac-modal-backdrop { z-index: 2; }

  .mac-chat-panel .mac-input-area {
    width: calc(100% - 20px);
    padding: 10px;
  }
  #mac-prompt-input-modal {
    padding: 10px 15px;
    min-height: 40px;
  }
  #mac-send-button-modal {
    width: 40px;
    height: 40px;
  }

  #mac-prompt-input-collapsed {
    padding: 19px 115px 19px 20px;
  }
}

/* ============================================================= */
/* === FIX: Show only hamburger on mobile, history on desktop === */
/* ============================================================= */

/* Default: show desktop history, hide hamburger */
.mac-desktop-history-btn { display: flex !important; }
.mac-mobile-menu-toggle { display: none !important; }

/* On mobile (≤768px): hide desktop history, show hamburger */
@media (max-width: 768px) {
  .mac-desktop-history-btn { display: none !important; }
  .mac-mobile-menu-toggle { display: block !important; }
}

/* ============================================================= */
/* === MOBILE FONT-SIZE + SPACING FIX (≤768px) === */
/* ============================================================= */

@media (max-width: 768px) {

  /* Sidebar general scaling */
  .mac-sidebar { font-size: 14px; }

  /* Buttons */
  .mac-sidebar-btn {
    font-size: 14px;
    padding: 9px 14px;
  }
  .mac-new-chat-btn { font-size: 15px; }
  .mac-voice-mode-btn { font-size: 14px; }

  /* Search input */
  .mac-history-search-input {
    font-size: 13px;
    padding: 7px 10px 7px 32px;
  }
  .mac-history-search-wrapper .search-icon {
    left: 18px;
    width: 14px;
    height: 14px;
  }

  /* Session list */
  .mac-session-list li a { padding: 10px 10px 10px 32px; }
  .mac-session-list .session-title {
    font-size: 14px;
    line-height: 1.3;
  }
  .mac-session-list .session-date { font-size: 12px; }

  /* Chat area font size */
  .mac-chat-panel .message {
    font-size: 15px;
    line-height: 1.45;
  }
  .message-timestamp { font-size: 12px; }

  /* Tabs and model select */
  .mac-chat-panel .mac-tab {
    font-size: 13px;
    padding: 8px 10px;
  }
  #mac-default-model-select {
    font-size: 12px;
    padding: 2px 5px;
  }

  /* Input area */
  #mac-prompt-input-modal {
    font-size: 14px;
    padding: 10px 14px;
  }
  #mac-send-button-modal {
    width: 38px;
    height: 38px;
    font-size: 18px;
  }

  /* Toolbar / header elements */
  .mac-header-top-row { padding: 8px 12px; }
  .mac-chat-panel .mac-toolbar label { font-size: 12px; }

  /* Model label under messages */
  .message-model-label { font-size: 11px; }

  /* Adjust top buttons layout spacing */
  .mac-mobile-menu-toggle {
    font-size: 22px;
    padding: 4px;
  }
}

/* =================================================================== */
/* === 9. ADD TO KNOWLEDGE BASE BUTTON + TOAST (v2.7 addition) === */
/* =================================================================== */

/* Positioning hook for Add button */
.user-wrapper,
.ai-wrapper,
.error-wrapper {
  position: relative; /* Needed so .mac-add-to-kb-btn anchors correctly */
}

/* * ===================================================================
 * === ADJUSTMENTS FOR BUTTON INSIDE BUBBLE ===
 * We'll adjust the 'right' and 'bottom' properties relative to the message bubble.
 * The .ai-wrapper now needs position: relative; and the message itself
 * needs its own padding adjusted to make space for the button.
 * =================================================================== */
.mac-add-to-kb-btn {
  position: absolute;
  /* Adjust these values to position inside the bubble */
  bottom: 6px; /* Position from the bottom of the AI message bubble */
  right: 5px;  /* Position from the right of the AI message bubble */
  background-color: #0073e6;
  color: white;
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease, background-color 0.2s ease;
  transform: scale(0.8);
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Keep text stable: pseudo-content prevents layout shift */
.mac-add-to-kb-btn:before {
  content: '+';
  font-weight: bold;
  font-size: 16px;
  line-height: 1;
}

/* Shows on wrapper hover OR button hover (prevents flicker) */
.ai-wrapper:hover .mac-add-to-kb-btn,
.mac-add-to-kb-btn:hover {
  opacity: 1;
  transform: scale(1);
}

.mac-add-to-kb-btn:hover {
  background-color: #005bb5;
  transform: scale(1.1);
}

.mac-add-to-kb-btn.mac-added {
  background-color: #28a745; /* Green for success */
  cursor: default;
}
.mac-add-to-kb-btn.mac-added:before {
  content: '✓';
}

.mac-add-to-kb-btn.mac-loading {
  background-color: #ffc107; /* Yellow for loading */
  color: #333;
  cursor: wait;
}
.mac-add-to-kb-btn.mac-loading:before {
  content: '...';
  font-weight: bold;
  line-height: 1;
}

/* Toast Notification */
.mac-toast-notification {
  position: fixed;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #333;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  z-index: 2147483647;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
  transition: top 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.mac-toast-notification.mac-toast-show { top: 20px; }
.mac-toast-notification.mac-toast-success { background-color: #28a745; }
.mac-toast-notification.mac-toast-error { background-color: #dc3545; }


/* IMPORTANT: ADJUSTMENTS FOR THE AI MESSAGE ITSELF */
/* To make space for the button, we need to increase padding on the AI message */
.mac-chat-panel .message.ai {
  padding-right: 45px; /* Increase right padding to make space for the button */
  position: relative; /* Ensure the button positions relative to this bubble */
}