:root {
  --bg: #0f1115;
  --bg2: #171a21;
  --bg3: #1f2430;
  --border: #2a3140;
  --text: #e6e9ef;
  --muted: #8b94a7;
  --accent: #6c8cff;
  --accent2: #4a6aef;
  --green: #3ecf8e;
  --red: #ff5c5c;
  --yellow: #ffc24c;
  --orange: #ff8a3d;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

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

button, .btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: background .15s;
}
button:hover, .btn:hover { background: var(--accent2); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary { background: var(--bg3); border: 1px solid var(--border); }
button.secondary:hover { background: var(--border); }
button.danger { background: var(--red); }
button.danger:hover { background: #e04848; }
button.small { padding: 4px 10px; font-size: 12px; }

input, textarea, select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding: 16px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar h1 { font-size: 18px; margin-bottom: 20px; color: var(--accent); }
.sidebar a {
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar a:hover { background: var(--bg3); text-decoration: none; }
.sidebar a.active { background: var(--bg3); color: var(--accent); }
.sidebar .spacer { flex: 1; }
.sidebar .user { font-size: 12px; color: var(--muted); padding: 8px 12px; }

.main { flex: 1; padding: 32px; max-width: 100%; overflow-x: auto; }
.main h2 { margin-bottom: 20px; font-size: 22px; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 360px;
}
.login-card h1 { color: var(--accent); margin-bottom: 24px; text-align: center; }
.login-card .field { margin-bottom: 16px; }
.login-card .error { color: var(--red); margin-bottom: 12px; font-size: 13px; }
.login-card button { width: 100%; padding: 10px; }

/* Cards / tables */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}
.card h3 { margin-bottom: 12px; font-size: 16px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
tr:hover td { background: var(--bg3); }

/* Status badges */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.badge.active { background: rgba(62,207,142,.15); color: var(--green); }
.badge.token_error { background: rgba(255,92,92,.15); color: var(--red); }
.badge.error { background: rgba(255,138,61,.15); color: var(--orange); }
.badge.unknown { background: rgba(139,148,167,.15); color: var(--muted); }
.badge.blocked { background: rgba(255,92,92,.15); color: var(--red); }

/* Chat */
.chat-layout { display: flex; gap: 0; height: calc(100vh - 100px); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--bg2); }
.conv-list {
  width: 320px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}
.conv-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.conv-item:hover { background: var(--bg3); }
.conv-item.active { background: var(--bg3); border-left: 3px solid var(--accent); }
.conv-item .name { font-weight: 600; margin-bottom: 2px; }
.conv-item .ad { font-size: 12px; color: var(--muted); }
.conv-item .last { font-size: 12px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .unread { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-left: 6px; }

.conv-detail { flex: 1; display: flex; flex-direction: column; }
.conv-header { padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--bg2); }
.conv-header .buyer { font-weight: 600; }
.conv-header .ad-title { font-size: 12px; color: var(--muted); }
.conv-header .ad-price { color: var(--green); font-weight: 600; }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.seller { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.buyer { align-self: flex-start; background: var(--bg3); }
.msg .time { font-size: 10px; opacity: .6; margin-top: 4px; }

.send-bar { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.send-bar textarea { resize: none; height: 60px; }

.empty { text-align: center; color: var(--muted); padding: 40px; }
.loading { text-align: center; color: var(--muted); padding: 40px; }
.error { color: var(--red); }

.row { display: flex; gap: 12px; align-items: center; }
.row .grow { flex: 1; }
.muted { color: var(--muted); }
.mb { margin-bottom: 12px; }
.mono { font-family: "SF Mono", Consolas, monospace; font-size: 12px; }
