/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* === emBlue Design Tokens === */
:root {
  --emblue-primary: #004DBC;
  --emblue-primary-hover: #0F68E8;
  --emblue-primary-light: #D4E4FF;
  --emblue-secondary: #D3DDEA;
  --emblue-secondary-hover: #F4F5FA;
  --emblue-tertiary: #FC7E00;
  --emblue-tertiary-hover: #FF9C39;
  --emblue-success: #18C678;
  --emblue-success-light: #E1FFF0;
  --emblue-warning: #FFB114;
  --emblue-warning-light: #FFF7E1;
  --emblue-info: #11CFFA;
  --emblue-info-light: #CFF6FE;
  --emblue-negative: #FF4242;
  --emblue-negative-light: #FFC1BC;
  --emblue-disabled: #A7B1CC;
  --emblue-disabled-bg: #EAF1F9;
  --emblue-text: #111827;
  --emblue-subheadings: #364365;
  --emblue-tiles: #002646;
  --emblue-borders: #D3DDEA;
  --emblue-app-background: #D3DDEA;
  --emblue-muted: #F4F5FA;

  --radius-sm: 2px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.08);
}

html, body {
  height: 100%;
  font-family: 'Roboto', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--emblue-app-background);
  color: var(--emblue-text);
  overflow: hidden;
  font-size: 14px;
}

/* === Login Screen === */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--emblue-app-background);
}

.login-card {
  width: 380px;
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--emblue-borders);
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  padding: 40px 32px;
  text-align: center;
}

.login-logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--emblue-primary);
  margin-bottom: 4px;
}

.login-tagline {
  font-size: 13px;
  color: var(--emblue-subheadings);
  margin-bottom: 28px;
}

.login-form {
  text-align: left;
}

.login-form .form-group {
  margin-bottom: 16px;
}

.login-form label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--emblue-text);
}

.login-form input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  background: #ffffff;
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-sm);
  color: var(--emblue-text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: all 0.15s;
}

.login-form input:focus {
  border-color: var(--emblue-primary);
  box-shadow: 0 0 0 1px var(--emblue-primary);
}

.login-error {
  color: var(--emblue-negative);
  font-size: 13px;
  margin-bottom: 12px;
  min-height: 18px;
}

.login-btn {
  width: 100%;
  height: 40px;
  background: var(--emblue-primary);
  border: none;
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

.login-btn:hover {
  background: var(--emblue-primary-hover);
}

.login-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.login-screen.hidden,
.app.hidden {
  display: none !important;
}

/* === App Layout === */
.app {
  display: flex;
  height: 100vh;
}

/* === Sidebar === */
.sidebar {
  width: 272px;
  min-width: 272px;
  background: #ffffff;
  border-right: 1px solid var(--emblue-borders);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 20px;
  overflow-y: auto;
  transition: width 0.25s ease, min-width 0.25s ease, padding 0.25s ease;
}

/* Toggle button */
.sidebar-toggle {
  background: none;
  border: none;
  color: var(--emblue-disabled);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  align-self: flex-end;
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  color: var(--emblue-primary);
  background: var(--emblue-muted);
}

/* === Sidebar Collapsed === */
.sidebar.collapsed {
  width: 56px;
  min-width: 56px;
  padding: 12px 8px;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.sidebar.collapsed .sidebar-toggle {
  align-self: center;
}

/* Hide ALL text labels and sections */
.sidebar.collapsed .nav-label,
.sidebar.collapsed .tagline,
.sidebar.collapsed .sidebar-history,
.sidebar.collapsed .sidebar-templates h3,
.sidebar.collapsed .sidebar-header {
  display: none;
}

/* Nav → circular icon buttons */
.sidebar.collapsed .sidebar-nav {
  gap: 4px;
}

.sidebar.collapsed .nav-btn {
  justify-content: center;
  padding: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  gap: 0;
}

.sidebar.collapsed .nav-icon {
  font-size: 1.15rem;
  width: auto;
}

/* Templates → hide all, show only via JS toggle */
.sidebar.collapsed .sidebar-templates {
  position: relative;
  align-items: center;
}

.sidebar.collapsed .template-btn {
  display: none;
}

.sidebar.collapsed .sidebar-templates::before {
  content: "✦";
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--emblue-borders);
  color: var(--emblue-subheadings);
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s;
}

.sidebar.collapsed .sidebar-templates:hover::before {
  background: var(--emblue-primary);
  color: #ffffff;
  border-color: var(--emblue-primary);
}

/* Popover for templates when collapsed */
.sidebar.collapsed .sidebar-templates:hover .template-btn {
  display: flex;
  position: absolute;
  left: 52px;
  background: #ffffff;
  border: 1px solid var(--emblue-borders);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  border-radius: var(--radius-md);
  white-space: nowrap;
  z-index: 100;
  width: auto;
  padding: 7px 14px;
}

.sidebar.collapsed .sidebar-templates:hover .template-btn:nth-child(1) { top: -80px; }
.sidebar.collapsed .sidebar-templates:hover .template-btn:nth-child(2) { top: -48px; }
.sidebar.collapsed .sidebar-templates:hover .template-btn:nth-child(3) { top: -16px; }
.sidebar.collapsed .sidebar-templates:hover .template-btn:nth-child(4) { top: 16px; }
.sidebar.collapsed .sidebar-templates:hover .template-btn:nth-child(5) { top: 48px; }
.sidebar.collapsed .sidebar-templates:hover .template-btn:nth-child(6) { top: 80px; }
.sidebar.collapsed .sidebar-templates:hover .template-btn:nth-child(7) { top: 112px; }

/* Footer → icon only */
.sidebar.collapsed .sidebar-footer {
  padding-top: 4px;
  border: none;
}

.sidebar.collapsed .clear-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.sidebar.collapsed .clear-btn .nav-label {
  display: none;
}

.sidebar.collapsed .clear-btn .nav-icon {
  font-size: 1.1rem;
}

.sidebar-header {
  text-align: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--emblue-borders);
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--emblue-primary);
  letter-spacing: -0.01em;
}

.tagline {
  font-size: 12px;
  color: var(--emblue-subheadings);
  margin-top: 4px;
}

/* Nav */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--emblue-subheadings);
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  font-family: inherit;
}

.nav-btn:hover {
  background: var(--emblue-muted);
  color: var(--emblue-text);
}

.nav-btn.active {
  background: var(--emblue-primary);
  color: #ffffff;
  font-weight: 500;
}

.nav-icon {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
}

/* History */
.sidebar-history h3 {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--emblue-disabled);
  margin-bottom: 8px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 200px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 12px;
  background: #ffffff;
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-sm);
  color: var(--emblue-subheadings);
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  font-family: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item:hover {
  background: var(--emblue-primary);
  color: #ffffff;
  border-color: var(--emblue-primary);
}

.history-item.active {
  background: var(--emblue-primary-light);
  border-color: var(--emblue-primary);
  color: var(--emblue-primary);
  font-weight: 500;
}

.history-empty {
  font-size: 12px;
  color: var(--emblue-disabled);
  padding: 4px 0;
}

/* Templates */
.sidebar-templates h3 {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--emblue-disabled);
  margin-bottom: 8px;
}

.template-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 12px;
  margin-bottom: 3px;
  background: #ffffff;
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-sm);
  color: var(--emblue-subheadings);
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  font-family: inherit;
}

.tpl-icon {
  flex-shrink: 0;
  width: 18px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--emblue-disabled);
  font-style: normal;
}

.template-btn:hover {
  background: var(--emblue-primary);
  color: #ffffff;
  border-color: var(--emblue-primary);
}

.template-btn:hover .tpl-icon {
  color: #ffffff;
}

/* Footer */
.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--emblue-borders);
}

.clear-btn {
  width: 100%;
  padding: 8px;
  background: #ffffff;
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-sm);
  color: var(--emblue-subheadings);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.clear-btn:hover {
  border-color: var(--emblue-negative);
  color: var(--emblue-negative);
}

/* === Main Content === */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #ffffff;
  margin: 8px 8px 8px 0;
  border-radius: var(--radius-lg);
  border: 1px solid var(--emblue-borders);
  box-shadow: var(--shadow-card);
}

.view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}

.view.active {
  display: flex;
}

/* === Chat View — Split Layout === */
.chat-split {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  transition: flex 0.3s ease;
}

.chat-split.has-preview .chat-panel {
  flex: 0 0 42%;
  max-width: 42%;
  border-right: 1px solid var(--emblue-borders);
}

/* Live Preview (right side) */
.live-preview {
  display: none;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  background: var(--emblue-app-background);
}

.chat-split.has-preview .live-preview {
  display: flex;
}

.live-preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: #ffffff;
  border-bottom: 1px solid var(--emblue-borders);
}

.live-preview-modes {
  display: flex;
  gap: 2px;
  background: var(--emblue-muted);
  border-radius: var(--radius-md);
  padding: 2px;
}

.lp-mode {
  padding: 4px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--emblue-subheadings);
  font-size: 12px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.lp-mode.active {
  background: #ffffff;
  color: var(--emblue-text);
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.live-preview-actions {
  display: flex;
  gap: 4px;
}

.live-preview-actions .action-btn {
  padding: 4px 10px;
  font-size: 12px;
}

.live-preview-content {
  flex: 1;
  overflow: auto;
  padding: 16px;
  display: flex;
  justify-content: center;
}

.live-preview-frame-wrapper {
  width: 100%;
  max-width: 100%;
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--emblue-borders);
  overflow: hidden;
  transition: max-width 0.3s ease;
}

.live-preview-frame {
  width: 100%;
  min-height: 500px;
  border: none;
  background: #ffffff;
}

.live-preview-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--emblue-disabled);
  font-size: 14px;
  gap: 4px;
  text-align: center;
  padding: 24px;
}

.live-preview-empty p:first-child {
  font-size: 2rem;
}

.live-preview-content.hidden {
  display: none;
}

.live-preview-empty.hidden {
  display: none;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--emblue-muted);
}

.message {
  display: flex;
  gap: 12px;
  max-width: 80%;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  background: var(--emblue-secondary-hover);
  border: 1px solid var(--emblue-borders);
}

.message.user .message-avatar {
  background: color-mix(in srgb, var(--emblue-primary) 15%, white);
  border-color: var(--emblue-primary-light);
}

.message-content {
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  line-height: 1.6;
  font-size: 14px;
  color: var(--emblue-text);
  border: 1px solid var(--emblue-borders);
  box-shadow: var(--shadow-card);
}

.message.user .message-content {
  background: var(--emblue-primary);
  border-color: var(--emblue-primary);
  color: #ffffff;
}

.message-content p {
  margin-bottom: 8px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content pre {
  background: var(--emblue-tiles);
  color: #e2e8f0;
  border-radius: var(--radius-md);
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 12px;
  max-height: 200px;
  border: 1px solid var(--emblue-borders);
}

.message-content code {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
}

.message-content .preview-inline-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 6px 16px;
  background: var(--emblue-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

.message.user .message-content .preview-inline-btn {
  background: #ffffff;
  color: var(--emblue-primary);
}

.message-content .preview-inline-btn:hover {
  background: var(--emblue-primary-hover);
}

.message.user .message-content .preview-inline-btn:hover {
  background: var(--emblue-muted);
}

/* Loading indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 8px 0;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--emblue-disabled);
  animation: bounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Chat Input */
.chat-input-area {
  padding: 12px 24px 8px;
  border-top: 1px solid var(--emblue-borders);
  background: #ffffff;
  position: relative;
}

/* === Contact Fields Panel === */
.fields-panel {
  position: absolute;
  bottom: 100%;
  left: 24px;
  width: 320px;
  max-height: 360px;
  background: #ffffff;
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-lg);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  z-index: 50;
  overflow: hidden;
}

.fields-panel.hidden {
  display: none;
}

.fields-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--emblue-borders);
}

.fields-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--emblue-text);
}

.fields-panel-close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--emblue-disabled);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.fields-panel-close:hover {
  color: var(--emblue-negative);
}

.fields-search {
  margin: 8px 12px;
  height: 30px;
  padding: 0 10px;
  background: var(--emblue-muted);
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-sm);
  color: var(--emblue-text);
  font-size: 12px;
  font-family: inherit;
  outline: none;
}

.fields-search:focus {
  border-color: var(--emblue-primary);
}

.fields-search::placeholder {
  color: var(--emblue-disabled);
}

.fields-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.fields-group-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--emblue-disabled);
  padding: 8px 6px 4px;
}

.field-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
}

.field-item:hover {
  background: var(--emblue-muted);
}

.field-item-var {
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 11px;
  color: var(--emblue-primary);
  background: color-mix(in srgb, var(--emblue-primary) 8%, white);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.field-item-label {
  font-size: 12px;
  color: var(--emblue-subheadings);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-item-type {
  font-size: 10px;
  color: var(--emblue-disabled);
  flex-shrink: 0;
}

.fields-loading {
  text-align: center;
  padding: 20px;
  font-size: 12px;
  color: var(--emblue-disabled);
}

.fields-btn {
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -1px;
}

/* Chat attachments preview */
.chat-attachments {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-bottom: 0;
}

.chat-attachments:empty {
  display: none;
}

.attachment-preview {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-md);
  border: 1px solid var(--emblue-borders);
  overflow: hidden;
  background: var(--emblue-muted);
  margin-bottom: 8px;
}

.attachment-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--emblue-negative);
  color: #ffffff;
  border: none;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--emblue-disabled);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.attach-btn:hover {
  color: var(--emblue-primary);
  background: var(--emblue-muted);
}

.input-wrapper {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: #ffffff;
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  transition: all 0.15s;
}

.input-wrapper:focus-within {
  border-color: var(--emblue-primary);
  box-shadow: 0 0 0 1px var(--emblue-primary);
}

#chatInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--emblue-text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
}

#chatInput::placeholder {
  color: var(--emblue-disabled);
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--emblue-primary);
  border: none;
  color: #ffffff;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-btn:hover {
  background: var(--emblue-primary-hover);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Model selector bar */
.chat-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 6px;
}

/* Token counter */
.token-counter {
  display: flex;
  align-items: center;
  gap: 4px;
}

.token-label {
  font-size: 11px;
  color: var(--emblue-disabled);
  font-weight: 500;
}

.token-value {
  font-size: 11px;
  font-weight: 600;
  color: var(--emblue-subheadings);
  font-variant-numeric: tabular-nums;
}

.token-detail {
  font-size: 10px;
  color: var(--emblue-disabled);
}

/* Mode selector (segmented control) */
.mode-selector {
  display: flex;
  gap: 2px;
  background: var(--emblue-muted);
  border-radius: var(--radius-md);
  padding: 2px;
}

.mode-btn {
  padding: 3px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--emblue-subheadings);
  font-size: 11px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
}

.mode-btn:hover:not(.active) {
  color: var(--emblue-text);
}

.mode-btn.active {
  background: #ffffff;
  color: var(--emblue-text);
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* === Preview View === */
.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  border-bottom: 1px solid var(--emblue-borders);
  background: #ffffff;
}

.preview-modes {
  display: flex;
  gap: 2px;
  background: var(--emblue-muted);
  border-radius: var(--radius-md);
  padding: 3px;
}

.preview-mode {
  padding: 6px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--emblue-subheadings);
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.preview-mode.active {
  background: #ffffff;
  color: var(--emblue-text);
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* Preview View Toggle */
.preview-view-toggle {
  display: flex;
  gap: 2px;
  background: var(--emblue-muted);
  border-radius: var(--radius-md);
  padding: 3px;
}

.view-toggle-btn {
  padding: 6px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--emblue-subheadings);
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.view-toggle-btn.active {
  background: #ffffff;
  color: var(--emblue-text);
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.view-toggle-btn:hover:not(.active) {
  color: var(--emblue-text);
}

.preview-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  padding: 6px 16px;
  background: #ffffff;
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-sm);
  color: var(--emblue-subheadings);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.action-btn:hover {
  background: var(--emblue-muted);
  color: var(--emblue-text);
}

.preview-container {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 24px;
  background: var(--emblue-app-background);
  overflow: auto;
}

.preview-frame-wrapper {
  width: 100%;
  max-width: 100%;
  transition: max-width 0.3s ease;
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--emblue-borders);
  overflow: hidden;
}

.preview-frame {
  width: 100%;
  min-height: 600px;
  border: none;
  background: #ffffff;
}

/* Code Editor */
.code-editor-container {
  flex: 1;
  display: flex;
  padding: 24px;
  background: var(--emblue-app-background);
  overflow: auto;
}

.code-editor-container.hidden {
  display: none;
}

.code-editor {
  width: 100%;
  min-height: 100%;
  padding: 16px;
  background: var(--emblue-tiles);
  color: #e2e8f0;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-lg);
  resize: none;
  outline: none;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  box-shadow: var(--shadow-card);
}

.code-editor:focus {
  border-color: var(--emblue-primary);
  box-shadow: 0 0 0 1px var(--emblue-primary);
}

.no-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--emblue-subheadings);
  font-size: 14px;
  gap: 8px;
  background: var(--emblue-app-background);
}

.no-preview p:first-child {
  font-size: 16px;
  font-weight: 500;
  color: var(--emblue-text);
}

.no-preview.hidden {
  display: none;
}

.preview-container.hidden {
  display: none;
}

/* === Images View === */
.images-view {
  overflow: hidden;
}

.images-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  border-bottom: 1px solid var(--emblue-borders);
  background: #ffffff;
}

.images-tabs {
  display: flex;
  gap: 2px;
  background: var(--emblue-muted);
  border-radius: var(--radius-md);
  padding: 3px;
}

.images-tab {
  padding: 6px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--emblue-subheadings);
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.images-tab.active {
  background: #ffffff;
  color: var(--emblue-text);
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.images-toolbar-actions {
  display: flex;
  gap: 8px;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  background: var(--emblue-primary);
  border: none;
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

.upload-btn:hover {
  background: var(--emblue-primary-hover);
}

/* Panels */
.images-panel {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.images-panel.hidden {
  display: none;
}

/* Dropzone */
.upload-dropzone {
  border: 2px dashed var(--emblue-borders);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  transition: all 0.2s;
  margin-bottom: 24px;
  cursor: default;
}

.upload-dropzone.dragover {
  border-color: var(--emblue-primary);
  background: color-mix(in srgb, var(--emblue-primary) 5%, white);
}

.dropzone-icon {
  font-size: 2rem;
  margin-bottom: 8px;
}

.dropzone-text {
  font-size: 14px;
  color: var(--emblue-subheadings);
  margin-bottom: 4px;
}

.dropzone-hint {
  font-size: 12px;
  color: var(--emblue-disabled);
}

/* Images Grid */
.images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.image-card {
  background: #ffffff;
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all 0.15s;
  box-shadow: var(--shadow-card);
}

.image-card:hover {
  border-color: var(--emblue-primary);
  box-shadow: 0 2px 8px rgba(0, 77, 188, 0.12);
}

.image-card-preview {
  width: 100%;
  height: 120px;
  background: var(--emblue-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.image-card-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.image-card-info {
  padding: 10px 12px 4px;
}

.image-card-name {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--emblue-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-card-size {
  font-size: 11px;
  color: var(--emblue-disabled);
}

.image-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.img-tag {
  padding: 1px 8px;
  background: var(--emblue-muted);
  border-radius: var(--radius-sm);
  font-size: 10px;
  color: var(--emblue-subheadings);
}

.image-card-actions {
  display: flex;
  gap: 4px;
  padding: 6px 12px 10px;
}

.img-action-btn {
  flex: 1;
  padding: 4px;
  background: var(--emblue-muted);
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.img-action-btn:hover {
  background: var(--emblue-primary);
  border-color: var(--emblue-primary);
  color: #ffffff;
}

.img-action-btn.delete-img-btn:hover {
  background: var(--emblue-negative);
  border-color: var(--emblue-negative);
}

.images-empty {
  text-align: center;
  padding: 24px;
  color: var(--emblue-disabled);
  font-size: 14px;
}

/* Stock Library */
.stock-search {
  margin-bottom: 20px;
}

.stock-search-input {
  width: 100%;
  max-width: 400px;
  height: 32px;
  padding: 0 12px;
  background: #ffffff;
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-sm);
  color: var(--emblue-text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: all 0.15s;
}

.stock-search-input:focus {
  border-color: var(--emblue-primary);
  box-shadow: 0 0 0 1px var(--emblue-primary);
}

.stock-search-input::placeholder {
  color: var(--emblue-disabled);
}

.stock-category {
  margin-bottom: 28px;
}

.stock-category-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--emblue-text);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--emblue-borders);
}

.stock-loading {
  text-align: center;
  padding: 24px;
  color: var(--emblue-disabled);
  font-size: 14px;
}

/* === Send View === */
.send-view-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
}

/* Config Section */
.config-section {
  max-width: 480px;
  margin: 0 auto 16px auto;
  padding: 0 24px;
}

.config-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--emblue-muted);
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s;
}

.config-header:hover {
  background: var(--emblue-secondary-hover);
}

.config-header h3 {
  font-size: 14px;
  font-weight: 500;
  color: var(--emblue-text);
  margin: 0;
  flex: 1;
}

.config-status {
  font-size: 12px;
  font-weight: 500;
  padding: 2px 12px;
  border-radius: var(--radius-sm);
}

.config-status.configured {
  background: var(--emblue-success-light);
  color: var(--emblue-success);
}

.config-status.not-configured {
  background: var(--emblue-warning-light);
  color: #92600e;
}

.config-expand-btn {
  background: none;
  border: none;
  color: var(--emblue-disabled);
  font-size: 12px;
  cursor: pointer;
  transition: transform 0.2s;
  padding: 4px;
}

.config-expand-btn.expanded {
  transform: rotate(180deg);
}

.config-body {
  display: none;
  padding: 16px;
  border: 1px solid var(--emblue-borders);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  background: #ffffff;
}

.config-body.open {
  display: block;
}

.config-alert {
  margin: 8px 0;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  display: none;
  border-left: 4px solid;
}

.config-alert.success {
  display: block;
  background: var(--emblue-success-light);
  color: var(--emblue-success);
  border-color: var(--emblue-success);
}

.config-alert.error {
  display: block;
  background: var(--emblue-negative-light);
  color: var(--emblue-negative);
  border-color: var(--emblue-negative);
}

.config-save-btn {
  width: 100%;
  height: 32px;
  padding: 0 16px;
  background: var(--emblue-primary);
  border: none;
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

.config-save-btn:hover {
  background: var(--emblue-primary-hover);
}

.config-save-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Rate Limit Bar */
.rate-limit-bar {
  max-width: 480px;
  margin: 0 auto 16px auto;
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rate-limit-label {
  font-size: 12px;
  color: var(--emblue-subheadings);
}

.rate-limit-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--emblue-primary);
}

.rate-limit-bar.low .rate-limit-value {
  color: var(--emblue-negative);
  font-weight: 700;
}

.rate-limit-bar.low .rate-limit-label {
  color: var(--emblue-negative);
}

/* Senders Select */
.form-group select {
  width: 100%;
  height: 32px;
  padding: 0 12px;
  background: #ffffff;
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-sm);
  color: var(--emblue-text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: all 0.15s;
  cursor: pointer;
}

.form-group select:focus {
  border-color: var(--emblue-primary);
  box-shadow: 0 0 0 1px var(--emblue-primary);
}

.field-hint {
  font-size: 12px;
  color: var(--emblue-subheadings);
  margin-top: 4px;
}

.field-hint.error {
  color: var(--emblue-negative);
}

/* Send Actions */
.send-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.test-send-btn {
  flex: 0 0 auto;
  height: 40px;
  padding: 0 16px;
  background: #ffffff;
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-sm);
  color: var(--emblue-subheadings);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.test-send-btn:hover {
  background: var(--emblue-muted);
  color: var(--emblue-text);
}

/* Test Send Dialog */
.test-send-dialog {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--emblue-primary);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--emblue-primary) 5%, white);
}

.test-send-dialog h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--emblue-text);
  margin-bottom: 12px;
}

.test-send-alert {
  margin: 8px 0;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  display: none;
  border-left: 4px solid;
}

.test-send-alert.success {
  display: block;
  background: var(--emblue-success-light);
  color: var(--emblue-success);
  border-color: var(--emblue-success);
}

.test-send-alert.error {
  display: block;
  background: var(--emblue-negative-light);
  color: var(--emblue-negative);
  border-color: var(--emblue-negative);
}

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

.test-send-cancel {
  height: 32px;
  padding: 0 16px;
  background: #ffffff;
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-sm);
  color: var(--emblue-subheadings);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.test-send-cancel:hover {
  background: var(--emblue-muted);
}

.test-send-confirm {
  height: 32px;
  padding: 0 16px;
  background: var(--emblue-primary);
  border: none;
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.test-send-confirm:hover {
  background: var(--emblue-primary-hover);
}

.test-send-confirm:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-form-container {
  max-width: 480px;
  margin: 40px auto;
  padding: 0 24px;
}

.send-form-container h2 {
  margin-bottom: 24px;
  font-size: 18px;
  font-weight: 600;
  color: var(--emblue-text);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--emblue-text);
}

.form-group input {
  width: 100%;
  height: 32px;
  padding: 0 12px;
  background: #ffffff;
  border: 1px solid var(--emblue-borders);
  border-radius: var(--radius-sm);
  color: var(--emblue-text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: all 0.15s;
}

.form-group input:focus {
  border-color: var(--emblue-primary);
  box-shadow: 0 0 0 1px var(--emblue-primary);
}

.form-group input::placeholder {
  color: var(--emblue-disabled);
}

.submit-btn {
  flex: 1;
  height: 40px;
  padding: 0 16px;
  background: var(--emblue-primary);
  border: none;
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

.submit-btn:hover {
  background: var(--emblue-primary-hover);
}

.submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-status {
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  border-left: 4px solid;
}

.send-status.success {
  background: var(--emblue-success-light);
  color: var(--emblue-success);
  border-color: var(--emblue-success);
  border: 1px solid var(--emblue-success);
  border-left: 4px solid var(--emblue-success);
}

.send-status.error {
  background: var(--emblue-negative-light);
  color: var(--emblue-negative);
  border-color: var(--emblue-negative);
  border: 1px solid var(--emblue-negative);
  border-left: 4px solid var(--emblue-negative);
}

.no-html-warning {
  display: none;
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--emblue-warning-light);
  color: #92600e;
  border: 1px solid var(--emblue-warning);
  border-left: 4px solid var(--emblue-warning);
  border-radius: var(--radius-md);
  font-size: 14px;
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #ffffff;
  color: var(--emblue-text);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--emblue-borders);
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--emblue-secondary);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--emblue-disabled);
}

/* === Responsive === */
@media (max-width: 768px) {
  .sidebar {
    width: 56px;
    min-width: 56px;
    padding: 12px 8px;
    align-items: center;
  }

  .sidebar-header .tagline,
  .sidebar-templates,
  .sidebar-history,
  .nav-btn span:not(.nav-icon),
  .clear-btn {
    display: none;
  }

  .logo {
    font-size: 1.1rem;
  }

  .nav-btn {
    justify-content: center;
    padding: 10px;
  }

  .message {
    max-width: 95%;
  }

  .main {
    margin: 4px 4px 4px 0;
  }
}
