:root {
  --bg-primary: #f5f5f5;
  --bg-sidebar: #fff;
  --bg-card: #fff;
  --bg-input: #f8f9fa;
  --text-primary: #333;
  --text-secondary: #666;
  --text-muted: #999;
  --border: #e0e0e0;
  --border-light: #eee;
  --accent: #00bfa5;
  --accent-hover: #00a693;
  --accent-light: #e0f7f4;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --danger: #ff5252;
  --success: #4caf50;
  --warning: #ff9800;
  --info: #2196f3;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ========== Toast 通知 ========== */
.toast-container {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  min-width: 280px;
  max-width: 400px;
  animation: toastIn 0.3s ease;
  border-left: 4px solid var(--accent);
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.info { border-left-color: var(--info); }

.toast-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--danger); }
.toast.warning .toast-icon { color: var(--warning); }
.toast.info .toast-icon { color: var(--info); }

.toast-message {
  flex: 1;
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.4;
}

.toast-close {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.2s;
}

.toast-close:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.toast.hiding {
  animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(100px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100px);
  }
}

/* ========== Tooltip 竖排样式 ========== */
[data-tooltip] {
  position: relative;
  cursor: help;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 14px;
  background: rgba(30, 30, 30, 0.95);
  color: #fff;
  font-size: 11px;
  font-weight: normal;
  border-radius: 8px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  z-index: 1000;
  min-width: 160px;
  max-width: 200px;
  text-align: left;
  line-height: 1.6;
  white-space: pre-line;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  pointer-events: none;
}

[data-tooltip]::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(30, 30, 30, 0.95);
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  z-index: 1000;
}

[data-tooltip]:hover::after,
[data-tooltip]:hover::before {
  opacity: 1;
  visibility: visible;
}

/* ========== 顶部导航 ========== */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

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

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ========== 连接按钮组 ========== */
.conn-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.conn-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid var(--border);
}

.conn-btn.hidden {
  display: none;
}

.connect-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.connect-btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.disconnect-btn {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.disconnect-btn:hover {
  background: var(--danger);
  color: #fff;
}

/* ========== 连接信息（可点击编辑） ========== */
.conn-info-display {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 180px;
}

.conn-info-display:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.conn-info-display.hidden {
  display: none;
}

.conn-info-placeholder {
  color: var(--text-muted);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
}

.conn-info-display.has-value .conn-info-placeholder {
  color: var(--text-secondary);
}

.conn-info-input {
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-primary);
  outline: none;
  min-width: 280px;
}

.conn-info-input.hidden {
  display: none;
}

/* ========== 导航按钮 ========== */
.nav-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.nav-btn:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.settings-btn:hover {
  background: var(--accent-light);
  color: var(--accent);
}

/* ========== 主布局 ========== */
.main-container {
  flex: 1;
  display: grid;
  grid-template-columns: 220px 1fr;
  overflow: hidden;
  min-height: 0;
}

/* 左侧订阅栏 */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.add-sub-btn {
  margin: 12px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.add-sub-btn:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.sub-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px;
}

.sub-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: var(--bg-input);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.sub-item:hover {
  background: var(--accent-light);
}

.sub-item-content {
  flex: 1;
  min-width: 0;
}

.sub-alias {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub-topic {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub-qos {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: 6px;
  padding: 2px 5px;
  background: rgba(0,0,0,0.05);
  border-radius: 3px;
}

.sub-delete {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s;
}

.sub-item:hover .sub-delete {
  opacity: 1;
}

.sub-delete:hover {
  color: var(--danger);
}

/* ========== 中间消息区 ========== */
.message-area {
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  min-height: 0;
  overflow: hidden;
}

.msg-tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.msg-tab-list {
  display: flex;
  gap: 4px;
}

.msg-tab {
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.msg-tab:hover {
  color: var(--text-primary);
  background: var(--bg-input);
}

.msg-tab.active {
  color: var(--accent);
  background: var(--accent-light);
}

.msg-count {
  font-size: 12px;
  color: var(--text-muted);
}

.msg-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.msg-item {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}

.msg-item.incoming {
  align-self: flex-start;
}

.msg-item.outgoing {
  align-self: flex-end;
}

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.msg-item.incoming .msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.msg-item.outgoing .msg-bubble {
  background: var(--accent);
  color: #fff;
}

.msg-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
}

.msg-item.incoming .msg-header {
  color: var(--text-secondary);
}

.msg-item.outgoing .msg-header {
  color: rgba(255,255,255,0.85);
}

.msg-topic {
  font-weight: 600;
  font-size: 13px;
}

.msg-qos {
  padding: 2px 6px;
  background: rgba(0,0,0,0.06);
  border-radius: 3px;
  font-size: 11px;
}

.msg-item.outgoing .msg-qos {
  background: rgba(255,255,255,0.2);
}

.msg-retain {
  padding: 2px 6px;
  background: #ff9800;
  color: #fff;
  border-radius: 3px;
  font-size: 11px;
}

.msg-payload {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}

.msg-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}

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

.msg-item.outgoing .msg-time {
  color: rgba(255,255,255,0.6);
}

.msg-sub-tag {
  font-size: 10px;
  padding: 2px 6px;
  background: rgba(0,0,0,0.06);
  border-radius: 3px;
  color: var(--text-muted);
}

.msg-item.outgoing .msg-sub-tag {
  background: rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.8);
}

/* ========== 底部输入区域 - 固定在底部 ========== */
.input-area {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 16px 20px 14px;
  flex-shrink: 0;
}

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

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.toolbar-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  flex-shrink: 0;
  white-space: nowrap;
}

.toolbar-topic {
  width: 200px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}

.toolbar-topic:focus {
  border-color: var(--accent);
}

.toolbar-topic.error {
  border-color: var(--danger);
  background: #ffebee;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

.toolbar-select {
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

.toolbar-select:focus {
  border-color: var(--accent);
}

/* Toggle 开关 */
.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-switch.active {
  background: var(--accent);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.toggle-switch.active::after {
  transform: translateX(16px);
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  margin-left: auto;
}

.send-btn:hover {
  background: var(--accent-hover);
}

.send-btn:active {
  transform: scale(0.98);
}

.input-row {
  display: flex;
  gap: 12px;
}

.input-content {
  flex: 1;
  min-height: 80px;
  max-height: 140px;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 13px;
  color: var(--text-primary);
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  line-height: 1.5;
}

.input-content:focus {
  border-color: var(--accent);
}

.input-content::placeholder {
  color: var(--text-muted);
}

/* ========== 空状态 ========== */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}

.empty-state svg {
  margin-bottom: 14px;
  opacity: 0.25;
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 6px;
}

.empty-state span {
  font-size: 12px;
  opacity: 0.6;
}

/* ========== 设置面板 ========== */
.settings-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
}

.settings-overlay.show {
  opacity: 1;
  visibility: visible;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  max-width: 100%;
  height: 100%;
  background: var(--bg-card);
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  z-index: 1001;
}

.settings-overlay.show .settings-panel {
  transform: translateX(0);
}

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

.settings-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.settings-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.settings-close:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

.settings-row {
  margin-bottom: 14px;
}

.settings-row label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.settings-row input,
.settings-row select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}

.settings-row input:focus,
.settings-row select:focus {
  border-color: var(--accent);
}

.settings-row input::placeholder {
  color: var(--text-muted);
}

.settings-row-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.settings-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
}

.settings-footer button {
  flex: 1;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-disconnect {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-disconnect:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: #ffebee;
}

.btn-connect {
  background: var(--accent);
  border: none;
  color: #fff;
}

.btn-connect:hover {
  background: var(--accent-hover);
}

/* ========== 订阅弹窗 ========== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 22px;
  width: 400px;
  max-width: 90%;
}

.modal h3 {
  font-size: 16px;
  margin-bottom: 16px;
}

.modal-row {
  margin-bottom: 14px;
  position: relative;
}

.modal-row label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.modal-row input,
.modal-row select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
}

.modal-row input:focus,
.modal-row select:focus {
  border-color: var(--accent);
}

.modal-row-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-row-half label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.modal-row-half input,
.modal-row-half select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
}

.modal-row-half input:focus,
.modal-row-half select:focus {
  border-color: var(--accent);
}

/* 颜色选择器 */
.color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-option {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
}

.color-option:hover {
  transform: scale(1.1);
}

.color-option.selected {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px var(--bg-card);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.modal-btn {
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.modal-btn.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.modal-btn.secondary:hover {
  border-color: var(--text-muted);
}

.modal-btn.primary {
  background: var(--accent);
  border: none;
  color: #fff;
}

.modal-btn.primary:hover {
  background: var(--accent-hover);
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
  .main-container {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
  .settings-panel {
    width: 100%;
  }
  .toolbar-topic {
    width: 140px;
  }
  .conn-info-display {
    min-width: 140px;
  }
  .conn-info-input {
    min-width: 180px;
  }
}
