/**
 * tgskin 后台通用样式（开发者端 / 管理员端共用）
 * 风格：White Premium Design System（白底侧边栏 + 橙强调）
 * 参考：达便聚合控制台 console.css — 严格 1:1 复刻
 *
 * 含：设计 Token / 侧边栏壳 / 顶栏 / 卡片 / 表格 / 表单 / 登录页 / Toast / Modal
 */

/* ============================================================
   Design Tokens
   ============================================================ */
:root {
  /* 色彩体系 - 白色系主调 */
  --color-primary: #0f172a;
  --color-primary-light: #1e293b;
  --color-primary-muted: #475569;

  /* 侧边栏 - 纯净白灰 */
  --bg-sidebar: #ffffff;
  --bg-sidebar-hover: #f8fafc;
  --bg-sidebar-active: #fff7ed;
  --border-sidebar: #f1f5f9;

  /* 强调色：品牌暖橙 */
  --color-accent: #ea580c;
  --color-accent-hover: #c2410c;
  --color-accent-light: #fff7ed;
  --color-accent-text: #9a3412;

  /* 背景色 */
  --bg-page: #f8fafc;
  --bg-surface: #ffffff;
  --bg-elevated: #f1f5f9;

  /* 文字色 */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-on-primary: #ffffff;
  --text-accent: #ea580c;

  /* 边框与阴影 */
  --border-default: #e2e8f0;
  --border-strong: #cbd5e1;
  --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.05), 0 2px 4px -1px rgba(15, 23, 42, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.06), 0 4px 6px -2px rgba(15, 23, 42, 0.03);
  --shadow-glow: 0 0 0 3px rgba(234, 88, 12, 0.15);

  /* 状态色 */
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #2563eb;

  /* 尺寸 */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --sidebar-width: 260px;
  --topbar-height: 64px;

  /* 过渡 */
  --ease: 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-page);
  min-height: 100%;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* ============================================================
   布局 (Layout)
   ============================================================ */
.layout { display: flex; min-height: 100vh; }

/* ============================================================
   侧边栏 (Sidebar) — 白色主题
   ============================================================ */

/* ---- 手机优先：默认隐藏（覆盖模式） ---- */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 200;
  box-shadow: 2px 0 8px rgba(15, 23, 42, 0.03);
  transition: width var(--ease), transform var(--ease);
  overflow: hidden;
  border-right: 1px solid var(--border-default);
  transform: translateX(-100%);
}

/* 手机：sidebar-open 显示侧边栏 */
.layout.sidebar-open .sidebar {
  transform: translateX(0);
}

/* ---- 桌面 ≥992px：默认展开（push 模式） ---- */
@media (min-width: 992px) {
  .sidebar {
    transform: translateX(0);
  }
  .layout.sidebar-collapsed .sidebar {
    width: 60px;
    transform: translateX(0);
  }
  /* 折叠窄条：隐藏文字，只显示图标 */
  .layout.sidebar-collapsed .sidebar .sidebar-brand span:last-child,
  .layout.sidebar-collapsed .sidebar .nav-cap,
  .layout.sidebar-collapsed .sidebar .nav-link span:last-child {
    display: none;
  }
  .layout.sidebar-collapsed .sidebar .sidebar-brand {
    justify-content: center;
    padding: 0;
  }
  .layout.sidebar-collapsed .sidebar .sidebar-nav {
    padding: 16px 8px;
  }
  .layout.sidebar-collapsed .sidebar .nav-link {
    justify-content: center;
    padding: 10px 0;
  }
  .layout.sidebar-collapsed .sidebar .sidebar-foot {
    padding: 12px 8px;
    justify-content: center;
  }
  .layout.sidebar-collapsed .sidebar .sidebar-foot .avatar,
  .layout.sidebar-collapsed .sidebar .sidebar-foot-user {
    display: none;
  }
}

/* 侧边栏遮罩（仅手机覆盖模式） */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 199;
  background: rgba(15, 23, 42, 0.35);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.layout.sidebar-open .sidebar-backdrop {
  display: block;
  opacity: 1;
}
@media (min-width: 992px) {
  .sidebar-backdrop {
    display: none !important;
  }
}

/* 品牌区 */
.sidebar-brand {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border-default);
  flex-shrink: 0;
  background: #fff;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.sidebar-brand .logo {
  width: 36px;
  height: 36px;
  background: var(--color-accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(234, 88, 12, 0.2);
  font-size: 16px;
  font-weight: 800;
  color: #fff;
}

/* 导航菜单 */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  background: #fff;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }

.nav-cap {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 20px 12px 6px;
  white-space: nowrap;
  text-transform: uppercase;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  user-select: none;
  position: relative;
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-sidebar-hover);
}

.nav-link.active {
  color: var(--color-accent) !important;
  background: var(--color-accent-light) !important;
  font-weight: 600;
}

/* 激活项左侧的橙色指示条 */
.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--color-accent);
  border-radius: 0 2px 2px 0;
}

.nav-link .ico {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-link .ico svg {
  width: 18px;
  height: 18px;
  stroke: var(--text-muted);
  stroke-width: 1.8;
  fill: none;
  transition: stroke 0.15s;
}

.nav-link:hover .ico svg,
.nav-link.active .ico svg {
  stroke: var(--color-accent);
}

/* 侧边栏底部用户信息 */
.sidebar-foot {
  border-top: 1px solid var(--border-default);
  padding: 16px;
  flex-shrink: 0;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-foot .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #fff;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(234, 88, 12, 0.2);
}

.sidebar-foot .meta {
  flex: 1;
  min-width: 0;
}

.sidebar-foot .name {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-foot .role {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.sidebar-foot-user {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

/* 侧边栏折叠按钮（桌面专用） */
.sidebar-collapse-btn {
  display: none;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.sidebar-collapse-btn:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
@media (min-width: 992px) {
  .sidebar-collapse-btn {
    display: flex;
  }
}

/* ============================================================
   顶部栏 (Topbar)
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.topbar-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 100px;
  background: var(--color-accent-light);
  color: var(--color-accent);
  border: 1px solid rgba(234, 88, 12, 0.2);
}

/* 汉堡菜单（手机专用） */
.hamburger {
  display: block;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--text-secondary);
  padding: 4px;
}
@media (min-width: 992px) {
  .hamburger { display: none; }
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-user {
  font-size: 14px;
  color: var(--text-secondary);
}

.topbar-user b {
  color: var(--text-primary);
  font-weight: 600;
}

/* 主区（手机默认全宽，桌面跟随侧边栏） */
.main {
  flex: 1;
  margin-left: 0;
  min-width: 0;
  transition: margin-left var(--ease);
}
@media (min-width: 992px) {
  .main {
    margin-left: var(--sidebar-width);
  }
  .layout.sidebar-collapsed .main {
    margin-left: 60px;
  }
}

.content {
  padding: 32px;
  background: var(--bg-page);
  min-height: calc(100vh - var(--topbar-height));
}

/* ============================================================
   卡片 (Card)
   ============================================================ */
.card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-default);
  padding: 28px;
  box-shadow: var(--shadow-md);
}

.card + .card { margin-top: 20px; }

.card-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.card-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}

/* ============================================================
   统计卡片网格
   ============================================================ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon svg { width: 24px; height: 24px; }

.stat-icon.i-total    { background: #eff6ff; color: #2563eb; }
.stat-icon.i-pending  { background: #fef3c7; color: #b45309; }
.stat-icon.i-approved { background: #dcfce7; color: #15803d; }
.stat-icon.i-rejected { background: #fee2e2; color: #b91c1c; }
.stat-icon.i-today    { background: var(--color-accent-light); color: var(--color-accent); }

.stat-meta .num {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.stat-meta .lbl {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============================================================
   表格 (Table)
   ============================================================ */
.table-wrap { overflow-x: auto; }

table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table.tbl th,
table.tbl td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
}

table.tbl th {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--bg-elevated);
}

table.tbl tbody tr:hover {
  background: var(--bg-page);
}

/* ============================================================
   徽章 (Badge)
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-radius: 100px;
  background: var(--bg-page);
  color: var(--text-muted);
  border: 1px solid var(--border-default);
}

.badge-pending  { background: #fef3c7; color: #b45309; border-color: rgba(180,83,9,0.15); }
.badge-approved { background: #dcfce7; color: #15803d; border-color: rgba(21,128,61,0.15); }
.badge-rejected { background: #fee2e2; color: #b91c1c; border-color: rgba(185,28,28,0.15); }

.badge-required { background: #fee2e2; color: #b91c1c; border-color: rgba(185,28,28,0.15); font-weight:600; }
.badge-optional { background: #f1f5f9; color: #64748b; border-color: rgba(100,116,139,0.15); font-weight:500; }

.badge--accent {
  background: var(--color-accent-light);
  color: var(--color-accent);
  border-color: rgba(234, 88, 12, 0.2);
}

/* ============================================================
   按钮 (Button)
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  text-decoration: none;
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-block { width: 100%; display: flex; }

.btn-lg {
  height: 52px;
  font-size: 16px;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
  box-shadow: 0 2px 6px rgba(234, 88, 12, 0.2);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-accent-hover);
  box-shadow: 0 4px 12px rgba(234, 88, 12, 0.3);
  transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) { transform: translateY(0); box-shadow: none; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-page);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
  box-shadow: 0 2px 8px rgba(220,38,38,0.3);
  transform: translateY(-1px);
}

/* ============================================================
   表单 (Form)
   ============================================================ */
.form-item { margin-bottom: 20px; }

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.form-control {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  outline: none;
  transition: all 0.2s;
  font-family: inherit;
}

.form-control:focus {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-glow);
  background: #fff;
}

.form-control::placeholder { color: var(--text-muted); }

textarea.form-control {
  height: auto;
  min-height: 100px;
  padding: 12px 16px;
  resize: vertical;
}

select.form-control { cursor: pointer; }

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
  font-size: 14px;
}

/* ============================================================
   登录页 (Login)
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-page);
  padding: 24px;
}

.login-form {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px;
}

.login-form h2 {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0 0 6px;
  letter-spacing: -0.02em;
  text-align: center;
}

.login-form .sub {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0 0 28px;
  text-align: center;
}

.login-form .form-control { height: 52px; }

/* ============================================================
   Toast 通知
   ============================================================ */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 7px;
  font-size: 13px;
  line-height: 1.5;
  color: #2A3547;
  background: #fff;
  border: 1px solid #ebf1f6;
  box-shadow: rgba(145,158,171,0.2) 0 0 2px 0, rgba(145,158,171,0.12) 0 12px 24px -4px;
  pointer-events: auto;
  animation: toastIn 0.2s ease;
  transition: opacity 0.2s ease;
  max-width: 420px;
  min-width: 160px;
  word-break: break-word;
}

.toast-item.toast-out { opacity: 0; }

.toast-success .toast-icon { color: #16a34a; }
.toast-error   .toast-icon { color: #ef4444; }
.toast-warning .toast-icon { color: #f59e0b; }
.toast-info    .toast-icon { color: #64748b; }
.toast-loading .toast-icon { color: #2A3547; }

.toast-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast-icon svg { width: 15px; height: 15px; }

.toast-loading .toast-icon svg { animation: toastSpin 0.8s linear infinite; }

.toast-close {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  margin-left: 6px;
  cursor: pointer;
  color: #7C8FAC;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s;
  border: none;
  background: none;
}

.toast-close:hover { color: #2A3547; }
.toast-close svg { width: 12px; height: 12px; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ============================================================
   Modal 弹窗
   ============================================================ */
.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 99998;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal-mask.is-open { opacity: 1; }

.modal-box {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  transform: translateY(12px) scale(0.98);
  transition: transform 0.2s cubic-bezier(0.4,0,0.2,1);
}

.modal-mask.is-open .modal-box { transform: translateY(0) scale(1); }

.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.modal-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.modal-icon svg { width: 22px; height: 22px; }

.modal-icon-danger  { color: var(--danger); }
.modal-icon-warning { color: var(--warning); }
.modal-icon-success { color: var(--success); }
.modal-icon-default { color: var(--color-accent); }

.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-content {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 22px;
  padding-left: 32px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-actions .btn {
  height: 40px;
  padding: 0 18px;
  font-size: 14px;
}

/* ============================================================
   响应式 (Responsive)
   ============================================================ */
@media (max-width: 992px) {
  .topbar { left: 0; }
}

@media (max-width: 640px) {
  .content { padding: 16px; }
  .card { padding: 20px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding: 0 16px; }
  .topbar-right > span { display: none; }
}
