/* ── Admin Panel — Core Styles ───────────────────────────── */

/* ===== CSS VARIABLES ===== */
:root, [data-theme="dark"] {
  --bg: #121212;
  --bg-2: #1a1a1a;
  --bg-3: #222;
  --bg-4: #2a2a2a;
  --border: rgba(255,255,255,0.08);
  --border-2: rgba(255,255,255,0.12);
  --text-1: #e0e0e0;
  --text-2: #a0a0a0;
  --text-3: #6b7280;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --accent-dim: rgba(59,130,246,0.12);
  --success: #10b981;
  --success-dim: rgba(16,185,129,0.12);
  --warn: #f59e0b;
  --warn-dim: rgba(245,158,11,0.12);
  --danger: #ef4444;
  --danger-dim: rgba(239,68,68,0.12);
  --font-body: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --r: 6px;
  --sidebar-width: 240px;
}

/* ===== RESET ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: var(--bg); color: var(--text-1); font-family: var(--font-body); font-size: 13px; overflow: hidden; }

/* ===== TYPOGRAPHY HIERARCHY ===== */
.admin-title { font-size: 24px; font-weight: 600; color: var(--text-1); margin: 0 0 16px; }
.admin-section { font-size: 16px; font-weight: 600; color: var(--text-1); margin: 24px 0 12px; }
.admin-subsection { font-size: 14px; font-weight: 600; color: var(--text-2); margin: 16px 0 8px; }
.admin-label { font-size: 11px; font-weight: 500; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
.admin-value { font-family: var(--font-mono); font-size: 14px; font-weight: 500; color: var(--text-1); }
.admin-kpi-value { font-family: var(--font-mono); font-size: 28px; font-weight: 700; color: var(--text-1); }

/* ===== LAYOUT GRID ===== */
.admin-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: 44px 1fr;
  height: 100vh;
  transition: grid-template-columns 0.2s ease;
}
.admin-layout.collapsed { --sidebar-width: 56px; }

/* ===== SIDEBAR ===== */
.admin-sidebar {
  grid-row: 1 / -1;
  grid-column: 1;
  background: #0f0f1e;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 200;
}
.admin-sidebar::-webkit-scrollbar { width: 4px; }
.admin-sidebar::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 2px; }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  height: 44px; min-height: 44px; padding: 0 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo {
  font-size: 13px; font-weight: 600; color: var(--text-1);
  white-space: nowrap; overflow: hidden;
}
.sidebar-logo span { color: var(--accent); }
.sidebar-toggle {
  background: none; border: none; color: var(--text-3); cursor: pointer;
  font-size: 14px; padding: 4px; border-radius: 4px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
}
.sidebar-toggle:hover { color: var(--text-1); background: rgba(255,255,255,0.05); }
.sidebar-toggle svg { width: 14px; height: 14px; }

.sidebar-nav { flex: 1; padding: 8px 0; }
.sidebar-group { margin-bottom: 4px; }
.sidebar-group-label {
  font-size: 10px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 12px 16px 4px; white-space: nowrap; overflow: hidden;
}
.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  height: 36px; padding: 0 16px;
  font-size: 13px; color: var(--text-2);
  text-decoration: none; cursor: pointer;
  transition: all 0.1s; position: relative;
  white-space: nowrap; overflow: hidden;
}
.sidebar-item:hover { background: rgba(255,255,255,0.05); color: var(--text-1); }
.sidebar-item.active {
  color: var(--accent); background: var(--accent-dim);
  border-left: 3px solid var(--accent); padding-left: 13px;
}
.sidebar-item svg {
  width: 16px; height: 16px; flex-shrink: 0;
  stroke: currentColor; fill: none; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
}
.sidebar-item-label { overflow: hidden; text-overflow: ellipsis; }
.sidebar-badge {
  background: #e74c3c; color: white; border-radius: 8px;
  padding: 1px 6px; font-size: 10px; margin-left: auto; flex-shrink: 0;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 8px 0;
}
.sidebar-footer .sidebar-item { color: var(--text-3); font-size: 12px; }
.sidebar-footer .sidebar-item:hover { color: var(--text-2); }
.sidebar-user {
  padding: 8px 16px; font-size: 11px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Collapsed state */
.admin-layout.collapsed .sidebar-logo,
.admin-layout.collapsed .sidebar-group-label,
.admin-layout.collapsed .sidebar-item-label,
.admin-layout.collapsed .sidebar-badge,
.admin-layout.collapsed .sidebar-user { display: none; }
.admin-layout.collapsed .sidebar-header { justify-content: center; padding: 0; }
.admin-layout.collapsed .sidebar-item { justify-content: center; padding: 0 20px; gap: 0; }
.admin-layout.collapsed .sidebar-item.active { padding-left: 17px; }
.admin-layout.collapsed .sidebar-group-label { height: 8px; padding: 4px 0; }

/* Tooltip for collapsed state */
.admin-layout.collapsed .sidebar-item[data-title]:hover::after {
  content: attr(data-title);
  position: absolute; left: 56px; top: 50%; transform: translateY(-50%);
  background: var(--bg-4); color: var(--text-1); border: 1px solid var(--border-2);
  padding: 4px 10px; border-radius: 4px; font-size: 12px;
  white-space: nowrap; z-index: 1000; pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

/* ===== TOPBAR ===== */
.admin-topbar {
  grid-row: 1; grid-column: 2;
  display: flex; align-items: center; justify-content: space-between;
  height: 44px; padding: 0 24px;
  background: var(--bg-2); border-bottom: 1px solid var(--border);
}
.admin-topbar-left { display: flex; align-items: center; gap: 12px; }
.admin-topbar-left a { color: var(--text-2); text-decoration: none; font-size: 12px; }
.admin-topbar-left a:hover { color: var(--text-1); }
.admin-topbar h1 { font-size: 14px; font-weight: 600; }
.admin-topbar-right { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text-2); }
.admin-topbar-right a { color: var(--text-2); text-decoration: none; }
.admin-topbar-right a:hover { color: var(--text-1); }
.admin-hamburger {
  display: none; background: none; border: none; color: var(--text-2);
  cursor: pointer; padding: 4px;
}
.admin-hamburger svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.5; }

/* ===== CONTENT AREA ===== */
.admin-main {
  grid-row: 2; grid-column: 2;
  overflow-y: auto;
  background: var(--bg);
}

/* Main content */
.admin-content { max-width: 1200px; margin: 0 auto; padding: 24px; }

/* ===== KPI CARDS ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.kpi-card {
  background: var(--bg-3); border: 1px solid var(--border); border-radius: var(--r);
  padding: 16px; display: flex; flex-direction: column; gap: 4px;
  position: relative; overflow: hidden;
}
.kpi-value { font-size: 28px; font-weight: 700; font-family: var(--font-mono); color: var(--text-1); }
.kpi-label { font-size: 11px; font-weight: 500; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-row { display: flex; align-items: baseline; gap: 8px; }
.kpi-trend { font-size: 11px; }
.kpi-trend.up { color: var(--success); background: var(--success-dim); font-size: 12px; font-weight: 600; border-radius: 4px; padding: 1px 6px; }
.kpi-trend.down { color: var(--danger); background: var(--danger-dim); font-size: 12px; font-weight: 600; border-radius: 4px; padding: 1px 6px; }
.kpi-trend.flat { color: var(--text-3); background: var(--bg-3); font-size: 12px; font-weight: 600; border-radius: 4px; padding: 1px 6px; }
.kpi-meta { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.kpi-sparkline { width: 100%; height: 32px; margin-top: 8px; }
.kpi-card.pending .kpi-value { color: var(--warn); }
.kpi-card.shipped .kpi-value { color: var(--success); }
.kpi-card.voted .kpi-value { color: var(--accent); font-size: 14px; font-family: var(--font-body); }
.kpi-card.feedback .kpi-value { color: var(--success); }

/* ===== TABS ===== */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  padding: 10px 16px; font-size: 12px; font-weight: 500;
  color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.tab:hover { color: var(--text-1); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-count { font-family: var(--font-mono); font-size: 11px; margin-left: 4px; opacity: 0.6; }

/* ===== TOOLBAR ===== */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.toolbar-search {
  flex: 1; max-width: 300px; padding: 7px 12px; font-size: 12px;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: var(--r);
  color: var(--text-1); outline: none;
}
.toolbar-search:focus { border-color: var(--accent); }
.toolbar-search::placeholder { color: var(--text-3); }
.toolbar-filter {
  padding: 6px 10px; font-size: 11px;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: var(--r);
  color: var(--text-2); cursor: pointer;
}
.toolbar-filter:hover { border-color: var(--accent); color: var(--text-1); }

/* ===== TABLE ===== */
.admin-table, .backlog-table { width: 100%; border-collapse: collapse; }
.admin-table th, .backlog-table th {
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-3); padding: 10px 12px;
  border-bottom: 1px solid var(--border-2);
  position: sticky; top: 0; background: var(--bg-2); z-index: 1;
}
.admin-table tbody tr, .backlog-table tbody tr {
  height: 44px; cursor: pointer; transition: background 0.15s;
}
.admin-table tbody tr:hover, .backlog-table tbody tr:hover { background: rgba(255,255,255,0.04); }
.admin-table tbody tr.selected, .backlog-table tr.selected { background: var(--accent-dim); }
.admin-table td, .backlog-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: top;
}
.backlog-table .col-check { width: 32px; }
.backlog-table .col-status { width: 90px; }
.backlog-table .col-category { width: 120px; }
.backlog-table .col-priority { width: 70px; }
.backlog-table .col-votes { width: 60px; text-align: center; }
.backlog-table .col-actions { width: 140px; }
.td-title { font-weight: 500; color: var(--text-1); margin-bottom: 2px; }
.td-desc { color: var(--text-2); font-size: 11px; line-height: 1.4; }

/* Inline action reveal on hover */
.table-row-actions { opacity: 0; transition: opacity 0.15s; display: flex; gap: 4px; }
tbody tr:hover .table-row-actions { opacity: 1; }

/* Status badges (unified) */
.status-badge { font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 10px; display: inline-block; }
.status-badge.pending { color: var(--warn); background: var(--warn-dim); }
.status-badge.shipped { color: var(--success); background: var(--success-dim); }
.status-badge.failed { color: var(--danger); background: var(--danger-dim); }
.status-badge.in_progress { color: var(--accent); background: var(--accent-dim); }

/* Monospace for numeric columns */
.admin-table .col-num, .backlog-table .col-num {
  font-family: var(--font-mono); font-size: 13px; text-align: right;
}

/* ===== BADGES ===== */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
}
.badge-pending { background: var(--warn-dim); color: var(--warn); }
.badge-in_progress { background: var(--accent-dim); color: var(--accent); }
.badge-shipped { background: var(--success-dim); color: var(--success); }
.badge-rejected { background: var(--danger-dim); color: var(--danger); }
.badge-generated { background: rgba(168,85,247,0.12); color: #c084fc; }
.badge-promoted { background: var(--success-dim); color: var(--success); }

.badge-quality { background: rgba(37,99,235,0.12); color: #60a5fa; }
.badge-missing_feature { background: var(--warn-dim); color: #fbbf24; }
.badge-new_type { background: var(--success-dim); color: #34d399; }
.badge-feature_request { background: rgba(236,72,153,0.12); color: #f472b6; }
.badge-prompt_improvement { background: rgba(168,85,247,0.12); color: #c084fc; }
.badge-ux_issue { background: var(--warn-dim); color: #fbbf24; }
.badge-bot_failure { background: var(--danger-dim); color: #f87171; }
.badge-user_pattern { background: var(--accent-dim); color: var(--accent); }
.badge-modify_existing { background: var(--accent-dim); color: var(--accent); }

/* ===== PRIORITY ===== */
.priority { font-family: var(--font-mono); font-size: 11px; }
.priority-high { color: var(--danger); }
.priority-med { color: var(--warn); }
.priority-low { color: var(--text-3); }

/* ===== ACTION BUTTONS ===== */
.btn-action {
  padding: 4px 10px; border-radius: 4px; font-size: 11px; cursor: pointer;
  border: 1px solid; transition: all 0.15s; background: transparent;
}
.btn-ship { border-color: var(--success); color: var(--success); }
.btn-ship:hover { background: var(--success-dim); }
.btn-reject { border-color: var(--danger); color: var(--danger); }
.btn-reject:hover { background: var(--danger-dim); }
.btn-progress { border-color: var(--accent); color: var(--accent); }
.btn-progress:hover { background: var(--accent-dim); }

/* ===== BULK ACTIONS BAR ===== */
.bulk-bar {
  display: none; align-items: center; gap: 12px;
  padding: 8px 16px; margin-bottom: 12px;
  background: var(--accent-dim); border: 1px solid var(--accent); border-radius: var(--r);
  font-size: 12px;
}
.bulk-bar.visible { display: flex; }
.bulk-count { font-weight: 600; color: var(--accent); font-family: var(--font-mono); }

/* ===== DETAIL PANEL ===== */
.detail-panel {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: min(420px, 90vw);
  background: var(--bg-2);
  border-left: 1px solid var(--border-2);
  box-shadow: -4px 0 24px rgba(0,0,0,0.3);
  border-radius: 8px 0 0 8px;
  z-index: 200;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.detail-panel.open { transform: translateX(0); }
.detail-panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.detail-panel-header h3 { font-size: 16px; font-weight: 600; color: var(--text-1); margin: 0; }
.detail-panel-close {
  background: none; border: none; color: var(--text-3); cursor: pointer;
  padding: 4px; border-radius: 4px;
}
.detail-panel-close:hover { background: var(--bg-3); color: var(--text-1); }
.detail-panel-body { flex: 1; overflow-y: auto; padding: 20px; }
.detail-panel-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 199; }
/* Legacy detail-panel inner styles (backward compat) */
.detail-close { cursor: pointer; color: var(--text-3); font-size: 18px; float: right; padding: 4px; border-radius: 4px; }
.detail-close:hover { color: var(--text-1); background: var(--bg-3); }
.detail-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; padding-right: 24px; }
.detail-section { margin-bottom: 16px; }
.detail-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; margin-bottom: 4px; letter-spacing: 0.5px; }
.detail-value { font-size: 13px; line-height: 1.5; }
.detail-evidence { font-style: italic; color: var(--text-2); font-size: 12px; padding: 8px 12px; background: var(--bg-3); border-radius: var(--r); }
.detail-actions { display: flex; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ===== EMPTY STATE ===== */
.empty-state, .admin-empty { text-align: center; padding: 48px 24px; color: var(--text-3); font-size: 14px; }
.empty-state-icon, .admin-empty-icon { font-size: 32px; margin-bottom: 12px; opacity: 0.4; }
.empty-state-text { font-size: 14px; }
.admin-empty-title { font-size: 16px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.admin-empty-hint { font-size: 13px; color: var(--text-3); }

/* ===== TOAST ===== */
.toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 500; }
.toast {
  background: var(--bg-3); border: 1px solid var(--border-2); border-radius: var(--r);
  padding: 10px 14px; font-size: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  animation: toastIn 0.2s ease;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ===== TOOLTIPS ===== */
[data-tooltip] {
  position: relative;
  cursor: help;
}
[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-4);
  color: var(--text-1);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 12px;
  white-space: normal;
  max-width: 300px;
  z-index: 1000;
  pointer-events: none;
  line-height: 1.4;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

/* ===== MODAL ===== */
.admin-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 300; display: flex; align-items: center; justify-content: center;
}
.admin-modal {
  background: var(--bg-2); border: 1px solid var(--border-2); border-radius: 8px;
  max-width: 480px; width: 90vw; box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.admin-modal-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.admin-modal-body { padding: 20px; }
.admin-modal-footer {
  padding: 12px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ===== MOBILE OVERLAY ===== */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 150;
}
.sidebar-overlay.visible { display: block; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .admin-layout { --sidebar-width: 56px; }
  .admin-layout .sidebar-logo,
  .admin-layout .sidebar-group-label,
  .admin-layout .sidebar-item-label,
  .admin-layout .sidebar-badge,
  .admin-layout .sidebar-user { display: none; }
  .admin-layout .sidebar-header { justify-content: center; padding: 0; }
  .admin-layout .sidebar-item { justify-content: center; padding: 0 20px; gap: 0; }
  .admin-layout .sidebar-item.active { padding-left: 17px; }
  .admin-layout .sidebar-item[data-title]:hover::after {
    content: attr(data-title);
    position: absolute; left: 56px; top: 50%; transform: translateY(-50%);
    background: var(--bg-4); color: var(--text-1); border: 1px solid var(--border-2);
    padding: 4px 10px; border-radius: 4px; font-size: 12px;
    white-space: nowrap; z-index: 1000; pointer-events: none;
  }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-panel { width: 100%; }
}
@media (max-width: 600px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar {
    position: fixed; left: -240px; top: 0; bottom: 0; width: 240px;
    transition: left 0.2s ease; z-index: 200;
  }
  .admin-sidebar.mobile-open { left: 0; }
  .admin-hamburger { display: block; }
  .admin-topbar { grid-column: 1; }
  .admin-main { grid-column: 1; }
}
