/* ============================================================
   SSL 证书托管模块 - 独立模式前端原型 - 公共样式
   ------------------------------------------------------------
   说明：
   1. 全部配色使用 CSS 变量，方便后续接入 CRM V2 主题换肤
   2. 弹窗统一使用 flex 居中（.modal-mask 内 align-items/justify-content 居中）
   3. 页面布局：左侧固定导航 + 右侧内容区
   ============================================================ */

/* ---------- CSS 变量（主题配置区） ---------- */
:root {
  /* 主色系 */
  --primary: #2563eb;            /* 主色（按钮/链接/高亮） */
  --primary-light: #3b82f6;      /* 主色浅（hover） */
  --primary-bg: #eff6ff;         /* 主色背景底 */
  --success: #16a34a;            /* 成功 */
  --success-bg: #f0fdf4;         /* 成功背景底 */
  --warning: #d97706;            /* 警告 */
  --warning-bg: #fffbeb;         /* 警告背景底 */
  --danger: #dc2626;             /* 危险/失败 */
  --danger-bg: #fef2f2;          /* 危险背景底 */
  --info: #0891b2;               /* 信息 */
  --info-bg: #ecfeff;            /* 信息背景底 */

  /* 中性色 */
  --bg: #f1f5f9;                 /* 页面背景 */
  --card: #ffffff;               /* 卡片背景 */
  --text: #1e293b;               /* 主文本 */
  --text-secondary: #64748b;     /* 次级文本 */
  --text-muted: #94a3b8;         /* 弱文本 */
  --border: #e2e8f0;             /* 边框 */
  --border-strong: #cbd5e1;      /* 强边框 */

  /* 尺寸与圆角 */
  --radius: 8px;                 /* 卡片圆角 */
  --radius-sm: 4px;              /* 小组件圆角 */
  --sidebar-width: 220px;        /* 侧边栏宽度 */
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);       /* 卡片阴影 */
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.15);  /* 弹窗阴影 */

  /* 字体 */
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC",
          "Microsoft YaHei", "Segoe UI", sans-serif;
}

/* ---------- 基础重置 ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-light); }

/* ---------- 整体布局（侧边栏 + 主内容） ---------- */
.layout { display: flex; min-height: 100vh; }

/* 侧边栏 */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: #ffffff;           /* 白底侧边栏 */
  color: var(--text);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  padding: 18px 20px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-logo .badge {
  font-size: 11px;
  background: var(--primary);
  color: #fff;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.sidebar-nav { padding: 12px 0; flex: 1; overflow-y: auto; }

.sidebar-nav .nav-group {
  padding: 12px 20px 6px;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 1px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.15s;
}
.nav-item:hover { background: #f1f5f9; color: var(--text); }
.nav-item.active {
  background: var(--primary-bg);
  border-left-color: var(--primary);
  color: var(--primary);
}
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; }

/* 主内容区 */
.main { flex: 1; padding: 24px 28px; min-width: 0; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 20px; font-weight: 700; }
.page-header .sub { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }

/* ---------- 卡片 ---------- */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.panel-title {
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-body { padding: 18px; }

/* 统计卡片（看板） */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.stat-card .stat-label { color: var(--text-secondary); font-size: 13px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.stat-card .stat-desc { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.stat-card.accent-primary { border-top: 3px solid var(--primary); }
.stat-card.accent-success { border-top: 3px solid var(--success); }
.stat-card.accent-warning { border-top: 3px solid var(--warning); }
.stat-card.accent-danger  { border-top: 3px solid var(--danger); }

/* 双栏布局（看板图表区） */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  background: #f8fafc;
  text-align: left;
  padding: 10px 12px;
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f8fafc; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  transition: all 0.15s;
  user-select: none;
}
.btn:hover { background: var(--primary-light); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary { background: #fff; color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: #f1f5f9; color: var(--text); }

.btn-success { background: var(--success); }
.btn-success:hover { background: #15803d; }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }

.btn-warning { background: var(--warning); }
.btn-warning:hover { background: #b45309; }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ---------- 表单 ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13px; }
.form-group .required::after { content: " *"; color: var(--danger); }
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  background: #fff;
  color: var(--text);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
textarea.form-control { resize: vertical; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12px; line-height: 1.5; }
select.form-control { cursor: pointer; }
.form-tip { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* ---------- 筛选工具条 ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar .form-control { width: auto; min-width: 120px; }
.toolbar .search-input { width: 240px; }

/* ---------- 标签 / 徽章 ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.6;
}
.badge-primary { background: var(--primary-bg); color: var(--primary); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-info    { background: var(--info-bg);    color: var(--info); }
.badge-muted   { background: #f1f5f9; color: var(--text-secondary); }

/* 来源标签（auto/manual） */
.badge-auto   { background: var(--info-bg);  color: var(--info); }
.badge-manual { background: var(--warning-bg); color: var(--warning); }

/* ---------- 到期倒计时颜色 ---------- */
.expire-danger  { color: var(--danger);  font-weight: 600; }
.expire-warning { color: var(--warning); font-weight: 600; }
.expire-ok      { color: var(--success); }

/* ---------- 弹窗（统一 flex 居中） ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;                      /* 关键：flex 容器 */
  align-items: center;                /* 垂直居中 */
  justify-content: center;            /* 水平居中 */
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-mask.show { opacity: 1; pointer-events: auto; }

.modal {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 520px;
  max-width: calc(100vw - 48px);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  transform: translateY(8px);
  transition: transform 0.2s;
}
.modal-mask.show .modal { transform: translateY(0); }

.modal-header {
  padding: 16px 20px;
  font-size: 16px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-close { cursor: pointer; color: var(--text-muted); font-size: 18px; line-height: 1; padding: 4px; }
.modal-close:hover { color: var(--danger); }

.modal-body { padding: 20px; overflow-y: auto; }

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---------- Toast 通知（代替 alert） ---------- */
.toast-wrap {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  min-width: 220px;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: #1e293b;
  color: #fff;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: toast-in 0.25s ease;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warning); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ---------- 日志回显区 ---------- */
.log-viewer {
  background: #0f172a;
  color: #e2e8f0;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.7;
  padding: 14px;
  border-radius: var(--radius-sm);
  min-height: 220px;
  max-height: 420px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.log-viewer .log-ok  { color: #4ade80; }
.log-viewer .log-err { color: #f87171; }
.log-viewer .log-muted { color: #64748b; }

/* ---------- 简单图表（纯 CSS/JS 演示） ---------- */
.chart-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 180px;
  padding: 10px 6px 0;
}
.chart-bar .bar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: flex-end;
}
.chart-bar .bar {
  width: 70%;
  background: var(--primary);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  min-height: 4px;
  transition: height 0.4s ease;
}
.chart-bar .bar.warn { background: var(--warning); }
.chart-bar .bar.danger { background: var(--danger); }
.chart-bar .bar-label { font-size: 12px; color: var(--text-secondary); }
.chart-bar .bar-value { font-size: 12px; font-weight: 600; }

/* 环形进度（部署成功率） */
.ring-wrap { display: flex; align-items: center; justify-content: center; padding: 10px 0 6px; }
.ring {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: conic-gradient(var(--success) var(--pct, 0%), var(--border) 0);
  position: relative;
}
.ring::after {
  content: "";
  position: absolute;
  inset: 14px;
  background: var(--card);
  border-radius: 50%;
}
.ring .ring-text { position: relative; z-index: 1; text-align: center; }
.ring .ring-text .num { font-size: 26px; font-weight: 700; }
.ring .ring-text .unit { font-size: 12px; color: var(--text-secondary); }

/* 告警列表 */
.alert-list { list-style: none; }
.alert-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 4px;
  border-bottom: 1px dashed var(--border);
}
.alert-list li:last-child { border-bottom: none; }
.alert-list .alert-domain { font-weight: 600; }
.alert-list .alert-time { color: var(--text-muted); font-size: 12px; }

/* 空状态 */
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
}
.empty .empty-icon { font-size: 36px; margin-bottom: 8px; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .sidebar { position: static; width: 100%; height: auto; }
  .layout { flex-direction: column; }
  .sidebar-nav { display: flex; flex-wrap: wrap; }
  .nav-item { flex: 1; border-left: none; border-bottom: 2px solid transparent; justify-content: center; }
  .nav-item.active { border-bottom-color: var(--primary); }
}
