@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  --bg-deepest: #06060f;
  --bg-deep: #0c0c1d;
  --bg-surface: #12122a;
  --bg-elevated: #1a1a3a;
  --bg-hover: #222250;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.1);
  --text-primary: #f5f5fa;
  --text-secondary: #b0b0c8;
  --text-muted: #7878a0;
  --accent: #92c329;
  --accent-hover: #7daa1f;
  --accent-glow: rgba(146, 195, 41, 0.15);
  --accent-gradient: linear-gradient(135deg, #92c329, #6b9e1a);
  --green: #92c329;
  --red: #f87171;
  --claude-green: #92c329;
  --msg-self: rgba(146, 195, 41, 0.08);
  --msg-other: rgba(255, 255, 255, 0.04);
  --msg-claude: rgba(146, 195, 41, 0.06);
  --glass: rgba(255, 255, 255, 0.03);
  --glass-border: rgba(255, 255, 255, 0.06);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-deepest);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.hidden { display: none !important; }
.error { color: var(--red); margin-top: 0.5rem; font-size: 0.8rem; font-weight: 500; }

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); }

/* =========================================
   LOGIN SCREEN
   ========================================= */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-deepest);
  position: relative;
  overflow: hidden;
}

/* Animated gradient orbs */
#login-screen::before,
#login-screen::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.4;
  animation: float 12s ease-in-out infinite;
}

#login-screen::before {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(146, 195, 41, 0.3), transparent 70%);
  top: -150px;
  right: -100px;
}

#login-screen::after {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(107, 158, 26, 0.3), transparent 70%);
  bottom: -100px;
  left: -100px;
  animation-delay: -6s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -30px) scale(1.05); }
  66% { transform: translate(-20px, 20px) scale(0.95); }
}

.login-box {
  background: rgba(18, 18, 42, 0.7);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  padding: 2.5rem 2rem;
  border-radius: var(--radius-xl);
  border: 1px solid var(--glass-border);
  width: 360px;
  box-shadow: var(--shadow-lg), 0 0 60px rgba(146, 195, 41, 0.05);
  position: relative;
  z-index: 1;
}

.login-box h1 {
  text-align: center;
  margin-bottom: 0.25rem;
  font-size: 1.6rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.login-box .login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 1.75rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.login-box input {
  width: 100%;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  transition: var(--transition);
}

.login-box input::placeholder { color: var(--text-muted); }

.login-box input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(146, 195, 41, 0.04);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-box button {
  width: 100%;
  padding: 0.8rem;
  background: var(--accent-gradient);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  margin-top: 0.25rem;
  letter-spacing: 0.01em;
}

.login-box button:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(146, 195, 41, 0.25);
}

.login-box button:active { transform: translateY(0); }

/* =========================================
   CHAT LAYOUT
   ========================================= */

#chat-screen {
  display: flex;
  height: 100vh;
  background: var(--bg-deep);
}

/* Sidebar */

#sidebar {
  width: 240px;
  background: var(--bg-deepest);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#sidebar-header {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

#sidebar-header h2 {
  font-size: 1rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.01em;
}

#user-list {
  flex: 1;
  padding: 0.75rem;
  overflow-y: auto;
}

.user-item {
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

#sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}

#logout-btn {
  width: 100%;
  padding: 0.55rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 500;
  transition: var(--transition);
}

#logout-btn:hover {
  color: var(--red);
  border-color: rgba(248, 113, 113, 0.3);
  background: rgba(248, 113, 113, 0.06);
}

/* Main Chat */

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
}

#chat-header {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  font-size: 0.9rem;
  background: rgba(6, 6, 15, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  transition: var(--transition);
}

.status-dot.connected {
  background: var(--green);
  box-shadow: 0 0 6px rgba(146, 195, 41, 0.5);
}

.status-dot.disconnected {
  background: var(--red);
  box-shadow: 0 0 6px rgba(248, 113, 113, 0.3);
}

/* Messages */

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: var(--bg-deep);
}

.message {
  max-width: 72%;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-lg);
  line-height: 1.5;
  word-wrap: break-word;
  transition: var(--transition);
  position: relative;
}

.message.self {
  align-self: flex-end;
  background: var(--msg-self);
  border: 1px solid rgba(146, 195, 41, 0.1);
  border-bottom-right-radius: 4px;
}

.message.other {
  align-self: flex-start;
  background: var(--msg-other);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.claude {
  align-self: flex-start;
  background: var(--msg-claude);
  border: 1px solid rgba(146, 195, 41, 0.1);
  border-left: 3px solid var(--claude-green);
  max-width: 82%;
  border-bottom-left-radius: 4px;
}

.message.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-style: italic;
  border: none;
  padding: 0.4rem 0.75rem;
  max-width: 90%;
}

.message .meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
  font-weight: 500;
}

.message .text {
  font-size: 0.9rem;
  color: var(--text-primary);
  line-height: 1.5;
}

.message.self .text { color: #e8f6ff; }
.message.claude .text { color: #e0f5ed; }

/* Input Bar */

#input-bar {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  background: rgba(6, 6, 15, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#message-input {
  flex: 1;
  padding: 0.65rem 1rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  color: var(--text-primary);
  font-size: 0.9rem;
  resize: none;
  max-height: 120px;
  font-family: inherit;
  transition: var(--transition);
  line-height: 1.4;
}

#message-input::placeholder { color: var(--text-muted); }

#message-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(146, 195, 41, 0.03);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#send-btn {
  padding: 0.65rem 1.1rem;
  background: var(--accent-gradient);
  color: #fff;
  border: none;
  border-radius: var(--radius-xl);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#send-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(146, 195, 41, 0.25);
}

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

#attach-btn {
  padding: 0.65rem 0.75rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  cursor: pointer;
  font-size: 1.05rem;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#attach-btn:hover {
  color: var(--accent);
  border-color: rgba(146, 195, 41, 0.3);
  background: var(--accent-glow);
}

/* File Attachments */

.file-attachment {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 0.35rem;
  transition: var(--transition);
}

.file-attachment:hover { background: rgba(255, 255, 255, 0.06); }

.file-attachment a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
  word-break: break-all;
  transition: var(--transition);
}

.file-attachment a:hover { text-decoration: underline; color: var(--accent-hover); }

.file-attachment .file-size {
  color: var(--text-muted);
  font-size: 0.72rem;
  white-space: nowrap;
}

.file-icon { font-size: 1.1rem; }

#messages.drag-over {
  border: 2px dashed var(--accent);
  background: var(--accent-glow);
  border-radius: var(--radius-md);
}

/* Search Panel */

#search-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 320px;
  height: 100%;
  background: rgba(6, 6, 15, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
}

#search-panel-header {
  display: flex;
  gap: 0.5rem;
  padding: 0.85rem;
  border-bottom: 1px solid var(--border);
}

#search-input {
  flex: 1;
  padding: 0.55rem 0.85rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: inherit;
  transition: var(--transition);
}

#search-input::placeholder { color: var(--text-muted); }
#search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#search-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 0.5rem;
  transition: var(--transition);
}

#search-close:hover { color: var(--red); }

#search-results {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.search-result {
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 0.25rem;
  transition: var(--transition);
  border: 1px solid transparent;
}

.search-result:hover {
  background: var(--bg-hover);
  border-color: var(--border);
}

.search-result .sr-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  font-weight: 500;
}

.search-result .sr-preview {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

.search-result .sr-preview mark {
  background: rgba(146, 195, 41, 0.25);
  color: var(--text-primary);
  padding: 1px 3px;
  border-radius: 3px;
}

.search-no-results {
  text-align: center;
  color: var(--text-muted);
  padding: 2.5rem;
  font-size: 0.85rem;
}

/* Message highlight from search */
@keyframes highlight-flash {
  0% { background: rgba(146, 195, 41, 0.2); border-color: rgba(146, 195, 41, 0.3); }
  100% { background: transparent; border-color: transparent; }
}

.message.highlight { animation: highlight-flash 2s ease-out; }

/* Search button in header */
#search-btn {
  margin-left: 0.5rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.05rem;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

#search-btn:hover {
  color: var(--accent);
  background: var(--accent-glow);
}

/* Last seen in header */
#last-seen {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: auto;
}

/* Mobile */
@media (max-width: 600px) {
  #sidebar { display: none; }
  .message { max-width: 88%; }
  .message.claude { max-width: 94%; }
  #search-panel { width: 100%; }
  .login-box { width: calc(100% - 2rem); margin: 0 1rem; }
  #chat-header { padding: 0.75rem 1rem; }
  #messages { padding: 0.75rem; }
  #input-bar { padding: 0.6rem 0.75rem; }
}
