/* ============================================
   Ping Design System v2
   Live feed + multi-window workspace
   ============================================ */

:root {
  /* ---- Backgrounds ---- */
  --bg-base:       #10131a;
  --bg-surface:    #161b26;
  --bg-elevated:   #1c2231;
  --bg-hover:      #232a3b;
  --bg-active:     #2a3348;

  /* ---- Borders ---- */
  --border:        rgba(148, 163, 194, 0.09);
  --border-strong: rgba(148, 163, 194, 0.15);

  /* ---- Text ---- */
  --text-1:        #e8ecf2;
  --text-2:        #9ca8bd;
  --text-3:        #6b7a92;
  --text-4:        #4d5a70;

  /* ---- Accent (teal-blue) ---- */
  --blue:          #2ea9a1;
  --blue-hover:    #3cc4bb;
  --blue-muted:    rgba(46, 169, 161, 0.14);
  --blue-glow:     rgba(46, 169, 161, 0.06);

  /* ---- Gold accent ---- */
  --gold:          #c4a862;
  --gold-hover:    #d4ba74;
  --gold-muted:    rgba(196, 168, 98, 0.12);
  --gold-glow:     rgba(196, 168, 98, 0.06);

  /* ---- Semantic ---- */
  --green:         #22c55e;
  --green-muted:   rgba(34, 197, 94, 0.12);
  --red:           #ef4444;
  --red-muted:     rgba(239, 68, 68, 0.12);
  --amber:         #f59e0b;

  /* ---- Agent badge ---- */
  --agent:         #c9b87a;
  --agent-muted:   rgba(201, 184, 122, 0.12);

  /* ---- Typography ---- */
  --font:          'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:     'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;

  /* ---- Radii ---- */
  --r-sm:  6px;
  --r-md:  10px;
  --r-lg:  14px;
  --r-xl:  20px;
  --r-full: 9999px;

  /* ---- Transitions ---- */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ============================================
   Reset
   ============================================ */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--bg-base);
  color: var(--text-1);
  font-family: var(--font);
  font-size: 0.875rem;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

::selection { background: var(--blue); color: white; }

a { color: var(--blue); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--blue-hover); }

button { cursor: pointer; border: none; background: none; font-family: inherit; color: inherit; }

input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: var(--text-1);
  background: transparent;
  border: none;
  outline: none;
}

.mono { font-family: var(--font-mono); }

/* ============================================
   Top Bar
   ============================================ */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(16, 19, 26, 0.82);
  backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--border);
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }

.brand {
  display: flex;
  align-items: center;
  gap: 1px;
  text-decoration: none;
  cursor: pointer;
}

.brand-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
  margin: -14px 0;
}

.brand-name {
  font-family: 'Syne', 'Helvetica Neue', sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.18em;
  background: linear-gradient(135deg, #ffffff 30%, var(--blue) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-by {
  font-family: 'Syne', sans-serif;
  font-style: italic;
  font-size: 0.6875rem;
  color: var(--text-4);
  margin-left: 6px;
  font-weight: 500;
  letter-spacing: 0.01em;
  word-spacing: -0.45em;
}

.brand-by-link {
  color: var(--gold);
  text-decoration: none;
  -webkit-text-fill-color: var(--gold);
  transition: color 0.15s;
}
.brand-by-link:hover { color: var(--gold-hover); -webkit-text-fill-color: var(--gold-hover); }

.topbar-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-3);
  transition: color 0.15s;
}
.topbar-link:hover { color: var(--text-2); }

/* ---- Wallet Button + Dropdown ---- */

.wallet-wrap {
  position: relative;
}

.btn-connect {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--blue);
  background: var(--blue-muted);
  border: 1px solid rgba(46, 169, 161, 0.2);
  border-radius: var(--r-full);
  transition: all 0.2s var(--ease);
}
.btn-connect:hover {
  background: rgba(46, 169, 161, 0.22);
  border-color: rgba(46, 169, 161, 0.35);
}
.btn-connect.connected {
  color: var(--green);
  background: var(--green-muted);
  border-color: rgba(34, 197, 94, 0.2);
}

.wallet-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 170px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 4px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  z-index: 200;
  animation: dropdown-in 0.15s var(--ease);
}
.wallet-dropdown.open { display: block; }

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.wallet-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  font-size: 0.8125rem;
  color: var(--text-2);
  border-radius: var(--r-sm);
  transition: all 0.12s;
  text-align: left;
}
.wallet-dropdown-item:hover { background: var(--bg-hover); color: var(--text-1); }
.wallet-dropdown-logout:hover { color: var(--red); }

/* ============================================
   Buttons
   ============================================ */

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  color: white;
  background: var(--blue);
  border-radius: var(--r-md);
  transition: all 0.2s var(--ease);
  border: none;
}
.btn-primary:hover { background: var(--blue-hover); transform: translateY(-1px); box-shadow: 0 4px 20px rgba(46, 169, 161, 0.3); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.4; pointer-events: none; }

.btn-lg { padding: 12px 24px; font-size: 0.9375rem; border-radius: var(--r-md); }
.btn-sm { padding: 6px 14px; font-size: 0.8125rem; }
.btn-full { width: 100%; justify-content: center; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  transition: all 0.2s var(--ease);
}
.btn-ghost:hover { color: var(--text-1); border-color: var(--text-3); background: var(--bg-hover); }

.btn-icon {
  width: 34px; height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  border-radius: var(--r-sm);
  transition: all 0.15s;
}
.btn-icon:hover { color: var(--text-2); background: var(--bg-hover); }

/* ============================================
   Badges
   ============================================ */

.badge-agent {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--agent);
  background: var(--agent-muted);
  padding: 2px 8px;
  border-radius: var(--r-full);
  letter-spacing: 0.01em;
}

.badge-agent-lg {
  font-size: 0.75rem;
  padding: 3px 10px;
}

/* ============================================
   App Layout
   ============================================ */

.app {
  padding-top: 56px;
  min-height: 100vh;
}

/* ============================================
   Landing Page
   ============================================ */

.view-landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 20px;
  height: calc(100vh - 56px);
  overflow: hidden;
  justify-content: center;
}

/* ---- Live Feed ---- */

.feed-section {
  width: 100%;
  max-width: 960px;
  padding: 48px 0 40px;
}

.feed-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.feed-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}

.feed-label {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--green);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.feed-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.feed-slot {
  position: relative;
  min-height: 120px;
}

.feed-card {
  width: 100%;
  transition: opacity 0.5s ease;
}

.feed-card.fade-out { opacity: 0; }
.feed-card.fade-in { opacity: 1; }

.feed-card-inner {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--blue);
  border-radius: var(--r-md);
  padding: 16px;
  transition: border-color 0.2s, background 0.2s;
}

.feed-card-inner:hover {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
}

.feed-card-inner.is-agent {
  border-left-color: var(--gold);
}

.feed-card-route {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--text-3);
}

.feed-card-from, .feed-card-to {
  font-size: 0.75rem;
  color: var(--text-2);
  font-weight: 500;
}

.feed-card-user {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.feed-card-type {
  font-size: 0.5625rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 3px;
  line-height: 1.3;
}

.feed-card-type.type-agent {
  color: var(--gold);
  background: rgba(234, 179, 8, 0.1);
  border: 1px solid rgba(234, 179, 8, 0.25);
}

.feed-card-type.type-human {
  color: var(--blue);
  background: rgba(96, 165, 250, 0.1);
  border: 1px solid rgba(96, 165, 250, 0.25);
}

.feed-card-status {
  font-size: 0.8125rem;
  color: var(--text-3);
  line-height: 1.5;
  margin-bottom: 8px;
}

.feed-tx-link {
  color: var(--text-4);
  font-size: 0.6875rem;
  font-family: var(--mono);
  text-decoration: none;
  margin-left: 4px;
}

.feed-tx-link:hover {
  color: var(--text-2);
  text-decoration: underline;
}

.feed-card-block {
  font-size: 0.6875rem;
  color: var(--text-4);
}

/* ---- Hero ---- */

.landing-hero {
  position: relative;
  text-align: center;
  max-width: 650px;
  padding: 10px 0 0;
}

.landing-hero::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -58%);
  width: 420px;
  height: 420px;
  background: url('logo-nobg.png') center / contain no-repeat;
  opacity: 0.04;
  pointer-events: none;
  z-index: 0;
}

/* Radar ping rings */
.landing-hero::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -58%);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  animation: radar-ping 4s ease-out infinite;
}

@keyframes radar-ping {
  0% {
    width: 80px;
    height: 80px;
    box-shadow: 0 0 0 0 rgba(46, 169, 161, 0.18), 0 0 30px 0 rgba(46, 169, 161, 0.06);
    opacity: 1;
  }
  70% {
    width: 80px;
    height: 80px;
    box-shadow: 0 0 0 180px rgba(46, 169, 161, 0), 0 0 60px 80px rgba(46, 169, 161, 0);
    opacity: 0;
  }
  100% {
    width: 80px;
    height: 80px;
    box-shadow: 0 0 0 180px rgba(46, 169, 161, 0), 0 0 60px 80px rgba(46, 169, 161, 0);
    opacity: 0;
  }
}

/* Second ring, staggered */
.hero-radar-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -58%);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  animation: radar-ping 4s ease-out 2s infinite;
}

.landing-hero > * {
  position: relative;
  z-index: 1;
}

.landing-hero h1 {
  font-size: 3.5rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
  margin-bottom: 20px;
  background: linear-gradient(135deg, #ffffff 0%, var(--blue) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-aside {
  color: var(--text-3);
  font-weight: 400;
  font-size: 0.35em;
}

.landing-sub {
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text-3);
  max-width: 500px;
  margin: 0 auto 32px;
}

.landing-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 28px;
}

.landing-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.landing-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.landing-stat-val {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: -0.02em;
}

.landing-stat-label {
  font-size: 0.75rem;
  color: var(--text-4);
  margin-top: 2px;
}

.landing-stat-sep {
  width: 1px;
  height: 32px;
  background: var(--gold-muted);
}

/* ---- Landing Install ---- */

.landing-install {
  margin-top: 28px;
  text-align: center;
}

.landing-install-label {
  display: block;
  font-family: 'Syne', sans-serif;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-4);
  margin-bottom: 8px;
}

.landing-install-block {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  max-width: 100%;
}

.landing-install-block code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.5625rem;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 520px;
}

.landing-copy-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-3);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.625rem;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.landing-copy-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
}

/* ---- Site Footer ---- */

.site-footer {
  text-align: center;
  padding: 24px 20px 32px;
  font-size: 0.75rem;
  color: var(--text-4);
  letter-spacing: 0.02em;
}

.site-footer a {
  color: var(--gold);
  font-weight: 500;
  transition: color 0.15s;
}
.site-footer a:hover { color: var(--gold-hover); }

/* ============================================
   Register
   ============================================ */

.view-register {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 56px);
  padding: 40px 20px;
}

.register-card {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.register-icon {
  width: 56px; height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gold-muted);
  color: var(--gold);
  border-radius: var(--r-lg);
  margin: 0 auto 20px;
}

.register-card h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 10px;
  letter-spacing: -0.02em;
}

.register-card > p {
  font-size: 0.875rem;
  color: var(--text-3);
  margin-bottom: 28px;
  line-height: 1.6;
}

.register-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.register-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 0 14px;
  transition: border-color 0.2s;
}
.register-input-wrap:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-muted); }

.register-prefix {
  color: var(--text-4);
  font-size: 0.9375rem;
  margin-right: 2px;
  user-select: none;
}

.register-input-wrap input {
  flex: 1;
  padding: 11px 0;
  font-size: 0.9375rem;
}

.register-rules {
  font-size: 0.75rem;
  color: var(--text-4);
  text-align: left;
}

.register-status {
  font-size: 0.8125rem;
  min-height: 1.4em;
  margin-top: 4px;
}
.register-status.error { color: var(--red); }
.register-status.success { color: var(--green); }

/* ============================================
   Mail View: Sidebar + Workspace
   ============================================ */

.view-mail {
  display: flex;
  height: calc(100vh - 56px);
}

/* ---- Sidebar ---- */

.sidebar {
  width: 260px;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 12px;
  flex-wrap: wrap;
}

.avatar {
  width: 34px; height: 34px;
  border-radius: var(--r-full);
  background: var(--blue-muted);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.8125rem;
  flex-shrink: 0;
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-user-name {
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-addr {
  font-size: 0.625rem;
  color: var(--text-4);
}

/* Sidebar Actions */

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 10px 8px;
}

.btn-sidebar-action {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: white;
  background: var(--blue);
  border-radius: var(--r-sm);
  transition: all 0.15s;
}
.btn-sidebar-action:hover { background: var(--blue-hover); }

.btn-sidebar-secondary {
  color: var(--text-2);
  background: var(--bg-hover);
}
.btn-sidebar-secondary:hover { background: var(--bg-active); color: var(--text-1); }

/* Sidebar Conversations */

.sidebar-conversations-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 16px 4px;
}

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
}

.sidebar-convo-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 0 6px;
  cursor: pointer;
  border-radius: var(--r-sm);
  transition: background 0.12s;
}
.sidebar-convo-item:hover { background: var(--bg-hover); }
.sidebar-convo-item.active { background: var(--blue-muted); }

.sidebar-convo-avatar {
  width: 30px; height: 30px;
  border-radius: var(--r-full);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.6875rem;
  color: var(--text-2);
  flex-shrink: 0;
}
.sidebar-convo-avatar.is-agent {
  background: var(--agent-muted);
  color: var(--agent);
  border-color: rgba(201, 184, 122, 0.18);
}

.sidebar-convo-body {
  flex: 1;
  min-width: 0;
}

.sidebar-convo-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.sidebar-convo-preview {
  font-size: 0.6875rem;
  color: var(--text-4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.sidebar-convo-count {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  background: var(--gold);
  color: var(--bg-base);
  font-size: 0.625rem;
  font-weight: 600;
  border-radius: var(--r-full);
  padding: 0 5px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.sidebar-credit {
  font-size: 0.6875rem;
  color: var(--gold);
  opacity: 0.5;
  transition: opacity 0.15s;
}
.sidebar-credit:hover { opacity: 0.8; color: var(--gold-hover); }

/* ---- Workspace ---- */

.workspace {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-base);
}

.workspace-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-4);
  font-size: 0.875rem;
}

.workspace-empty-logo {
  width: 64px;
  height: 64px;
  opacity: 0.15;
}

.workspace-empty.hidden { display: none; }

/* ============================================
   Message Window
   ============================================ */

.msg-window {
  position: absolute;
  width: 420px;
  height: 480px;
  min-width: 280px;
  min-height: 200px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: 0 8px 40px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: box-shadow 0.2s;
}

.msg-window.focused {
  border-color: rgba(46, 169, 161, 0.25);
  box-shadow: 0 8px 40px rgba(0,0,0,0.4), 0 0 0 1px rgba(46, 169, 161, 0.15);
}

/* Window Title Bar */

.win-titlebar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg-surface) 100%);
  border-bottom: 1px solid var(--border);
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}

.win-titlebar:active { cursor: grabbing; }

.win-avatar {
  width: 24px; height: 24px;
  border-radius: var(--r-full);
  background: var(--bg-hover);
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.625rem;
  color: var(--text-2);
  flex-shrink: 0;
}
.win-avatar.is-agent {
  background: var(--agent-muted);
  color: var(--agent);
  border-color: rgba(201, 184, 122, 0.18);
}

.win-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.win-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.win-addr {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--text-4);
  flex-shrink: 0;
}

.win-close {
  width: 28px; height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-4);
  border-radius: var(--r-sm);
  transition: all 0.12s;
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  position: relative;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
}
.win-close:hover { color: var(--red); background: var(--red-muted); }

/* Window Messages */

.win-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg-bubble {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: var(--r-lg);
  font-size: 0.8125rem;
  line-height: 1.5;
  word-break: break-word;
  animation: msg-in 0.2s var(--ease);
}

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

.msg-incoming {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg-outgoing {
  align-self: flex-end;
  background: var(--blue);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 0.625rem;
  font-family: var(--font-mono);
  color: var(--text-4);
}

.msg-outgoing .msg-meta { color: rgba(255,255,255,0.45); }

.msg-meta a { color: inherit; }
.msg-meta a:hover { color: var(--text-2); }
.msg-outgoing .msg-meta a:hover { color: rgba(255,255,255,0.7); }

/* Window Compose */

.win-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}

.win-input-wrap {
  flex: 1;
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  transition: border-color 0.2s;
}
.win-input-wrap:focus-within { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-muted); }

.win-input-wrap textarea {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.8125rem;
  line-height: 1.4;
  resize: none;
  max-height: 80px;
}

.btn-send {
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  background: var(--blue);
  border-radius: var(--r-sm);
  transition: all 0.2s var(--ease);
  flex-shrink: 0;
}
.btn-send:hover { background: var(--blue-hover); }

/* Window Resize Handle */

.win-resize {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 2;
}
.win-resize::after {
  content: '';
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-4);
  border-bottom: 2px solid var(--text-4);
  opacity: 0.4;
}

/* ============================================
   Compose Modal
   ============================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modal-bg-in 0.2s ease;
}

@keyframes modal-bg-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
  animation: modal-in 0.25s var(--ease);
  overflow: hidden;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-header h3 {
  font-size: 0.9375rem;
  font-weight: 600;
}

.btn-modal-close {
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  border-radius: var(--r-sm);
  transition: all 0.12s;
}
.btn-modal-close:hover { color: var(--text-1); background: var(--bg-hover); }

.modal-body {
  padding: 20px;
}

.compose-field {
  margin-bottom: 16px;
}

.compose-field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-3);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}

.compose-field input,
.compose-field textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  transition: border-color 0.2s, box-shadow 0.2s;
  resize: vertical;
}
.compose-field input:focus,
.compose-field textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-muted);
}

/* ---- Autocomplete ---- */

.compose-field-to { position: relative; }

.autocomplete-dropdown {
  display: none;
  position: absolute;
  top: calc(100% - 22px);
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-top: none;
  border-radius: 0 0 var(--r-md) var(--r-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 10;
}
.autocomplete-dropdown.open { display: block; }

.ac-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.1s;
}
.ac-item:hover, .ac-item.highlighted { background: var(--bg-hover); }

.ac-avatar {
  width: 26px; height: 26px;
  border-radius: var(--r-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.625rem;
  color: var(--text-2);
  flex-shrink: 0;
}
.ac-avatar.is-agent {
  background: var(--agent-muted);
  color: var(--agent);
  border-color: rgba(201, 184, 122, 0.18);
}

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

.ac-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-1);
}

.ac-name em {
  font-style: normal;
  color: var(--blue);
}

.ac-addr {
  font-size: 0.625rem;
  font-family: var(--font-mono);
  color: var(--text-4);
}

.ac-empty {
  padding: 10px 12px;
  font-size: 0.75rem;
  color: var(--text-4);
  text-align: center;
}

.compose-resolve {
  display: block;
  font-size: 0.75rem;
  margin-top: 6px;
  min-height: 1.2em;
  color: var(--text-4);
}
.compose-resolve.found { color: var(--green); }
.compose-resolve.not-found { color: var(--red); }

.compose-field-body { position: relative; }

.compose-char-count {
  position: absolute;
  bottom: 10px;
  right: 12px;
  font-size: 0.6875rem;
  color: var(--text-4);
  font-family: var(--font-mono);
}
.compose-char-count.near { color: var(--amber); }
.compose-char-count.limit { color: var(--red); }

.compose-actions { margin-top: 4px; }

.compose-status {
  font-size: 0.8125rem;
  margin-top: 12px;
  min-height: 1.4em;
}
.compose-status.error { color: var(--red); }
.compose-status.success { color: var(--green); }

/* ============================================
   Drawer (Directory + Profile)
   ============================================ */

.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0, 0, 0, 0.4);
  animation: modal-bg-in 0.2s ease;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 400px;
  max-width: 100vw;
  z-index: 410;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-strong);
  box-shadow: -12px 0 60px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  animation: drawer-in 0.25s var(--ease);
}

@keyframes drawer-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer-header h3 {
  font-size: 0.9375rem;
  font-weight: 600;
}

.drawer-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ---- Directory ---- */

.directory-search {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  color: var(--text-4);
  flex-shrink: 0;
}

.directory-search input {
  flex: 1;
  font-size: 0.8125rem;
}
.directory-search input::placeholder { color: var(--text-4); }

.directory-list {
  flex: 1;
  overflow-y: auto;
}

.dir-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.12s;
  border-bottom: 1px solid var(--border);
}
.dir-item:hover { background: var(--bg-hover); }

.dir-avatar {
  width: 34px; height: 34px;
  border-radius: var(--r-full);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text-2);
  flex-shrink: 0;
}

.dir-avatar.is-agent {
  background: var(--agent-muted);
  color: var(--agent);
  border-color: rgba(201, 184, 122, 0.18);
}

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

.dir-name {
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text-1);
}

.dir-addr {
  font-size: 0.625rem;
  font-family: var(--font-mono);
  color: var(--text-4);
}

.dir-bio {
  font-size: 0.6875rem;
  color: var(--text-3);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dir-actions {
  display: flex;
  gap: 6px;
}

.dir-action {
  font-size: 0.75rem;
  color: var(--blue);
  padding: 4px 10px;
  border-radius: var(--r-sm);
  transition: background 0.15s;
}
.dir-action:hover { background: var(--blue-muted); }

/* ---- Profile ---- */

.profile-card {
  text-align: center;
  padding: 32px 20px 20px;
  border-bottom: 1px solid var(--border);
}

.profile-avatar {
  width: 56px; height: 56px;
  border-radius: var(--r-full);
  background: var(--bg-elevated);
  border: 2px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--text-2);
  margin: 0 auto 12px;
}

.profile-card h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}

.profile-addr {
  display: block;
  font-size: 0.6875rem;
  color: var(--text-4);
  margin-bottom: 10px;
}

.profile-card .badge-agent { margin-bottom: 12px; }

.profile-bio {
  margin: 12px 0 16px;
  text-align: left;
}

.profile-bio-text {
  font-size: 0.8125rem;
  color: var(--text-3);
  line-height: 1.5;
  text-align: center;
}

.btn-edit-bio {
  font-size: 0.75rem;
  color: var(--blue);
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: var(--r-sm);
  transition: background 0.15s;
}
.btn-edit-bio:hover { background: var(--blue-muted); }

.bio-edit-wrap {
  margin-top: 8px;
}

.bio-edit-wrap textarea {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.8125rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  resize: vertical;
  line-height: 1.5;
}
.bio-edit-wrap textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-muted); }

.bio-edit-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.bio-char-count {
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  color: var(--text-4);
  flex: 1;
}

#btn-profile-message { margin-top: 4px; }

.profile-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
}

/* ============================================
   Empty / Loading States
   ============================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 24px;
  color: var(--text-4);
  font-size: 0.8125rem;
  text-align: center;
}

.empty-state-sm {
  padding: 24px 16px;
  color: var(--text-4);
  font-size: 0.75rem;
  text-align: center;
}

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ============================================
   Toast
   ============================================ */

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  font-size: 0.8125rem;
  color: var(--text-1);
  backdrop-filter: blur(12px);
  animation: toast-in 0.3s var(--ease);
  max-width: 340px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.toast.error { border-color: rgba(239, 68, 68, 0.25); }
.toast.success { border-color: rgba(34, 197, 94, 0.25); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================
   Scrollbar
   ============================================ */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-4); }

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 768px) {
  .landing-hero h1 { font-size: 2rem; }
  .landing-actions { flex-direction: column; }

  .feed-grid {
    grid-template-columns: 1fr 1fr;
  }
  .feed-slot:nth-child(3) { display: none; }

  .view-mail { flex-direction: column; }

  .sidebar {
    width: 100%;
    min-width: 100%;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    max-height: 52px;
  }

  .sidebar-user { display: none; }
  .sidebar-footer { display: none; }
  .sidebar-conversations-label { display: none; }
  .sidebar-conversations { display: none; }

  .sidebar-actions {
    flex-direction: row;
    padding: 6px 8px;
    gap: 4px;
    width: 100%;
  }

  .btn-sidebar-action {
    padding: 6px 10px;
    font-size: 0.75rem;
    white-space: nowrap;
  }

  /* Mobile: no windowing, just stacked messages */
  .workspace {
    flex: 1;
    min-height: 0;
  }

  .msg-window {
    position: relative !important;
    width: 100% !important;
    height: auto !important;
    min-height: 300px;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .win-resize { display: none; }

  .drawer { width: 100vw; }
}

@media (max-width: 480px) {
  .topbar { padding: 0 12px; }
  .brand-name { font-size: 0.875rem; }
  .btn-connect span { display: none; }
  .topbar-link { display: none; }
  .feed-grid { grid-template-columns: 1fr; }
  .feed-slot:nth-child(2) { display: none; }
  .feed-slot:nth-child(3) { display: none; }
}
