/* ===== Admin Panel Styles ===== */
:root {
  --admin-primary: #0f1f3d;
  --admin-accent: #1e40af;
  --admin-border: #e2e8f0;
  --admin-bg: #f8fafc;
  --admin-text: #1e293b;
  --admin-muted: #64748b;
}

* { box-sizing: border-box; }

body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif; }

/* Sidebar */
.admin-sidebar {
  width: 220px;
  background: white;
  border-right: 1px solid var(--admin-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
}

.sidebar-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--admin-border);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--admin-muted);
  text-decoration: none;
  margin-bottom: 4px;
  transition: all 0.15s ease;
  font-weight: 500;
}

.nav-item:hover {
  background: #f1f5f9;
  color: var(--admin-text);
}

.nav-item.active {
  background: var(--admin-primary);
  color: white;
}

.nav-item.active svg {
  color: #c9a84c;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--admin-border);
}

.back-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--admin-muted);
  text-decoration: none;
  transition: color 0.15s;
}

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

/* Main */
.admin-main {
  margin-left: 220px;
  min-height: 100vh;
}

.admin-topbar {
  height: 60px;
  background: white;
  border-bottom: 1px solid var(--admin-border);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}

.admin-page {
  padding: 24px 28px;
}

/* Cards */
.admin-card {
  background: white;
  border: 1px solid var(--admin-border);
  border-radius: 12px;
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--admin-border);
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--admin-text);
  margin: 0;
}

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.stat-card {
  background: white;
  border: 1px solid var(--admin-border);
  border-radius: 12px;
  padding: 20px 24px;
}

.stat-label {
  font-size: 13px;
  color: var(--admin-muted);
  font-weight: 500;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--admin-text);
  line-height: 1.2;
}

.stat-sub {
  font-size: 12px;
  color: var(--admin-muted);
  margin-top: 6px;
}

/* Chart */
.chart-container {
  padding: 20px;
  position: relative;
  height: 220px;
}

.chart-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--admin-muted);
  font-size: 13px;
}

/* Table */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--admin-muted);
  border-bottom: 1px solid var(--admin-border);
  white-space: nowrap;
  background: #f8fafc;
}

.admin-table td {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--admin-text);
}

.admin-table tr:hover td {
  background: #f8fafc;
}

.table-empty {
  text-align: center;
  color: var(--admin-muted);
  padding: 40px 16px !important;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-amber { background: #fef3c7; color: #92400e; }

/* Inputs */
.admin-input {
  padding: 8px 12px;
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  transition: border 0.15s;
  background: white;
  color: var(--admin-text);
}

.admin-input:focus {
  border-color: var(--admin-accent);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

.admin-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  resize: vertical;
  font-family: inherit;
}

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

/* Buttons */
.btn-sm {
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  background: #f1f5f9;
  color: var(--admin-text);
  border: 1px solid var(--admin-border);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-sm:hover { background: #e2e8f0; }

.btn-primary {
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  background: var(--admin-primary);
  color: white;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary:hover { background: #1a3a6e; }

.btn-danger {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  background: #fee2e2;
  color: #991b1b;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
}

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

.btn-action {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  background: #f1f5f9;
  color: var(--admin-text);
  border: 1px solid var(--admin-border);
  cursor: pointer;
  transition: all 0.15s;
  margin-right: 4px;
}

.btn-action:hover { background: #e2e8f0; }

/* Pagination */
.pagination {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
}

.page-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--admin-border);
  background: white;
  cursor: pointer;
  font-size: 13px;
  color: var(--admin-text);
  transition: all 0.15s;
}

.page-btn:hover { background: #f1f5f9; }
.page-btn.active { background: var(--admin-primary); color: white; border-color: var(--admin-primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Activity list */
.activity-list {
  padding: 8px 0;
  max-height: 400px;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid #f1f5f9;
}

.activity-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.activity-info {
  flex: 1;
  min-width: 0;
}

.activity-title {
  font-size: 13px;
  color: var(--admin-text);
  font-weight: 500;
}

.activity-time {
  font-size: 12px;
  color: var(--admin-muted);
}

/* Conversation list */
.conv-list {
  max-height: 500px;
  overflow-y: auto;
}

.conv-item {
  padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background 0.15s;
}

.conv-item:hover { background: #f8fafc; }
.conv-item.active { background: #eff6ff; border-left: 3px solid var(--admin-accent); }

.conv-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--admin-text);
  margin-bottom: 4px;
}

.conv-item-meta {
  font-size: 12px;
  color: var(--admin-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Conversation detail */
.conv-detail {
  padding: 20px;
}

.conv-detail-empty {
  text-align: center;
  color: var(--admin-muted);
  padding: 60px 20px;
}

.detail-row {
  display: flex;
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
}

.detail-label {
  width: 100px;
  font-size: 13px;
  color: var(--admin-muted);
  font-weight: 500;
  flex-shrink: 0;
}

.detail-value {
  font-size: 13px;
  color: var(--admin-text);
  flex: 1;
}

.msg-preview {
  background: #f8fafc;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--admin-text);
}

.msg-preview .msg-role {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.msg-role.ai { color: #1e40af; }
.msg-role.user { color: #059669; }

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

.modal-content {
  background: white;
  border-radius: 12px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.modal-close {
  font-size: 24px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--admin-muted);
  padding: 0;
  line-height: 1;
}

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

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

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--admin-text);
  margin-bottom: 6px;
}

/* Settings */
.settings-grid {
  padding: 20px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid #f1f5f9;
}

.setting-label {
  font-size: 14px;
  color: var(--admin-text);
  font-weight: 500;
}

.setting-value {
  font-size: 14px;
  color: var(--admin-muted);
  font-weight: 600;
}

/* Settings sections */
.settings-section {
  background: #fff;
  border-radius: 12px;
  padding: 20px 24px;
  border: 1px solid #f1f5f9;
}

.settings-section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--admin-text);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid #f1f5f9;
}

/* Form elements */
.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--admin-text);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 14px;
  color: var(--admin-text);
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.form-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Status badge */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.status-active {
  background: #dcfce7;
  color: #059669;
}

.status-inactive {
  background: #fef3c7;
  color: #d97706;
}

/* Responsive */
@media (max-width: 768px) {
  .admin-sidebar {
    width: 60px;
  }
  .sidebar-header { padding: 18px 8px; }
  .sidebar-header > div > div:last-child { display: none; }
  .nav-item span { display: none; }
  .back-link span { display: none; }
  .admin-main { margin-left: 60px; }
  .admin-page { padding: 16px; }
}
