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

:root {
  --bg: #000000;
  --bg-secondary: #0a0a0a;
  --bg-tertiary: #1c1c1e;
  --bg-bubble-me: #1a1a2e;
  --bg-bubble-other: #1c1c1e;
  --text-primary: #f5f5f7;
  --text-secondary: #86868b;
  --text-tertiary: #6e6e73;
  --accent: #0a84ff;
  --border: #2c2c2e;
  --radius: 16px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 680px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Header */
#header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 16px 20px 12px;
  border-bottom: 0.5px solid var(--border);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-top h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

#toggle-filters,
#logout-btn,
#upload-btn,
#delete-chat-btn {
  background: var(--bg-tertiary);
  border: none;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

#toggle-filters:hover,
#upload-btn:hover {
  color: var(--text-primary);
  background: var(--border);
}

#toggle-filters.active {
  color: var(--accent);
  background: rgba(10, 132, 255, 0.15);
}

#logout-btn:hover {
  color: #ff453a;
  background: rgba(255, 69, 58, 0.12);
}

#delete-chat-btn:hover {
  color: #ff453a;
  background: rgba(255, 69, 58, 0.12);
}

/* Search */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
}

.search-bar svg {
  position: absolute;
  left: 12px;
  color: var(--text-tertiary);
  pointer-events: none;
}

#search-input {
  width: 100%;
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 14px 10px 38px;
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font);
  outline: none;
  transition: background 0.2s;
}

#search-input::placeholder {
  color: var(--text-tertiary);
}

#search-input:focus {
  background: #2c2c2e;
}

/* Filters */
.filters {
  padding-top: 14px;
  animation: slideDown 0.25s ease;
}

.filters.hidden {
  display: none;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.filter-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.filter-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-field.full {
  flex: 1;
}

.filter-field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-field input,
.filter-field select {
  background: var(--bg-tertiary);
  border: none;
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  -webkit-appearance: none;
}

.filter-field select {
  cursor: pointer;
}

.filter-field input::-webkit-calendar-picker-indicator {
  filter: invert(1);
}

.filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

.btn-ghost {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-family: var(--font);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-ghost:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.btn-primary {
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  padding: 8px 20px;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary:hover {
  opacity: 0.85;
}

/* Stats */
.stats {
  padding: 10px 20px;
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: center;
  letter-spacing: 0.3px;
}

/* Chat wrapper + floating date */
#chat-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.floating-date-wrapper {
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.floating-date {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: rgba(28, 28, 30, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 5px 16px;
  border-radius: 20px;
  letter-spacing: 0.3px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.floating-date.visible {
  opacity: 1;
}

/* Chat */
#chat-container {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 16px 24px;
}

#messages {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.load-more {
  display: flex;
  justify-content: center;
  padding: 16px;
  min-height: 48px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}

.spinner.visible {
  display: block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Date separator */
.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 0 12px;
}

.date-separator span {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  padding: 4px 14px;
  border-radius: 20px;
  letter-spacing: 0.3px;
}

/* Messages */
.message {
  display: flex;
  flex-direction: column;
  margin-bottom: 2px;
  max-width: 80%;
  animation: fadeIn 0.15s ease;
}

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

.message.me {
  align-self: flex-end;
  margin-left: auto;
}

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

.message.me + .message.other,
.message.other + .message.me {
  margin-top: 10px;
}

.message.system {
  align-self: center;
  max-width: 90%;
}

.bubble {
  padding: 6px 10px 6px 12px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  position: relative;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 6px;
  max-width: 100%;
  min-width: 0;
}

.bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  min-width: 0;
}

.bubble .msg-time {
  font-size: 10px;
  color: var(--text-tertiary);
  margin-left: auto;
  flex-shrink: 0;
  padding: 0;
  line-height: 1.8;
}

.message.me .bubble {
  background: var(--bg-bubble-me);
  border-bottom-right-radius: 6px;
}

.message.other .bubble {
  background: var(--bg-bubble-other);
  border-bottom-left-radius: 6px;
}

.message.me + .message.me .bubble {
  border-radius: 18px;
  border-bottom-right-radius: 6px;
}

.message.other + .message.other .bubble {
  border-radius: 18px;
  border-bottom-left-radius: 6px;
}

.message.system .bubble {
  background: transparent;
  color: var(--text-tertiary);
  font-size: 13px;
  text-align: center;
  font-style: italic;
}

.sender-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  padding: 0 4px;
  margin-bottom: 2px;
  margin-top: 8px;
}


/* Highlight search */
mark {
  background: rgba(10, 132, 255, 0.3);
  color: var(--text-primary);
  border-radius: 2px;
  padding: 0 1px;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--text-tertiary);
  text-align: center;
  gap: 8px;
}

.empty-state svg {
  margin-bottom: 8px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 15px;
}

/* Scrollbar */
#chat-container::-webkit-scrollbar {
  width: 6px;
}

#chat-container::-webkit-scrollbar-track {
  background: transparent;
}

#chat-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

#chat-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

@media (max-width: 500px) {
  #header {
    padding: 12px 16px 10px;
  }
  .header-top h1 {
    font-size: 24px;
  }
  .message {
    max-width: 88%;
  }
  #chat-container {
    padding: 8px 10px 20px;
  }
}
