/* ============================
   HOMER AGENT — OPENCLAW DARK THEME
   Simpsons-accented dark UI
   ============================ */

@font-face {
  font-family: "Simpsonfont";
  src: url("fonts/Simpsonfont.otf") format("opentype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Dark base */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a26;
  --bg-surface: #1e1e2e;
  --bg-hover: #252536;
  --bg-active: #2a2a3e;

  /* Simpsons accent colors */
  --accent: #FDD835;
  --accent-dim: rgba(253, 216, 53, 0.15);
  --accent-muted: rgba(253, 216, 53, 0.08);
  --accent-glow: rgba(253, 216, 53, 0.25);
  --homer-blue: #42A5F5;
  --homer-blue-dim: rgba(66, 165, 245, 0.15);
  --bart-red: #EF5350;
  --bart-red-dim: rgba(239, 83, 80, 0.15);
  --springfield-green: #66BB6A;
  --springfield-green-dim: rgba(102, 187, 106, 0.15);
  --donut-pink: #F48FB1;
  --marge-blue: #5C6BC0;

  /* Text */
  --text-primary: #e4e4e7;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --text-inverse: #0a0a0f;

  /* Borders */
  --border: #27273a;
  --border-light: #2e2e44;
  --border-active: #3a3a54;

  /* Misc */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  --transition: 150ms ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "Simpsonfont", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* === APP LAYOUT === */
#app {
  display: flex;
  height: 100vh;
  width: 100%;
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-secondary);
}

/* === TOP BAR === */
#topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

#sidebar-toggle {
  width: 34px;
  height: 34px;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}
#sidebar-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

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

.topbar-icon {
  font-size: 1.3rem;
}

.topbar-title h1 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.topbar-badge {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 20px;
}

.topbar-model {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.topbar-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.topbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
}

/* === MODE TOGGLE === */
.mode-toggle {
  display: flex;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.mode-btn {
  padding: 5px 12px;
  font-family: "Simpsonfont", "Inter", sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  border: none;
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.mode-btn:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}
.mode-btn.active {
  background: var(--accent);
  color: var(--text-inverse);
  font-weight: 600;
}

/* === CHAT AREA === */
#chat-area {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
  position: relative;
}

#chat-area::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url('639683975_974863651882669_6318976288150411501_n.jpg') center center / cover no-repeat;
  opacity: 0.12;
  pointer-events: none;
  z-index: 0;
}

#chat-container {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 800px;
  margin: 0 auto;
  padding-bottom: 16px;
}

/* === MESSAGE STYLES === */
.message-homer,
.message-user {
  animation: msg-in 0.25s ease-out;
}

.message-homer {
  display: flex;
  gap: 12px;
  padding: 16px 0;
}

.homer-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.bubble-homer {
  flex: 1;
  color: var(--text-primary);
  font-size: 0.92rem;
  line-height: 1.65;
  word-wrap: break-word;
  white-space: pre-wrap;
  background: rgba(26, 26, 38, 0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(253, 216, 53, 0.08);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.message-user {
  display: flex;
  justify-content: flex-end;
  padding: 16px 0;
}

.bubble-user {
  max-width: 75%;
  background: rgba(66, 165, 245, 0.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(66, 165, 245, 0.18);
  color: var(--text-primary);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
  padding: 12px 16px;
  font-size: 0.92rem;
  line-height: 1.65;
  word-wrap: break-word;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* === THINKING BLOCK === */
.thinking-block {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  margin: 8px 0;
  overflow: hidden;
  animation: msg-in 0.25s ease-out;
}

.thinking-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  user-select: none;
  transition: background var(--transition);
}
.thinking-header:hover {
  background: var(--bg-hover);
}

.thinking-toggle {
  margin-left: auto;
  font-size: 0.7rem;
  transition: transform 0.2s;
  color: var(--text-tertiary);
}

.thinking-block.collapsed .thinking-toggle {
  transform: rotate(-90deg);
}

.thinking-block.collapsed .thinking-content {
  display: none;
}

.thinking-content {
  font-family: "JetBrains Mono", monospace;
  white-space: pre-wrap;
  color: var(--text-secondary);
  font-size: 0.78rem;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
  padding: 0 14px 12px;
  border-top: 1px solid var(--border);
}

/* === TYPING INDICATOR === */
#typing-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
  max-width: 800px;
  margin: 0 auto;
}
#typing-indicator.hidden { display: none; }

.typing-dots {
  display: flex;
  gap: 4px;
}
.typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

.typing-text {
  font-size: 0.82rem;
  color: var(--text-tertiary);
  font-style: italic;
}

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

/* === INPUT AREA === */
#input-area {
  padding: 12px 24px 16px;
  flex-shrink: 0;
  max-width: 848px;
  width: 100%;
  margin: 0 auto;
}

#input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 16px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
#input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

#message-input {
  flex: 1;
  padding: 6px 0;
  font-family: "Simpsonfont", "Inter", sans-serif;
  font-size: 0.9rem;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  resize: none;
  max-height: 150px;
  line-height: 1.5;
}
#message-input::placeholder {
  color: var(--text-tertiary);
}

#send-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--accent);
  color: var(--text-inverse);
  cursor: pointer;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}
#send-btn:hover {
  background: #FFEB3B;
  transform: scale(1.05);
}
#send-btn:active {
  transform: scale(0.95);
}
#send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.input-footer {
  text-align: center;
  padding-top: 8px;
  font-size: 0.72rem;
  color: var(--text-tertiary);
}

/* === ANIMATIONS === */
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--bg-active);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-active);
}

/* === SVG HOMER AVATAR === */
.homer-avatar {
  position: relative;
  overflow: hidden;
}
.homer-avatar svg {
  width: 100%;
  height: 100%;
}
.homer-avatar .avatar-expression {
  display: none;
}
.homer-avatar .avatar-expression.active {
  display: block;
}

/* === SOUND TOGGLE === */
.sound-toggle {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  position: relative;
}
.sound-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
}
.sound-toggle.muted::after {
  content: '';
  position: absolute;
  width: 2px;
  height: 20px;
  background: var(--bart-red);
  transform: rotate(45deg);
  border-radius: 1px;
}

/* === LOADING SKELETON === */
.skeleton-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.skeleton-container.hidden {
  display: none;
}
.skeleton-msg {
  display: flex;
  gap: 12px;
  animation: msg-in 0.3s ease-out;
}
.skeleton-msg-user {
  justify-content: flex-end;
}
.skeleton-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-dim);
  flex-shrink: 0;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-bubble {
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.skeleton-bubble-homer {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  flex: 1;
  max-width: 70%;
}
.skeleton-bubble-user {
  background: var(--homer-blue-dim);
  border: 1px solid rgba(66, 165, 245, 0.15);
  width: 45%;
}
.skeleton-line {
  height: 10px;
  border-radius: 5px;
  background: var(--bg-active);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-line:nth-child(1) { width: 85%; animation-delay: 0s; }
.skeleton-line:nth-child(2) { width: 65%; animation-delay: 0.15s; }
.skeleton-line:nth-child(3) { width: 45%; animation-delay: 0.3s; }
.skeleton-donut {
  text-align: center;
  font-size: 2rem;
  opacity: 0.3;
  animation: skeleton-donut-bob 2s ease-in-out infinite;
  margin: 8px 0;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}
@keyframes skeleton-donut-bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-4px) rotate(10deg); }
}

/* === TYPING PERSONALITY === */
.typing-phrase {
  font-size: 0.82rem;
  color: var(--text-tertiary);
  font-style: italic;
  transition: opacity 0.3s ease;
}

/* === SEND BUTTON LOADING === */
#send-btn .send-icon { display: flex; }
#send-btn .send-spinner { display: none; }
#send-btn.loading .send-icon { display: none; }
#send-btn.loading .send-spinner {
  display: flex;
  animation: donut-spin 0.8s linear infinite;
}
@keyframes donut-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* === RESPONSIVE === */
@media (max-width: 900px) {
  #sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    z-index: 200;
    transition: left 0.25s ease;
  }
  #sidebar.open { left: 0; }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 199;
    backdrop-filter: blur(2px);
  }
  .sidebar-overlay.active { display: block; }

  #panel {
    display: none !important;
  }

  .topbar-model { display: none; }
  #panel-toggle { display: none; }

  #input-area {
    padding: 8px 12px 12px;
  }
}

@media (max-width: 600px) {
  .mode-toggle { display: none; }
  .topbar-badge { display: none; }
}
