/* CSS Variables & Theme Setup */
:root {
  --font-family-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-family-heading: 'Outfit', sans-serif;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.2);
  --glass-blur: blur(20px);
}

/* Base Scrollbar Styling */
html, body {
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Default Dark Theme Variables */
body, body.theme-dark {
  --bg-color: #080c14;
  --bg-gradient: radial-gradient(circle at 50% 0%, #111a2e 0%, #080c14 75%);
  --surface-color: rgba(17, 24, 39, 0.55);
  --surface-hover: rgba(31, 41, 55, 0.7);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(99, 102, 241, 0.5);
  
  --primary: #6366f1; /* Indigo */
  --primary-hover: #4f46e5;
  --primary-gradient: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  --accent: #10b981; /* Emerald */
  --accent-muted: rgba(16, 185, 129, 0.1);
  --danger: #ef4444;
  
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  
  --bubble-user: var(--primary-gradient);
  --bubble-user-text: #ffffff;
  --bubble-ai: rgba(255, 255, 255, 0.04);
}

/* White / Light Theme Variables */
body.theme-light {
  --bg-color: #f1f3f7;
  --bg-gradient: radial-gradient(circle at 50% 0%, #dee2e6 0%, #f1f3f7 80%);
  --surface-color: rgba(255, 255, 255, 0.75);
  --surface-hover: rgba(248, 249, 250, 0.85);
  --border-color: rgba(0, 0, 0, 0.07);
  --border-focus: rgba(79, 70, 229, 0.5);
  
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-gradient: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
  --accent: #059669;
  --accent-muted: rgba(5, 150, 105, 0.08);
  --danger: #dc2626;
  
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --bubble-user: var(--primary-gradient);
  --bubble-user-text: #ffffff;
  --bubble-ai: #ffffff;
}

/* Light Pink Theme Variables */
body.theme-pink {
  --bg-color: #fff1f2;
  --bg-gradient: radial-gradient(circle at 50% 0%, #ffe4e6 0%, #fff1f2 80%);
  --surface-color: rgba(255, 255, 255, 0.8);
  --surface-hover: rgba(254, 244, 245, 0.9);
  --border-color: rgba(244, 63, 94, 0.12);
  --border-focus: rgba(219, 39, 119, 0.5);
  
  --primary: #db2777; /* Deep Pink */
  --primary-hover: #be185d;
  --primary-gradient: linear-gradient(135deg, #db2777 0%, #c2185b 100%);
  --accent: #e11d48; /* Rose */
  --accent-muted: rgba(225, 29, 72, 0.06);
  --danger: #e11d48;
  
  --text-primary: #881337;
  --text-secondary: #9f1239;
  --text-muted: #fda4af;
  
  --bubble-user: var(--primary-gradient);
  --bubble-user-text: #ffffff;
  --bubble-ai: rgba(255, 255, 255, 0.65);
}

/* Tan / Sand Theme Variables */
body.theme-tan {
  --bg-color: #f6f4ee;
  --bg-gradient: radial-gradient(circle at 50% 0%, #eae5d8 0%, #f6f4ee 80%);
  --surface-color: rgba(255, 255, 255, 0.85);
  --surface-hover: rgba(24af, 247, 241, 0.9);
  --border-color: rgba(120, 113, 108, 0.15);
  --border-focus: rgba(217, 119, 6, 0.5);
  
  --primary: #d97706; /* Warm Amber */
  --primary-hover: #b45309;
  --primary-gradient: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  --accent: #78350f;
  --accent-muted: rgba(120, 53, 15, 0.06);
  --danger: #991b1b;
  
  --text-primary: #44403c;
  --text-secondary: #78716c;
  --text-muted: #a8a29e;
  
  --bubble-user: var(--primary-gradient);
  --bubble-user-text: #ffffff;
  --bubble-ai: rgba(255, 255, 255, 0.7);
}

/* Base Reset & Typography */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

button {
  background: none;
  border: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  outline: none;
  padding: 0;
}

body {
  font-family: var(--font-family-sans);
  background-color: var(--bg-color);
  background-image: var(--bg-gradient);
  color: var(--text-primary);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.4s ease, color 0.3s ease;
}

/* Background Blur Blobs */
.bg-blobs {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(140px);
  opacity: 0.12;
  animation: pulse 18s infinite alternate;
}

.blob-1 {
  top: -10%;
  left: 15%;
  width: 500px;
  height: 500px;
  background-color: var(--primary);
}

.blob-2 {
  bottom: 5%;
  right: 15%;
  width: 550px;
  height: 550px;
  background-color: var(--accent);
  animation-delay: -6s;
}

@keyframes pulse {
  0% { transform: scale(1) translate(0px, 0px); }
  50% { transform: scale(1.15) translate(30px, -40px); }
  100% { transform: scale(0.9) translate(-10px, 15px); }
}

/* Application Container (Strict Viewport Constrained) */
.app-container {
  width: 100%;
  height: 100%;
  display: flex;
  position: relative;
  z-index: 1;
  padding: 16px;
  gap: 16px;
  overflow: hidden;
}

/* Glassmorphism Panels */
.glass {
  background: var(--surface-color);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Lock Screen overlay */
.lock-screen-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 12, 20, 0.88);
  backdrop-filter: blur(28px);
  transition: opacity 0.5s ease, visibility 0.5s;
}

.lock-screen-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.lock-card {
  width: 100%;
  max-width: 440px;
  padding: 48px 40px;
  border-radius: var(--radius-xl);
  text-align: center;
  animation: slideUp 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-lg);
}

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

.lock-logo {
  font-family: var(--font-family-heading);
  font-size: 2.25rem;
  font-weight: 700;
  margin-bottom: 10px;
  background: linear-gradient(135deg, var(--text-primary) 30%, var(--primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.lock-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 32px;
}

.lock-form-group {
  margin-bottom: 22px;
  text-align: left;
}

.lock-form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.input-field {
  width: 100%;
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.12);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-family-sans);
  font-size: 0.95rem;
  outline: none;
  transition: var(--transition);
}

.theme-light .input-field {
  background: rgba(255, 255, 255, 0.6);
}

.input-field:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--border-focus);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-family-sans);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  margin-top: 10px;
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.btn-primary:active {
  transform: translateY(0);
}

/* Dashboard Layout Wrapper */
.dashboard {
  display: flex;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.dashboard.active {
  opacity: 1;
}

/* Floating Sidebar styling */
.sidebar {
  width: 360px;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
  z-index: 10;
  min-height: 0; /* Constraints to prevent vertical stretching */
}

.sidebar-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-logo {
  font-family: var(--font-family-heading);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 9999px;
  background-color: var(--accent-muted);
  color: var(--accent);
  border: 1px solid rgba(16, 185, 129, 0.15);
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent);
  display: inline-block;
  animation: blink 2.5s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 0; /* Crucial scroll constraint */
}

/* Custom scrollbars */
.sidebar-content::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
  width: 6px;
}
.sidebar-content::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(127, 127, 127, 0.12);
  border-radius: 10px;
}
.sidebar-content::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(127, 127, 127, 0.25);
}

/* Sidebar Sections styling */
.sidebar-section {
  display: flex;
  flex-direction: column;
}

.section-title {
  font-family: var(--font-family-heading);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-card {
  background: rgba(0, 0, 0, 0.08);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: background 0.3s ease;
}

.theme-light .section-card {
  background: #ffffff;
}

/* Preferences widgets */
.settings-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setting-row label {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.select-field {
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family-sans);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  transition: var(--transition);
}

.theme-light .select-field {
  background: rgba(0, 0, 0, 0.03);
}

.select-field:focus {
  border-color: var(--primary);
}

/* Profile / Custom Instructions editing */
.editable-area {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-family-sans);
  font-size: 0.92rem;
  resize: vertical;
  min-height: 50px;
  outline: none;
}

.editable-area::placeholder {
  color: var(--text-muted);
}

/* Memories list styling */
.memory-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
}

.memory-item {
  font-size: 0.85rem;
  background: rgba(127, 127, 127, 0.05);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  animation: fadeIn 0.3s ease;
  border: 1px solid var(--border-color);
}

.memory-item span {
  flex: 1;
  color: var(--text-primary);
}

.memory-delete {
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  font-size: 0.85rem;
  transition: var(--transition);
}

.memory-delete:hover {
  color: var(--danger);
}

/* Tasks list styling */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}

.task-item input[type="checkbox"] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.task-item.done span {
  text-decoration: line-through;
  color: var(--text-muted);
}

.task-item span {
  flex: 1;
}

.task-item-delete {
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  font-size: 0.9rem;
}

.task-item-delete:hover {
  color: var(--danger);
}

.task-input-wrapper {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.task-input {
  flex: 1;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.12);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.88rem;
  outline: none;
}

.theme-light .task-input {
  background: rgba(0, 0, 0, 0.03);
}

.task-input:focus {
  border-color: var(--primary);
}

/* Sidebar Footer (Signout/Lock) */
.sidebar-footer {
  padding: 18px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.btn-link {
  color: var(--text-secondary);
  background: none;
  border: none;
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
}

.btn-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

/* Chat Main Layout Card */
.chat-area {
  flex: 1;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0; /* Crucial height containment for scroll */
}

.chat-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-info h2 {
  font-family: var(--font-family-heading);
  font-size: 1.2rem;
  font-weight: 600;
}

.chat-info p {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.chat-actions {
  display: flex;
  gap: 12px;
}

/* Chat Messages Log Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: rgba(0, 0, 0, 0.015);
  min-height: 0; /* Constraints flex item size to scroll */
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  animation: fadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.message.assistant {
  align-self: flex-start;
}

.message-bubble {
  padding: 14px 20px;
  border-radius: var(--radius-lg);
  font-size: 0.98rem;
  line-height: 1.6;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.message.user .message-bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--bubble-ai);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.message-image {
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  border: 1px solid var(--border-color);
  display: block;
}

.message-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
  margin-left: 6px;
}

.message.user .message-meta {
  align-self: flex-end;
  margin-right: 6px;
}

/* Image Attachment Preview Bar */
.attachment-preview-container {
  display: none;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(127, 127, 127, 0.06);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  align-items: center;
}

.attachment-preview-container.active {
  display: flex;
}

.attachment-thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border-color);
}

.attachment-name {
  font-size: 0.85rem;
  color: var(--text-secondary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-remove {
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  font-size: 1.2rem;
  transition: var(--transition);
}

.attachment-remove:hover {
  color: var(--danger);
}

/* Typing Indicator styling */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 10px 16px;
  background: var(--bubble-ai);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: fit-content;
  align-self: flex-start;
  margin-top: 8px;
  box-shadow: var(--shadow-sm);
}

.typing-dot {
  width: 6px;
  height: 6px;
  background-color: var(--text-secondary);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Chat Input Container Panel */
.chat-input-container {
  padding: 20px 24px 24px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  gap: 12px;
  align-items: center;
  background: rgba(0, 0, 0, 0.12);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 12px 18px;
  transition: var(--transition);
}

.theme-light .chat-input-wrapper {
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}

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

.chat-input-wrapper textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-family-sans);
  font-size: 0.96rem;
  resize: none;
  min-height: 24px;
  max-height: 120px;
  line-height: 1.5;
}

.chat-input-wrapper textarea::placeholder {
  color: var(--text-muted);
}

.btn-attach {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.35rem;
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  border-radius: 50%;
}

.btn-attach:hover {
  color: var(--primary);
  background: rgba(127, 127, 127, 0.08);
}

.btn-send {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-send:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-send:active {
  transform: translateY(0);
}

.btn-audit {
  background: rgba(16, 185, 129, 0.1);
  color: var(--accent);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: var(--transition);
}

.btn-audit:hover {
  background: rgba(16, 185, 129, 0.18);
  transform: translateY(-1px);
}

.btn-audit:active {
  transform: translateY(0);
}

/* Prompt Context Monitor Area */
.debug-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.debug-panel-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}

.debug-panel-toggle:hover {
  color: var(--text-primary);
}

.debug-panel {
  display: none;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: pre-wrap;
  max-height: 120px;
  overflow-y: auto;
}

.theme-light .debug-panel {
  background: rgba(255, 255, 255, 0.8);
}

.debug-panel.active {
  display: block;
}

/* Utility classes */
.hidden {
  display: none !important;
}

.card-save-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 500;
  background: rgba(127, 127, 127, 0.08);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  text-align: center;
  transition: var(--transition);
}

.card-save-btn:hover {
  background: rgba(127, 127, 127, 0.15);
  color: var(--text-primary);
}

.token-counter {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 9999px;
  background-color: var(--accent-muted);
  color: var(--accent);
  border: 1px solid rgba(16, 185, 129, 0.15);
  font-family: var(--font-family-heading);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 4px;
}
