/* ===== Theme System =====
 * Dark (default) is defined in :root in main.css — untouched.
 * Each body[data-theme="..."] block overrides CSS variables and
 * component-specific hardcoded values for that theme.
 * ================================================================= */

/* ──────────────── Light ──────────────── */
body[data-theme="light"] {
  --bg-dark:          #f0f0f5;
  --bg-card:          rgba(0, 0, 0, 0.05);
  --bg-card-hover:    rgba(0, 0, 0, 0.08);
  --border:           rgba(0, 0, 0, 0.1);
  --text:             #1a1a1e;
  --text-muted:       #6b7280;
  --accent:           #3b82f6;
  --accent-secondary: #0284c7;
  --gradient:         linear-gradient(135deg, #3b82f6 0%, #0284c7 50%, #3b82f6 100%);
  --glass:            rgba(245, 245, 250, 0.8);
  --shadow:           0 8px 32px rgba(0, 0, 0, 0.1);
}
html:has(body[data-theme="light"]) {
  background: #f0f0f5;
  background-image: none;
}
body[data-theme="light"] {
  background-color: #f0f0f5;
  background-image: none;
}

/* ──────────────── Midnight Blue ──────────────── */
body[data-theme="midnight"] {
  --bg-dark:          #060c1c;
  --bg-card:          rgba(75, 130, 220, 0.07);
  --bg-card-hover:    rgba(75, 130, 220, 0.12);
  --border:           rgba(75, 130, 220, 0.15);
  --text:             #c8dcff;
  --text-muted:       #6e96c4;
  --accent:           #4b8ef1;
  --accent-secondary: #2563eb;
  --gradient:         linear-gradient(135deg, #4b8ef1 0%, #2563eb 50%, #4b8ef1 100%);
  --glass:            rgba(6, 12, 30, 0.65);
  --shadow:           0 8px 32px rgba(0, 0, 0, 0.55);
}
html:has(body[data-theme="midnight"]) {
  background: #060c1c;
  background-image: none;
}
body[data-theme="midnight"] {
  background-color: #060c1c;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(75, 142, 241, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(37, 99, 235, 0.08), transparent);
}

/* ──────────────── Sepia / Warm Dark ──────────────── */
body[data-theme="sepia"] {
  --bg-dark:          #1c1208;
  --bg-card:          rgba(210, 155, 75, 0.07);
  --bg-card-hover:    rgba(210, 155, 75, 0.12);
  --border:           rgba(210, 155, 75, 0.14);
  --text:             #f0e2c8;
  --text-muted:       #b09070;
  --accent:           #d97706;
  --accent-secondary: #b45309;
  --gradient:         linear-gradient(135deg, #d97706 0%, #b45309 50%, #d97706 100%);
  --glass:            rgba(28, 18, 8, 0.65);
  --shadow:           0 8px 32px rgba(0, 0, 0, 0.55);
}
html:has(body[data-theme="sepia"]) {
  background: #1c1208;
  background-image: none;
}
body[data-theme="sepia"] {
  background-color: #1c1208;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(217, 119, 6, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(180, 83, 9, 0.08), transparent);
}

/* ──────────────── White + Red Bubble ──────────────── */
body[data-theme="red-bubble"] {
  --bg-dark:          #ffffff;
  --bg-card:          rgba(0, 0, 0, 0.04);
  --bg-card-hover:    rgba(0, 0, 0, 0.07);
  --border:           rgba(0, 0, 0, 0.1);
  --text:             #1a1a1e;
  --text-muted:       #6b7280;
  --accent:           #dc2626;
  --accent-secondary: #b91c1c;
  --gradient:         linear-gradient(135deg, #dc2626 0%, #b91c1c 50%, #dc2626 100%);
  --glass:            rgba(255, 255, 255, 0.85);
  --shadow:           0 8px 32px rgba(0, 0, 0, 0.1);
}
html:has(body[data-theme="red-bubble"]) {
  background: #ffffff;
  background-image: none;
}
body[data-theme="red-bubble"] {
  background-color: #ffffff;
  background-image: none;
}

/* =================================================================
   Component overrides — hardcoded values in existing CSS files
   ================================================================= */

/* --- Settings panel background --- */
body[data-theme="light"] .settings-panel,
body[data-theme="red-bubble"] .settings-panel {
  background: rgba(238, 238, 244, 0.97);
}
body[data-theme="midnight"] .settings-panel {
  background: rgba(4, 8, 22, 0.97);
}
body[data-theme="sepia"] .settings-panel {
  background: rgba(20, 12, 4, 0.97);
}

/* --- Modal card backgrounds --- */
body[data-theme="light"] .upgrade-modal__card,
body[data-theme="light"] .about-modal__card,
body[data-theme="red-bubble"] .upgrade-modal__card,
body[data-theme="red-bubble"] .about-modal__card {
  background: rgba(240, 240, 245, 0.98);
}
body[data-theme="midnight"] .upgrade-modal__card,
body[data-theme="midnight"] .about-modal__card {
  background: rgba(4, 8, 22, 0.98);
}
body[data-theme="sepia"] .upgrade-modal__card,
body[data-theme="sepia"] .about-modal__card {
  background: rgba(20, 12, 4, 0.98);
}

/* --- User message bubble (hardcoded gradient in chat.css) --- */
body[data-theme="light"] .message.user .message-bubble {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.22), rgba(2, 132, 199, 0.16));
  border: 1px solid rgba(59, 130, 246, 0.3);
}
body[data-theme="midnight"] .message.user .message-bubble {
  background: linear-gradient(135deg, rgba(75, 142, 241, 0.38), rgba(37, 99, 235, 0.28));
  border: 1px solid rgba(75, 142, 241, 0.3);
}
body[data-theme="sepia"] .message.user .message-bubble {
  background: linear-gradient(135deg, rgba(217, 119, 6, 0.32), rgba(180, 83, 9, 0.24));
  border: 1px solid rgba(217, 119, 6, 0.3);
}

/* Red Bubble: both AI and user bubbles are red with white text */
body[data-theme="red-bubble"] .message.user .message-bubble,
body[data-theme="red-bubble"] .message.noesis .message-bubble {
  background: #dc2626;
  border: 1px solid #b91c1c;
  color: #ffffff;
}

/* --- Active mode tab (hardcoded rgba in chat.css) --- */
body[data-theme="light"] .mode-tab.active,
body[data-theme="red-bubble"] .mode-tab.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.4);
}
body[data-theme="midnight"] .mode-tab.active {
  background: rgba(75, 142, 241, 0.18);
  border-color: rgba(75, 142, 241, 0.4);
}
body[data-theme="sepia"] .mode-tab.active {
  background: rgba(217, 119, 6, 0.15);
  border-color: rgba(217, 119, 6, 0.4);
}

/* --- Menu card accent (hardcoded in sidebar.css) --- */
body[data-theme="light"] .menu-card.accent,
body[data-theme="red-bubble"] .menu-card.accent {
  border-color: rgba(59, 130, 246, 0.4);
  background: rgba(59, 130, 246, 0.08);
}
body[data-theme="midnight"] .menu-card.accent {
  border-color: rgba(75, 142, 241, 0.4);
  background: rgba(75, 142, 241, 0.08);
}
body[data-theme="sepia"] .menu-card.accent {
  border-color: rgba(217, 119, 6, 0.4);
  background: rgba(217, 119, 6, 0.08);
}

/* --- Menu card hover border (hardcoded in sidebar.css) --- */
body[data-theme="light"] .menu-card:hover,
body[data-theme="red-bubble"] .menu-card:hover {
  border-color: rgba(59, 130, 246, 0.3);
}
body[data-theme="midnight"] .menu-card:hover {
  border-color: rgba(75, 142, 241, 0.3);
}
body[data-theme="sepia"] .menu-card:hover {
  border-color: rgba(217, 119, 6, 0.3);
}

/* --- Active slot badge (hardcoded white rgba in header.css) --- */
body[data-theme="light"] .active-slot-badge,
body[data-theme="red-bubble"] .active-slot-badge {
  color: rgba(0, 0, 0, 0.4);
  border-color: rgba(0, 0, 0, 0.12);
}

/* --- Inline-styled form inputs (light & red-bubble need dark-on-light) --- */
body[data-theme="light"] #settingsUserSection input,
body[data-theme="red-bubble"] #settingsUserSection input,
body[data-theme="light"] #resetPasswordModal input,
body[data-theme="red-bubble"] #resetPasswordModal input {
  background: rgba(0, 0, 0, 0.05) !important;
  border-color: rgba(0, 0, 0, 0.15) !important;
  color: #1a1a1e !important;
}
body[data-theme="light"] #settingsUserSection input::placeholder,
body[data-theme="red-bubble"] #settingsUserSection input::placeholder,
body[data-theme="light"] #resetPasswordModal input::placeholder,
body[data-theme="red-bubble"] #resetPasswordModal input::placeholder {
  color: #9ca3af !important;
}

/* "パスワードを忘れた" link (inline style override) */
body[data-theme="light"] [data-action="show-forgot-password"],
body[data-theme="red-bubble"] [data-action="show-forgot-password"] {
  color: rgba(0, 0, 0, 0.45) !important;
}

/* =================================================================
   Theme selector UI (inside settings panel body)
   ================================================================= */
.theme-selector {
  margin-bottom: 8px;
}

.theme-selector__label {
  font-size: 0.688rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.theme-selector__options {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.theme-option:hover {
  background: var(--bg-card-hover);
}

.theme-option input[type="radio"] {
  display: none;
}

.theme-option__swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid transparent;
  transition: outline 0.15s;
}

.theme-option__swatch--dark       { background: #0a0a0f; border-color: #8b5cf6; }
.theme-option__swatch--light      { background: #f0f0f5; border-color: #3b82f6; }
.theme-option__swatch--midnight   { background: #060c1c; border-color: #4b8ef1; }
.theme-option__swatch--sepia      { background: #1c1208; border-color: #d97706; }
.theme-option__swatch--red-bubble { background: #ffffff; border-color: #dc2626; }

.theme-option__name {
  font-size: 0.813rem;
  color: var(--text);
  transition: color 0.15s;
}

.theme-option input[type="radio"]:checked + .theme-option__swatch {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="radio"]:checked ~ .theme-option__name {
  font-weight: 600;
}
