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

:root {
  --bg: #fafafa;
  --bg-panel: #ffffff;
  --bg-sidebar: #f5f5f5;
  --bg-hover: #f0f0f0;
  --bg-active: #e8e8e8;
  --text: #1a1a1a;
  --text-secondary: #666;
  --text-muted: #999;
  --text-sidebar: #666;
  --text-sidebar-active: #1a1a1a;
  --border: #e5e5e5;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 6px;
  --font: -apple-system, "Segoe UI", "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --transition: 150ms ease;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  text-decoration: underline;
}

/* ===== Login Screen ===== */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 48px 32px;
}

.login-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 4px;
  margin-bottom: 32px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-field input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition);
  background: var(--bg-panel);
}

.form-field input:focus {
  border-color: var(--accent);
}

.login-error {
  font-size: 13px;
  color: var(--danger);
  min-height: 18px;
}

.login-back {
  display: block;
  text-align: center;
  margin-top: 24px;
  font-size: 13px;
  color: var(--text-muted);
}

.login-back:hover {
  color: var(--text-secondary);
  text-decoration: none;
}

/* ===== Buttons ===== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  background: var(--text);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity var(--transition);
  white-space: nowrap;
}

.btn-primary:hover { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-full { width: 100%; padding: 12px; }

.btn-danger {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  background: none;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
}

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

.btn-text-only {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: color var(--transition);
}

.btn-text-only:hover { color: var(--text); }

/* ===== Admin Shell ===== */
.admin-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

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

.topbar-title {
  font-size: 15px;
  font-weight: 600;
}

.topbar-sep {
  color: var(--text-muted);
}

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

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.topbar-user {
  color: var(--text);
  font-weight: 500;
}

.topbar-role {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.topbar-link {
  color: var(--text-muted);
  font-size: 13px;
}

.topbar-link:hover {
  color: var(--text);
  text-decoration: none;
}

/* Body layout */
.admin-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 200px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: none;
  border: none;
  color: var(--text-sidebar);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}

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

.nav-item.active {
  color: var(--text-sidebar-active);
  background: var(--bg-active);
  border-left-color: var(--accent);
  font-weight: 500;
}

.nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

/* Panel area */
.panel-area {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.panel-header h2 {
  font-size: 18px;
  font-weight: 600;
}

/* ===== Stats Row ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

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

/* ===== Section Blocks ===== */
.section-block {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.section-block h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

.section-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
}

/* ===== Tables ===== */
.table-wrap {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.data-table td {
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: var(--bg-hover);
}

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

/* Status badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}

.badge-active {
  background: #dcfce7;
  color: var(--success);
}

.badge-inactive {
  background: #fee2e2;
  color: var(--danger);
}

.action-cell {
  display: flex;
  gap: 6px;
  align-items: center;
}

.btn-toggle {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: none;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-toggle:hover {
  border-color: var(--text);
  color: var(--text);
}

.btn-send {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: none;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
}

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

/* ===== Forms ===== */
.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.inline-form input,
.inline-form select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  background: var(--bg);
  transition: border-color var(--transition);
}

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

.form-feedback {
  font-size: 13px;
  min-height: 18px;
  margin-top: 4px;
}

/* ===== Autocomplete ===== */
.autocomplete-wrap {
  position: relative;
  flex: 1;
  min-width: 240px;
}

.autocomplete-wrap input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  background: var(--bg);
  transition: border-color var(--transition);
}

.autocomplete-wrap input:focus {
  border-color: var(--accent);
}

.autocomplete-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  z-index: 100;
}

.autocomplete-item {
  padding: 9px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition);
}

.autocomplete-item:hover {
  background: var(--bg-hover);
}

.autocomplete-item strong {
  color: var(--accent);
  font-weight: 600;
}

.autocomplete-empty {
  padding: 12px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.search-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  width: 220px;
  background: var(--bg);
  transition: border-color var(--transition);
}

.search-input:focus {
  border-color: var(--accent);
}

/* ===== KV Rows ===== */
.kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.kv-row:last-child {
  border-bottom: none;
}

.kv-label {
  color: var(--text-secondary);
}

.kv-value {
  font-weight: 500;
}

/* ===== Generation Log ===== */
.gen-log {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.gen-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.gen-log-status {
  font-weight: 500;
}

.gen-log-body {
  padding: 12px 16px;
  background: #1e1e2e;
  font-family: "JetBrains Mono", "Cascadia Code", "Consolas", monospace;
  font-size: 12px;
  line-height: 1.8;
  color: #cdd6f4;
}

.gen-log-line {
  white-space: pre-wrap;
  word-break: break-all;
}

.gen-log-line .time {
  color: #6c7086;
  margin-right: 8px;
}

/* ===== Keywords ===== */
.keyword-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.keyword-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 12px;
  color: var(--text-secondary);
}

.keyword-tag .category {
  font-size: 10px;
  color: var(--text-muted);
}

.keyword-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  line-height: 1;
  transition: color var(--transition);
}

.keyword-remove:hover {
  color: var(--danger);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .sidebar {
    width: 60px;
  }

  .nav-label {
    display: none;
  }

  .nav-item {
    justify-content: center;
    padding: 10px;
    border-left: none;
    border-bottom: 3px solid transparent;
  }

  .nav-item.active {
    border-left: none;
    border-bottom-color: var(--accent);
  }

  .panel-area {
    padding: 20px;
  }

  .inline-form {
    flex-wrap: wrap;
  }

  .topbar-label,
  .topbar-sep {
    display: none;
  }
}

/* ===== Toast Notification ===== */
.admin-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  min-width: 260px;
  max-width: 400px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  color: #fff;
  background: var(--text);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  z-index: 9999;
  opacity: 0;
  transform: translateY(12px);
  transition: all 300ms ease;
  pointer-events: none;
}

.admin-toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

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

/* ===== Confirm Bar ===== */
.confirm-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  margin: 8px 0;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  font-size: 13px;
  color: #92400e;
}

.confirm-bar .confirm-text {
  flex: 1;
}

.confirm-bar .confirm-yes {
  padding: 4px 14px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
}

.confirm-bar .confirm-no {
  padding: 4px 14px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  color: var(--text-secondary);
}
