/* ==========================================================================
   TezTrollBox — Modernized Dark Glassmorphism Design System
   Matches eye.tez.cool, stake.tez.cool & tez.cool Suite
   ========================================================================== */

:root {
  --bg-deep: #090b16;
  --bg-surface: #0f1322;
  --bg-glass: rgba(15, 19, 34, 0.72);
  --bg-glass-elevated: rgba(24, 30, 52, 0.88);
  --bg-glass-hover: rgba(34, 42, 72, 0.78);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-bright: rgba(162, 124, 238, 0.38);
  --border-cyan: rgba(0, 242, 242, 0.35);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-cyan: #00f2f2;
  --accent-purple: #a27cee;
  --accent-indigo: #6366f1;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;

  --font-display: 'Monda', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-pill: 9999px;

  --shadow-glass: 0 16px 40px -8px rgba(0, 0, 0, 0.6), 0 0 1px 1px rgba(255, 255, 255, 0.05);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-deep);
  background-image:
    radial-gradient(circle at 18% 18%, rgba(127, 75, 231, 0.16) 0%, transparent 45%),
    radial-gradient(circle at 82% 80%, rgba(0, 242, 242, 0.1) 0%, transparent 45%),
    radial-gradient(circle at 50% 50%, #11152c 0%, #090b16 100%);
  color: var(--text-primary);
  font-family: var(--font-sans);
  overflow: hidden;
  color-scheme: dark;
}

a {
  color: inherit;
  text-decoration: none;
}

/* Ambient Starfield */
.ambient-stars {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(1px 1px at 15% 25%, rgba(255, 255, 255, 0.45) 50%, transparent 100%),
    radial-gradient(1.5px 1.5px at 72% 18%, rgba(162, 124, 238, 0.5) 50%, transparent 100%),
    radial-gradient(1px 1px at 42% 68%, rgba(0, 242, 242, 0.45) 50%, transparent 100%),
    radial-gradient(1.5px 1.5px at 88% 62%, rgba(255, 255, 255, 0.35) 50%, transparent 100%),
    radial-gradient(1px 1px at 26% 84%, rgba(162, 124, 238, 0.4) 50%, transparent 100%);
  background-size: 550px 550px;
  opacity: 0.65;
}

/* ==========================================================================
   App Shell & Original TezCool Header
   ========================================================================== */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
}

.header, .header-content {
  display: flex;
  align-items: center;
  width: 100%;
}

.header {
  height: 80px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: 0 0;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.26);
  padding: 16px 24px;
  z-index: 100;
  transition: .3s;
}

.header-content {
  justify-content: center;
  max-width: 1400px;
  margin: 0 auto;
}

.nav-menu {
  align-items: center;
  display: flex;
  gap: 24px;
  list-style: none;
  margin: 0;
  padding: 0;
  justify-content: center;
}

.nav-item {
  color: #ffffff;
  font-family: "Monda", Helvetica, sans-serif;
  font-size: 1rem;
  font-weight: 400;
  padding: 8px 16px;
  border-radius: 16px;
  transition: .3s;
  cursor: pointer;
  position: relative;
  text-decoration: none;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.01);
  color: #a27cee;
}

.nav-item.active {
  background: linear-gradient(180deg, rgba(162, 124, 238, 1) 0%, rgba(127, 75, 231, 1) 100%);
  color: #ffffff;
}

@media (max-width: 1200px) {
  .nav-menu { gap: 16px; }
  .nav-item { font-size: .9rem; padding: 8px; }
}

@media (max-width: 1024px) {
  .nav-menu { gap: 8px; }
  .nav-item { font-size: .8rem; padding: 6px 8px; }
}

@media (max-width: 768px) {
  .header { padding: 8px 16px; }
  .nav-item { font-size: .7rem; padding: 4px 6px; }
}

@media (max-width: 640px) {
  .nav-item { font-size: .65rem; padding: 4px; }
  .nav-menu { gap: 4px; }
  .header { height: 130px; }
}

@media (max-width: 480px) {
  .header-content { flex-wrap: wrap; gap: 8px; }
  .nav-menu { order: 2; width: 100%; justify-content: center; flex-wrap: wrap; gap: 8px; }
  .nav-item { font-size: .7rem; padding: 4px 8px; }
  .header { height: 130px; }
}

/* ==========================================================================
   Main Chat Workspace
   ========================================================================== */
.trollbox-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-width: 1020px;
  width: 100%;
  margin: 0 auto;
  padding: 96px 18px 18px;
}

.frame-mode .trollbox-main {
  padding-top: 82px;
}

@media (max-width: 640px) {
  .trollbox-main {
    padding-top: 142px;
  }
}

/* Top Control Bar inside Chat */
.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
  box-shadow: var(--shadow-glass);
  flex-shrink: 0;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 10px var(--accent-emerald);
  animation: pulseDot 2s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.65; }
}

.contract-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.contract-pill:hover {
  color: var(--accent-cyan);
  border-color: var(--border-cyan);
  background: rgba(0, 242, 242, 0.06);
}

.stats-pill {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wallet-badge {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 5px 11px 5px 6px;
  border-radius: var(--radius-pill);
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  font-family: var(--font-mono);
  font-size: 12px;
  color: #a7f3d0;
}

.wallet-badge.visible {
  display: inline-flex;
}

.wallet-badge img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
}

.btn-wallet {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 15px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(162, 124, 238, 0.45);
  background: linear-gradient(135deg, rgba(162, 124, 238, 0.25), rgba(99, 102, 241, 0.25));
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-wallet:hover {
  background: linear-gradient(135deg, rgba(162, 124, 238, 0.4), rgba(99, 102, 241, 0.4));
  border-color: var(--accent-purple);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(127, 75, 231, 0.3);
}

.btn-wallet.disconnect {
  background: rgba(244, 63, 94, 0.14);
  border-color: rgba(244, 63, 94, 0.35);
  color: #fda4af;
}

.btn-wallet.disconnect:hover {
  background: rgba(244, 63, 94, 0.24);
  border-color: var(--accent-rose);
  box-shadow: 0 6px 16px rgba(244, 63, 94, 0.25);
}

/* ==========================================================================
   Chat Feed Container & Messages
   ========================================================================== */
.chat-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-glass);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-glass);
  overflow: hidden;
  position: relative;
}

.messages-viewport {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.messages-viewport::-webkit-scrollbar {
  width: 6px;
}
.messages-viewport::-webkit-scrollbar-track {
  background: transparent;
}
.messages-viewport::-webkit-scrollbar-thumb {
  background: rgba(162, 124, 238, 0.3);
  border-radius: 999px;
}
.messages-viewport::-webkit-scrollbar-thumb:hover {
  background: rgba(162, 124, 238, 0.55);
}

/* Loading & Empty States */
.chat-state-box {
  margin: auto;
  text-align: center;
  padding: 36px 24px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.spinner-ring-sm {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(162, 124, 238, 0.2);
  border-top-color: var(--accent-cyan);
  animation: spin 0.9s linear infinite;
}

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

/* Message Item */
.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
  cursor: pointer;
  position: relative;
}

.msg-row:hover {
  background: rgba(162, 124, 238, 0.08);
  border-color: rgba(162, 124, 238, 0.26);
}

.msg-row.own-message {
  background: linear-gradient(135deg, rgba(162, 124, 238, 0.12), rgba(99, 102, 241, 0.08));
  border-color: rgba(162, 124, 238, 0.3);
}

.msg-row.highlight-flash {
  animation: highlightPulse 1.6s ease;
}

@keyframes highlightPulse {
  0%, 100% {
    background: rgba(255, 255, 255, 0.025);
    border-color: rgba(255, 255, 255, 0.05);
  }
  30% {
    background: rgba(0, 242, 242, 0.2);
    border-color: var(--accent-cyan);
    box-shadow: 0 0 20px rgba(0, 242, 242, 0.25);
  }
}

.msg-avatar-link {
  flex-shrink: 0;
  position: relative;
}

.msg-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  border: 1.5px solid rgba(162, 124, 238, 0.4);
  object-fit: cover;
  display: block;
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.msg-avatar-link:hover .msg-avatar {
  transform: scale(1.08);
  border-color: var(--accent-cyan);
}

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

.msg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.msg-author-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.msg-author {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-purple);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-author:hover {
  color: var(--accent-cyan);
  text-decoration: underline;
}

.msg-id-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
}

.msg-meta-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.msg-reply-hint {
  opacity: 0;
  font-size: 11px;
  color: var(--accent-cyan);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: opacity 0.15s ease;
}

.msg-row:hover .msg-reply-hint {
  opacity: 1;
}

.msg-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* Reply Quote inside Message */
.msg-reply-quote {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  margin-bottom: 6px;
  border-radius: var(--radius-sm);
  background: rgba(0, 242, 242, 0.06);
  border-left: 2.5px solid var(--accent-cyan);
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-reply-quote:hover {
  background: rgba(0, 242, 242, 0.12);
  color: var(--text-primary);
}

.msg-reply-quote strong {
  color: var(--accent-cyan);
  font-family: var(--font-display);
  font-weight: 600;
}

/* Message Content */
.msg-text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-link {
  color: var(--accent-cyan);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg-link:hover {
  color: #67e8f9;
}

.msg-gif {
  margin-top: 6px;
  max-width: min(320px, 100%);
  max-height: 220px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  display: block;
}

.msg-youtube {
  margin-top: 8px;
  width: min(420px, 100%);
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

.msg-youtube iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

/* ==========================================================================
   Reply Banner & Pending Transaction Bar
   ========================================================================== */
.reply-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: rgba(0, 242, 242, 0.08);
  border-top: 1px solid rgba(0, 242, 242, 0.25);
  font-size: 12.5px;
  color: var(--text-secondary);
}

.reply-banner.active {
  display: flex;
}

.reply-banner-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-banner-info strong {
  color: var(--accent-cyan);
  font-family: var(--font-display);
}

.btn-cancel-reply {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}

.btn-cancel-reply:hover {
  color: var(--text-primary);
  border-color: var(--accent-rose);
}

/* Pending TX Bar */
.tx-status-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 16px;
  background: rgba(162, 124, 238, 0.14);
  border-top: 1px solid rgba(162, 124, 238, 0.3);
  font-size: 12.5px;
  color: #e9d5ff;
}

.tx-status-bar.active {
  display: flex;
}

.tx-status-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ==========================================================================
   Composer / Input Area
   ========================================================================== */
.composer-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(9, 11, 22, 0.72);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.tool-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
  flex-shrink: 0;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
}

.tool-icon-btn:hover,
.tool-icon-btn.active {
  color: var(--accent-cyan);
  border-color: var(--border-cyan);
  background: rgba(0, 242, 242, 0.1);
}

.composer-input-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.composer-input {
  width: 100%;
  height: 40px;
  padding: 0 64px 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.composer-input:focus {
  border-color: var(--accent-purple);
  background: rgba(255, 255, 255, 0.06);
}

.composer-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.char-counter {
  position: absolute;
  right: 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  pointer-events: none;
}

.char-counter.warn {
  color: var(--accent-amber);
}
.char-counter.limit {
  color: var(--accent-rose);
}

.btn-send {
  height: 40px;
  padding: 0 18px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(0, 242, 242, 0.4);
  background: linear-gradient(135deg, rgba(0, 242, 242, 0.22), rgba(162, 124, 238, 0.28));
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(0, 242, 242, 0.35), rgba(162, 124, 238, 0.4));
  border-color: var(--accent-cyan);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 242, 242, 0.2);
}

.btn-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ==========================================================================
   Popovers: Emoji Picker & GIF Picker
   ========================================================================== */
.picker-popover {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 16px;
  width: min(360px, calc(100vw - 32px));
  height: 340px;
  background: var(--bg-glass-elevated);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glass);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 60;
}

.picker-popover.open {
  display: flex;
}

.picker-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
  scrollbar-width: none;
}
.picker-header::-webkit-scrollbar {
  display: none;
}

.emoji-cat-btn {
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.65;
  transition: all 0.15s ease;
}

.emoji-cat-btn:hover,
.emoji-cat-btn.active {
  opacity: 1;
  background: rgba(162, 124, 238, 0.2);
}

.emoji-grid {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  align-content: start;
}

.emoji-item {
  font-size: 20px;
  padding: 5px;
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: center;
  transition: transform 0.12s ease, background 0.12s ease;
}

.emoji-item:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.18);
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
.toast-stack {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-glass-elevated);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-bright);
  color: var(--text-primary);
  font-size: 13px;
  box-shadow: var(--shadow-glass);
  animation: slideInUp 0.22s ease;
}

.toast-item.error {
  border-color: rgba(244, 63, 94, 0.5);
  color: #fecdd3;
}

@keyframes slideInUp {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 768px) {
  .trollbox-main {
    padding: 92px 10px 12px;
  }
  .chat-toolbar {
    padding: 8px 12px;
  }
  .contract-pill {
    display: none;
  }
}

@media (max-width: 640px) {
  .trollbox-main {
    padding: 142px 10px 12px;
  }
}
