:root {
  --bg: #0a0b0f;
  --bg2: #12131a;
  --bg3: #1a1c25;
  --bg4: #242730;
  --border: rgba(255,255,255,.06);
  --border2: rgba(255,255,255,.10);
  --text: #f4f5f7;
  --text2: #b8bcc8;
  --muted: #6b7280;
  --accent: #7c8cff;
  --accent2: #9aa5ff;
  --accent-glow: rgba(124,140,255,.18);
  --accent-soft: rgba(124,140,255,.08);
  --green: #34d399;
  --green-soft: rgba(52,211,153,.12);
  --red: #f87171;
  --red-soft: rgba(248,113,113,.12);
  --yellow: #fbbf24;
  --orange: #fb923c;
  --blue: #60a5fa;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 10px 30px rgba(0,0,0,.45), 0 2px 6px rgba(0,0,0,.3);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.35);
  --shadow-glow: 0 0 0 3px var(--accent-glow);
}

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

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; cursor: pointer; transition: color .15s; }
a:hover { color: var(--accent2); }

/* Buttons */
button, .btn {
  background: linear-gradient(180deg, var(--accent) 0%, #6b7cff 100%);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: all .15s cubic-bezier(.4,0,.2,1);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.1);
}
button:hover, .btn:hover { background: linear-gradient(180deg, var(--accent2) 0%, var(--accent) 100%); box-shadow: 0 2px 8px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,.15); transform: translateY(-1px); }
button:active { transform: translateY(0) scale(.98); }
button:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; transform: none; }
button.secondary { background: var(--bg3); border: 1px solid var(--border2); color: var(--text2); box-shadow: none; }
button.secondary:hover { background: var(--bg4); border-color: rgba(124,140,255,.35); color: var(--text); box-shadow: none; transform: none; }
button.danger { background: linear-gradient(180deg, var(--red) 0%, #e56060 100%); }
button.danger:hover { background: linear-gradient(180deg, #ff8585 0%, var(--red) 100%); box-shadow: 0 2px 8px rgba(248,113,113,.3); }
button.ghost { background: transparent; color: var(--muted); padding: 6px 10px; box-shadow: none; }
button.ghost:hover { background: var(--bg3); color: var(--text); box-shadow: none; transform: none; }
button.small { padding: 6px 12px; font-size: 12px; }
button.icon-only { padding: 6px 8px; }

input, textarea, select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border2);
  padding: 10px 13px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-family: inherit;
  width: 100%;
  transition: all .15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: var(--shadow-glow); background: var(--bg2); }
input::placeholder, textarea::placeholder { color: var(--muted); }

/* Layout */
.app { display: flex; height: 100vh; }

.sidebar {
  width: 232px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding: 20px 12px 14px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.sidebar .brand {
  font-size: 16px;
  font-weight: 700;
  padding: 6px 12px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -.3px;
}
.sidebar .brand .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 12px var(--green);
}
.sidebar .brand .txt {
  background: linear-gradient(135deg, #fff 0%, #a0adff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.sidebar a {
  color: var(--text2);
  padding: 10px 12px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 13px;
  font-weight: 500;
  transition: all .12s;
  user-select: none;
  position: relative;
}
.sidebar a:hover { background: var(--bg3); color: var(--text); }
.sidebar a.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.sidebar a.active::before {
  content: "";
  position: absolute;
  left: -12px; top: 8px; bottom: 8px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
  box-shadow: 0 0 8px var(--accent);
}
.sidebar a .icon { font-size: 15px; width: 20px; display: inline-flex; justify-content: center; }
.sidebar .spacer { flex: 1; }
.sidebar .user {
  font-size: 11px;
  color: var(--muted);
  padding: 10px 12px 4px;
  border-top: 1px solid var(--border);
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar .user .avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, #6b7cff 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
  box-shadow: 0 2px 6px rgba(124,140,255,.4);
}

.main { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.main .page { flex: 1; overflow-y: auto; padding: 28px 32px; }
.main h2 { margin-bottom: 20px; font-size: 22px; font-weight: 700; letter-spacing: -.4px; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, rgba(124,140,255,.15) 0%, var(--bg) 55%);
}
.login-card {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 40px 36px;
  width: 380px;
  box-shadow: var(--shadow);
}
.login-card .logo {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 32px;
  text-align: center;
  letter-spacing: -.5px;
  background: linear-gradient(135deg, #fff 0%, #a0adff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.login-card .field { margin-bottom: 14px; }
.login-card .error { color: var(--red); margin-bottom: 12px; font-size: 13px; }
.login-card button { width: 100%; padding: 12px; font-size: 14px; }

/* Cards */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
  transition: border-color .15s;
}
.card:hover { border-color: var(--border2); }
.card h3 { margin-bottom: 14px; font-size: 15px; font-weight: 600; }
.card .sub { color: var(--muted); font-size: 12px; margin-bottom: 14px; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }

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

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; }
.badge.active { background: var(--green-soft); color: var(--green); }
.badge.active::before { background: var(--green); box-shadow: 0 0 6px var(--green); }
.badge.token_error, .badge.blocked { background: var(--red-soft); color: var(--red); }
.badge.token_error::before, .badge.blocked::before { background: var(--red); }
.badge.error { background: rgba(251,146,60,.12); color: var(--orange); }
.badge.error::before { background: var(--orange); }
.badge.unknown { background: rgba(107,116,136,.12); color: var(--muted); }
.badge.unknown::before { background: var(--muted); }

/* Accounts split layout */
.split { display: flex; height: 100%; }

.acc-list {
  width: 280px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  background: var(--bg2);
}
.acc-list-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--bg2);
  z-index: 2;
  backdrop-filter: blur(8px);
}
.acc-list-header .ttl { font-size: 13px; font-weight: 600; letter-spacing: -.2px; }
.acc-list-header .cnt { font-size: 11px; color: var(--muted); }
.acc-item {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: all .12s;
  position: relative;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.acc-item:hover { background: var(--bg3); }
.acc-item.active { background: var(--bg3); }
.acc-item.active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.acc-item .avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, #6b7cff 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(124,140,255,.35);
}
.acc-item .body { flex: 1; min-width: 0; }
.acc-item .name { font-weight: 600; font-size: 14px; margin-bottom: 4px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.acc-item .meta { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.acc-item .meta .sep { opacity: .5; }
.acc-item .actions {
  margin-top: 10px;
  display: flex;
  gap: 5px;
  opacity: 0;
  transition: opacity .15s;
}
.acc-item:hover .actions, .acc-item.active .actions { opacity: 1; }

/* Chat */
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg); min-width: 0; }
.chat-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); gap: 12px; padding: 40px; text-align: center; }
.chat-empty .icon { font-size: 48px; opacity: .25; }

.conv-list {
  width: 320px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  background: var(--bg2);
}
.conv-list-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: .3px;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  background: var(--bg2);
  z-index: 1;
  backdrop-filter: blur(8px);
}
.conv-item {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: all .12s;
  display: flex;
  gap: 11px;
  align-items: flex-start;
  position: relative;
}
.conv-item:hover { background: var(--bg3); }
.conv-item.active { background: var(--bg3); }
.conv-item.active::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.conv-item .conv-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4a4f5c 0%, #2a2d38 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.conv-item .body { flex: 1; min-width: 0; }
.conv-item .name { font-weight: 600; font-size: 13.5px; margin-bottom: 2px; display: flex; align-items: center; gap: 6px; }
.conv-item .name > span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .ad { font-size: 12px; color: var(--text2); margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .last { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.conv-bl-btn { padding: 3px 6px; font-size: 12px; background: transparent; border: 1px solid transparent; border-radius: 4px; cursor: pointer; opacity: 0; transition: opacity .15s, background .15s; color: inherit; }
.conv-item:hover .conv-bl-btn { opacity: .55; }
.conv-bl-btn:hover { opacity: 1 !important; background: rgba(239, 68, 68, .15); border-color: rgba(239, 68, 68, .4); }

.conv-detail { flex: 1; display: flex; flex-direction: column; background: var(--bg); min-width: 0; }
.conv-header { padding: 16px 20px; border-bottom: 1px solid var(--border); background: var(--bg2); display: flex; align-items: center; gap: 12px; }
.conv-header .header-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4a4f5c 0%, #2a2d38 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.conv-header .header-body { flex: 1; min-width: 0; }
.conv-header .buyer { font-weight: 600; font-size: 15px; letter-spacing: -.2px; }
.conv-header .ad-title { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.conv-header .ad-price { color: var(--green); font-weight: 600; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: radial-gradient(ellipse at 50% 0%, rgba(124,140,255,.03) 0%, var(--bg) 60%);
}
.msg {
  max-width: 100%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  line-height: 1.45;
  width: fit-content;
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.msg.seller {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent) 0%, #6b7cff 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(124,140,255,.25);
}
.msg.buyer {
  align-self: flex-start;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text);
}
.msg-wrap { display: flex; flex-direction: column; max-width: min(75%, 560px); align-items: flex-end; margin-top: 2px; }
.msg-wrap.buyer-wrap { align-self: flex-start; align-items: flex-start; }
.msg-wrap.seller-wrap { align-self: flex-end; }
.msg-status { font-size: 10px; color: var(--muted); margin-top: 3px; padding: 0 6px; display: flex; gap: 4px; align-items: center; }
.msg-status .check { color: var(--muted); }
.msg-status .check.read { color: var(--blue); }

.send-bar {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  background: var(--bg2);
  align-items: flex-end;
}
.send-bar textarea {
  resize: none;
  min-height: 44px;
  max-height: 120px;
  padding: 12px 14px;
  background: var(--bg3);
  border-color: var(--border2);
  border-radius: 22px;
}
.send-bar textarea:focus { background: var(--bg3); }
.send-bar button {
  padding: 0 20px;
  height: 44px;
  border-radius: 22px;
}

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

.row { display: flex; gap: 12px; align-items: center; }
.row .grow { flex: 1; }
.muted { color: var(--muted); }
.mono { font-family: "SF Mono", "JetBrains Mono", Consolas, monospace; font-size: 12px; background: var(--bg); padding: 2px 6px; border-radius: 4px; }

.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 12px;
  color: var(--text2);
  overflow-x: auto;
  line-height: 1.6;
}

/* Tabs bar in AccountView */
.tabs-bar {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  display: flex;
  gap: 4px;
  align-items: center;
}
.tab-btn {
  padding: 7px 14px !important;
  font-size: 12.5px !important;
  border-radius: 8px !important;
  background: transparent !important;
  color: var(--muted) !important;
  border: none !important;
  box-shadow: none !important;
  transition: all .15s !important;
}
.tab-btn:hover { background: var(--bg3) !important; color: var(--text) !important; transform: none !important; }
.tab-btn.active { background: var(--accent-soft) !important; color: var(--accent) !important; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fade .18s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 24px;
  min-width: 380px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: pop .18s cubic-bezier(.4,0,.2,1);
}
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(6px); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h3 { font-size: 16px; font-weight: 600; letter-spacing: -.2px; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.15); }

/* Text selection */
::selection { background: var(--accent-glow); color: var(--text); }


/* ============ Toasts (nowe wiadomosci) ============ */
.toaster {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
  pointer-events: none;
}
.toast {
  background: linear-gradient(180deg, var(--bg3), var(--bg2));
  border: 1px solid var(--border2);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  color: var(--text);
  cursor: pointer;
  pointer-events: auto;
  animation: toastIn .28s ease-out;
  transition: transform .15s ease, box-shadow .15s ease;
}
.toast:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(0,0,0,.55); }
.toast-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.toast-acc { font-size: 12px; color: var(--accent2); font-weight: 600; }
.toast-buyer { font-size: 13px; color: var(--text); font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-x {
  background: transparent; border: none; color: var(--muted);
  font-size: 20px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.toast-x:hover { color: var(--text); }
.toast-ad { font-size: 12px; color: var(--muted); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-text {
  font-size: 13px; color: var(--text2);
  overflow-wrap: anywhere; word-break: normal;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ============ Unread badge na liscie kont ============ */
.unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: linear-gradient(135deg, #f87171, #ef4444);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(239,68,68,.35);
  animation: unreadPulse 2s ease-in-out infinite;
}
@keyframes unreadPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
