/**
 * 管理后台专用样式
 *
 * 定位：只补充工作台类页面特有的结构（抽屉式侧栏、数据表格、状态徽章、指标卡、空态），
 * 配色与圆角统一复用 listenwrite-common.css 的 --lw-* 设计令牌，避免与全站视觉割裂。
 */

/* ===== 布局骨架 ===== */
.admin-shell {
  display: flex;
  min-height: 100vh;
}

.admin-sidebar {
  width: 16rem;
  flex: 0 0 16rem;
  background: #fff;
  border-right: 1px solid var(--lw-border, #e5e6eb);
  display: flex;
  flex-direction: column;
}

.admin-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.admin-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #fff;
  border-bottom: 1px solid var(--lw-border, #e5e6eb);
}

.admin-content {
  flex: 1 1 auto;
  padding: 1rem;
}

@media (min-width: 768px) {
  .admin-content {
    padding: 1.5rem;
  }
}

/* ===== 侧栏导航 ===== */
.admin-nav {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
  flex: 1 1 auto;
}

.admin-nav button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  color: var(--lw-text, #3d4451);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.admin-nav button:hover {
  background: var(--lw-surface-muted, #f2f2f2);
}

.admin-nav button.active,
.admin-nav button[aria-current="page"] {
  background: var(--lw-primary-soft, #e8f0ff);
  color: var(--lw-primary, #165dff);
  font-weight: 600;
}

/* 侧栏内的图标固定宽度，避免不同长度的图标造成文字错位 */
.admin-nav button i {
  width: 1.25rem;
  text-align: center;
}

/* ===== 移动端抽屉式侧栏 ===== */
.admin-sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.admin-sidebar-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 767px) {
  .admin-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.24s ease;
    box-shadow: 0 8px 32px rgba(17, 24, 39, 0.18);
  }

  .admin-sidebar.is-open {
    transform: translateX(0);
  }
}

/* ===== 卡片与面板 ===== */
.admin-card {
  background: #fff;
  border: 1px solid var(--lw-border, #e5e6eb);
  border-radius: 0.75rem;
  padding: 1.25rem;
}

.admin-card-title {
  font-size: 1rem;
  font-weight: 600;
}

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* ===== 统计卡 ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 1rem;
}

@media (min-width: 640px) {
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .stat-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

.stat-card {
  background: #fff;
  border: 1px solid var(--lw-border, #e5e6eb);
  border-radius: 0.75rem;
  padding: 1.25rem;
}

.stat-label {
  font-size: 0.8125rem;
  color: var(--lw-text-muted, #86909c);
}

.stat-value {
  margin-top: 0.25rem;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
}

/* ===== 图表容器 ===== */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

@media (min-width: 768px) {
  .chart-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.chart-card {
  background: #fff;
  border: 1px solid var(--lw-border, #e5e6eb);
  border-radius: 0.75rem;
  padding: 1rem 1.25rem 1.25rem;
}

.chart-card.is-wide {
  grid-column: 1 / -1;
}

/* 画布高度由容器约束，避免 Chart.js 在隐藏视图里初始化得到 0 宽度 */
.chart-canvas-wrap {
  position: relative;
  height: 12.5rem;
}

/* ===== 表格 ===== */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.admin-table th {
  text-align: left;
  font-weight: 500;
  color: var(--lw-text-muted, #86909c);
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--lw-border, #e5e6eb);
  white-space: nowrap;
}

.admin-table td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--lw-border-soft, #f2f3f5);
  vertical-align: middle;
}

.admin-table tbody tr:hover {
  background: var(--lw-surface-muted, #fafbfc);
}

.admin-table .cell-ellipsis {
  max-width: 18rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-table .cell-nowrap {
  white-space: nowrap;
}

/* ===== 徽章 ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: nowrap;
}

.badge-role-admin {
  background: #fdece8;
  color: #d4380d;
}

.badge-role-user {
  background: #e8f0ff;
  color: #165dff;
}

.badge-ok {
  background: #e8fff6;
  color: #0f9d58;
}

.badge-off {
  background: #f2f3f5;
  color: #86909c;
}

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: opacity 0.15s ease, background-color 0.15s ease;
  white-space: nowrap;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--lw-primary, #165dff);
  color: #fff;
}

.btn-ghost {
  background: #fff;
  border-color: var(--lw-border, #e5e6eb);
  color: var(--lw-text, #3d4451);
}

.btn-danger {
  background: #fff;
  border-color: #ffccc7;
  color: #d4380d;
}

.btn-sm {
  padding: 0.25rem 0.625rem;
  font-size: 0.8125rem;
}

.btn:active {
  transform: scale(0.97);
}

/* ===== 空态 / 加载态 ===== */
.admin-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 2.5rem 1rem;
  color: var(--lw-text-muted, #86909c);
}

.admin-empty i {
  font-size: 1.75rem;
  opacity: 0.6;
}

.admin-skeleton-row td {
  padding: 0.75rem;
}

.admin-skeleton {
  height: 0.75rem;
  border-radius: 999px;
  background: linear-gradient(90deg, #f2f3f5 25%, #e9ebef 37%, #f2f3f5 63%);
  background-size: 400% 100%;
  animation: admin-skeleton-shimmer 1.2s ease-in-out infinite;
}

@keyframes admin-skeleton-shimmer {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

/* 降级：用户声明减少动效时关闭骨架闪烁 */
@media (prefers-reduced-motion: reduce) {
  .admin-skeleton {
    animation: none;
  }

  .admin-sidebar,
  .admin-sidebar-backdrop {
    transition: none;
  }
}

/* ===== 分页 ===== */
.admin-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* ===== 弹窗 ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(17, 24, 39, 0.5);
  padding: 1rem;
}

.modal-backdrop.is-open {
  display: flex;
}

.modal-panel {
  background: #fff;
  border-radius: 0.75rem;
  width: 100%;
  max-width: 56rem;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-panel.is-narrow {
  max-width: 26rem;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--lw-border-soft, #f2f3f5);
  position: sticky;
  top: 0;
  background: #fff;
}

.modal-body {
  padding: 1.25rem;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--lw-border-soft, #f2f3f5);
}

/* 表单字段：统一 label 与控件间距，并在校验失败时给出可见反馈 */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.field-label {
  font-size: 0.8125rem;
  color: var(--lw-text-muted, #86909c);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--lw-border, #e5e6eb);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  background: #fff;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--lw-primary-soft, #e8f0ff);
  border-color: var(--lw-primary, #165dff);
}

.field.has-error input,
.field.has-error select,
.field.has-error textarea {
  border-color: #f53f3f;
}

.field-error {
  min-height: 1rem;
  font-size: 0.75rem;
  color: #f53f3f;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 0.75rem;
}

@media (min-width: 640px) {
  .field-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .field-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.field-grid .span-2 {
  grid-column: span 1;
}

@media (min-width: 640px) {
  .field-grid .span-2 {
    grid-column: span 2;
  }
}

@media (min-width: 1024px) {
  .field-grid .span-4 {
    grid-column: span 4;
  }
}

/* ===== 落地页转化指标 ===== */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 1rem;
}

@media (min-width: 640px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.metric-card {
  border: 1px solid var(--lw-border, #e5e6eb);
  border-radius: 0.75rem;
  padding: 1rem;
}

.metric-label {
  font-size: 0.8125rem;
  color: var(--lw-text-muted, #86909c);
}

.metric-value {
  font-size: 1.375rem;
  font-weight: 700;
  margin-top: 0.25rem;
}

/* ===== 详情描述列表 ===== */
.detail-list {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 0.5rem 1rem;
  font-size: 0.875rem;
}

.detail-list dt {
  color: var(--lw-text-muted, #86909c);
}

.detail-list dd {
  word-break: break-word;
}

/* 屏幕阅读器专用文本 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
