:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --tab-active: #1677ff;
  --success: #059669;
  --success-bg: #ecfdf5;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --info: #1d4ed8;
  --info-bg: #eff6ff;
  --radius: 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==================== App Frame (yeaiagent-style) ==================== */
.admin-layout {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
}

.layout-sider {
  display: flex;
  flex-direction: column;
  width: 248px;
  height: 100vh;
  flex-shrink: 0;
  background: linear-gradient(180deg, #1e1e2e 0%, #2d2d44 100%);
  color: rgba(255, 255, 255, 0.85);
  transition: width 0.2s ease, transform 0.2s ease;
  z-index: 40;
  overflow: hidden;
  user-select: none;
}

.layout-sider.collapsed {
  width: 68px;
}

.layout-sider-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
  min-height: 58px;
}

.layout-sider.collapsed .layout-sider-header {
  padding: 14px 12px;
  justify-content: center;
  gap: 6px;
}

.layout-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
  min-width: 0;
}

.layout-logo-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.35);
}

.layout-logo-text {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.layout-sider.collapsed .layout-logo-text {
  display: none;
}

.sider-collapse-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.65);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.sider-collapse-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.layout-sider.collapsed .sider-collapse-btn {
  margin-left: 0;
}

.layout-menu {
  padding: 12px 8px;
  flex: 1 1 0%;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.layout-menu::-webkit-scrollbar {
  width: 4px;
}

.layout-menu::-webkit-scrollbar-track {
  background: transparent;
}

.layout-menu::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}

.layout-menu::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

.sider-group {
  margin-top: 4px;
}

.sider-group-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  margin: 4px 0 2px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
  font-family: inherit;
}

.sider-group-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.sider-group-left {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.sider-group-chevron {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  transition: transform 0.15s ease;
}

.sider-group-btn.closed .sider-group-chevron {
  transform: rotate(-90deg);
}

.sider-sublist {
  background: rgba(0, 0, 0, 0.14);
  border-radius: 8px;
  padding: 3px 4px;
  margin: 2px 0 6px;
}

.sider-sublist.closed {
  display: none;
}

.layout-sider.collapsed .sider-group-btn {
  display: none;
}

.layout-sider.collapsed .sider-sublist,
.layout-sider.collapsed .sider-sublist.closed {
  display: block;
  background: transparent;
  padding: 0;
  margin: 2px 0;
}

.sider-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin: 2px 0;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
  font-family: inherit;
}

.sider-item:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.sider-item.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.35);
}

.sider-item-icon {
  width: 18px;
  text-align: center;
  font-size: 14px;
  flex-shrink: 0;
}

.sider-item-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sider-badge {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
}

.sider-item.active .sider-badge {
  background: rgba(255, 255, 255, 0.28);
}

.layout-sider.collapsed .sider-item {
  justify-content: center;
  padding: 10px 6px;
}

.layout-sider.collapsed .sider-item-label,
.layout-sider.collapsed .sider-badge {
  display: none;
}

.layout-sider-footer {
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.layout-user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.layout-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.layout-user-meta {
  min-width: 0;
}

.layout-user-name {
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.layout-user-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(255, 255, 255, 0.58);
  font-size: 11px;
  margin-top: 2px;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
  flex-shrink: 0;
}

.status-dot.online {
  background: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25);
}

.sider-footer-btn {
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.86);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  transition: all 0.15s ease;
}

.sider-footer-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.layout-sider.collapsed .layout-user-meta,
.layout-sider.collapsed .sider-footer-label {
  display: none;
}

.layout-sider.collapsed .layout-user-row {
  justify-content: center;
}

/* ==================== Right Content Area ==================== */
.layout-content {
  display: flex;
  flex-direction: column;
  flex: 1 1 0%;
  height: 100vh;
  min-width: 0;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

.page-tabs-bar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  height: 42px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  flex-shrink: 0;
  z-index: 20;
  user-select: none;
}

.page-tabs-left {
  display: flex;
  align-items: stretch;
  flex: 1 1 0%;
  min-width: 0;
}

.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 100%;
  border: none;
  border-right: 1px solid #e5e7eb;
  background: #ffffff;
  color: #334155;
  font-size: 17px;
  cursor: pointer;
  flex-shrink: 0;
}

.page-tabs-scroll {
  display: flex;
  align-items: stretch;
  flex: 1 1 0%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.page-tabs-scroll::-webkit-scrollbar {
  display: none;
}

.page-tab-item {
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding: 0 15px;
  border-right: 1px solid #e5e7eb;
  border-top: 2px solid transparent;
  background: #fcfcfd;
  color: #64748b;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  flex-shrink: 0;
}

.page-tab-item:hover {
  background: #f8fafc;
  color: #1e293b;
}

.page-tab-item.active {
  background: #ffffff;
  color: var(--tab-active);
  font-weight: 600;
  border-top: 2px solid var(--tab-active);
}

.page-tab-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 8px;
  background: #cbd5e1;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.page-tab-item.active .page-tab-dot {
  background: var(--tab-active);
  box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.2);
}

.page-tabs-right {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-left: 1px solid #e5e7eb;
  background: #ffffff;
  flex-shrink: 0;
}

.layout-page-body {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 24px 48px;
  width: 100%;
}

.layout-page-body.full-bleed {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.layout-page-body::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.layout-page-body::-webkit-scrollbar-track {
  background: transparent;
}

.layout-page-body::-webkit-scrollbar-thumb {
  background: #d5d9e2;
  border-radius: 4px;
}

.layout-page-body::-webkit-scrollbar-thumb:hover {
  background: #bcc2ce;
}

.sider-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 35;
}

.sider-backdrop.open {
  display: block;
}

@media (max-width: 900px) {
  .layout-sider {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
  }

  .layout-sider.mobile-open {
    transform: translateX(0);
  }

  .layout-sider.collapsed {
    width: 248px;
  }

  .layout-sider.collapsed .layout-logo-text,
  .layout-sider.collapsed .sider-item-label,
  .layout-sider.collapsed .sider-badge,
  .layout-sider.collapsed .layout-user-meta,
  .layout-sider.collapsed .sider-footer-label,
  .layout-sider.collapsed .sider-group-btn {
    display: flex;
  }

  .layout-sider.collapsed .sider-item {
    justify-content: flex-start;
    padding: 9px 12px;
  }

  .mobile-menu-btn {
    display: inline-flex;
  }

  .page-tabs-right .badge {
    display: none;
  }

  .layout-page-body {
    padding: 14px 14px 36px;
  }
}

/* ==================== Shared Workspace Primitives ==================== */
.page-inner {
  max-width: 1380px;
  margin: 0 auto;
}

.page-head-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

.page-head-bar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.page-head-bar p {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 12.5px;
}

.welcome-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 18px;
  background: linear-gradient(135deg, #1e1e2e 0%, #312e81 60%, #4f46e5 100%);
  color: #ffffff;
  padding: 22px 26px;
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(49, 46, 129, 0.18);
}

.welcome-banner h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  color: #fff;
}

.welcome-banner p {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: 13px;
  max-width: 720px;
}

.banner-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.25);
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}

.banner-btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 15px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.35);
  cursor: pointer;
}

.banner-btn-ghost:hover {
  background: rgba(255, 255, 255, 0.24);
}

.banner-btn-white {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 15px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: #312e81;
  background: #ffffff;
  border: 1px solid #ffffff;
  cursor: pointer;
}

.banner-btn-white:hover {
  background: #eef2ff;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.card-title {
  margin: 0 0 14px;
  font-size: 15.5px;
  font-weight: 700;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

@media (max-width: 960px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: 15px 16px;
  text-decoration: none;
  color: inherit;
  display: block;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.07);
}

.kpi-card .stat-value {
  font-size: 22px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.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-neutral { background: #f1f5f9; color: #334155; }
.badge-info { background: var(--info-bg); color: var(--info); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}

.btn:hover:not(:disabled) {
  background: var(--surface-muted);
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

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

.input,
.select,
.textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}

.label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.stat-box {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  margin-top: 4px;
}

.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
}

.alert-info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }
.alert-warning { background: var(--warning-bg); border: 1px solid #fde68a; color: #92400e; }
.alert-danger { background: var(--danger-bg); border: 1px solid #fecaca; color: #991b1b; }
.alert-success { background: var(--success-bg); border: 1px solid #a7f3d0; color: #065f46; }

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  text-align: left;
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-muted);
  white-space: nowrap;
}

.row-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.checkbox-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

.ig-link {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.ig-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

.step-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

@media (max-width: 900px) {
  .step-strip {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  .step-strip {
    grid-template-columns: 1fr;
  }
}

.step-pill {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 12px;
}

.step-pill strong {
  color: var(--primary);
  display: block;
  margin-bottom: 2px;
}

/* ==================== Global Key Config Modal ==================== */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-card {
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.22);
}

.modal-card.modal-wide {
  max-width: 720px;
}

.sider-footer-actions {
  display: flex;
  gap: 6px;
}

.sider-footer-actions .sider-footer-btn {
  flex: 1;
}

.layout-sider.collapsed .sider-footer-actions {
  flex-direction: column;
}

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

.modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}
