/* ============================
   Admin CSS
   ============================ */
:root {
  --bg: #f5f6fa;
  --bg-card: #ffffff;
  --text: #1a1d26;
  --text-sec: #5a6178;
  --text-muted: #8b92a8;
  --border: #e8eaf0;
  --accent: #4f6ef7;
  --accent-hover: #3d5ce5;
  --accent-light: #eef1fe;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
button { border: none; background: none; cursor: pointer; font-family: inherit; }
ul { list-style: none; }

/* Header */
.admin-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
}

.admin-header-inner {
  display: flex;
  align-items: center;
  height: 100%;
  gap: 20px;
}

.back-link {
  font-size: 0.85rem;
  color: var(--text-sec);
  white-space: nowrap;
  transition: color 0.2s;
}

.back-link:hover { color: var(--accent); }

.admin-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
}

.header-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 16px;
  font-size: 0.82rem;
  font-weight: 500;
  border-radius: var(--radius);
  transition: all 0.2s;
  white-space: nowrap;
}

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

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

.btn-outline {
  border: 1px solid var(--border);
  color: var(--text-sec);
  background: var(--bg-card);
}

.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger {
  color: var(--danger);
  padding: 4px 10px;
  font-size: 0.78rem;
}

.btn-danger:hover { background: #fef2f2; }

.btn-edit {
  color: var(--accent);
  padding: 4px 10px;
  font-size: 0.78rem;
}

.btn-edit:hover { background: var(--accent-light); }

/* Tabs */
.admin-tabs {
  display: flex;
  gap: 0;
  padding: 0 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 12px 20px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-sec);
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab:hover { color: var(--accent); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Main */
.admin-main {
  padding: 20px 24px;
  max-width: 1400px;
}

.panel { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); }

.panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  gap: 8px;
}

.filter-group select,
.filter-group input {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.82rem;
  font-family: inherit;
  outline: none;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.2s;
}

.filter-group input { width: 200px; }
.filter-group select { min-width: 140px; }
.filter-group select:focus,
.filter-group input:focus { border-color: var(--accent); }

.result-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Layout with sidebar */
.layout-with-sidebar {
  display: flex;
  min-height: 500px;
}
.panel-sidebar {
  width: 220px;
  border-right: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}
.panel-sidebar .sidebar-header {
  padding: 14px 20px;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-sec);
  border-bottom: 1px solid var(--border);
}
.sidebar-cat-list {
  padding: 10px 0;
}
.sidebar-cat-list li {
  padding: 10px 20px;
  font-size: 0.85rem;
  color: var(--text-sec);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sidebar-cat-list li:hover {
  background: #f9fafc;
}
.sidebar-cat-list li.active {
  color: var(--accent);
  background: var(--accent-light);
  font-weight: 600;
  border-right: 3px solid var(--accent);
}
.sidebar-cat-list li .cat-count {
  font-size: 0.75rem;
  background: #e2e8f0;
  padding: 2px 8px;
  border-radius: 10px;
  color: var(--text-muted);
}
.sidebar-cat-list li.active .cat-count {
  background: #fff;
  color: var(--accent);
}
.panel-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

@media (max-width: 768px) {
  .layout-with-sidebar { flex-direction: column; }
  .panel-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
}

/* Table */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  color: var(--text-sec);
  background: #fafbfd;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: #f8f9fc; }

.data-table .logo-cell img {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  object-fit: contain;
  background: var(--bg);
}

.data-table .logo-cell .fallback {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.data-table .desc-cell {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-sec);
}

.data-table .url-cell {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.data-table .url-cell a { color: var(--accent); }
.data-table .url-cell a:hover { text-decoration: underline; }

.actions-cell {
  white-space: nowrap;
}
.actions-cell > button {
  margin-right: 4px;
}
.actions-cell > button:last-child {
  margin-right: 0;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.visible {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border-radius: 12px;
  width: 520px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 1.3rem;
  color: var(--text-muted);
  transition: background 0.2s;
}

.modal-close:hover { background: var(--bg); }

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

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

/* Form */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-sec);
  margin-bottom: 5px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
}

.form-group textarea {
  resize: vertical;
  min-height: 60px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 20px;
  background: #333;
  color: #fff;
  border-radius: var(--radius);
  font-size: 0.85rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 2000;
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Login Overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-overlay.hidden { display: none; }

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  text-align: center;
  animation: modalIn 0.3s ease;
}

.login-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.login-card h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 0.82rem;
  color: var(--text-sec);
  margin-bottom: 20px;
}

.login-error {
  color: var(--danger);
  font-size: 0.82rem;
  margin-bottom: 10px;
  min-height: 20px;
}

.login-card .form-group {
  text-align: left;
}

.login-btn {
  width: 100%;
  padding: 10px;
  font-size: 0.95rem;
  margin-top: 8px;
}

/* Responsive */
@media (max-width: 768px) {
  .admin-header-inner { flex-wrap: wrap; height: auto; padding: 12px 0; }
  .admin-header { height: auto; }
  .header-actions { width: 100%; }
  .panel-toolbar { flex-direction: column; align-items: flex-start; }
  .filter-group { flex-direction: column; width: 100%; }
  .filter-group input { width: 100%; }
  .admin-main { padding: 12px; }
}
