:root {
  --bg: #f4f7f6;
  --bg-deep: #e2e8e4;
  --panel: rgba(255, 255, 255, 0.85);
  --sidebar: rgba(248, 250, 249, 0.85);
  --sidebar-top: rgba(255, 255, 255, 0.6);
  --chat-bg: transparent;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f7a65;
  --brand-hover: #0c6150;
  --brand-deep: #064034;
  --brand-soft: #d1fae5;
  --incoming: #ffffff;
  --outgoing: #ecfdf5;
  --danger: #e11d48;
  --danger-hover: #be123c;
  --danger-soft: #ffe4e6;
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --shadow-glass: 0 8px 32px 0 rgba(15, 122, 101, 0.1);
  --glass-border: 1px solid rgba(255, 255, 255, 0.4);
  --grad-1: #bbf7d0;
  --grad-2: #99f6e4;
  --grad-3: #e0e7ff;
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-card: rgba(255, 255, 255, 0.6);
  --glass-card-hover: rgba(255, 255, 255, 0.9);
  --glass-card-border: rgba(255, 255, 255, 0.8);
  --glass-solid: rgba(255, 255, 255, 0.8);
  --glass-input: rgba(255, 255, 255, 0.9);
  --glass-input-border: rgba(203, 213, 225, 0.8);
  --chat-bg-color: rgba(255, 255, 255, 0.4);
  --chat-header-bg: rgba(255, 255, 255, 0.8);
  --reply-bg: rgba(255, 255, 255, 0.8);
  --chat-pattern: rgba(15, 122, 101, 0.05);
  --border-light: rgba(255, 255, 255, 0.5);
  --border-dark: rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-deep: #020617;
  --panel: rgba(30, 41, 59, 0.85);
  --sidebar: rgba(15, 23, 42, 0.85);
  --sidebar-top: rgba(15, 23, 42, 0.6);
  --chat-bg: transparent;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --line: rgba(255, 255, 255, 0.1);
  --brand: #10b981;
  --brand-hover: #059669;
  --brand-deep: #34d399;
  --brand-soft: rgba(16, 185, 129, 0.15);
  --incoming: #1e293b;
  --outgoing: #064e3b;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
  --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
  --glass-border: 1px solid rgba(255, 255, 255, 0.05);
  --grad-1: #064e3b;
  --grad-2: #0f766e;
  --grad-3: #1e1b4b;
  --glass-bg: rgba(15, 23, 42, 0.7);
  --glass-card: rgba(30, 41, 59, 0.6);
  --glass-card-hover: rgba(30, 41, 59, 0.9);
  --glass-card-border: rgba(255, 255, 255, 0.1);
  --glass-solid: rgba(30, 41, 59, 0.8);
  --glass-input: rgba(15, 23, 42, 0.9);
  --glass-input-border: rgba(255, 255, 255, 0.2);
  --chat-bg-color: rgba(15, 23, 42, 0.4);
  --chat-header-bg: rgba(15, 23, 42, 0.8);
  --reply-bg: rgba(15, 23, 42, 0.8);
  --chat-pattern: rgba(255, 255, 255, 0.05);
  --border-light: rgba(255, 255, 255, 0.1);
  --border-dark: rgba(255, 255, 255, 0.1);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: 
    radial-gradient(circle at top left, var(--grad-1) 0%, transparent 40%),
    radial-gradient(circle at bottom right, var(--grad-2) 0%, transparent 40%),
    linear-gradient(135deg, var(--bg) 0%, var(--grad-3) 100%);
  background-color: var(--bg);
  background-attachment: fixed;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Splash Screen */
.splash-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.splash-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.splash-logo {
  width: 90px;
  height: 90px;
  animation: playfulBounce 2s infinite ease-in-out;
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  object-fit: contain;
}

@keyframes playfulBounce {
  0%, 100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-20px) scale(1.05);
  }
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(15, 122, 101, 0.2);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(15, 122, 101, 0.4);
}

button, input, textarea {
  font: inherit;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(1440px, calc(100vw - 40px));
  height: calc(100vh - 40px);
  margin: 20px auto;
  display: grid;
  grid-template-columns: 380px 1fr;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: var(--glass-border);
  border-radius: 28px;
  overflow: hidden;
  box-shadow: var(--shadow-glass);
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border-light);
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  z-index: 10;
  box-shadow: 1px 0 10px rgba(0,0,0,0.02);
}

.sidebar-header, .conversation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
}

.sidebar-header {
  background: var(--sidebar-top);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border-dark);
}

.brand h1, .section-heading h2, .conversation-header h2 {
  margin: 0;
}

.brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--brand-deep);
  letter-spacing: -0.01em;
}

.section-heading h2 {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.75rem;
  color: var(--brand);
  font-weight: 700;
}

.subtle {
  color: var(--muted);
  font-weight: 400;
}

.auth-card, .stats-card, .issues-card, .inbox-panel, .recent-panel {
  flex: 0 0 auto;
  margin: 0 16px 16px;
  padding: 20px;
  display: grid;
  gap: 16px;
  background: var(--glass-card);
  border: 1px solid var(--glass-card-border);
  border-radius: 20px;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.auth-card:hover, .stats-card:hover, .issues-card:hover, .inbox-panel:hover, .recent-panel:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.auth-card {
  margin-top: 16px;
}

.stats-heading {
  padding: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-tile {
  padding: 16px;
  border-radius: 16px;
  background: var(--glass-solid);
  border: 1px solid var(--border-light);
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
  transition: transform 0.2s ease;
}

.stat-tile:hover {
  transform: scale(1.02);
}

.stat-label, .stat-value {
  margin: 0;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.stat-value {
  margin-top: 6px;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--brand-deep);
  letter-spacing: -0.02em;
}

.incident-list {
  display: grid;
  gap: 10px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 6px;
}

.incident-item {
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--glass-solid);
  border: 1px solid var(--glass-input-border);
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
  transition: all 0.2s;
}
.incident-item:hover {
  background: var(--glass-card-hover);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.incident-title, .incident-meta {
  margin: 0;
}

.incident-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
}

.incident-meta {
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

.auth-copy {
  display: grid;
  gap: 6px;
}

.push-controls {
  display: grid;
  gap: 10px;
  margin-top: 4px;
}

.push-controls .subtle {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.4;
}

.auth-copy label {
  font-weight: 600;
  color: var(--ink);
  font-size: 0.95rem;
}

.auth-copy .subtle, #auth-status {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.4;
}

.auth-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--glass-input-border);
  border-radius: 12px;
  padding: 12px 16px;
  background: var(--glass-input);
  color: var(--ink);
  font-size: 0.95rem;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.02);
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(15, 122, 101, 0.15);
}

button {
  padding: 12px 20px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  box-shadow: 0 2px 4px rgba(15, 122, 101, 0.2);
}

button:hover:not(:disabled) {
  background: var(--brand-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(15, 122, 101, 0.3);
}

button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(15, 122, 101, 0.2);
}

button.secondary {
  background: var(--brand-soft);
  color: var(--brand-deep);
  box-shadow: none;
}

button.secondary:hover:not(:disabled) {
  background: #a7f3d0;
}

button.danger {
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: none;
}

button.danger:hover:not(:disabled) {
  background: #fecdd3;
  color: var(--danger-hover);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.icon-button {
  min-width: 82px;
}

.inbox-panel, .recent-panel {
  min-height: 340px;
  display: flex;
  flex-direction: column;
}

.handoff-list, .recent-list {
  border-top: 1px solid var(--border-dark);
  height: 260px;
  min-height: 260px;
  max-height: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  background: transparent;
  border-radius: 0 0 16px 16px;
  margin: 0 -8px;
  padding: 0 8px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0 12px;
}

.count-chip {
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: 0 2px 4px rgba(15, 122, 101, 0.2);
}

.handoff-item {
  width: 100%;
  padding: 14px;
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 14px;
  background: transparent;
  color: inherit;
  text-align: left;
  border-bottom: 1px solid var(--border-dark);
  border-radius: 12px;
  margin-bottom: 4px;
  transition: all 0.2s ease;
  box-shadow: none;
}

.handoff-item:hover {
  background: var(--glass-card-hover);
  transform: translateX(4px);
  box-shadow: var(--shadow-sm);
}

.handoff-item.active {
  background: var(--glass-solid);
  box-shadow: 0 0 0 2px var(--brand-soft), var(--shadow-md);
  transform: translateX(4px);
}

.list-empty {
  margin: 0;
  padding: 24px 16px;
  font-size: 0.9rem;
  text-align: center;
}

.handoff-avatar, .avatar-chip {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-hover));
  color: #fff;
  font-weight: 600;
  font-size: 1.1rem;
  box-shadow: 0 4px 8px rgba(15, 122, 101, 0.2);
}

.handoff-main {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.handoff-topline, .handoff-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.handoff-name, .handoff-updated, .handoff-preview, .handoff-waid, .handoff-status {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.handoff-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
}

.handoff-updated, .handoff-waid, .handoff-status {
  font-size: 0.8rem;
  color: var(--muted);
}

.handoff-preview {
  font-size: 0.9rem;
  color: #475569;
}

.conversation-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--chat-bg-color);
  position: relative;
}

.conversation-header {
  background: var(--chat-header-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-light);
  box-shadow: 0 4px 20px -10px rgba(0,0,0,0.05);
  z-index: 10;
}

.conversation-summary {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.conversation-copy {
  min-width: 0;
  flex: 1;
}

.conversation-summary h2, #conversation-meta {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.conversation-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.2;
}

#conversation-name, #conversation-meta {
  display: block;
}

#conversation-meta {
  font-size: 0.85rem;
  margin-top: 4px;
}

.conversation-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.back-button {
  display: none;
  flex: 0 0 auto;
}

.back-button::before {
  content: "\2190";
  margin-right: 8px;
  font-size: 1.1rem;
  line-height: 1;
}

.messages {
  padding: 24px;
  overflow-y: auto;
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 16px;
  background-image: 
    radial-gradient(var(--chat-pattern) 1px, transparent 1px);
  background-size: 24px 24px;
  scroll-behavior: smooth;
}

.empty-state {
  place-items: center;
  color: var(--muted);
  font-size: 1.1rem;
  font-weight: 500;
}

.message-row {
  display: flex;
  animation: fadeIn 0.3s ease forwards;
}

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

.message-row.user {
  justify-content: flex-start;
}

.message-row.assistant {
  justify-content: flex-end;
}

.message-bubble {
  max-width: min(72ch, 85%);
  padding: 12px 16px;
  border-radius: 18px;
  background: var(--incoming);
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(255,255,255,0.8);
  position: relative;
  transition: transform 0.2s;
}

.message-bubble:hover {
  transform: translateY(-1px);
}

.message-row.user .message-bubble {
  border-bottom-left-radius: 4px;
}

.message-row.assistant .message-bubble {
  background: var(--outgoing);
  border-bottom-right-radius: 4px;
  border: 1px solid rgba(15, 122, 101, 0.1);
}

.message-role, .message-time {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.message-time {
  text-align: right;
  margin-top: 4px;
  opacity: 0.7;
}

.message-media {
  margin: 8px 0;
}

.message-media:empty {
  display: none;
}

.message-image {
  display: block;
  max-width: min(300px, 100%);
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: var(--shadow-sm);
  transition: transform 0.3s ease;
}
.message-image:hover {
  transform: scale(1.02);
}

.message-audio {
  width: min(300px, 100%);
  border-radius: 20px;
}

.media-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--brand-deep);
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(15, 122, 101, 0.1);
}

.audio-meta {
  margin-top: 8px;
}

.audio-download {
  color: var(--brand);
  font-size: 0.85rem;
  text-decoration: none;
  font-weight: 600;
}

.audio-download:hover {
  text-decoration: underline;
}

.document-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--brand-deep);
  text-decoration: none;
  font-weight: 600;
  word-break: break-word;
}

.document-link::before {
  content: "\1F4CE";
  font-size: 1.2rem;
}

.document-link:hover {
  text-decoration: underline;
  color: var(--brand-hover);
}

.message-content {
  margin: 6px 0;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
}

.reply-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: end;
  padding: 20px 24px;
  background: var(--reply-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-light);
  box-shadow: 0 -4px 20px -10px rgba(0,0,0,0.05);
}

.composer-stack {
  display: grid;
  gap: 8px;
}

.composer-shell {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  background: var(--glass-input);
  border: 1px solid var(--glass-input-border);
  border-radius: 20px;
  padding: 8px 12px;
  transition: all 0.2s ease;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.composer-shell:focus-within {
  border-color: var(--brand);
  background: var(--panel);
  box-shadow: 0 0 0 3px rgba(15, 122, 101, 0.15);
}

.composer-shell.drag-active {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: 0 0 0 3px rgba(15, 122, 101, 0.2);
}

.composer-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-left: 12px;
}

.composer-icon {
  width: 40px;
  height: 40px;
  min-width: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  transition: all 0.2s;
}

.composer-icon:hover:not(:disabled) {
  background: rgba(15, 122, 101, 0.1);
  color: var(--brand);
}

.attachment-name {
  font-size: 0.85rem;
  color: var(--muted);
}

.attachment-clear {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 600;
  border: none;
}
.attachment-clear:hover {
  background: #fecdd3;
}

.composer {
  display: block;
  width: 100%;
}

.composer textarea {
  resize: none;
  min-height: 44px;
  max-height: 150px;
  border: 0;
  outline: none;
  padding: 10px 8px;
  background: transparent;
  box-shadow: none;
  font-size: 1rem;
  line-height: 1.5;
}

.composer textarea:focus {
  outline: none;
  border: 0;
  box-shadow: none;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }
  
  .app-shell {
    width: 100%;
    height: 100vh;
    margin: 0;
    border-radius: 0;
    grid-template-columns: 1fr;
    border: none;
  }
  
  .sidebar {
    border-right: 0;
  }
  
  .conversation-header, .reply-form, .auth-controls {
    grid-template-columns: 1fr;
  }
  
  .conversation-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  
  .sidebar, .conversation-panel {
    grid-column: 1;
    grid-row: 1;
    height: 100vh;
  }
  
  .conversation-panel {
    display: none;
  }
  
  .app-shell.mobile-conversation-open .sidebar {
    display: none;
  }
  
  .app-shell.mobile-conversation-open .conversation-panel {
    display: grid;
  }
  
  .back-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  
  .conversation-summary {
    display: grid;
    grid-template-columns: auto 48px minmax(0, 1fr);
    width: 100%;
  }
}

@media (max-width: 560px) {
  .auth-card, .stats-card, .issues-card, .inbox-panel, .recent-panel {
    margin: 0 12px 12px;
    padding: 16px;
  }
  
  .conversation-header {
    padding: 16px;
  }
  
  .messages {
    padding: 16px;
  }
  
  .reply-form {
    padding: 16px;
  }
  
  .composer-shell {
    border-radius: 16px;
  }
}
