:root {
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --font-size: 16px;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --bg: #ffffff;
  --surface: #f8fafc;
  --surface-2: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #334155;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
  }
}

html[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --border: #334155;
}

html[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f8fafc;
  --surface-2: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
}

html[data-font-size="small"] {
  --font-size: 14px;
}

html[data-font-size="normal"] {
  --font-size: 16px;
}

html[data-font-size="large"] {
  --font-size: 19px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-family);
  font-size: var(--font-size);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* Auth */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100vw;
  padding: 24px;
  background: var(--surface);
}

.auth-logo {
  width: 96px;
  height: 96px;
  margin-bottom: 16px;
  border-radius: 24px;
  object-fit: contain;
}

.auth-screen h1 {
  margin: 0 0 8px;
  font-size: 1.8rem;
}

.auth-screen p {
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.auth-form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-form input {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.btn {
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn:active {
  background: var(--primary-dark);
}

.btn-danger {
  background: var(--danger);
}

/* Chat list */
.chat-list {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
}

.chat-list-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
}

.chat-list-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

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

.chat-list-actions button {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px;
  color: var(--text);
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  gap: 12px;
}

.chat-item:active {
  background: var(--surface);
}

.chat-item-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.chat-item-info {
  flex: 1;
  min-width: 0;
}

.chat-item-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-meta {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.chat-item-badge {
  background: var(--danger);
  color: white;
  border-radius: 50%;
  min-width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

/* Chat view */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header .back-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
}

.chat-header h3 {
  margin: 0;
  flex: 1;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
}

.message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  word-wrap: break-word;
}

.message.own {
  align-self: flex-end;
  background: var(--primary);
  color: white;
}

.message-sos {
  background: var(--danger) !important;
  color: white !important;
}

.message-meta {
  font-size: 0.7rem;
  opacity: 0.75;
  margin-top: 4px;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-input-area input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.chat-input-area button {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-input-area button.recording {
  background: var(--danger);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* Offline banner */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--danger);
  color: white;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 1000;
  font-weight: 600;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
}

/* Settings */
.settings-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--bg);
}

.settings-group {
  margin-bottom: 24px;
}

.settings-group h4 {
  margin: 0 0 12px 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.settings-group select {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.settings-group .btn {
  width: 100%;
}

@media (min-width: 768px) {
  #app {
    flex-direction: row;
  }
  .chat-list {
    width: 320px;
    border-right: 1px solid var(--border);
  }
}
