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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 20px;
  color: #333;
}

.container {
  max-width: 800px;
  margin: 0 auto;
}

.page {
  animation: fadeIn 0.3s ease-in;
}

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

.card {
  background: white;
  border-radius: 12px;
  padding: 30px;
  margin-bottom: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  background: white;
  padding: 20px 30px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

h1 {
  color: #667eea;
  font-size: 28px;
  margin-bottom: 20px;
}

h2 {
  color: #444;
  font-size: 20px;
  margin-bottom: 15px;
}

.hint {
  color: #666;
  font-size: 14px;
  margin: 10px 0;
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 16px;
  margin-bottom: 15px;
  transition: border-color 0.3s;
  font-family: inherit;
}

input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: #667eea;
}

textarea {
  resize: vertical;
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 14px;
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  display: inline-block;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.btn-secondary {
  background: #6c757d;
  color: white;
}

.btn-danger {
  background: #dc3545;
  color: white;
  padding: 8px 16px;
  font-size: 14px;
}

.error-message {
  color: #dc3545;
  background: #f8d7da;
  padding: 12px;
  border-radius: 6px;
  margin-top: 15px;
  display: none;
  border: 1px solid #f5c6cb;
}

.error-message.show {
  display: block;
  animation: shake 0.3s;
}

.success-message {
  color: #155724;
  background: #d4edda;
  padding: 12px;
  border-radius: 6px;
  margin-top: 15px;
  display: none;
  border: 1px solid #c3e6cb;
}

.success-message.show {
  display: block;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

#qrcode-container {
  text-align: center;
  margin: 20px 0;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
}

#qrcode-container img {
  max-width: 250px;
  border: 5px solid white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

#token-input {
  text-align: center;
  font-size: 24px;
  letter-spacing: 8px;
  font-weight: 600;
}

.key-item {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 15px;
  border: 2px solid #e9ecef;
  transition: border-color 0.3s;
}

.key-item:hover {
  border-color: #667eea;
}

.key-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.key-comment {
  font-weight: 600;
  color: #495057;
  font-size: 16px;
}

.key-date {
  color: #6c757d;
  font-size: 12px;
}

.key-content {
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 12px;
  color: #495057;
  background: white;
  padding: 10px;
  border-radius: 6px;
  word-break: break-all;
  margin-bottom: 10px;
}

.empty-state {
  text-align: center;
  padding: 40px;
  color: #6c757d;
}

.empty-state-icon {
  font-size: 64px;
  margin-bottom: 15px;
  opacity: 0.5;
}

.loading {
  text-align: center;
  padding: 20px;
  color: #667eea;
}

.spinner {
  border: 3px solid #f3f3f3;
  border-top: 3px solid #667eea;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 20px auto;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@media (max-width: 600px) {
  .container {
    padding: 10px;
  }

  .card {
    padding: 20px;
  }

  .header {
    flex-direction: column;
    gap: 15px;
  }

  h1 {
    font-size: 24px;
  }
}

/* ==================== SSH 隧道端口功能样式 ==================== */

/* 申请端口 toggle 行 */
.port-request-row {
  margin-bottom: 15px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type="checkbox"] {
  width: auto;
  margin: 0;
  padding: 0;
  cursor: pointer;
  accent-color: #667eea;
  width: 16px;
  height: 16px;
}

.toggle-text {
  font-size: 14px;
  color: #555;
}

/* 公钥列表标题栏（含刷新按钮） */
.keys-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.keys-list-header h2 {
  margin-bottom: 0;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}

/* 隧道信息区块 */
.tunnel-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #e9ecef;
}

.tunnel-none {
  color: #aaa;
}

.tunnel-none-text {
  font-size: 13px;
  color: #aaa;
}

/* 活跃/关闭状态标签 */
.tunnel-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.tunnel-status.active {
  background: #d4edda;
  color: #155724;
}

.tunnel-status.inactive {
  background: #e9ecef;
  color: #6c757d;
}

/* 状态小圆点 */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.tunnel-status.active .status-dot {
  background: #28a745;
  box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.4);
  animation: pulse-green 1.5s ease-in-out infinite;
}

.tunnel-status.inactive .status-dot {
  background: #9aa0a6;
}

@keyframes pulse-green {
  0%   { box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.5); }
  70%  { box-shadow: 0 0 0 6px rgba(40, 167, 69, 0); }
  100% { box-shadow: 0 0 0 0 rgba(40, 167, 69, 0); }
}

/* 端口号显示 */
.tunnel-port {
  font-size: 13px;
  color: #495057;
  background: #f1f3f5;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: 'Monaco', 'Courier New', monospace;
}

/* 操作按钮 */
.btn-copy {
  background: #17a2b8;
  color: white;
  padding: 4px 10px;
  font-size: 12px;
}

.btn-copy:hover {
  background: #138496;
}

.btn-release {
  background: #fd7e14;
  color: white;
  padding: 4px 10px;
  font-size: 12px;
}

.btn-release:hover {
  background: #e96900;
}

.btn-allocate {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 4px 10px;
  font-size: 12px;
}

.btn-allocate:hover {
  opacity: 0.9;
}

@media (max-width: 600px) {
  .tunnel-info {
    gap: 6px;
  }
  .keys-list-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}

/* ==================== 手动端口输入 ==================== */

.port-assign-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
}

.port-manual-input {
  flex: 1;
  min-width: 160px;
  max-width: 220px;
  padding: 6px 10px;
  border: 2px solid #dee2e6;
  border-radius: 6px;
  font-size: 13px;
  font-family: 'Monaco', 'Courier New', monospace;
  margin-bottom: 0;
  transition: border-color 0.2s;
}

.port-manual-input:focus {
  outline: none;
  border-color: #667eea;
}

.or-divider {
  color: #aaa;
  font-size: 13px;
  white-space: nowrap;
}

.btn-set-port {
  background: #20c997;
  color: white;
  padding: 5px 12px;
  font-size: 13px;
}

.btn-set-port:hover {
  background: #17a589;
}

/* ==================== 隧道操作按钮行 ==================== */

.tunnel-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.btn-guide {
  background: #6f42c1;
  color: white;
  padding: 4px 10px;
  font-size: 12px;
}

.btn-guide:hover {
  background: #5936a2;
}

/* ==================== 配置指南 Modal ==================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 1000;
  padding: 24px 16px;
  overflow-y: auto;
  backdrop-filter: blur(2px);
}

.modal-box {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 720px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  animation: modal-in 0.2s ease;
}

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

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.modal-header h2 {
  color: white;
  font-size: 18px;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
  transition: color 0.2s;
}

.modal-close:hover {
  color: white;
}

.modal-body {
  padding: 24px;
  max-height: 70vh;
  overflow-y: auto;
}

/* 指南内容 */
.guide-section {
  margin-bottom: 24px;
}

.guide-section h3 {
  font-size: 15px;
  color: #444;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #f0f0f0;
}

.guide-section ul {
  list-style: none;
  padding: 0;
  background: #f8f9fa;
  border-radius: 8px;
  padding: 12px 16px;
}

.guide-section ul li {
  padding: 3px 0;
  font-size: 14px;
  color: #555;
}

.guide-section p {
  font-size: 14px;
  color: #555;
  margin: 8px 0;
  line-height: 1.6;
}

.guide-note {
  color: #888 !important;
  font-size: 13px !important;
}

.copy-wrap {
  position: relative;
  margin: 8px 0;
}

.code-block {
  background: #1e1e2e;
  color: #cdd6f4;
  font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
  font-size: 12.5px;
  line-height: 1.6;
  padding: 14px 110px 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre;
  margin: 0;
}

.guide-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 10px;
  font-size: 12px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  color: #cdd6f4;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.2s;
}

.guide-copy-btn:hover {
  background: rgba(255,255,255,0.28);
  transform: none;
  box-shadow: none;
}

code {
  background: #f0f0f0;
  border-radius: 4px;
  padding: 1px 5px;
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 12px;
  color: #c0392b;
}

.badge-active {
  display: inline-block;
  background: #d4edda;
  color: #155724;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
}

@media (max-width: 600px) {
  .modal-body {
    padding: 16px;
  }
  .code-block {
    padding: 12px 12px 40px;
  }
  .guide-copy-btn {
    top: auto;
    bottom: 8px;
    right: 8px;
  }
  .port-manual-input {
    min-width: 120px;
  }
}
