:root {
  color-scheme: dark;
  --bg: #020617;
  --panel: #0f172a;
  --panel-strong: #111827;
  --panel-soft: rgba(15, 23, 42, 0.72);
  --border: #1e293b;
  --text: #cbd5e1;
  --text-strong: #f8fafc;
  --text-muted: #64748b;
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.12);
  --blue: #38bdf8;
  --blue-soft: rgba(56, 189, 248, 0.14);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
  min-height: 100vh;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  display: flex;
  min-height: 100vh;
  background: linear-gradient(180deg, #020617 0%, #020817 100%);
}

.sidebar {
  background: var(--panel);
  border-color: var(--border);
  z-index: 2;
}

.sidebar.left {
  width: 16rem;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar.right {
  width: 16rem;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.panel-header {
  min-height: 3.5rem;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.65);
}

.brand-mark {
  color: var(--green);
  margin-right: 0.625rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 800;
}

.brand-text,
.chat-header h1,
.right-title,
.username,
.message-user,
.section-title,
.stats-title,
.count-pill,
.prompt-symbol {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.brand-text {
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-strong);
}

.brand-text span {
  color: var(--green);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.75rem;
}

.section-block + .section-block {
  margin-top: 1.5rem;
}

.section-title {
  margin-bottom: 0.75rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.channel-list,
.user-list {
  display: grid;
  gap: 0.25rem;
}

.channel-button,
.icon-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  transition: 160ms ease;
}

.channel-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  padding: 0.6rem 0.65rem;
  border-radius: 0.5rem;
  text-align: left;
}

.channel-label {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.channel-button:hover,
.icon-button:hover {
  background: rgba(30, 41, 59, 0.7);
  color: var(--text-strong);
}

.channel-button.active {
  background: rgba(30, 41, 59, 0.92);
  color: var(--text-strong);
}

.hash {
  margin-right: 0.5rem;
  color: var(--green);
  font-weight: 800;
}

.unread-pill {
  min-width: 1.2rem;
  padding: 0.08rem 0.4rem;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.18);
  color: #86efac;
  font-size: 0.68rem;
  font-weight: 800;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  text-align: center;
}

.user-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.84);
}

.user-footer-button {
  flex: 1;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.user-footer-button:hover .username,
.user-footer-button:hover .subtle-line {
  color: var(--text-strong);
}

.user-meta {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.subtle-line,
.chat-header p,
.message-timestamp,
.composer-meta,
.you-marker,
.message-time {
  color: var(--text-muted);
  font-size: 0.76rem;
}

.status-dot,
.presence-dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  margin-right: 0.45rem;
}

.status-dot.web,
.presence-dot {
  background: var(--green);
}

.main-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.chat-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.app-stage {
  flex: 1;
  min-height: 0;
  padding: 1rem;
}

.aprs-layout {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18rem;
  gap: 1rem;
}

.aprs-map-card,
.aprs-panel,
.aprs-station-list {
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  background: rgba(15, 23, 42, 0.56);
}

.aprs-map-card {
  min-height: 28rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.aprs-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.aprs-toolbar-title,
.aprs-panel-title,
.aprs-station-name {
  color: var(--text-strong);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 700;
}

.aprs-toolbar-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.aprs-status {
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.14);
  color: #7dd3fc;
  font-size: 0.72rem;
}

.aprs-status.warning {
  background: rgba(251, 191, 36, 0.12);
  color: #fde68a;
}

.aprs-map-frame {
  flex: 1;
  min-height: 24rem;
}

.aprs-map {
  width: 100%;
  height: 100%;
  min-height: 24rem;
}

.aprs-sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.aprs-panel {
  padding: 0.9rem 1rem;
}

.aprs-panel-copy,
.aprs-station-meta,
.aprs-empty {
  margin-top: 0.35rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.aprs-station-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.6rem;
}

.aprs-station-item {
  width: 100%;
  padding: 0.7rem 0.75rem;
  border: 0;
  border-radius: 0.65rem;
  background: transparent;
  color: inherit;
  text-align: left;
}

.aprs-station-item:hover {
  background: rgba(30, 41, 59, 0.75);
}

.aprs-station-item + .aprs-station-item {
  margin-top: 0.3rem;
}

.chat-header {
  min-height: 3.5rem;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.32);
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-header h1 {
  margin: 0;
  color: var(--text-strong);
  font-size: 1rem;
}

.chat-header h1 span {
  color: var(--text-muted);
  margin-right: 0.25rem;
}

.chat-header p {
  margin: 0.12rem 0 0;
}

.icon-button {
  border-radius: 0.45rem;
  padding: 0.5rem 0.65rem;
  color: var(--text-muted);
}

.icon-button.active {
  background: rgba(30, 41, 59, 0.92);
  color: var(--text-strong);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1rem 1.5rem;
}

.chat-stage.locked .messages,
.chat-stage.locked .composer {
  filter: blur(12px);
  user-select: none;
  pointer-events: none;
}

.guest-lock-screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(2, 6, 23, 0.24);
}

.app-lock-screen {
  position: static;
  min-height: 100%;
}

.guest-lock-card {
  width: min(32rem, 100%);
  padding: 1.4rem;
  border: 1px solid rgba(34, 197, 94, 0.24);
  border-radius: 0.95rem;
  background: rgba(15, 23, 42, 0.94);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  text-align: center;
}

.guest-lock-kicker {
  color: #86efac;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.guest-lock-card h2 {
  margin: 0.55rem 0 0;
  color: var(--text-strong);
  font-size: 1.35rem;
}

.guest-lock-card p {
  margin: 0.75rem 0 0;
  color: var(--text);
  line-height: 1.6;
}

.guest-lock-actions {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.empty-state {
  min-height: 100%;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--text-muted);
}

.empty-icon {
  margin-bottom: 0.75rem;
  font-size: 2rem;
  color: rgba(100, 116, 139, 0.4);
}

.message-row {
  display: flex;
  gap: 0.75rem;
}

.message-row.compact {
  margin-top: 0.25rem;
}

.message-row.spaced {
  margin-top: 1rem;
}

.message-avatar,
.message-time {
  width: 2rem;
  flex: 0 0 2rem;
}

.message-time {
  padding-top: 0.3rem;
  text-align: right;
}

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

.message-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.25rem;
}

.message-user {
  font-weight: 700;
  color: var(--text-strong);
}

.message-body p {
  margin: 0;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #334155;
  border-radius: 0.35rem;
  font-weight: 800;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.avatar.md {
  width: 2rem;
  height: 2rem;
  font-size: 0.8rem;
}

.avatar.sm {
  width: 1.65rem;
  height: 1.65rem;
  font-size: 0.7rem;
}

.avatar.ssh {
  background: rgba(20, 83, 45, 0.55);
  color: #bbf7d0;
}

.avatar.web {
  background: rgba(30, 64, 175, 0.45);
  color: #bfdbfe;
}

.connection-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border-radius: 0.4rem;
  border: 1px solid transparent;
  padding: 0.2rem 0.45rem;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.connection-badge.small {
  font-size: 0.64rem;
  padding: 0.12rem 0.36rem;
}

.connection-badge.ssh {
  background: var(--green-soft);
  border-color: rgba(34, 197, 94, 0.28);
  color: #86efac;
}

.connection-badge.web {
  background: var(--blue-soft);
  border-color: rgba(56, 189, 248, 0.28);
  color: #7dd3fc;
}

.root-badge {
  background: var(--red-soft);
  border: 1px solid rgba(248, 113, 113, 0.28);
  color: var(--red);
  border-radius: 0.4rem;
  padding: 0.12rem 0.35rem;
  font-size: 0.64rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.composer {
  border-top: 1px solid var(--border);
  padding: 1rem;
  background: rgba(15, 23, 42, 0.48);
}

.composer-form {
  position: relative;
}

.composer-form input {
  width: 100%;
  border-radius: 0.55rem;
  border: 1px solid #334155;
  background: #020617;
  color: var(--text-strong);
  padding: 0.9rem 5.5rem 0.9rem 3rem;
  font-size: 0.95rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.composer-form input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14);
}

.composer-form input:disabled {
  color: var(--text-muted);
  border-color: rgba(51, 65, 85, 0.75);
  background: rgba(2, 6, 23, 0.9);
}

.prompt-symbol {
  position: absolute;
  top: 0.9rem;
  left: 1rem;
  color: var(--text-muted);
  font-weight: 800;
}

.send-button {
  position: absolute;
  right: 0.5rem;
  top: 0.45rem;
  border: 0;
  border-radius: 0.45rem;
  padding: 0.55rem 0.8rem;
  background: #16a34a;
  color: white;
  font-weight: 700;
}

.send-button:disabled {
  background: #334155;
  color: #64748b;
}

.composer-meta {
  margin-top: 0.55rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.composer-meta strong {
  color: #7dd3fc;
}

.count-pill {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.8rem;
  height: 1.35rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: rgba(30, 41, 59, 0.95);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 800;
}

.count-pill.small {
  margin-left: 0.45rem;
  min-width: 1.2rem;
  height: 1rem;
  font-size: 0.64rem;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.15rem 0;
}

.user-row:hover {
  cursor: default;
}

.user-presence {
  position: relative;
}

.presence-dot {
  position: absolute;
  right: -0.1rem;
  bottom: -0.1rem;
  width: 0.65rem;
  height: 0.65rem;
  margin: 0;
  border: 2px solid var(--panel);
}

.user-row-meta {
  min-width: 0;
  flex: 1;
}

.user-row-name {
  color: var(--text-strong);
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.user-row-badges {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.stats-card {
  margin-top: 2rem;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  background: rgba(2, 6, 23, 0.82);
  padding: 0.85rem;
}

.stats-title {
  padding-bottom: 0.5rem;
  margin-bottom: 0.55rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text);
}

.stats-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.8rem;
}

.stats-row + .stats-row {
  margin-top: 0.45rem;
}

.ssh-text {
  color: #86efac;
}

.web-text {
  color: #7dd3fc;
}

.fatal {
  padding: 2rem;
  color: #fecaca;
}

.leaflet-container {
  background: #020617;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: #0f172a;
  color: var(--text);
}

.auth-overlay {
  z-index: 20;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 21;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.auth-card {
  width: min(28rem, 100%);
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  background: rgba(15, 23, 42, 0.98);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  padding: 1rem;
}

.auth-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.auth-title {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-strong);
}

.auth-subtitle,
.auth-note,
.auth-summary-line {
  margin-top: 0.3rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.auth-account-summary {
  margin-top: 1rem;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  background: rgba(2, 6, 23, 0.55);
}

.auth-account-summary code {
  color: #7dd3fc;
  word-break: break-all;
}

.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.auth-tab,
.auth-button {
  border-radius: 0.55rem;
  border: 1px solid var(--border);
  padding: 0.7rem 0.9rem;
  background: rgba(2, 6, 23, 0.7);
  color: var(--text);
}

.auth-tab.active {
  border-color: rgba(34, 197, 94, 0.4);
  background: rgba(20, 83, 45, 0.32);
  color: #dcfce7;
}

.auth-form {
  display: grid;
  gap: 0.85rem;
  margin-top: 1rem;
}

.auth-label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.86rem;
  color: var(--text);
}

.auth-input {
  width: 100%;
  border-radius: 0.55rem;
  border: 1px solid #334155;
  background: #020617;
  color: var(--text-strong);
  padding: 0.8rem 0.9rem;
}

.auth-input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14);
}

.auth-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.8rem;
  flex-wrap: wrap;
}

.auth-button.primary {
  background: #16a34a;
  border-color: #16a34a;
  color: white;
  font-weight: 700;
}

.auth-button.secondary {
  background: rgba(30, 41, 59, 0.92);
}

.auth-button.danger {
  background: rgba(127, 29, 29, 0.28);
  border-color: rgba(248, 113, 113, 0.3);
  color: #fecaca;
}

.auth-button:disabled {
  opacity: 0.65;
  cursor: default;
}

.auth-error {
  border: 1px solid rgba(248, 113, 113, 0.28);
  background: rgba(127, 29, 29, 0.22);
  color: #fecaca;
  border-radius: 0.55rem;
  padding: 0.75rem 0.85rem;
  font-size: 0.82rem;
}

.auth-error.compact {
  margin-top: 0.75rem;
  padding: 0.6rem 0.7rem;
}

.menu-overlay {
  z-index: 24;
}

.user-menu {
  position: fixed;
  z-index: 25;
  min-width: 10rem;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  background: rgba(15, 23, 42, 0.98);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
  padding: 0.45rem;
}

.user-menu-title {
  padding: 0.5rem 0.6rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.user-menu-item {
  width: 100%;
  border: 0;
  border-radius: 0.5rem;
  padding: 0.65rem 0.7rem;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.user-menu-item:hover {
  background: rgba(30, 41, 59, 0.85);
}

.user-menu-item.danger {
  color: #fecaca;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 1;
}

.mobile-only {
  display: none;
}

@media (max-width: 1100px) {
  .sidebar.right {
    display: none;
  }

  .aprs-layout {
    grid-template-columns: 1fr;
  }

  .aprs-sidebar {
    max-height: 18rem;
  }
}

@media (max-width: 820px) {
  .mobile-only {
    display: inline-flex;
  }

  .sidebar.left {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    height: 100vh;
  }

  .sidebar.left.open {
    transform: translateX(0);
  }

  .composer-meta {
    flex-direction: column;
  }
}
