:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e3e5e9;
  --text: #1c1e21;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --incoming: #ffffff;
  --outgoing: #4f46e5;
  --outgoing-text: #ffffff;
  --owner: #059669;
  --danger: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --border: #2a2e37;
    --text: #e6e8eb;
    --muted: #9aa1ac;
    --accent: #818cf8;
    --accent-soft: #1f2333;
    --incoming: #232733;
    --outgoing: #4f46e5;
    --outgoing-text: #ffffff;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar .brand {
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar .brand .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}

.topbar nav a { margin-left: 16px; font-size: 14px; color: var(--muted); }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-box {
  width: 340px;
  padding: 32px;
}

.login-box h1 { font-size: 18px; margin: 0 0 4px; }
.login-box p.sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn:hover { opacity: 0.92; text-decoration: none; }

.errorlist { color: var(--danger); font-size: 13px; list-style: none; padding: 0; margin: 0 0 12px; }

.search-row { margin-bottom: 16px; }
.search-row input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
}

.conv-list { list-style: none; margin: 0; padding: 0; }
.conv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.conv-row:last-child { border-bottom: none; }
.conv-row:hover { background: var(--accent-soft); }

.conv-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.conv-participant { font-weight: 600; font-size: 14px; }
.conv-account { color: var(--muted); font-size: 12px; }
.conv-preview {
  color: var(--muted);
  font-size: 13px;
  max-width: 480px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-meta { text-align: right; font-size: 12px; color: var(--muted); white-space: nowrap; }
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  margin-top: 4px;
}

.conv-preview mark {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0 2px;
  border-radius: 3px;
}

.empty { padding: 48px 24px; text-align: center; color: var(--muted); }

.pagination { display: flex; gap: 8px; justify-content: center; margin-top: 18px; font-size: 13px; }

.thread-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.thread-header h1 { font-size: 16px; margin: 0; }
.thread-header .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.thread-body { padding: 20px; display: flex; flex-direction: column; gap: 10px; }

.bubble-row { display: flex; }
.bubble-row.incoming { justify-content: flex-start; }
.bubble-row.outgoing { justify-content: flex-end; }

.bubble {
  max-width: 62%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
}
.bubble-row.incoming .bubble {
  background: var(--incoming);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble-row.outgoing .bubble {
  background: var(--outgoing);
  color: var(--outgoing-text);
  border-bottom-right-radius: 4px;
}

.bubble .meta {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 11px;
  margin-top: 6px;
  opacity: 0.75;
}

.tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(0,0,0,0.08);
}
.bubble-row.outgoing .tag { background: rgba(255,255,255,0.2); }

.attachment {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  text-decoration: underline;
}

.attachment-media {
  display: block;
  max-width: 220px;
  border-radius: 10px;
  margin-top: 6px;
}
