/* Pehredaar dashboard — minimal stylesheet
   System fonts, light + dark via prefers-color-scheme, monospace tracebacks.
   No external dependencies. */

/* ── Custom properties ───────────────────────────────────────────────────── */
:root {
  --bg: #f8f9fa;
  --bg-card: #ffffff;
  --fg: #212529;
  --fg-muted: #6c757d;
  --border: #dee2e6;
  --accent: #0d6efd;
  --accent-hover: #0a58ca;
  --success: #198754;
  --warning: #ffc107;
  --danger: #dc3545;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --bg-elevated: #eef0f3;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-card: #161b22;
    --fg: #c9d1d9;
    --fg-muted: #8b949e;
    --border: #30363d;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --success: #3fb950;
    --warning: #d29922;
    --danger: #f85149;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --bg-elevated: #1c2128;
  }
}

/* ── Reset + base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

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

/* ── Layout — sidebar grid ───────────────────────────────────────────────── */
body {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
  margin: 0;
}

aside#sidebar {
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

aside#sidebar h1 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--fg);
  letter-spacing: -0.02em;
  padding: 0 0.25rem;
  margin-bottom: 0.25rem;
}

aside#sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

nav a {
  display: block;
  font-size: 13px;
  color: var(--fg-muted);
  padding: 8px 10px;
  border-radius: var(--radius);
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
}
nav a:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--fg);
  text-decoration: none;
}
nav a.active {
  background: rgba(13, 110, 253, 0.1);
  color: var(--accent);
  font-weight: 600;
}
@media (prefers-color-scheme: dark) {
  nav a:hover { background: rgba(255, 255, 255, 0.06); }
  nav a.active { background: rgba(88, 166, 255, 0.12); }
}

main.content {
  padding: 1.5rem;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}
/* Flex children default to min-width:auto — that's content-min-width,
   which lets a child with unbreakable text (long URL in <h2>, wide JSON
   in <pre>) force its parent wider than the flex container. Clamp every
   direct child so internal overflow-x scrolling actually works. */
main.content > * { min-width: 0; max-width: 100%; }
/* Long URLs / fingerprints / unbreakable strings in headings must wrap
   instead of pushing the section width. */
main.content h1, main.content h2, main.content h3,
main.content h4, main.content p { overflow-wrap: anywhere; word-break: break-word; }

/* Legacy <main> (no .content class) — kept for any pages not yet migrated */
main {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ── Cards / sections ────────────────────────────────────────────────────── */
section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
}

section h2 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
  margin-bottom: 0.75rem;
}

/* ── Table overflow wrapper ──────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  max-width: 100%;
}

/* ── Tables ──────────────────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--fg-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

/* Issue-title columns: long traceback/exception messages otherwise stretch
   the table past the viewport. Truncate with ellipsis; full text on hover
   via the title attribute on the link. */
#recent-issues { table-layout: fixed; }
#recent-issues th:nth-child(1), #recent-issues td:nth-child(1) { width: 8em; }
#recent-issues th:nth-child(2), #recent-issues td:nth-child(2) { width: 9em; }
#recent-issues th:nth-child(3), #recent-issues td:nth-child(3) {
  max-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#recent-issues th:nth-child(4), #recent-issues td:nth-child(4) { width: 8em; }
#recent-issues th:nth-child(5), #recent-issues td:nth-child(5) { width: 5em; text-align: right; }
#recent-issues td:nth-child(3) a { display: inline; }

#issues-table { table-layout: fixed; }
#issues-table th:nth-child(1), #issues-table td:nth-child(1) { width: 7em; }
#issues-table th:nth-child(2), #issues-table td:nth-child(2) {
  max-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#issues-table th:nth-child(3), #issues-table td:nth-child(3) { width: 7em; }
#issues-table th:nth-child(4), #issues-table td:nth-child(4) { width: 8em; }
#issues-table th:nth-child(5), #issues-table td:nth-child(5) { width: 8em; }
#issues-table th:nth-child(6), #issues-table td:nth-child(6) { width: 4em; text-align: right; }

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(0, 0, 0, 0.03); }
@media (prefers-color-scheme: dark) { tr:hover td { background: rgba(255,255,255,0.03); } }

/* ── Forms / filters ─────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 0.75rem;
}

input[type="search"],
input[type="text"],
select {
  font: inherit;
  font-size: 13px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.6rem;
  outline: none;
  transition: border-color 0.15s;
}

input[type="search"]:focus,
input[type="text"]:focus,
select:focus {
  border-color: var(--accent);
}

input[type="search"] { min-width: 220px; }

.trace-extra { margin-top: 0.75rem; }
.trace-extra summary { cursor: pointer; font-size: 12px; color: var(--fg-muted); padding: 4px 0; }
.trace-extra summary:hover { color: var(--fg); }
.trace.trace-meta { font-size: 11px; margin-top: 4px; opacity: 0.9; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
button {
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.85rem;
  background: var(--bg-card);
  color: var(--fg);
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: var(--bg); border-color: var(--accent); color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.trace-header { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.copy-trace-btn { padding: 4px 10px; font-size: 12px; }
.copy-trace-btn:disabled { opacity: 0.6; cursor: default; }
.status-actions { display: flex; gap: 8px; margin: 8px 0 12px 0; flex-wrap: wrap; }
.status-btn { padding: 4px 12px; font-size: 13px; }
.status-btn:disabled { opacity: 0.6; cursor: default; }

/* ── Status badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge-open    { background: rgba(220,53,69,0.15);  color: var(--danger); }
.badge-resolved{ background: rgba(25,135,84,0.15);  color: var(--success); }
.badge-ignored { background: rgba(108,117,125,0.15);color: var(--fg-muted); }
.badge-ok      { background: rgba(25,135,84,0.15);  color: var(--success); }
.badge-down    { background: rgba(220,53,69,0.15);  color: var(--danger); }

/* ── Traceback / monospace ───────────────────────────────────────────────── */
pre.trace {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  overflow-x: auto;
  white-space: pre;
  color: var(--fg);
  counter-reset: line;
}

/* ── Health summary ──────────────────────────────────────────────────────── */
#health-content {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  font-size: 13px;
}
.stat-item { display: flex; flex-direction: column; gap: 0.15rem; }
.stat-label { font-size: 11px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--fg); }

/* ── Loading / empty states ──────────────────────────────────────────────── */
.loading { color: var(--fg-muted); font-style: italic; font-size: 13px; }
.empty-state { text-align: center; color: var(--fg-muted); padding: 2rem; }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-end;
  font-size: 12px;
  color: var(--fg-muted);
}

/* ── Source registration modal ───────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.24);
  padding: 1.5rem 2rem;
  width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin-bottom: 1rem; font-size: 1.1rem; }
.modal-form { display: flex; flex-direction: column; gap: 0.75rem; }
.modal-form label { font-size: 12px; font-weight: 600; color: var(--fg-muted); text-transform: uppercase; margin-bottom: 0.2rem; display: block; }
.modal-form input, .modal-form select, .modal-form textarea {
  width: 100%; padding: 0.45rem 0.65rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--fg); font-size: 13px;
}
.modal-form textarea { min-height: 64px; resize: vertical; }
.modal-footer { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }
.modal-footer button { padding: 0.4rem 1rem; border-radius: var(--radius); cursor: pointer; border: 1px solid var(--border); }
.modal-footer .btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.modal-footer .btn-primary:hover { background: var(--accent-hover); }
.one-time-secret {
  border: 2px solid var(--danger) !important;
  font-family: var(--mono); font-size: 12px;
  background: rgba(220,53,69,0.08) !important;
  word-break: break-all; padding: 0.5rem;
  border-radius: var(--radius);
}
.secret-warning {
  color: var(--danger); font-weight: 700; font-size: 13px; margin: 0.5rem 0;
}
.copy-button {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.25rem 0.6rem; font-size: 11px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-elevated); cursor: pointer; color: var(--fg);
}
.copy-button:hover { background: var(--border); }
.snippet-block { position: relative; margin-top: 0.5rem; }
.snippet-block pre {
  font-family: var(--mono); font-size: 11px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.75rem; overflow-x: auto;
  max-height: 220px; white-space: pre; color: var(--fg);
}
.snippet-copy-btn { position: absolute; top: 0.35rem; right: 0.35rem; }
