* {
  box-sizing: border-box;
  font-family: system-ui, sans-serif;
}

:root {
  --focus-primary: #00b4ff;
  --focus-secondary: #00ecbc;
  --focus-accent: #00c8ff;
  --focus-bg-start: #0a1a24;
  --focus-bg-end: #02060a;
  --focus-text: #e6fbff;
  --focus-text-soft: #7fdcff;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, var(--focus-bg-start), var(--focus-bg-end));
  color: var(--focus-text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Header */
.header {
  height: 48px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--focus-accent);
  opacity: 0.6;
  transition: opacity 0.3s ease;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--focus-text-soft);
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
}

.icon-btn:hover {
  color: var(--focus-accent);
}

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

/* Core */
.core-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.core {
  width: 220px;
  height: 220px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  letter-spacing: 2px;
  background: rgba(0, 180, 255, 0.08);
  box-shadow:
    0 0 40px rgba(0, 180, 255, 0.4),
    inset 0 0 25px rgba(0, 180, 255, 0.25);
  transition: box-shadow 0.4s ease;
}

.core.active {
  box-shadow:
    0 0 60px rgba(0, 220, 255, 0.8),
    inset 0 0 30px rgba(0, 220, 255, 0.4);
}

/* Chat — مكان عرض الرسائل (Output) */
.chat {
  flex: 1;
  min-height: 0;
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.chat:empty {
  display: none;
}

.msg {
  width: fit-content;
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 14px;
  margin-bottom: 10px;
  font-size: 14px;
  line-height: 1.4;
}

.msg.user {
  background: linear-gradient(135deg, var(--focus-primary), var(--focus-secondary));
  color: #001018;
  margin-left: auto;
  align-self: flex-end;
}

.msg.ai {
  background: rgba(255,255,255,0.08);
  color: var(--focus-text);
  border: 1px solid rgba(255,255,255,0.12);
}

/* Input */
.input-bar {
  height: 56px;
  display: flex;
  padding: 8px;
  gap: 8px;
}

.input-bar input {
  flex: 1;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--focus-primary);
  border-radius: 10px;
  color: var(--focus-text);
  padding: 0 12px;
  font-size: 16px;
}

.input-bar input:focus {
  outline: none;
  border-color: var(--focus-accent);
}

.input-bar input::placeholder {
  color: var(--focus-text-soft);
  opacity: 0.6;
}

.input-bar button {
  width: 56px;
  border-radius: 10px;
  border: none;
  background: var(--focus-primary);
  color: #001018;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.input-bar button:hover {
  background: var(--focus-accent);
}

.input-bar button:active {
  background: var(--focus-secondary);
}

/* History */
.history {
  position: fixed;
  right: 0;
  top: 0;
  width: 240px;
  height: 100%;
  background: var(--focus-bg-end);
  padding: 16px;
  border-left: 1px solid var(--focus-primary);
  z-index: 100;
}

.history h3 {
  margin: 0 0 16px 0;
  color: var(--focus-text-soft);
  font-size: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.close-panel {
  background: none;
  border: none;
  color: var(--focus-text-soft);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 4px;
}

.close-panel:hover {
  color: var(--focus-accent);
  background: rgba(255,255,255,0.1);
}

.history button {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--focus-primary);
  color: var(--focus-text);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  width: 100%;
}

.history button:hover {
  background: rgba(0, 0, 0, 0.4);
  border-color: var(--focus-accent);
}

.history #newChatBtn {
  background: linear-gradient(135deg, var(--focus-primary), var(--focus-secondary));
  color: #001018;
  font-weight: 600;
  border: none;
}

.history #newChatBtn:hover {
  opacity: 0.9;
}

/* Chat item hover effect */
.chat-item:hover {
  background: rgba(0, 180, 255, 0.15) !important;
  border-color: var(--focus-accent) !important;
}

.delete-chat-btn:hover {
  background: rgba(255,77,77,1) !important;
}

/* Message actions (copy, regenerate) */
.msg {
  position: relative;
}

.msg-content {
  flex: 1;
}

.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.2s;
}

.msg:hover .msg-actions {
  opacity: 1;
}

.msg-action-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--focus-text-soft);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.msg-action-btn:hover {
  background: rgba(255,255,255,0.2);
  color: var(--focus-accent);
  border-color: var(--focus-accent);
}

.msg-action-btn svg {
  display: block;
}

/* Markdown styling in messages */
.msg-content pre {
  background: rgba(0,0,0,0.3);
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}

.msg-content code {
  background: rgba(0,0,0,0.3);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
}

.msg-content pre code {
  background: none;
  padding: 0;
}

.msg-content p {
  margin: 8px 0;
}

.msg-content ul, .msg-content ol {
  margin: 8px 0;
  padding-left: 24px;
}

.msg-content blockquote {
  border-left: 3px solid var(--focus-accent);
  padding-left: 12px;
  margin: 8px 0;
  opacity: 0.8;
}

.msg-content h1, .msg-content h2, .msg-content h3 {
  margin: 12px 0 8px 0;
  color: var(--focus-accent);
}

.msg-content a {
  color: var(--focus-accent);
  text-decoration: underline;
}

.msg-content table {
  border-collapse: collapse;
  margin: 8px 0;
  width: 100%;
}

.msg-content th, .msg-content td {
  border: 1px solid rgba(255,255,255,0.2);
  padding: 6px 12px;
  text-align: left;
}

.msg-content th {
  background: rgba(0,0,0,0.3);
  font-weight: 600;
}

/* Search input focus */
#searchChats:focus {
  outline: none;
  border-color: var(--focus-accent);
}

.hidden {
  display: none;
}

/* Settings Panel */
.settings {
  position: fixed;
  right: 0;
  top: 0;
  width: 300px;
  height: 100%;
  background: var(--focus-bg-end);
  padding: 16px;
  padding-bottom: 32px;
  border-left: 1px solid var(--focus-primary);
  box-shadow: -20px 0 40px rgba(0,0,0,0.6);
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
}

.settings h3 {
  margin: 0 0 20px 0;
  color: var(--focus-text-soft);
  font-size: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.setting {
  margin-bottom: 20px;
  font-size: 14px;
}

.setting label {
  display: block;
  margin-bottom: 8px;
  color: var(--focus-text-soft);
  font-weight: 500;
}

.setting label input[type="checkbox"] {
  margin-right: 8px;
  margin-left: 0;
}

.settings select {
  width: 100%;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--focus-primary);
  border-radius: 6px;
  color: var(--focus-text);
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  appearance: auto; /* Ensure native dropdown appears */
  -webkit-appearance: menulist; /* For WebKit browsers */
  -moz-appearance: menulist; /* For Firefox */
  z-index: 1000; /* Ensure dropdown appears above other elements */
  position: relative;
}

.settings select:focus {
  outline: none;
  border-color: var(--focus-accent);
  box-shadow: 0 0 0 2px rgba(0, 180, 255, 0.2);
}

/* Ensure dropdown options are visible */
.settings select option {
  background: rgba(10, 26, 36, 0.95);
  color: var(--focus-text);
  padding: 8px;
}

.settings select optgroup {
  background: rgba(0, 180, 255, 0.1);
  color: var(--focus-accent);
  font-weight: 600;
  padding: 4px 8px;
}

.settings select optgroup option {
  background: rgba(0,0,0,0.6);
  color: var(--focus-text);
  padding-left: 20px;
}

.danger {
  margin-top: 32px;
  margin-bottom: 16px;
  background: #ff4d4d;
  border: none;
  padding: 12px;
  width: 100%;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s ease;
}

.danger:hover {
  background: #ff6666;
}

/* Focus Mode Theme Customizer */
.focus-theme-customizer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.focus-color-picker {
  display: flex;
  align-items: center;
  gap: 8px;
}

.focus-color-picker label {
  min-width: 60px;
  font-size: 12px;
  margin: 0;
}

.focus-color-picker input[type="color"] {
  width: 50px;
  height: 32px;
  border: 2px solid var(--focus-primary);
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  padding: 2px;
}

.focus-color-picker input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.focus-color-picker input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

.focus-apply-btn,
.focus-reset-btn {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  margin-top: 4px;
}

.focus-apply-btn {
  background: linear-gradient(135deg, var(--focus-primary), var(--focus-secondary));
  color: #001018;
}

.focus-apply-btn:hover {
  opacity: 0.9;
}

.focus-reset-btn {
  background: rgba(255,255,255,0.1);
  color: var(--focus-text);
  border: 1px solid var(--focus-primary);
}

.focus-reset-btn:hover {
  background: rgba(255,255,255,0.15);
}

/* Keep style: just size + active state, no theme break */
.input-bar #micBtn svg {
  width: 18px;
  height: 18px;
}

/* Lucide uses currentColor */
.input-bar #micBtn {
  color: var(--focus-accent);
}

/* When listening */
.input-bar #micBtn.active {
  outline: 2px solid var(--focus-accent);
  outline-offset: 2px;
}

/* Speak button (TTS) - same style as mic */
.input-bar #speakBtn svg {
  width: 18px;
  height: 18px;
}

.input-bar #speakBtn {
  color: var(--focus-accent);
}

.input-bar #speakBtn.active {
  outline: 2px solid var(--focus-accent);
  outline-offset: 2px;
}

/* Use Last Image button */
.input-bar #useLastImageBtn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: rgba(0, 180, 255, 0.1);
  color: var(--focus-accent);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.input-bar #useLastImageBtn:hover {
  background: rgba(0, 180, 255, 0.2);
  transform: scale(1.05);
}

.input-bar #useLastImageBtn:active {
  transform: scale(0.95);
}

/* =========================
   Pure White Theme (data-theme="white")
   ========================= */

[data-theme="white"] {
  /* Backgrounds */
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #ffffff;

  /* Text */
  --text: #0b1220;
  --text-2: #1f2a3a;
  --muted: #526074;

  /* Borders */
  --border: rgba(11, 18, 32, 0.10);
  --border-2: rgba(11, 18, 32, 0.06);

  /* AI0 identity accent (blue ring) */
  --accent: #0ea5e9;
  --accent-2: #38bdf8;
  --accent-soft: rgba(14,165,233,0.10);

  /* Shadows (very light to keep "clean") */
  --shadow-soft: 0 10px 30px rgba(2, 6, 23, 0.08);

  /* Chat bubbles */
  --bubble-ai: #ffffff;
  --bubble-ai-border: rgba(11,18,32,0.10);

  --bubble-user: rgba(14,165,233,0.10);
  --bubble-user-border: rgba(14,165,233,0.22);

  /* Focus glow */
  --glow: 0 0 0 6px rgba(14,165,233,0.10);
}

/* App base */
[data-theme="white"] body,
[data-theme="white"] .app {
  background: var(--bg);
  color: var(--text);
}

/* Body background */
body[data-theme="white"] {
  background: #ffffff;
  color: var(--text);
}

/* Containers */
[data-theme="white"] .panel,
[data-theme="white"] .chat-shell,
body[data-theme="white"] .header,
body[data-theme="white"] .main,
body[data-theme="white"] .settings,
body[data-theme="white"] .history {
  background: var(--panel);
  border-color: var(--border);
  box-shadow: var(--shadow-soft);
}

/* Messages */
body[data-theme="white"] .msg.ai {
  background: var(--bubble-ai);
  border: 1px solid var(--bubble-ai-border);
  color: var(--text);
}

body[data-theme="white"] .msg.user {
  background: var(--bubble-user);
  border: 1px solid var(--bubble-user-border);
  color: var(--text);
}

/* Inputs */
body[data-theme="white"] input,
body[data-theme="white"] textarea {
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text);
}

body[data-theme="white"] input:focus,
body[data-theme="white"] textarea:focus {
  border-color: rgba(14,165,233,0.55);
  box-shadow: var(--glow);
}

/* Buttons */
body[data-theme="white"] .btn,
body[data-theme="white"] .icon-btn {
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text);
}

body[data-theme="white"] .btn.primary,
body[data-theme="white"] #sendBtn {
  background: linear-gradient(135deg, rgba(14,165,233,0.98), rgba(56,189,248,0.98));
  border: 1px solid rgba(14,165,233,0.30);
  color: #fff;
}

/* Big ring (keeps AI0 identity) */
body[data-theme="white"] .core {
  background: radial-gradient(circle at 50% 50%,
    rgba(14,165,233,0.18),
    rgba(14,165,233,0.05) 55%,
    transparent 72%);
  border: 1px solid rgba(14,165,233,0.28);
  box-shadow:
    0 0 0 10px rgba(14,165,233,0.06),
    0 18px 50px rgba(2, 6, 23, 0.08);
  color: var(--text);
}

/* Header adjustments */
body[data-theme="white"] .header {
  border-bottom: 1px solid var(--border);
}

body[data-theme="white"] .dot {
  background: var(--accent);
}

/* Settings panel */
body[data-theme="white"] .settings {
  border-left: 1px solid var(--border);
}

body[data-theme="white"] .settings select {
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text);
}

body[data-theme="white"] .settings select option {
  background: #ffffff;
  color: var(--text);
}

/* History panel */
body[data-theme="white"] .history {
  border-left: 1px solid var(--border);
}

body[data-theme="white"] .history button {
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text);
}

body[data-theme="white"] .history button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* Input bar */
body[data-theme="white"] .input-bar {
  border-top: 1px solid var(--border);
  background: var(--panel);
}

body[data-theme="white"] .input-bar input {
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text);
}

body[data-theme="white"] .input-bar input::placeholder {
  color: var(--muted);
}

/* Message actions */
body[data-theme="white"] .msg-action-btn {
  background: rgba(11, 18, 32, 0.05);
  border: 1px solid var(--border);
  color: var(--text-2);
}

body[data-theme="white"] .msg-action-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* Code blocks */
body[data-theme="white"] .msg-content pre {
  background: rgba(11, 18, 32, 0.05);
  border: 1px solid var(--border);
}

body[data-theme="white"] .msg-content code {
  background: rgba(11, 18, 32, 0.05);
  border: 1px solid var(--border);
}

/* Links */
body[data-theme="white"] .msg-content a {
  color: var(--accent);
}

/* Tables */
body[data-theme="white"] .msg-content th,
body[data-theme="white"] .msg-content td {
  border: 1px solid var(--border);
}

body[data-theme="white"] .msg-content th {
  background: rgba(11, 18, 32, 0.05);
}
