/* GOOGLE FONTS IMPORT */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
  --primary-color: #19263a;
  --secondary-color: #64b5f6;
  --highlight: #22c55e;
  --danger: #ef4444;
  --danger-dark: #b91c1c;
  --light-bg: #f6f8fa;
  --dark-bg: #101926;
  --card-bg: #fff;
  --card-bg-dark: #1c283a;
  --accent-bg: #f1f3fa;
  --accent-bg-dark: #232f42;
  --border: #ebebef;
  --border-dark: #253040;
  --border-focus: #4abd8b99;
  --shadow: 0 4px 24px 0 rgba(13,22,39,0.12);
  --radius-huge: 28px;
  --radius-large: 16px;
  --radius-med: 10px;
  --radius-small: 5px;

  --font-body: 'Inter', 'Roboto', Arial, sans-serif;
  --font-mono: 'Fira Mono', 'Roboto Mono', Consolas, monospace;
}

html, body {
  height: 100%;
  margin: 0;
  scroll-behavior: smooth;
  font-family: var(--font-body);
  color: #232b3e;
  background: var(--light-bg);
  box-sizing: border-box;
  -webkit-text-size-adjust: 100%;
}

*, *:before, *:after {
  box-sizing: inherit;
}

body {
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height for mobile */
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* === TOP HEADER ========== */
#webcam-toggle {
  height: 54px;
  min-height: 54px;
  background: linear-gradient(90deg, var(--primary-color) 80%, var(--secondary-color) 100%);
  color: #fff;
  font-size: 1.21rem;
  letter-spacing: 1px;
  font-weight: 600;
  box-shadow: 0 2.5px 16px rgba(22,30,50,0.05);
  border-bottom: 2px solid #202c47;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: 2rem;
  user-select: none;
  cursor: pointer;
  z-index: 1400;
  transition: background .18s;
}
#webcam-toggle:hover, #webcam-toggle:focus {
  background: linear-gradient(90deg, #20304a 80%, #4893cc 100%);
}

.theme-dark #webcam-toggle {
  background: linear-gradient(90deg, #101926 80%, #3b5998 100%);
  color: #dadada;
  border-bottom: 2px solid #192944;
}
.theme-dark #webcam-toggle:hover, .theme-dark #webcam-toggle:focus {
  background: linear-gradient(90deg, #19263a 80%, #447fb6 100%);
}

.main-flex {
  flex: 1;
  height: calc(100vh - 54px);
  height: calc(100dvh - 54px); /* Dynamic viewport height */
  display: flex;
  flex-direction: row;
  overflow: hidden;
  background: var(--light-bg);
  min-width: 0;
}

.theme-dark .main-flex {
  background: var(--dark-bg);
}

/* SIDEBAR (CAM & SETTINGS) */
#webcam-container {
  width: 0;
  min-width: 0;
  height: 100%;
  background: var(--card-bg-dark);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: width .3s cubic-bezier(.65,.1,.65,1), min-width .3s;
  box-shadow: none;
  border-right: none;
}

#webcam-container.expanded {
  width: 390px;
  min-width: 290px;
  box-shadow: 2px 0 38px 0 #18214216;
  border-right: 2px solid var(--border-dark);
}

.theme-dark #webcam-container {
  background: var(--card-bg-dark);
  border-right: 2px solid var(--border-dark);
}
.theme-dark #webcam-container.expanded {
  box-shadow: 2px 0 38px 0 #04080d70;
  border-right: 2px solid var(--border-dark);
}

@media (max-width: 900px) {
  #webcam-container.expanded {
    width: 98vw;
    min-width: 0;
  }
}

/* SIDEBAR MENU */
#settings-container {
  position: relative;
  z-index: 1201;
  height: 100%;
  min-width: 0;
  width: 100%;
  background: var(--accent-bg);
  border-left: none;
  box-shadow: none;
  transition: width 0.3s;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
#settings-container.open {
  width: 100%;
  min-width: 0;
  background: var(--accent-bg);
}

.theme-dark #settings-container,
.theme-dark #settings-container.open {
  background: var(--accent-bg-dark);
}

#settings-menu {
  padding: 30px 14px 24px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  overflow-y: auto;
  height: 100%;
  scrollbar-width: thin;
}

@media (max-width: 900px) {
  #settings-menu {
    padding: 17px 5px 25px 5px;
  }
}

/* MENU SECTIONS */
.settings-section {
  background: var(--card-bg);
  border-radius: var(--radius-huge);
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  padding: 21px 17px 13px 17px;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 13px;
  position: relative;
  transition: box-shadow .18s, border-color .18s;
}
.settings-section:hover, .settings-section:focus-within {
  box-shadow: 0 4px 32px 0 #7ed4c829;
  border-color: var(--border-focus);
}

.theme-dark .settings-section {
  background: var(--card-bg-dark);
  border: 1.5px solid var(--border-dark);
  box-shadow: 0 4px 24px 0 #080F24bb;
}

.settings-section h3 {
  font-size: 1.19rem;
  font-weight: 600;
  color: var(--primary-color);
  padding-bottom: 4px;
  border-bottom: 2px solid var(--highlight);
  margin: 0 0 11px 0;
  letter-spacing: .5px;
  text-align: left;
}

.theme-dark .settings-section h3 {
  color: #b1e1c1;
  border-bottom: 2px solid var(--highlight);
}

/* Section subtitle (optional) */
.settings-section .subtitle {
  color: #65748a;
  font-size: .97em;
  font-weight: 400;
  margin-bottom: 6px;
}

.theme-dark .settings-section .subtitle {
  color: #72e5bb;
}

/* Webcam preview */
#cam-settings-section video {
  width: 198px;
  height: 144px;
  background: #102135;
  border-radius: var(--radius-large);
  border: 1.5px solid var(--border-dark);
  box-shadow: 0 2px 16px #18214214;
  aspect-ratio: 11 / 8;
  margin-bottom: 11px;
  object-fit: cover;
  display: block;
  transition: filter 0.36s, transform 0.42s;
}

.theme-dark #cam-settings-section video {
  background: #263356;
  border: 1.5px solid #314161;
  box-shadow: 0 2px 15px #01092e55;
}

video.grayscale { filter: grayscale(1); }
video.mirrored { transform: scaleX(-1); }

/* Labels inside settings */
.settings-section label {
  display: flex;
  align-items: center;
  font-size: 1em;
  font-weight: 500;
  color: #22304c;
  margin-bottom: 3px;
  gap: 7px;
}

.theme-dark .settings-section label {
  color: #d7e7f5;
}

.settings-section label > input[type="checkbox"] {
  width: 1.2em;
  height: 1.2em;
  margin-right: 7px;
  accent-color: var(--highlight);
}

/* Inputs, selects, textareas */
.settings-section select,
.settings-section textarea,
.settings-section input[type="text"],
.settings-section input[type="number"] {
  border: 1.5px solid var(--border-dark);
  border-radius: var(--radius-med);
  padding: 7.5px 13px;
  font-size: 1em;
  background: var(--accent-bg);
  transition: border .18s;
  margin-bottom: 11px;
  font-family: var(--font-body);
  color: #232b3e;
  outline: none;
  box-sizing: border-box;
}

.theme-dark .settings-section textarea,
.theme-dark .settings-section select,
.theme-dark .settings-section input[type="text"], 
.theme-dark .settings-section input[type="number"] {
  background: var(--accent-bg-dark);
  border: 1.5px solid var(--border-dark);
  color: #e1f3dc;
}

.settings-section textarea {
  min-height: 52px;
  background: var(--accent-bg);
  resize: vertical;
}

.theme-dark .settings-section textarea,
.theme-dark .settings-section input,
.theme-dark .settings-section select {
  color-scheme: dark;
}

.settings-section select[multiple] {
  min-height: 120px;
  max-height: 234px;
}

.settings-section select:focus,
.settings-section textarea:focus,
.settings-section input[type="text"]:focus,
.settings-section input[type="number"]:focus {
  border: 1.5px solid var(--highlight);
  outline: none;
}

.settings-section button {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 11px 0;
  border-radius: var(--radius-large);
  background: var(--highlight);
  color: #fff;
  font-size: 1.03rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: background .15s, color .13s;
  box-shadow: 0 2px 10px 0 #00d92c13;
}

.theme-dark .settings-section button,
.theme-dark #send-button,
.theme-dark #clear-chat-button,
.theme-dark #save-persona-button {
  box-shadow: 0 2px 12px 0 #05392330;
  background: var(--highlight);
  color: #101926;
}

.theme-dark .settings-section button:hover,
.theme-dark #send-button:hover,
.theme-dark #save-persona-button:hover {
  background: #19c160;
  color: #fff;
}

#clear-chat-button {
  background: var(--danger);
  margin-top: 9px;
}

.theme-dark #clear-chat-button {
  background: #cf3535;
}

#clear-chat-button:hover, #clear-chat-button:focus {
  background: var(--danger-dark);
}

.theme-dark #clear-chat-button:hover {
  background: #b91c1c;
}

#save-persona-button {
  background: var(--secondary-color);
}

.theme-dark #save-persona-button {
  background: #498df1;
  color: #10213f;
}

.theme-dark #save-persona-button:hover {
  background: #346db2;
  color: #fff;
}

#save-persona-button:hover {
  background: #447fb6;
}

/* Custom persona cardlook */
#custom-persona-settings {
  background: var(--accent-bg);
  padding: 14px 9px 12px 12px;
  border-radius: var(--radius-med);
  border: 1.5px solid var(--border-dark);
  margin-top: 2px;
  box-shadow: none;
}

.theme-dark #custom-persona-settings {
  background: var(--accent-bg-dark);
  border: 1.5px solid var(--border-dark);
}

#custom-persona-settings label {
  font-size: .99em;
  font-weight: 400;
}

/* Extra: Option groups separation if used */
.settings-section .option-group {
  margin-bottom: 11px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e6e9f0;
}

/* CHAT AREA ============================ */
#chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  background: var(--card-bg);
  box-shadow: 0 3px 42px rgba(60,80,130,0.07);
  border-radius: 0;
  transition: margin .20s cubic-bezier(.71,.01,.61,.89);
  position: relative;
  min-width: 0;
}

.theme-dark #chat-container {
  background: var(--card-bg-dark);
  box-shadow: 0 4px 56px #2d4b5c1a;
}

#chat-container.shrink {
  margin-right: 340px;
}
@media (max-width: 900px) {
  #chat-container.shrink {
    margin-right: 0;
  }
}

/* Messages area (reverse for chat feed) */
#chat-messages {
  flex: 1;
  padding: 36px 11vw 112px 11vw;
  background: var(--card-bg);
  display: flex;
  flex-direction: column-reverse;
  border-radius: 0 0 var(--radius-huge) var(--radius-huge);
  overflow-y: auto;
  min-height: 0;
  max-width: 900px;
  margin: 0 auto;
}

.theme-dark #chat-messages {
  background: var(--card-bg-dark);
  color: #e7f4f5;
  scrollbar-color: #3bd892 #1a3127;
}

@media (max-width:800px) {
  #chat-messages {
    padding: 13px 6vw 93px 6vw;
    max-width: 100vw;
  }
}

@media (max-width:600px) {
  #chat-messages {
    padding: 7px 2vw 89px 2vw;
    border-radius: 0 !important;
  }
}

/* Each message */
.message {
  display: inline-block;
  background: #f5f8ee;
  padding: 14px 24px;
  margin-bottom: 16px;
  border-radius: 22px;
  max-width: 91%;
  word-break: break-word;
  font-size: 1.11em;
  line-height: 1.62;
  box-shadow: 0 3px 13px rgba(70,128,64,0.08);
  position: relative;
  border: 1.2px solid rgba(220,233,200,0.07);
  transition: background .18s;
}

.theme-dark .message {
  background: #223639;
  color: #cdf7e6;
  border: 1.2px solid #0e2a1c;
  box-shadow: 0 3px 13px #22ebbb18;
}

/* user (right bubble) */
.user-message {
  background: linear-gradient(90deg, #e3ecff 80%, #c0ddff 100%);
  align-self: flex-end;
  text-align: right;
  color: #246add;
  border-top-right-radius: 8px;
  border-bottom-right-radius: 20px;
}

.theme-dark .user-message {
  background: linear-gradient(90deg, #2c4256 70%, #31476c 100%);
  color: #39edff;
}

.ai-message {
  background: linear-gradient(90deg, #e9f7df 70%, #f0ffee 98%);
  align-self: flex-start;
  text-align: left;
  color: #224b19;
  border-top-left-radius: 8px;
  border-bottom-left-radius: 22px;
}

.theme-dark .ai-message {
  background: linear-gradient(90deg, #193123 92%, #023f25 100%);
  color: #7be497;
}

.message.error-message {
  background: linear-gradient(90deg, #ffeaea 75%, #ffecec 100%);
  color: var(--danger-dark);
  border: 1.5px solid #ffb9b9;
}

.theme-dark .message.error-message {
  background: linear-gradient(90deg, #61011b 75%, #a30b29 100%);
  color: #ffe4e4;
  border: 1.5px solid #b94b4b;
}

/* Typing indicator */
.typing-indicator {
  font-style: italic;
  color: #84878f;
  opacity: 0.80;
  align-self: flex-start;
  padding: 8px 26px;
  font-size: 1em;
}

.theme-dark .typing-indicator {
  color: #89a8ad;
}

/*=== INPUT BAR ==========*/
#chat-input-area {
  width: 100vw;
  display: flex;
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  background: var(--card-bg);
  border-top: 2px solid #eaeef3;
  box-shadow: 0 -2px 36px 0 #e0edfc1c;
  align-items: center;
  padding: 12px 14vw 12px 12vw;
  z-index: 1600;
  gap: 9px;
}

.theme-dark #chat-input-area {
  background: var(--accent-bg-dark);
  border-top: 2px solid #22334b;
  box-shadow: 0 -2px 28px 0 #132b2830;
}

#chat-input-area input, #chat-input-area button {
  font-size: 1.05em;
}

#chat-input {
  flex: 1;
  padding: 13px 17px;
  border-radius: var(--radius-huge);
  border: 1.5px solid var(--border-dark);
  background: var(--accent-bg);
  outline: none;
  transition: border .17s, box-shadow .13s;
  font-family: var(--font-body);
  margin-right: 8px;
  min-width: 0;
}

.theme-dark #chat-input {
  background: #19293c;
  border: 1.5px solid #446766;
  color: #c2fde4;
}

#chat-input:focus {
  border: 1.5px solid var(--highlight);
  box-shadow: 0 0 5px #c1fee7;
}

.theme-dark #chat-input:focus {
  border: 1.5px solid var(--highlight);
  box-shadow: 0 0 5px #57ffde;
}

#send-button {
  min-width: 94px;
  padding: 0 27px;
  height: 45px;
  border-radius: var(--radius-large);
  font-size: .98em;
  font-weight: 600;
  background: var(--highlight);
  color: #fff;
  letter-spacing: 0.04em;
  border: none;
  cursor: pointer;
  transition: background .14s, color .13s;
  box-shadow: 0 1px 7px 0 #22c55c10;
}

.theme-dark #send-button {
  background: var(--highlight);
  color: #0a3712;
}

#send-button:hover, #send-button:focus {
  background: #0b893b;
}

.theme-dark #send-button:hover,
.theme-dark #send-button:focus {
  background: #34dd7c;
  color: #0a161c;
}

#image-gen-button {
    min-width: 46px;
    padding: 0;
    height: 45px;
    border-radius: var(--radius-large);
    background: var(--secondary-color);
    color: #fff;
    border: none;
    cursor: pointer;
    transition: background 0.14s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
}

#image-gen-button:hover, #image-gen-button:focus {
    background: #447fb6;
    transform: translateY(-1px);
}

.theme-dark #image-gen-button {
    background: #498df1;
    color: #10213f;
}

.theme-dark #image-gen-button:hover,
.theme-dark #image-gen-button:focus {
    background: #346db2;
    color: #fff;
}

#eye-mode-toggle {
    min-width: 46px;
    padding: 0;
    height: 45px;
    border-radius: var(--radius-large);
    background: var(--highlight);
    color: #fff;
    border: none;
    cursor: pointer;
    transition: background 0.14s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
}

#eye-mode-toggle:hover, #eye-mode-toggle:focus {
    background: #0b893b;
    transform: translateY(-1px);
}

#eye-mode-toggle.active {
    background: var(--secondary-color);
}

#eye-mode-toggle.active:hover {
    background: #447fb6;
}

.theme-dark #eye-mode-toggle {
    background: var(--highlight);
    color: #0a3712;
}

.theme-dark #eye-mode-toggle:hover,
.theme-dark #eye-mode-toggle:focus {
    background: #34dd7c;
    color: #0a161c;
}

.theme-dark #eye-mode-toggle.active {
    background: #498df1;
    color: #10213f;
}

.theme-dark #eye-mode-toggle.active:hover {
    background: #346db2;
    color: #fff;
}

/* Camera view overlay for EYE mode */
#camera-overlay {
    position: fixed;
    top: 54px;
    left: 20px;
    width: 320px;
    height: 240px;
    background: var(--card-bg-dark);
    border: 2px solid var(--highlight);
    border-radius: var(--radius-large);
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    z-index: 9999;
    display: none;
    overflow: hidden;
}

#camera-overlay.show {
    display: block;
}

#camera-overlay video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: calc(var(--radius-large) - 2px);
}

.theme-dark #camera-overlay {
    background: var(--card-bg-dark);
    border: 2px solid var(--highlight);
}

@media (max-width: 768px) {
    #camera-overlay {
        top: 48px;
        left: 10px;
        width: 240px;
        height: 180px;
    }
    
    #eye-mode-toggle {
        min-width: 42px;
        height: 42px;
    }
}

@media (max-width: 480px) {
    #camera-overlay {
        top: 44px;
        left: 5px;
        width: 200px;
        height: 150px;
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Enhanced message styling for generated images */
.message img {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    display: block;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    transition: transform 0.2s ease;
}

.message img:hover {
    transform: scale(1.02);
    cursor: pointer;
}

.theme-dark .message img {
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

/* Visual improvement for select dropdown */
.settings-section select, .settings-section input, .settings-section textarea {
  box-shadow: 0 1px 2.5px #d7f7de17;
}

/* Grouped controls (toggle + label) */
.settings-toggle-row {
  display: flex;
  align-items: center;
  gap: 17px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}

@media (max-width: 600px) {
  #settings-menu {
    gap: 13px;
  }
  #webcam-container.expanded {
    min-width: 0 !important;
    width: 99vw;
    max-width: 100vw;
  }
}

/* Hide scrollbars on mobile for clean look */
@media (max-width: 600px) {
  #chat-messages, #settings-menu {
    scrollbar-width: none;
  }
  #chat-messages::-webkit-scrollbar, #settings-menu::-webkit-scrollbar {
    display: none;
  }
}

/* Extra polish: input autofill color fix for Chrome/Edge */
input:-webkit-autofill { 
  box-shadow: 0 0 0 44px #e5f8e3 inset !important;
  -webkit-text-fill-color: #193f2c !important;
}

.theme-dark input:-webkit-autofill { 
  box-shadow: 0 0 0 44px #153a2fdd inset !important;
  -webkit-text-fill-color: #78f4c8 !important;
}

/* SVG icon (if used later, e.g. for theme) */
.icon-btn {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  border-radius: 50%;
  transition: background .14s;
}

.icon-btn:hover { background: #e3fbae; }

.theme-dark .icon-btn:hover {
  background: #233a3c;
}

/* DARK MODE OVERHAUL */
body.theme-dark, .theme-dark body {
  background: var(--dark-bg);
  color: #f0f3fa;
}

/* Accent colors for dark mode */
.theme-dark :root {
  --highlight: #48f192;
  --danger: #ff5570;
  --danger-dark: #b91c1c;
  --light-bg: #19283a;
  --dark-bg: #111c26;
  --card-bg-dark: #1a2536;
  --accent-bg-dark: #1c2432;
  --border-dark: #21684b;
}

/* --- Responsive tweaks for dark mode (reuse existing media queries) --- */
@media (max-width: 900px) {
  .theme-dark #webcam-container.expanded {
    background: var(--card-bg-dark);
  }
}

@media (max-width: 700px) {
  .theme-dark .settings-section {
    background: var(--card-bg-dark);
  }
}

/* RESPONSIVE IMPROVEMENTS */
@media (max-width: 768px) {
  #webcam-toggle {
    font-size: 1.1rem;
    padding-left: 1rem;
    height: 48px;
    min-height: 48px;
  }
  
  .main-flex {
    height: calc(100vh - 48px);
    height: calc(100dvh - 48px);
  }
  
  #chat-messages {
    padding: 10px 3vw 80px 3vw;
  }
  
  #chat-input-area {
    padding: 8px 3vw 8px 3vw;
  }
}

@media (max-width: 480px) {
  #webcam-toggle {
    font-size: 1rem;
    padding-left: 0.5rem;
    height: 44px;
    min-height: 44px;
  }
  
  .main-flex {
    height: calc(100vh - 44px);
    height: calc(100dvh - 44px);
  }
  
  #chat-messages {
    padding: 8px 2vw 75px 2vw;
  }
  
  #chat-input-area {
    padding: 6px 2vw 6px 2vw;
  }
  
  #send-button {
    min-width: 60px;
    padding: 0 10px;
    font-size: 0.9em;
  }
}

/* Landscape orientation fixes */
@media (orientation: landscape) and (max-height: 500px) {
  #webcam-toggle {
    height: 40px;
    min-height: 40px;
    font-size: 0.95rem;
  }
  
  .main-flex {
    height: calc(100vh - 40px);
    height: calc(100dvh - 40px);
  }
  
  #settings-menu {
    padding: 10px 8px 15px 8px;
    gap: 15px;
  }
}

/* ANALYSIS MODES POPUP STYLES */
.analysis-modes-popup-btn {
  background: var(--secondary-color) !important;
  color: #fff !important;
  font-size: 0.95em !important;
  padding: 8px 12px !important;
  margin-top: 8px !important;
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  border-radius: var(--radius-med) !important;
}

.theme-dark .analysis-modes-popup-btn {
  background: #498df1 !important;
  color: #10213f !important;
}

.analysis-modes-popup-btn:hover {
  background: #447fb6 !important;
}

.theme-dark .analysis-modes-popup-btn:hover {
  background: #346db2 !important;
  color: #fff !important;
}

.analysis-popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50000;
  padding: 20px;
}

.analysis-popup-overlay.show {
  display: flex;
}

.analysis-popup-modal {
  background: var(--card-bg);
  border-radius: var(--radius-huge);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.3);
  width: 90vw;
  max-width: 800px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border: 2px solid var(--highlight);
}

.theme-dark .analysis-popup-modal {
  background: var(--card-bg-dark);
  border: 2px solid var(--highlight);
}

.analysis-popup-header {
  padding: 20px 25px 15px 25px;
  border-bottom: 2px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.theme-dark .analysis-popup-header {
  border-bottom: 2px solid var(--border-dark);
}

.analysis-popup-header h2 {
  margin: 0;
  font-size: 1.4em;
  font-weight: 600;
  color: var(--primary-color);
}

.theme-dark .analysis-popup-header h2 {
  color: #b1e1c1;
}

.analysis-popup-close {
  background: none;
  border: none;
  font-size: 2em;
  cursor: pointer;
  color: var(--primary-color);
  padding: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.analysis-popup-close:hover {
  background: var(--accent-bg);
}

.theme-dark .analysis-popup-close {
  color: #b1e1c1;
}

.theme-dark .analysis-popup-close:hover {
  background: var(--accent-bg-dark);
}

.analysis-popup-content {
  padding: 20px 25px;
  flex: 1;
  overflow-y: auto;
}

.analysis-modes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin-top: 15px;
}

.analysis-mode-item {
  background: var(--accent-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-med);
  padding: 12px 15px;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}

.analysis-mode-item:hover {
  border-color: var(--highlight);
  background: var(--card-bg);
}

.analysis-mode-item.selected {
  border-color: var(--highlight);
  background: var(--highlight);
  color: #fff;
}

.theme-dark .analysis-mode-item {
  background: var(--accent-bg-dark);
  border: 2px solid var(--border-dark);
  color: #e1f3dc;
}

.theme-dark .analysis-mode-item:hover {
  border-color: var(--highlight);
  background: var(--card-bg-dark);
}

.theme-dark .analysis-mode-item.selected {
  background: var(--highlight);
  color: #101926;
}

.analysis-mode-title {
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 1.05em;
}

.analysis-mode-description {
  font-size: 0.9em;
  opacity: 0.8;
  line-height: 1.4;
}

.analysis-popup-actions {
  padding: 15px 25px 20px 25px;
  border-top: 2px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.theme-dark .analysis-popup-actions {
  border-top: 2px solid var(--border-dark);
}

.analysis-popup-apply, .analysis-popup-cancel {
  padding: 10px 20px;
  border-radius: var(--radius-med);
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
}

.analysis-popup-apply {
  background: var(--highlight);
  color: #fff;
}

.analysis-popup-apply:hover {
  background: #0b893b;
}

.analysis-popup-cancel {
  background: var(--accent-bg);
  color: var(--primary-color);
  border: 2px solid var(--border);
}

.analysis-popup-cancel:hover {
  background: var(--border);
}

.theme-dark .analysis-popup-apply {
  background: var(--highlight);
  color: #101926;
}

.theme-dark .analysis-popup-apply:hover {
  background: #34dd7c;
}

.theme-dark .analysis-popup-cancel {
  background: var(--accent-bg-dark);
  color: #d7e7f5;
  border: 2px solid var(--border-dark);
}

.theme-dark .analysis-popup-cancel:hover {
  background: var(--border-dark);
}

/* Mobile adjustments for popup */
@media (max-width: 768px) {
  .analysis-popup-modal {
    width: 95vw;
    max-height: 85vh;
  }
  
  .analysis-modes-grid {
    grid-template-columns: 1fr;
  }
  
  .analysis-popup-header {
    padding: 15px 20px 12px 20px;
  }
  
  .analysis-popup-content {
    padding: 15px 20px;
  }
  
  .analysis-popup-actions {
    padding: 12px 20px 15px 20px;
    flex-direction: column;
  }
}