:root {
  color-scheme: light;
  --app-background: #f7f7f7;
  --app-surface: #fff;
  --app-surface-muted: #f8f9fa;
  --app-text: #111;
  --app-text-muted: #666;
  --app-border: #cdcdcd;
  --app-border-strong: #e5e5e5;
  --app-filter-background: #fff;
  --app-sort-active: #f0f5ff;
  --app-row-hover: #f5f5f5;
  --app-chip-background: #e5e5e5;
  --app-chip-text: #333;
  --app-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  --app-score-high: #dc3545;
  --app-score-medium: #ffc107;
  --app-score-low: #28a745;
  --app-action-background: #6c757d;
  --app-tooltip-background: #333;
  --app-tooltip-text: #fff;
  --app-toast-error-bg: #c7162b;
  --app-toast-success-bg: #0e8420;
  --app-toast-info-bg: #1c63d5;
  --app-toast-text: #fff;
}

html.is-dark-theme {
  color-scheme: dark;
  --app-background: #13161b;
  --app-surface: #1b1f27;
  --app-surface-muted: #232834;
  --app-text: #f3f3f3;
  --app-text-muted: #c7c7c7;
  --app-border: #4b5563;
  --app-border-strong: #3c4657;
  --app-filter-background: #1b1f27;
  --app-sort-active: #22344f;
  --app-row-hover: #252b36;
  --app-chip-background: #394150;
  --app-chip-text: #f5f5f5;
  --app-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  --app-score-high: #ff6b7a;
  --app-score-medium: #ffd166;
  --app-score-low: #6ddf8d;
  --app-action-background: #596273;
  --app-tooltip-background: #0f131a;
  --app-tooltip-text: #fff;
  --app-toast-error-bg: #da3450;
  --app-toast-success-bg: #22a746;
  --app-toast-info-bg: #4788f0;
  --app-toast-text: #fff;
}

html.is-dark-theme h1,
html.is-dark-theme h2,
html.is-dark-theme h3,
html.is-dark-theme h4,
html.is-dark-theme h5,
html.is-dark-theme h6,
html.is-dark-theme th,
html.is-dark-theme td,
html.is-dark-theme label,
html.is-dark-theme legend {
  color: var(--app-text);
}

html.is-dark-theme a {
  color: #cfe8ff;
}

html.is-dark-theme input,
html.is-dark-theme select,
html.is-dark-theme textarea {
  color: var(--app-text);
  background: var(--app-surface);
  border-color: var(--app-border);
}

html.is-dark-theme button:not(.theme-toggle),
html.is-dark-theme .p-button {
  border-color: var(--app-border);
}

html.is-dark-theme table[role="grid"] th,
html.is-dark-theme table[role="grid"] td {
  border-color: var(--app-border);
}

html.is-dark-theme .p-tabs__link {
  color: var(--app-text);
}

html.is-dark-theme .p-tabs__link:hover,
html.is-dark-theme .p-tabs__link.is-active {
  color: var(--app-text);
}

html,
body,
body.is-paper {
  background: var(--app-background);
  color: var(--app-text);
}

.system-status-badges {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: 0.4rem;
}

.system-status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.72rem;
}

.system-status-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #0e8420;
  display: inline-block;
}

.system-status-dot.is-running {
  background: #f99b11;
}

.issue-detail-layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.issue-detail-card {
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid var(--app-border);
  border-radius: 0.5rem;
  background: var(--app-surface);
  box-shadow: var(--app-shadow);
}

.issue-detail-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 0.75rem;
  margin: 0;
}

.issue-detail-meta dt {
  font-weight: 600;
}

.issue-detail-meta dd {
  margin: 0;
}

.issue-detail-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--app-surface-muted);
  color: var(--app-text);
  padding: 1rem;
  border-radius: 0.35rem;
  border: 1px solid var(--app-border);
}

.issue-detail-body--markdown {
  background: var(--app-surface-muted);
  color: var(--app-text);
  padding: 1rem;
  border-radius: 0.35rem;
  border: 1px solid var(--app-border);
  word-break: break-word;
  overflow-wrap: break-word;
}

.issue-detail-body--markdown pre {
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  padding: 0.75rem;
  border-radius: 0.25rem;
  overflow-x: auto;
}

.issue-detail-body--markdown code {
  font-size: 0.9em;
}

.issue-detail-body--markdown img {
  max-width: 100%;
  height: auto;
}

.issue-detail-scores,
.issue-page-status__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.issue-page-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Override grid max-width */
@supports (display: grid) {
  .p-navigation__row--25-75,
  .p-stepped-list--detailed .p-stepped-list__item,
  .row--25-25-25-25,
  .row--25-25-50,
  .row--75-25-on-large,
  .row--75-25-on-medium,
  .row--75-25,
  .row--25-75-on-large,
  .row--50-50-on-large,
  .row--25-75-on-medium,
  .row--50-50-on-medium,
  .row--25-75,
  .row--50-50,
  .row,
  .p-equal-height-row,
  .p-divider {
    max-width: 120rem;
  }
}

.not-used {
  color: var(--app-text-muted);
  font-style: italic;
}

.outdated {
  color: var(--app-toast-error-bg);
  font-weight: 600;
}

.app-group-start {
  border-left: 2px solid var(--app-border-strong);
}

.app-group-header {
  border-left: 2px solid var(--app-border-strong);
}

/* ── Issue table: compact columns ── */
table[role="grid"] {
  table-layout: fixed;
  width: 100%;
}

table[role="grid"] th,
table[role="grid"] td {
  padding: 0.25rem 0.4rem;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Score headers need visible overflow for tooltips */
table[role="grid"] th[data-tooltip] {
  overflow: visible;
}

/* Clip header text via the link element so tooltip overflow still works */
table[role="grid"] th a {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Let title column wrap */
table[role="grid"] td:nth-child(2) {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
}

/* Summary column: truncate by default, expand on click */
table[role="grid"] td.summary-cell {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

table[role="grid"] tr.expanded td.summary-cell {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
}

/* Column widths */
table[role="grid"] col.col-issue     { width: 100px; }
table[role="grid"] col.col-title     { width: auto; }
table[role="grid"] col.col-author    { width: 90px; }
table[role="grid"] col.col-age       { width: 60px; }
table[role="grid"] col.col-score     { width: 80px; }
table[role="grid"] col.col-action    { width: 110px; }
table[role="grid"] col.col-summary   { width: auto; }

/* Column resize handle */
table[role="grid"] th {
  position: relative;
}

table[role="grid"] th .col-resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  cursor: col-resize;
  background: var(--app-border-strong);
  transition: background 0.15s;
}

table[role="grid"] th .col-resize-handle:hover,
table[role="grid"] th .col-resize-handle.resizing {
  background: #0066cc;
}

table[role="grid"] th:hover .col-resize-handle {
  background: var(--app-text-muted);
}

/* Active sort header highlight */
table[role="grid"] th:has(a.is-active) {
  background-color: var(--app-sort-active);
}

table tbody tr {
  background-color: var(--app-surface);
}

table tbody tr:nth-child(even) {
  background-color: var(--app-surface-muted);
}

/* Row hover highlight (global for all tables) */
table tbody tr:hover {
  background-color: var(--app-row-hover);
}

.score-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.score-high {
  background-color: var(--app-score-high);
  color: #fff;
}

.score-medium {
  background-color: var(--app-score-medium);
  color: #111;
}

.score-low {
  background-color: var(--app-score-low);
  color: #fff;
}

.action-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.8rem;
  background-color: var(--app-action-background);
  color: #fff;
}

.filter-bar {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid var(--app-border);
  border-radius: 4px;
  background: var(--app-filter-background);
  box-shadow: var(--app-shadow);
}

.filter-bar select[name="type"] {
  width: auto;
  min-width: 120px;
  max-width: 250px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.filter-group label {
  font-size: 0.875rem;
  font-weight: bold;
  color: var(--app-text);
}

/* Custom multi-select dropdown */
.multiselect {
  position: relative;
  min-width: 180px;
  max-width: 260px;
}

.multiselect.is-open {
  z-index: 60;
}

.multiselect__input-wrap {
  width: 100%;
  min-height: 2.4rem;
  border: 1px solid var(--app-border);
  border-radius: 4px;
  background: var(--app-surface);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}

.multiselect.has-selection .multiselect__input-wrap {
  border-color: #0066cc;
  border-width: 2px;
  padding: 0.19rem 0.44rem;
}

.multiselect__input-wrap:focus-within,
.multiselect.is-open .multiselect__input-wrap {
  outline: 2px solid #0066cc;
  outline-offset: 2px;
}

.multiselect__placeholder {
  color: var(--app-text-muted);
  font-size: 0.875rem;
}

.multiselect__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem;
}

.multiselect__chip {
  display: inline-flex;
  align-items: center;
  background: var(--app-chip-background);
  color: var(--app-chip-text);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  font-size: 0.8rem;
  line-height: 1.4;
  gap: 0.2rem;
}

.multiselect__chip-remove {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  color: var(--app-text-muted);
}

.multiselect__chip-remove:hover {
  color: var(--app-text);
}

.multiselect__dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: 4px;
  padding: 0.25rem;
  box-shadow: var(--app-shadow);
  z-index: 60;
}

.multiselect__options {
  max-height: 320px;
  overflow-y: auto;
  display: grid;
  gap: 0;
}

.multiselect__option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.4rem;
  cursor: pointer;
  font-size: 0.875rem;
  border-radius: 4px;
  margin: 0;
}

.multiselect__option:hover {
  background: var(--app-row-hover);
}

.multiselect__option input {
  margin: 0;
}

.multiselect__option span {
  flex: 1;
}

.sort-arrow {
  margin-left: 0.25rem;
}

th a.is-active {
  font-weight: 700;
  color: #0066cc !important;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-width: 3rem;
}

.theme-toggle__icon--sun {
  display: none;
}

html.is-dark-theme .theme-toggle__icon--sun {
  display: inline;
}

html.is-dark-theme .theme-toggle__icon--moon {
  display: none;
}

/* Tooltip for score column headers */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--app-tooltip-background);
  color: var(--app-tooltip-text);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.4;
  white-space: normal;
  text-transform: none;
  width: max-content;
  max-width: 260px;
  min-width: 120px;
  text-align: center;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-within::after {
  opacity: 1;
  visibility: visible;
}

/* Ensure table layout doesn't clip tooltips */
table thead {
  overflow: visible;
}

table {
  overflow: visible;
}

.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-block;
}

.admin-form {
  max-width: 480px;
  margin-bottom: 1rem;
}

.admin-form__row {
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.admin-form__row label {
  min-width: 100px;
}

.admin-form__row input[type="number"],
.admin-form__row select {
  flex: 1;
}

.toast-container {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.75rem;
  max-width: min(28rem, calc(100vw - 2rem));
}

.toast {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid var(--app-border);
  border-radius: 4px;
  color: var(--app-toast-text);
  box-shadow: var(--app-shadow);
  animation: toast-in 0.18s ease-out;
}

.toast.is-hiding {
  opacity: 0;
  transform: translateY(0.35rem);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast--error {
  background: var(--app-toast-error-bg);
}

.toast--success {
  background: var(--app-toast-success-bg);
}

.toast--info {
  background: var(--app-toast-info-bg);
}

.toast__close {
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(0.35rem);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.col-hidden {
  display: none !important;
}
