/*
  Modern app UI styling with CSS variables, multi-theme support, and
  component styles compatible with existing class names (btn/table/alert/modal).
  The goal is to replace Bootstrap dependency while preserving template markup.
*/

/* Base variables (Default: Purple Tech) */
:root {
  --primary: #4f46e5;
  --primary-600: #4f46e5;
  --primary-700: #4338ca;
  --primary-50: #eef2ff;
  --success: #10b981;
  --success-50: #ecfdf5;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;

  --bg: #f6f7fb;
  --content-bg: #ffffff; /* 默认主题右侧内容区白底 */
  --text: #1f2937;
  --muted: #6b7280;
  --card-bg: #ffffff;
  --card-border: #e5e7eb;
  --shadow: 0 8px 16px rgba(17, 24, 39, 0.06);

  /* 默认主题左侧白底导航 */
  --sidebar-bg: #ffffff;
  --sidebar-text: #1f2937;
  --sidebar-hover: #f3f4f6;

  --radius: 12px;
}

/* Deep Blue Business */
[data-theme="deepblue"] {
  --primary: #2563eb; --primary-600:#2563eb; --primary-700:#1e40af; --primary-50:#eff6ff;
  --bg: #eef2f7; --card-border:#e2e8f0; --sidebar-bg: linear-gradient(180deg,#1e3a8a,#1d4ed8);
}

/* Fresh Green */
[data-theme="green"] {
  --primary: #22c55e; --primary-600:#22c55e; --primary-700:#16a34a; --primary-50:#ecfdf5;
  --bg: #f4f8f5; --sidebar-bg: linear-gradient(180deg,#16a34a,#22c55e);
}

/* Orange Energy */
[data-theme="orange"] {
  --primary:#f97316; --primary-600:#f97316; --primary-700:#ea580c; --primary-50:#fff7ed;
  --bg:#fff7f2; --sidebar-bg: linear-gradient(180deg,#f59e0b,#f97316);
}

/* Pink Warm */
[data-theme="pink"] {
  --primary:#ec4899; --primary-600:#ec4899; --primary-700:#db2777; --primary-50:#fdf2f8;
  --bg:#fcf6fb; --sidebar-bg: linear-gradient(180deg,#db2777,#ec4899);
}

/* Dark Mode */
[data-theme="dark"] {
  --bg:#0f172a; --text:#e5e7eb; --muted:#94a3b8; --card-bg:#0b1220; --card-border:#1f2937;
  --content-bg:#0b1220; /* 暗黑主题下保持深色内容背景 */
  --sidebar-bg: linear-gradient(180deg,#0b1220,#111827);
  --shadow: 0 8px 18px rgba(0,0,0,0.35);
}

/* Cyberpunk */
[data-theme="cyber"] {
  --primary:#84cc16; --primary-600:#84cc16; --primary-700:#65a30d; --primary-50:#f7fee7;
  --bg:#0a0a0a; --text:#e4e4e7; --card-bg:#131316; --card-border:#262626;
  --sidebar-bg: linear-gradient(180deg,#7c3aed,#22d3ee);
}

/* Elegant Gray */
[data-theme="gray"] {
  --primary:#64748b; --primary-600:#64748b; --primary-700:#475569; --primary-50:#f1f5f9;
  --bg:#f3f4f6; --sidebar-bg: linear-gradient(180deg,#334155,#64748b);
}

/* Purple Dream */
[data-theme="purpledream"] {
  --primary:#8b5cf6; --primary-600:#8b5cf6; --primary-700:#7c3aed; --primary-50:#f5f3ff;
  --bg:#f6f3ff; --sidebar-bg: linear-gradient(180deg,#7c3aed,#a78bfa);
}

/* Reset */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg); color: var(--text);
}

/* Layout */
.app-layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar-bg); color: var(--sidebar-text);
  padding: 18px 14px; display:flex; flex-direction:column; gap:12px; position: sticky; top: 0; height: 100vh;
  border-right: 1px solid var(--card-border);
}
.sidebar .brand { font-weight: 700; font-size: 18px; letter-spacing: .5px; display:flex; align-items:center; gap:8px; }
.sidebar-nav { list-style:none; padding:0; margin: 8px 0 0; display:flex; flex-direction:column; gap:6px; }
.sidebar-nav a { color: var(--sidebar-text); text-decoration:none; padding:10px 12px; border-radius: 10px; display:flex; align-items:center; gap:10px; transition: background .15s ease, color .15s ease; }
.sidebar-nav a:hover { background: var(--sidebar-hover); }
/* Active/selected state: light background and left bar */
.sidebar-nav a.active {
  background: var(--primary-50);
  color: var(--primary-700);
  border-left: 4px solid var(--primary-600);
}
.sidebar .small { font-size:12px; opacity:.85; }

.content { display:flex; flex-direction:column; min-width:0; background: var(--content-bg); }
.topbar { display:flex; align-items:center; justify-content:space-between; padding: 14px 18px; backdrop-filter: saturate(180%) blur(6px);
  background: linear-gradient(180deg, rgba(255,255,255,0.7), rgba(255,255,255,0.5)); border-bottom: 1px solid var(--card-border);
}
.topbar .right { display:flex; align-items:center; gap:10px; }
.topbar .btn { white-space: nowrap; }

.container { padding: 18px; }

/* Card */
.card { background: var(--card-bg); border: 1px solid var(--card-border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: 10px 14px; border-bottom: 1px solid var(--card-border); font-weight:600; }
.card-body { padding: 14px; }

/* Buttons */
.btn { display:inline-flex; align-items:center; justify-content:center; gap:6px; padding: 8px 14px; border-radius: 10px; border:1px solid transparent; font-weight:600; cursor:pointer; transition: all .18s ease; text-decoration:none; color: var(--text); background: #fff; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 12px rgba(0,0,0,0.08); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-primary { background: var(--primary); color:#fff; }
.btn-primary:hover { background: var(--primary-700); }
.btn-outline-primary { color: var(--primary); background: var(--primary-50); border-color: var(--primary-600); }
.btn-outline-primary:hover { background: var(--primary-600); color:#fff; }
.btn-success { background: var(--success); color:#fff; }
.btn-outline-success { color: var(--success); background: var(--success-50); border-color: var(--success); }
.btn-outline-success:hover { background: var(--success); color:#fff; }
.btn-secondary { background:#e5e7eb; }
.btn-danger { background: var(--danger); color:#fff; }
.btn-outline-secondary { color:#374151; background:#f3f4f6; border-color:#d1d5db; }
.btn-outline-secondary:hover { background:#d1d5db; }
.btn-warning { background: var(--warning); color: #111827; }

/* Badge */
.badge { display:inline-block; padding: 4px 8px; border-radius: 10px; font-size: 12px; font-weight:600; }
.bg-primary { background: var(--primary); color:#fff; }
.bg-success { background: var(--success); color:#fff; }
.bg-secondary { background:#64748b; color:#fff; }
.bg-info { background: var(--info); color:#fff; }
.bg-warning { background: var(--warning); color:#fff; }

/* Table */
.table { width:100%; border-collapse: collapse; font-size: 14px; background: var(--card-bg); border:1px solid var(--card-border); border-radius: var(--radius); overflow:hidden; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--card-border); vertical-align: middle; }
.table thead th { background: var(--primary-50); color: #111827; font-weight:600; }
.table thead th a { color: inherit; text-decoration: none; display:inline-block; width:100%; }
.table-striped tbody tr:nth-child(odd) { background: rgba(0,0,0,0.02); }
.align-middle td, .align-middle th { vertical-align: middle; }
/* Row emphasis for status */
.table tr.error-row { background: #fff1f2; }
.table tr.success-row { background: #ecfdf5; }

/* Alert */
.alert { padding: 10px 14px; border:1px solid var(--card-border); border-radius: 10px; background:#fff; }
.alert-info { border-color:#93c5fd; background:#eff6ff; color:#1e3a8a; }
.alert-warning { border-color:#f59e0b; background:#fffbeb; color:#7c2d12; }
.alert-success { border-color:#10b981; background:#ecfdf5; color:#065f46; }
.alert-danger { border-color:#ef4444; background:#fee2e2; color:#7f1d1d; }

/* Progress */
.progress { background:#e5e7eb; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 8px; background: var(--primary); }

/* Pagination */
.pagination { display:flex; align-items:center; list-style:none; padding:0; gap:6px; }
.page-item .page-link { display:inline-flex; align-items:center; padding:6px 12px; border:1px solid var(--card-border); border-radius: 8px; text-decoration:none; color: var(--text); background:#fff; line-height: 1.2; }
.page-item .page-link:hover { border-color: var(--primary-600); color: var(--primary-600); }
.page-item.disabled .page-link { color: var(--muted); cursor: default; }

/* Forms */
.form-control, .form-select { width:100%; padding:10px 12px; border:1px solid var(--card-border); border-radius: 10px; background:#fff; color: var(--text); outline:none; transition: border-color .15s ease; }
.form-control:focus, .form-select:focus { border-color: var(--primary-600); box-shadow: 0 0 0 3px rgba(79,70,229,0.15); }
.form-label { font-weight:500; margin-bottom: 6px; display:block; }
.form-check { display:flex; align-items:center; gap:8px; }
.form-check-input { width:16px; height:16px; }

/* Search bar layout: keep controls on one line with right-aligned buttons */
.search-bar { display:flex; align-items:center; gap:10px; }
.search-bar .search-input { flex: 1; min-width: 420px; width: auto; }
.search-bar .btn { white-space: nowrap; }

/* Modal (Bootstrap-like markup) */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: none; align-items: center; justify-content: center; padding: 20px; z-index: 1000; }
.modal.open { display: flex; }
.modal-dialog { max-width: 860px; width: 100%; }
.modal-content { background: var(--card-bg); border:1px solid var(--card-border); border-radius: var(--radius); box-shadow: var(--shadow); overflow:hidden; }
.modal-header, .modal-footer { padding: 12px 14px; border-bottom: 1px solid var(--card-border); }
.modal-header { display:flex; align-items:center; justify-content:space-between; }
.modal-body { padding: 14px; }
.btn-close { width: 30px; height: 30px; border-radius: 8px; border:1px solid var(--card-border); background:#fff; cursor:pointer; }
.btn-close::before { content: "×"; display: block; text-align: center; line-height: 28px; font-size: 18px; color: var(--text); }

/* Utility */
.mt-3 { margin-top: 1rem; }
.mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.25rem; }
.mb-0 { margin-bottom: 0; }
.me-2 { margin-right: .5rem; }
.ms-2 { margin-left: .5rem; }
.ms-3 { margin-left: .75rem; }
.mt-2 { margin-top: .5rem; }
.w-100 { width: 100%; }
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.p-3 { padding: 1rem; }
.p-4 { padding: 1.25rem; }
.row { display:grid; gap: 12px; grid-template-columns: repeat(12, 1fr); }
.g-3 { gap: 1rem; }
.col-md-6 { grid-column: span 6; }
.col-md-4 { grid-column: span 4; }
.col-md-3 { grid-column: span 3; }
.col-12 { grid-column: span 12; }

/* Dashboard */
.dashboard-hero { padding: 16px; border-radius: var(--radius); box-shadow: var(--shadow);
  color: var(--primary-700);
  background: linear-gradient(90deg, var(--primary-50), var(--primary-600)); }
.dashboard-hero .title { font-size: 16px; font-weight:700; }
.dashboard-hero .desc { font-size: 13px; opacity:.95; }
.stat-card { display:flex; align-items:center; gap:12px; padding: 14px; }
.stat-icon { width: 40px; height: 40px; border-radius: 10px; display:flex; align-items:center; justify-content:center; color:#fff; font-size:18px; }
.chart-card .small { font-size: 12px; color: var(--muted); }
.col-12 { grid-column: span 12; }
.col-lg-4 { grid-column: span 12; }
@media (min-width: 992px) { .col-lg-4 { grid-column: span 4; } }

/* Flex utilities for inline layouts */
.d-flex { display: flex; }
.align-items-center { align-items: center; }

/* Keep per-page selector inline with pagination */
#perPageForm { display: inline-flex; align-items: center; margin: 0; padding: 0; position: relative; top: 8px; }
#perPageForm .form-select { width: auto; min-width: 120px; padding: 6px 12px; height: 36px; line-height: 1.2; border-radius: 8px; font-size: 14px; }
/* Match page-link height for perfect vertical alignment */
.pagination .page-link { height: 36px; }

/* Auth page layout */
.center-page { min-height: 100vh; display:flex; align-items:center; justify-content:center; padding: 18px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-flex { display:flex; align-items:center; gap:8px; }
.captcha-img { cursor:pointer; border-radius: 10px; border:1px solid var(--card-border); }

/* Gradient background like reference login page */
body.auth-page { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }

/* Card and form enhancements for login */
.auth-card .card { border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.auth-card .card-body { padding: 28px; }
.auth-card .form-control { border-width: 2px; }
.auth-card .form-control:focus { border-color: #667eea; box-shadow: 0 0 0 3px rgba(102,126,234,0.12); }

/* Login title area */
.auth-logo { text-align:center; margin-bottom: 22px; }
.auth-logo h1 { font-size: 1.75rem; color: #667eea; margin: 0 0 8px; }
.auth-logo p { color: var(--muted); font-size: .875rem; }

/* Gradient primary button for login */
.btn-gradient { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color:#fff; }
.btn-gradient:hover { transform: translateY(-2px); box-shadow: 0 10px 20px rgba(102,126,234,0.3); }
.btn-gradient:active { transform: translateY(0); }

/* Keep previous text wrapping utilities */
pre {
  background: #fafafa;
  padding: 8px;
  border: 1px solid #eee;
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-wrap: anywhere;
  margin: 0;
}
.wrap-text {
  white-space: pre-wrap;
  word-break: break-all;
  overflow-wrap: anywhere;
}
.url-wrap { word-break: break-all; overflow-wrap: anywhere; white-space: normal; }

/* Logs table layouts: fix column widths and alignment for consistency */
.op-logs-table { table-layout: fixed; }
.op-logs-table thead th:nth-child(1), .op-logs-table tbody td:nth-child(1) { width: 14%; text-align: center; }
.op-logs-table thead th:nth-child(2), .op-logs-table tbody td:nth-child(2) { width: 10%; text-align: center; }
.op-logs-table thead th:nth-child(3), .op-logs-table tbody td:nth-child(3) { width: 12%; text-align: center; }
.op-logs-table thead th:nth-child(4), .op-logs-table tbody td:nth-child(4) { width: 12%; text-align: center; }
.op-logs-table thead th:nth-child(5), .op-logs-table tbody td:nth-child(5) { width: 12%; text-align: center; }
.op-logs-table thead th:nth-child(6), .op-logs-table tbody td:nth-child(6) { width: 30%; }
.op-logs-table thead th:nth-child(7), .op-logs-table tbody td:nth-child(7) { width: 10%; text-align: center; }

.ai-logs-table { table-layout: fixed; }
.ai-logs-table thead th:nth-child(1), .ai-logs-table tbody td:nth-child(1) { width: 10%; text-align: center; }
.ai-logs-table thead th:nth-child(2), .ai-logs-table tbody td:nth-child(2) { width: 7%; text-align: center; }
.ai-logs-table thead th:nth-child(3), .ai-logs-table tbody td:nth-child(3) { width: 10%; text-align: center; }
.ai-logs-table thead th:nth-child(4), .ai-logs-table tbody td:nth-child(4) { width: 8%; text-align: center; }
.ai-logs-table thead th:nth-child(5), .ai-logs-table tbody td:nth-child(5) { width: 9%; text-align: center; }
.ai-logs-table thead th:nth-child(6), .ai-logs-table tbody td:nth-child(6) { width: 9%; text-align: center; }
.ai-logs-table thead th:nth-child(7), .ai-logs-table tbody td:nth-child(7) { width: 8%; text-align: center; }
.ai-logs-table thead th:nth-child(8), .ai-logs-table tbody td:nth-child(8) { width: 16%; }
.ai-logs-table thead th:nth-child(9), .ai-logs-table tbody td:nth-child(9) { width: 14%; }
.ai-logs-table thead th:nth-child(10), .ai-logs-table tbody td:nth-child(10) { width: 9%; }

.login-logs-table { table-layout: fixed; }
.login-logs-table thead th:nth-child(1), .login-logs-table tbody td:nth-child(1) { width: 18%; text-align: center; }
.login-logs-table thead th:nth-child(2), .login-logs-table tbody td:nth-child(2) { width: 16%; text-align: center; }
.login-logs-table thead th:nth-child(3), .login-logs-table tbody td:nth-child(3) { width: 18%; text-align: center; }
.login-logs-table thead th:nth-child(4), .login-logs-table tbody td:nth-child(4) { width: 12%; text-align: center; }
.login-logs-table thead th:nth-child(5), .login-logs-table tbody td:nth-child(5) { width: 36%; }

/* Top metrics style (for dashboard/report-like cards) */
.metric { background:#fff; border-radius: 10px; padding: 14px; border:1px solid var(--card-border); }
.metric h6 { margin:0; font-size: 12px; color: var(--muted); }
.metric .val { font-size: 18px; font-weight: 600; color: var(--text); }