/* Admin Portal Styles — Grayscale theme */
:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1e1e1e;
  --border: #2a2a2a;
  --text: #e0e0e0;
  --text-dim: #888;
  --accent: #fff;
  --danger: #e74c3c;
  --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* Fix for hidden attribute */
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Login Page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3rem 2.5rem;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-card h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.login-card .subtitle { color: var(--text-dim); margin-bottom: 2rem; font-size: 0.9rem; }

.field { text-align: left; margin-bottom: 1rem; }
.field label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.3rem; }
.field input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
.field input:focus { border-color: var(--text-dim); }

.error {
  background: rgba(231, 76, 60, 0.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 0.6rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

button {
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  margin-top: 0.5rem;
}
button:hover { opacity: 0.9; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Main Portal Layout */
.portal {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 0 1.5rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.sidebar-header h2 { font-size: 1.1rem; }
.sidebar-header .tag { font-size: 0.75rem; color: var(--text-dim); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1.5rem;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 0.9rem;
  color: var(--text-dim);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover, .nav-item.active { background: var(--surface2); color: var(--text); }
.nav-item .icon { font-size: 1.1rem; }
.nav-item .count { margin-left: auto; font-size: 0.75rem; background: var(--surface2); padding: 0.1rem 0.5rem; border-radius: 10px; }

.sidebar-footer {
  margin-top: auto;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

.logout-btn {
  background: none;
  color: var(--text-dim);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  padding: 0.5rem;
}
.logout-btn:hover { color: var(--danger); border-color: var(--danger); }

/* Main Content */
.main {
  flex: 1;
  padding: 2rem 3rem;
  overflow-y: auto;
}

.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 1.5rem;
}
.breadcrumb a { color: var(--text-dim); text-decoration: none; }
.breadcrumb a:hover { color: var(--text); }

.search-bar {
  margin-bottom: 2rem;
}
.search-bar input {
  width: 100%;
  max-width: 500px;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
.search-bar input:focus { border-color: var(--text-dim); }

.section-title {
  font-size: 1.2rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.doc-list { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 2rem; }

.doc-card {
  display: flex;
  align-items: center;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s;
}
.doc-card:hover { border-color: var(--text-dim); }

.doc-info { flex: 1; }
.doc-title { font-weight: 600; font-size: 0.95rem; }
.doc-desc { font-size: 0.8rem; color: var(--text-dim); margin-top: 0.2rem; }
.doc-meta { font-size: 0.75rem; color: var(--text-dim); display: flex; gap: 1rem; margin-top: 0.3rem; }

/* Document viewer */
.doc-viewer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  line-height: 1.8;
}
.doc-viewer h1, .doc-viewer h2, .doc-viewer h3 { margin: 1.5rem 0 0.75rem; }
.doc-viewer h1 { font-size: 1.6rem; }
.doc-viewer h2 { font-size: 1.3rem; }
.doc-viewer h3 { font-size: 1.1rem; }
.doc-viewer p { margin-bottom: 1rem; }
.doc-viewer code { background: var(--bg); padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.85em; }
.doc-viewer pre { background: var(--bg); padding: 1rem; border-radius: var(--radius); overflow-x: auto; margin: 1rem 0; }
.doc-viewer pre code { padding: 0; background: none; }
.doc-viewer ul, .doc-viewer ol { margin: 0.5rem 0 1rem 1.5rem; }
.doc-viewer a { color: var(--accent); }
.doc-viewer blockquote { border-left: 3px solid var(--border); padding-left: 1rem; color: var(--text-dim); margin: 1rem 0; }
.doc-viewer table { border-collapse: collapse; width: 100%; margin: 1rem 0; }
.doc-viewer th, .doc-viewer td { border: 1px solid var(--border); padding: 0.5rem 0.75rem; text-align: left; }
.doc-viewer th { background: var(--surface2); }

.back-btn {
  background: none;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
  width: auto;
}
.back-btn:hover { color: var(--text); border-color: var(--text-dim); }

/* Mobile */
@media (max-width: 768px) {
  .portal { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .main { padding: 1.5rem; }
  .sidebar { padding: 1rem 0; }
  .nav-item { padding: 0.5rem 1rem; }
}

/* ── Error Queue ──────────────────────────────────────────────────── */

.error-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  align-items: center;
}

.error-controls select,
.error-controls input {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.error-controls input {
  flex: 1;
  min-width: 150px;
}

.btn-small {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-small:hover { background: var(--surface); border-color: var(--text-dim); }

.error-stats {
  display: flex;
  gap: 1.2rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.error-stats b { color: var(--text); }
.text-critical { color: #ef5350 !important; }
.text-high { color: #ffa726 !important; }

.error-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.error-table th {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-weight: 500;
}
.error-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--surface2);
}
.error-row:hover { background: var(--surface2); }
.error-row.critical { border-left: 3px solid #ef5350; }
.error-row.high { border-left: 3px solid #ffa726; }
.error-row.medium { border-left: 3px solid #42a5f5; }
.error-row.low { border-left: 3px solid var(--border); }

.error-message {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: monospace;
  font-size: 0.8rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge.critical { background: #d32f2f; color: white; }
.badge.high { background: #f57c00; color: white; }
.badge.medium { background: #1976d2; color: white; }
.badge.low { background: #616161; color: white; }
.badge.new { background: #1565c0; color: white; }
.badge.analyzing { background: #7b1fa2; color: white; }
.badge.fixed { background: #2e7d32; color: white; }
.badge.ignored { background: #455a64; color: white; }

.actions button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.2rem;
  font-size: 0.9rem;
  opacity: 0.7;
}
.actions button:hover { opacity: 1; }

/* Error Detail Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.8rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); }

.error-detail h2 { margin: 0 0 1rem; }
.error-detail h3 { margin: 1rem 0 0.5rem; color: var(--text-dim); font-size: 0.9rem; }
.error-detail h4 { margin: 0.8rem 0 0.3rem; color: var(--text-dim); font-size: 0.85rem; }
.detail-row { margin: 0.3rem 0; font-size: 0.85rem; }
.detail-row code {
  background: var(--surface2);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.8rem;
}
.error-detail pre {
  background: var(--surface2);
  padding: 0.8rem;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-all;
}
.stack-trace {
  max-height: 200px;
  overflow-y: auto;
  color: #ef9a9a;
}

/* ── Metrics Dashboard ─────────────────────────────────────────── */

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.metric-card .metric-icon { font-size: 1.4rem; }
.metric-card .metric-label { font-size: 0.8rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.metric-card .metric-value { font-size: 1.8rem; font-weight: 700; line-height: 1.2; }
.metric-card .metric-sub { font-size: 0.75rem; color: var(--text-dim); }
.metric-card .metric-sub .up { color: #4caf50; }
.metric-card .metric-sub .down { color: #ef5350; }

.metrics-charts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}

.chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
}

.chart-section h3 {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-bottom: 1rem;
  font-weight: 500;
}

/* Horizontal bar chart */
.h-bar-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
  font-size: 0.8rem;
}

.h-bar-label { width: 70px; text-align: right; color: var(--text-dim); flex-shrink: 0; }
.h-bar-track { flex: 1; height: 22px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.h-bar-fill { height: 100%; border-radius: 3px; transition: width 0.4s ease; min-width: 2px; }
.h-bar-value { width: 40px; text-align: right; font-weight: 600; flex-shrink: 0; }

.h-bar-fill.critical { background: #ef5350; }
.h-bar-fill.high { background: #ffa726; }
.h-bar-fill.medium { background: #42a5f5; }
.h-bar-fill.low { background: #616161; }
.h-bar-fill.default { background: #78909c; }

/* Vertical bar chart */
.v-bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  height: 120px;
  padding-top: 0.5rem;
}

.v-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.v-bar-fill {
  width: 100%;
  max-width: 40px;
  background: #42a5f5;
  border-radius: 3px 3px 0 0;
  transition: height 0.4s ease;
  min-height: 2px;
}

.v-bar-value {
  font-size: 0.7rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.v-bar-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 0.3rem;
}

@media (max-width: 768px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .metrics-charts { grid-template-columns: 1fr; }
}

/* ── Users / Spy Mode ──────────────────────────────────────────── */

.user-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.stat-card .label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-card .value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.user-header-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
}

.user-header-card h2 { margin: 0 0 0.25rem; font-size: 1.3rem; }
.user-header-card .meta { font-size: 0.8rem; color: var(--text-dim); }

.user-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.user-actions .btn-small { font-size: 0.8rem; }

.user-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1.5fr 80px;
  align-items: center;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.35rem;
  cursor: pointer;
  transition: border-color 0.15s;
  font-size: 0.85rem;
}
.user-row:hover { border-color: var(--text-dim); }
.user-row-header {
  font-weight: 600;
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: default;
  background: transparent;
  border-color: transparent;
}
.user-row-header:hover { border-color: transparent; }

.prompt-preview {
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.chart-bar-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1rem 0;
}

.chart-bar-container h4 {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.chart-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
}

.chart-bar .bar-label {
  width: 100px;
  text-align: right;
  color: var(--text-dim);
  flex-shrink: 0;
}

.chart-bar .bar-fill {
  height: 20px;
  background: var(--accent);
  border-radius: 3px;
  min-width: 2px;
  transition: width 0.3s;
}

.chart-bar .bar-value {
  color: var(--text-dim);
  font-size: 0.75rem;
  flex-shrink: 0;
}

/* Support messages */
.support-msg.resolved {
  opacity: 0.6;
}
.support-msg.resolved:hover {
  opacity: 1;
}

/* Fix support message layout */
.support-msg {
  clear: both;
  overflow: visible;
}

.support-msg .btn-small {
  position: relative;
  z-index: 10;
  pointer-events: auto;
}

/* Status Cards */
.status-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  transition: all 0.2s;
}

.status-card.operational {
  border-color: #27ae60;
}

.status-card.degraded {
  border-color: #f39c12;
}

.status-card.down {
  border-color: var(--danger);
}

.status-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.status-label {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
}

.status-value {
  font-size: 0.95rem;
  font-weight: 600;
}

.status-value.operational {
  color: #27ae60;
}

.status-value.degraded {
  color: #f39c12;
}

.status-value.down {
  color: var(--danger);
}
