/* ============================================================
   OpenVPN Web Admin - 样式
   ============================================================ */
:root {
  --bg: #0f172a;
  --bg-2: #111827;
  --panel: #1f2937;
  --panel-2: #273344;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --primary: #6366f1;
  --primary-2: #4f46e5;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #334155;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }

/* ======== 顶部 ======== */
#topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
#topbar .brand {
  font-weight: 700;
  font-size: 1.1em;
  display: flex;
  align-items: center;
  gap: 8px;
}
#topbar .brand .logo { font-size: 1.4em; }
#topbar .tabs {
  display: flex;
  gap: 4px;
  flex: 1;
  flex-wrap: wrap;
}
#topbar .tabs .tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95em;
}
#topbar .tabs .tab:hover { color: var(--text); background: var(--panel-2); }
#topbar .tabs .tab.active {
  color: var(--text);
  background: var(--primary-2);
}
#topbar .user-area {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

/* ======== 视图 ======== */
.view { padding: 24px; max-width: 1280px; margin: 0 auto; }
.view h2 { margin-top: 0; }

/* ======== 登录页 ======== */
.login-card {
  max-width: 420px;
  margin: 80px auto;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin-top: 0; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 0.9em; }

/* 验证码 (数学题) */
.captcha-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-direction: row;
  margin-bottom: 6px;
}
.captcha-q {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 12px;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-family: 'Courier New', monospace;
  font-size: 1em;
  font-weight: 600;
  letter-spacing: 1px;
  color: #111827;
  user-select: none;
  min-width: 110px;
  justify-content: center;
}
.btn-sm { padding: 4px 10px; font-size: 0.85em; }

/* ======== 卡片 ======== */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card h3 { margin-top: 0; }
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}
.card-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.stats {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 20px;
}
.grid.stats .stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stat .label { color: var(--muted); font-size: 0.85em; }
.stat .value { font-size: 1.6em; font-weight: 700; margin-top: 6px; }
.stat.primary { border-left: 3px solid var(--primary); }
.stat.success { border-left: 3px solid var(--success); }
.stat.warning { border-left: 3px solid var(--warning); }
.stat.danger { border-left: 3px solid var(--danger); }

/* ======== 表单 ======== */
form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 0.9em;
  margin-bottom: 10px;
}
input[type=text], input[type=password], input[type=email], input[type=number], select, textarea {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.95em;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px 20px;
}
.form-grid .actions { grid-column: 1 / -1; }

/* ======== 按钮 ======== */
button {
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95em;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--panel-2); }
.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-success {
  background: transparent;
  color: var(--success);
  border-color: var(--success);
}
.btn-success:hover { background: var(--success); color: #fff; }
.block { width: 100%; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ======== 表格 ======== */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92em;
}
.data-table th, .data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.data-table th {
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 600;
}
.data-table tbody tr:hover { background: rgba(99, 102, 241, 0.08); }

/* ======== 标签 / 徽章 ======== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.78em;
  font-weight: 600;
  background: var(--panel-2);
  color: var(--muted);
}
.badge.active { background: rgba(16, 185, 129, 0.18); color: var(--success); }
.badge.inactive { background: rgba(239, 68, 68, 0.18); color: var(--danger); }
.badge.admin { background: rgba(99, 102, 241, 0.18); color: #a5b4fc; }
.badge.user { background: rgba(156, 163, 175, 0.18); color: var(--muted); }
.badge.online { background: rgba(16, 185, 129, 0.18); color: var(--success); }
.badge.offline { background: rgba(156, 163, 175, 0.18); color: var(--muted); }
.badge.vip { background: rgba(251, 191, 36, 0.18); color: #fbbf24; }
.badge.platinum { background: rgba(139, 92, 246, 0.18); color: #a78bfa; }
.badge.svip { background: rgba(236, 72, 153, 0.18); color: #f472b6; }

/* ======== KV 列表 ======== */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv .k { color: var(--muted); }
.kv .v { color: var(--text); }

/* ======== 公告 ======== */
.notice-list { display: flex; flex-direction: column; gap: 12px; }
.notice-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: var(--bg-2);
}
.notice-item .meta { color: var(--muted); font-size: 0.85em; margin-top: 4px; }
.notice-item .title { font-weight: 700; font-size: 1.05em; }
.notice-item .content { margin-top: 8px; white-space: pre-wrap; }
.notice-item .actions { margin-top: 8px; }

/* ======== 模态框 ======== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--panel);
  border-radius: var(--radius);
  width: min(560px, 92vw);
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-body { padding: 18px; overflow: auto; }

/* ======== Toast ======== */
#toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  padding: 10px 14px; border-radius: 6px;
  min-width: 220px; box-shadow: var(--shadow);
  animation: slide-in 0.2s;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slide-in { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ======== 工具 ======== */
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.9em; }
.check input { width: auto; }

@media (max-width: 720px) {
  #topbar { flex-wrap: wrap; padding: 10px 12px; gap: 12px; }
  #topbar .tabs { order: 3; width: 100%; }
  .view { padding: 14px; }
  .login-card { margin: 40px 14px; padding: 22px; }
}

/* ============================================================
   客服模块 (support) 样式
   ============================================================ */
.support-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  min-height: 540px;
}

.support-list {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 70vh;
}

.support-list-toolbar {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.support-list-toolbar .filter {
  flex: 1;
  display: flex;
  gap: 4px;
  background: var(--panel);
  border-radius: 6px;
  padding: 3px;
}

.support-list-toolbar .filter button {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 4px 10px;
  font-size: 0.82em;
  border-radius: 4px;
  flex: 1;
}

.support-list-toolbar .filter button.active {
  background: var(--primary-2);
  color: #fff;
}

.support-list-items {
  flex: 1;
  overflow-y: auto;
}

.support-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.support-item:hover { background: var(--panel-2); }
.support-item.active { background: rgba(99, 102, 241, 0.18); border-left: 3px solid var(--primary); padding-left: 11px; }
.support-item .top-line { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.support-item .username { font-weight: 600; font-size: 0.95em; }
.support-item .time { color: var(--muted); font-size: 0.78em; }
.support-item .preview {
  color: var(--muted);
  font-size: 0.85em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.support-item .badges { display: flex; gap: 4px; flex-wrap: wrap; }
.support-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.support-detail {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 540px;
  max-height: 70vh;
}

.support-detail-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.support-detail-header .meta { display: flex; flex-direction: column; gap: 2px; }
.support-detail-header .meta .user { font-weight: 700; font-size: 1.05em; }
.support-detail-header .meta .info { color: var(--muted); font-size: 0.82em; }

.support-messages {
  flex: 1;
  padding: 14px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, var(--bg-2), #0a0f1d);
}

.support-messages::-webkit-scrollbar { width: 6px; }
.support-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.support-msg {
  display: flex;
  flex-direction: column;
  max-width: 76%;
  animation: msgIn 0.2s ease;
}
.support-msg.user { align-self: flex-end; align-items: flex-end; }
.support-msg.agent { align-self: flex-start; align-items: flex-start; }
.support-msg.system { align-self: center; max-width: 90%; align-items: center; }

@keyframes msgIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.support-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.92em;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.support-msg.user .support-bubble {
  background: var(--primary-2);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.support-msg.agent .support-bubble {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}

.support-msg.system .support-bubble {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.82em;
}

.support-msg-meta {
  margin-top: 3px;
  font-size: 0.72em;
  color: var(--muted);
  padding: 0 4px;
}

.support-reply {
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--panel);
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
}

.support-reply textarea {
  flex: 1;
  min-height: 60px;
  max-height: 160px;
  resize: vertical;
  font-family: inherit;
  font-size: 0.92em;
}

.support-reply-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.support-reply-actions button { width: 100%; }
.support-reply-actions button i { margin-right: 4px; }

.support-detail-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.95em;
  padding: 40px;
  text-align: center;
}

.support-detail-closed-banner {
  background: rgba(245, 158, 11, 0.12);
  color: #fde68a;
  padding: 8px 14px;
  border-top: 1px solid rgba(245, 158, 11, 0.3);
  font-size: 0.85em;
  text-align: center;
}

.support-unread-dot {
  display: inline-block;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--danger);
  color: #fff;
  border-radius: 9px;
  font-size: 0.7em;
  font-weight: 700;
  text-align: center;
  line-height: 18px;
}

@media (max-width: 900px) {
  .support-layout {
    grid-template-columns: 1fr;
  }
  .support-list {
    max-height: 280px;
  }
  .support-detail {
    min-height: 460px;
  }
}

/* 顶部导航 - 客服徽标 */
#topbar .tabs .tab.support-tab { position: relative; }
#topbar .tabs .tab.support-tab .support-badge {
  position: absolute;
  top: 0;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--danger);
  color: #fff;
  border-radius: 8px;
  font-size: 0.65em;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
