/* Tailwind CSS CDN */
@import url('https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css');

/* ============ Design Tokens ============ */
:root {
  --accent: #00D9C0;
  --accent-2: #0EA5E9;
  --accent-grad: linear-gradient(135deg, #00D9C0 0%, #0EA5E9 100%);
  --bg-0: #0B1220;
  --bg-1: #111A2C;
  --bg-2: #1B2740;
  --text-1: #E6EDF7;
  --text-2: #8FA3C0;
  --ok: #22C55E;
  --warn: #F59E0B;
  --err: #EF4444;
  --line: rgba(143, 163, 192, 0.14);
  --glass: rgba(17, 26, 44, 0.72);
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --font: 'Inter', 'PingFang SC', 'Microsoft YaHei', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg-0);
  color: var(--text-1);
  font-family: var(--font);
  font-size: 14px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#bg-grid {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 60% 40% at 80% -10%, rgba(14, 165, 233, 0.12), transparent),
    radial-gradient(ellipse 50% 35% at 10% 110%, rgba(0, 217, 192, 0.08), transparent),
    linear-gradient(rgba(143,163,192,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(143,163,192,0.035) 1px, transparent 1px);
  background-size: auto, auto, 44px 44px, 44px 44px;
}
#app { position: relative; z-index: 1; }

.boot-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; color: var(--text-2); gap: 14px; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(0,217,192,0.15); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Auth 屏 ============ */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card {
  width: 400px; max-width: 100%;
  background: var(--glass); backdrop-filter: blur(18px);
  border: 1px solid var(--line); border-radius: 20px;
  padding: 40px 36px; box-shadow: var(--shadow);
  animation: riseIn 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes riseIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.auth-logo .mark {
  width: 42px; height: 42px; border-radius: 12px; background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px; color: #06121f;
  box-shadow: 0 0 24px rgba(0, 217, 192, 0.35);
}
.auth-logo h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: 0.5px; }
.auth-logo h1 span { color: var(--accent); }
.auth-sub { color: var(--text-2); font-size: 13px; margin: 0 0 26px; }

/* ============ 通用组件 ============ */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 7px; letter-spacing: 0.4px; }
.field input[type=text], .field input[type=password], .field select, .field textarea {
  width: 100%; padding: 11px 13px;
  background: rgba(11, 18, 32, 0.65); border: 1px solid var(--line);
  border-radius: 10px; color: var(--text-1); font-size: 14px;
  font-family: var(--font); outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0, 217, 192, 0.12);
}
.field textarea { font-family: var(--mono); font-size: 12px; min-height: 110px; resize: vertical; }
.field .hint { font-size: 12px; color: var(--text-2); margin-top: 6px; line-height: 1.6; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--text-1); font-size: 13px; font-weight: 600;
  font-family: var(--font); cursor: pointer; transition: all 0.18s; white-space: nowrap;
}
.btn:hover { border-color: rgba(0, 217, 192, 0.45); transform: translateY(-1px); }
.btn:active { transform: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent-grad); border: none; color: #06121f; font-weight: 700; box-shadow: 0 4px 18px rgba(0, 217, 192, 0.25); }
.btn-primary:hover { box-shadow: 0 6px 24px rgba(0, 217, 192, 0.4); }
.btn-block { width: 100%; padding: 12px; font-size: 14px; }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: rgba(239, 68, 68, 0.35); color: #f87171; }
.btn-danger:hover { border-color: #ef4444; background: rgba(239, 68, 68, 0.08); }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  font-family: var(--mono); letter-spacing: 0.2px;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok { color: #4ade80; background: rgba(34, 197, 94, 0.1); }
.badge-warn { color: #fbbf24; background: rgba(245, 158, 11, 0.1); }
.badge-err { color: #f87171; background: rgba(239, 68, 68, 0.1); }
.badge-gray { color: var(--text-2); background: rgba(143, 163, 192, 0.1); }
.badge-info { color: #38bdf8; background: rgba(14, 165, 233, 0.1); }
.badge-pulse::before { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }

/* 开关 */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px; cursor: pointer;
  background: rgba(143, 163, 192, 0.25); transition: 0.25s;
}
.switch .track::before {
  content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  left: 3px; top: 3px; background: #cbd5e1; transition: 0.25s;
}
.switch input:checked + .track { background: var(--accent-grad); }
.switch input:checked + .track::before { transform: translateX(18px); background: #06121f; }

/* ============ 应用骨架 ============ */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 22px;
  padding: 0 26px; height: 62px;
  background: rgba(11, 18, 32, 0.82); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 15px; letter-spacing: 0.5px; }
.topbar .brand .mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent-grad); color: #06121f; display: flex; align-items: center; justify-content: center; font-size: 15px; }
.topbar .brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 8px 16px; border-radius: 10px; color: var(--text-2); font-weight: 600;
  font-size: 13.5px; cursor: pointer; transition: 0.18s; text-decoration: none;
}
.nav a:hover { color: var(--text-1); background: rgba(143, 163, 192, 0.08); }
.nav a.active { color: var(--accent); background: rgba(0, 217, 192, 0.1); }

.container { max-width: 1240px; margin: 0 auto; padding: 26px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 22px; font-weight: 700; }
.page-head p { margin: 5px 0 0; color: var(--text-2); font-size: 13px; }

/* 统计卡 */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card {
  position: relative; overflow: hidden;
  background: var(--glass); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; transition: 0.2s;
}
.stat-card:hover { border-color: rgba(0, 217, 192, 0.3); transform: translateY(-2px); }
.stat-card .num { font-family: var(--mono); font-size: 30px; font-weight: 700; line-height: 1.1; }
.stat-card .lbl { color: var(--text-2); font-size: 12.5px; margin-top: 5px; letter-spacing: 0.3px; }
.stat-card::after {
  content: ''; position: absolute; right: -30px; top: -30px; width: 90px; height: 90px;
  border-radius: 50%; background: var(--accent-grad); opacity: 0.09;
}
.stat-card.c-ok .num { color: #4ade80; }
.stat-card.c-warn .num { color: #fbbf24; }

/* 面板 & 表格 */
.panel {
  background: var(--glass); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
.panel-toolbar { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-toolbar .search {
  flex: 1; min-width: 200px; max-width: 320px;
  padding: 9px 13px; background: rgba(11, 18, 32, 0.6);
  border: 1px solid var(--line); border-radius: 10px; color: var(--text-1);
  font-size: 13px; outline: none; font-family: var(--font);
}
.panel-toolbar .search:focus { border-color: var(--accent); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; padding: 12px 16px; color: var(--text-2); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.8px; font-weight: 600;
  border-bottom: 1px solid var(--line); background: rgba(11, 18, 32, 0.4);
}
.tbl td { padding: 13px 16px; border-bottom: 1px solid rgba(143, 163, 192, 0.07); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background 0.15s; }
.tbl tbody tr:hover { background: rgba(0, 217, 192, 0.03); }
.tbl .mono { font-family: var(--mono); font-size: 12.5px; }
.tbl .dim { color: var(--text-2); font-size: 12px; }
.tbl .actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { padding: 60px 20px; text-align: center; color: var(--text-2); }
.empty .big { font-size: 34px; margin-bottom: 10px; }

/* 抽屉 */
.drawer-mask { position: fixed; inset: 0; background: rgba(5, 9, 17, 0.6); backdrop-filter: blur(4px); z-index: 90; animation: fadeIn 0.2s; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 440px; max-width: 100vw;
  background: var(--bg-1); border-left: 1px solid var(--line); z-index: 91;
  padding: 26px; overflow-y: auto; animation: slideIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes slideIn { from { transform: translateX(60px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.drawer h3 { margin: 0 0 22px; font-size: 18px; display: flex; justify-content: space-between; align-items: center; }
.drawer .x { cursor: pointer; color: var(--text-2); font-size: 20px; background: none; border: none; }
.drawer .x:hover { color: var(--text-1); }
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; margin-bottom: 12px;
  background: rgba(11, 18, 32, 0.5); border: 1px solid var(--line); border-radius: 10px;
}
.switch-row .t { font-size: 13.5px; font-weight: 600; }
.switch-row .d { font-size: 12px; color: var(--text-2); margin-top: 3px; }
.drawer .foot { display: flex; gap: 10px; margin-top: 24px; }
.drawer .foot .btn { flex: 1; }

/* 证书卡片 */
.cert-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.cert-card {
  background: var(--glass); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; transition: 0.2s; position: relative; overflow: hidden;
}
.cert-card:hover { transform: translateY(-3px); border-color: rgba(0, 217, 192, 0.35); box-shadow: var(--shadow); }
.cert-card .domain { font-family: var(--mono); font-size: 16px; font-weight: 700; word-break: break-all; }
.cert-card .meta { display: flex; gap: 8px; margin: 10px 0 14px; flex-wrap: wrap; }
.days-bar { height: 6px; border-radius: 4px; background: rgba(143, 163, 192, 0.15); overflow: hidden; margin-bottom: 6px; }
.days-bar i { display: block; height: 100%; border-radius: 4px; background: var(--accent-grad); transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1); }
.days-bar i.low { background: linear-gradient(90deg, #F59E0B, #EF4444); }
.cert-card .days-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); font-family: var(--mono); }
.cert-card .btns { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

/* 设置 */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 18px; align-items: start; }
.set-card { background: var(--glass); backdrop-filter: blur(12px); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.set-card h3 { margin: 0 0 4px; font-size: 16px; }
.set-card .desc { color: var(--text-2); font-size: 12.5px; margin: 0 0 18px; line-height: 1.7; }
.set-card .btn { margin-top: 6px; }
.code-hint {
  font-family: var(--mono); font-size: 11.5px; color: var(--text-2);
  background: rgba(11, 18, 32, 0.6); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; line-height: 1.8; overflow-x: auto;
  white-space: pre; margin: 10px 0;
}

/* Toast */
#toast-wrap { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  display: flex; align-items: flex-start; gap: 10px; max-width: 420px;
  padding: 13px 16px; border-radius: 12px; font-size: 13px; line-height: 1.55;
  background: var(--bg-2); border: 1px solid var(--line); box-shadow: var(--shadow);
  animation: toastIn 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes toastIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast.ok { border-left: 3px solid var(--ok); }
.toast.err { border-left: 3px solid var(--err); }
.toast.warn { border-left: 3px solid var(--warn); }
.toast.out { animation: toastOut 0.3s forwards; }
@keyframes toastOut { to { transform: translateX(40px); opacity: 0; } }

/* Modal */
.modal-mask { position: fixed; inset: 0; background: rgba(5, 9, 17, 0.7); backdrop-filter: blur(5px); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px; animation: fadeIn 0.2s; }
.modal {
  width: 680px; max-width: 100%; max-height: 86vh; display: flex; flex-direction: column;
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); animation: riseIn 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.modal .m-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal .m-head h3 { margin: 0; font-size: 16px; }
.modal .m-body { padding: 20px 22px; overflow-y: auto; }
.modal .m-foot { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
pre.conf-view {
  font-family: var(--mono); font-size: 12px; line-height: 1.7; color: #a5d6ff;
  background: rgba(8, 13, 24, 0.9); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px; overflow: auto; margin: 0; max-height: 48vh; white-space: pre-wrap; word-break: break-all;
}
.log-view {
  font-family: var(--mono); font-size: 12px; line-height: 1.8;
  background: rgba(8, 13, 24, 0.9); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; max-height: 46vh; overflow-y: auto; white-space: pre-wrap;
}
.log-view .ts { color: var(--text-2); margin-right: 8px; }
.log-view .errline { color: #f87171; }

/* 响应式 */
@media (max-width: 760px) {
  .topbar { padding: 0 14px; gap: 10px; overflow-x: auto; }
  .topbar .brand span.tagline { display: none; }
  .container { padding: 14px; }
  .drawer { width: 100vw; }
  .tbl .hide-m { display: none; }
}
