/* ===========================================
   Grundlayout
   =========================================== */

body {
  background-color: #f1f5f9;
  color: #1e293b;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 0.82rem;
  line-height: 1.5;
  overflow-x: hidden;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

main.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: clamp(0.8rem, 2vw, 1.2rem);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===========================================
   Karten / Artikel (Repos)
   =========================================== */

article.repo-block {
  background-color: #ffffff;
  border: 1px solid #dce3eb;
  border-radius: 0.75rem;
  padding: 0.85rem 1rem;
  margin-bottom: 1.1rem;
  box-sizing: border-box;
  overflow: visible;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  min-width: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  position: relative;
}

.repo-local-indicator {
  position: absolute;
  top: 0.65rem;
  right: 0.75rem;
  background: rgba(148, 163, 184, 0.25);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  display: none;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: #0f172a;
  backdrop-filter: blur(2px);
  box-shadow: 0 3px 8px rgba(15, 23, 42, 0.15);
}

.repo-local-indicator.htmx-request {
  display: inline-flex;
}

.repo-local-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(14, 165, 233, 0.35);
  border-top-color: #0ea5e9;
  animation: spin 0.9s linear infinite;
}

.repo-local-label {
  font-weight: 600;
  letter-spacing: 0.01em;
}

.repo-block::-webkit-scrollbar {
  height: 6px;
}

.repo-block::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.25);
  border-radius: 999px;
}

.repo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  gap: 0.85rem;
  align-items: stretch;
}

@media (max-width: 900px) {
  .repo-grid {
    grid-template-columns: 1fr;
  }
}

/* ===========================================
   Buttons
   =========================================== */

button,
a.btn,
a.btn-secondary {
  padding: 0.32rem 0.7rem;
  border-radius: 0.4rem;
  border: none;
  cursor: pointer;
  font-size: 0.78rem;
  text-decoration: none;
  display: inline-block;
}

a.btn-secondary,
button.btn-secondary {
  background-color: #e1e8f0;
  color: #0f172a;
}

a.btn-secondary:hover,
button.btn-secondary:hover {
  background-color: #cbd5e1;
}

.btn {
  background-color: #dbeafe;
  color: #1e40af;
}

.btn:hover {
  background-color: #bfdbfe;
}

/* ===========================================
   Repo-Tabelle
   =========================================== */

table.repo-table {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  table-layout: fixed;
  font-size: 0.85rem;
}

/* Kopfzeile */
.repo-header th {
  background-color: #f8fafc;
  color: #334155;
  padding: 0.55rem 0.65rem;
  font-weight: 600;
  border-bottom: 1px solid #e2e8f0;
  text-transform: none;
  letter-spacing: 0.005em;
}

/* Repo-Titelzeile */
.repo-title-row td {
  background-color: #f1f5f9;
  color: #0369a1;
  font-family: monospace;
  font-weight: 700;
  font-size: 0.92rem;
  padding: 0.6rem;
  border-radius: 0.4rem;
  margin-top: 4px;
}

.repo-title-bar {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}

.repo-title {
  font-weight: 700;
  word-break: break-word;
}

.repo-title-secondary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: #0f172a;
}

.repo-locked {
  color: #b45309;
  font-size: 0.85rem;
}

.compact-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
}

.compact-control input {
  width: 4.5rem;
  padding: 0.2rem 0.4rem;
  border: 1px solid #cbd5f5;
  border-radius: 0.3rem;
  font-size: 0.78rem;
}

.compact-label {
  font-weight: 600;
  color: #0f172a;
}

.compact-button {
  background-color: #0ea5e9;
  color: #fff;
  border: none;
  padding: 0.32rem 0.7rem;
  border-radius: 0.4rem;
  cursor: pointer;
  font-size: 0.78rem;
}

.compact-button:hover {
  background-color: #0284c7;
}

.compact-output {
  display: none;
  background: #f8fafc;
  border: 1px dashed #cbd5f5;
  border-radius: 0.4rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
}

.stream-output {
  /* Alias-Klasse, falls mehr Ausgaben gestreamt werden */
}

.output-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.output-title {
  font-size: 0.8rem;
  color: #475569;
}

.output-close {
  background: transparent;
  color: #0f172a;
  border: 1px solid #cbd5e1;
  padding: 0.18rem 0.45rem;
  border-radius: 0.3rem;
  font-size: 0.75rem;
  cursor: pointer;
}

.output-close:hover {
  background: #e2e8f0;
}

.hidden {
  display: none !important;
}

/* Aktionen */
.repo-actions-row td {
  padding-top: 0.6rem;
}

.repo-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
  justify-content: flex-end;
}

.purge-launch {
  min-width: 110px;
}

/* Purge */
.repo-purge-row td {
  background: #f8fafc;
  border-radius: 0.4rem;
}

.purge-control {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.6rem 0.8rem;
  padding: 0.5rem 0.65rem;
}

.purge-inputs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.45rem 0.6rem;
  flex: 1 1 360px;
}

.purge-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.purge-label {
  font-size: 0.78rem;
  color: #475569;
}

.purge-field input {
  width: 100%;
  padding: 0.28rem 0.4rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.32rem;
  font-size: 0.8rem;
  color: #0f172a;
  background: #fff;
}

.purge-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.2rem;
}

.purge-dryrun {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.82rem;
}

/* Modal */
.modal.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
}

.modal-content {
  position: relative;
  width: min(560px, 92vw);
  margin: 6vh auto;
  background: #fff;
  border-radius: 0.6rem;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
  padding: 0.9rem 1rem 1rem;
  z-index: 1;
}

.modal-content-wide {
  width: min(1200px, 96vw);
}

.modal-body-scroll {
  max-height: 72vh;
  overflow: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.4rem;
}

.modal-title {
  font-weight: 700;
  color: #0f172a;
}

.modal-sub {
  font-size: 0.85rem;
  color: #475569;
}

.modal-close {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 0.4rem;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
}

.modal-body {
  padding: 0.2rem 0 0.6rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

.modal-layout .purge-actions {
  padding-top: 0;
}

/* Archiv-Zeilen */
.repo-table td {
  padding: 0.55rem 0.75rem;
}

.td-archive {
  padding-left: 1rem;
  word-break: break-word;
  white-space: normal;
}

.repo-table tbody tr.archive-row td {
  border-top: 1px solid #e2e8f0;
  border-bottom: 1px solid #e2e8f0;
}

.repo-table tbody tr.archive-row td:first-child {
  border-left: 1px solid #e2e8f0;
  border-radius: 0.35rem 0 0 0.35rem;
}

.repo-table tbody tr.archive-row td:last-child {
  border-right: 1px solid #e2e8f0;
  border-left: none;
  border-radius: 0 0.35rem 0.35rem 0;
}

.repo-table tbody tr.archive-row.row-odd td {
  background-color: #ffffff;
}

.repo-table tbody tr.archive-row.row-even td {
  background-color: #f8fafc;
}

.repo-table tbody tr.archive-row:hover td {
  background-color: #eef2f7;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

/* Summenzeile */
.repo-sum td {
  background-color: #f8fafc;
  font-size: 0.85rem;
  padding: 0.55rem 0.9rem;
  text-align: right;
  color: #475569;
  border-top: 1px solid #e2e8f0;
}

/* Footer der Repo-Tabelle */
.repo-footer td {
  padding-top: 0.6rem;
  text-align: right;
  border: none;
}

/* ===========================================
   Archiv-Details
   =========================================== */

.archive-detail-row td {
  padding: 0;
  border: 1px solid #e2e8f0;
  border-top: none;
  border-radius: 0 0 0.35rem 0.35rem;
}

.archive-detail {
  display: flex;
  gap: 1rem;
  background-color: #f1f5f9;
  border-radius: 0.4rem;
  padding: 0.6rem 0.8rem;
}

.detail-block {
  flex: 1;
  text-align: center;
}

.detail-label {
  font-size: 0.85rem;
  color: #0369a1;
  font-weight: 600;
}

.detail-value {
  color: #1e293b;
  font-size: 0.85rem;
  margin-top: 0.1rem;
}

.archive-action-group {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.archive-action-wrapper {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
  position: relative;
}

.archive-action-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 0.5rem;
  border: 1px solid #cbd5e1;
  background: #e2e8f0;
  color: #0f172a;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.archive-action-toggle:hover {
  background: #cbd5e1;
  border-color: #94a3b8;
}

.burger-icon {
  position: relative;
  width: 16px;
  height: 2px;
  border-radius: 999px;
  background: #0f172a;
}

.burger-icon::before,
.burger-icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 16px;
  height: 2px;
  border-radius: 999px;
  background: #0f172a;
}

.burger-icon::before {
  top: -5px;
}

.burger-icon::after {
  top: 5px;
}

@media (max-width: 1024px) {
  .archive-action-group {
    position: absolute;
    top: calc(100% + 0.35rem);
    right: 0;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 0.55rem;
    padding: 0.45rem 0.6rem;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: min(240px, 80vw);
    gap: 0.45rem;
    z-index: 20;
  }

  .archive-action-wrapper.menu-open .archive-action-group {
    display: flex;
  }

  .archive-action-group .btn,
  .archive-action-group .btn-secondary {
    width: 100%;
    text-align: center;
    justify-content: center;
  }

  .archive-action-toggle {
    display: inline-flex;
  }
}

.archive-content-row td {
  padding: 0;
  border: 1px solid #e2e8f0;
  border-top: none;
  border-radius: 0 0 0.35rem 0.35rem;
  background: #f8fafc;
}

.archive-content-box {
  padding: 0.6rem 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.archive-content-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.archive-content-title {
  font-weight: 700;
  color: #0f172a;
}

.archive-content-sub {
  font-size: 0.82rem;
  color: #475569;
}

.archive-content-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.archive-filter {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.archive-filter .acf-input {
  min-width: 220px;
  padding: 0.32rem 0.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.35rem;
  font-size: 0.85rem;
}

.filter-btn {
  padding: 0.3rem 0.65rem;
}

.btn-download {
  background-color: #0ea5e9;
  color: #fff !important;
}

.btn-download:hover {
  background-color: #0284c7;
}

.archive-content-table-wrapper {
  border: 1px solid #e2e8f0;
  border-radius: 0.4rem;
  overflow: auto;
  max-height: 340px;
  background: #fff;
}

.modal-table-wrapper {
  max-height: 520px;
}

.archive-content-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.archive-content-table th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  color: #475569;
  text-align: left;
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid #e2e8f0;
}

.archive-content-table td {
  padding: 0.38rem 0.55rem;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: top;
}

.archive-content-table tr:nth-child(even) td {
  background: #f8fafc;
}

.archive-content-table tr:hover td {
  background: #eaf1f8;
}

.act-path {
  font-family: monospace;
  word-break: break-all;
}

.act-type {
  width: 70px;
  color: #0f172a;
  font-weight: 600;
}

.act-mtime {
  width: 160px;
}

.act-size {
  width: 120px;
  text-align: right;
}

.act-dl {
  width: 130px;
  text-align: right;
}

.btn-inline {
  padding: 0.25rem 0.55rem;
}

.archive-content-empty,
.archive-content-note {
  font-size: 0.84rem;
  color: #475569;
}

.archive-content-note {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  padding: 0.45rem 0.6rem;
  border-radius: 0.35rem;
}

/* ===========================================
   Server-Karten (Startseite)
   =========================================== */
.server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
  margin-top: 0.8rem;
}

.server-card {
  background: #fff;
  border: 1px solid #dce3eb;
  border-radius: 0.75rem;
  padding: 0.9rem 1rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  position: relative;
}

.server-card-spinner {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(241, 245, 249, 0.85);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  z-index: 10;
  text-align: center;
  color: #0f172a;
}

.server-card-spinner.htmx-request {
  display: flex;
}

.spinner-circle-sm {
  width: 28px;
  height: 28px;
  border-width: 3px;
}

.server-card-head {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.server-card-title {
  font-weight: 800;
  font-size: 1rem;
  color: #0f172a;
}

.server-card-sub {
  color: #475569;
  font-size: 0.86rem;
}

.server-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.server-meta {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.server-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.86rem;
}

.status-ok { color: #047857; }
.status-fail { color: #b91c1c; }
.status-unknown { color: #64748b; }

.server-repos {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.repo-chip {
  background: #e0f2fe;
  color: #075985;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  font-size: 0.78rem;
  border: 1px solid #bae6fd;
}

.server-card-foot {
  display: flex;
  justify-content: flex-end;
}

.local-spinner {
  display: none;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  color: #0ea5e9;
}

.local-spinner.htmx-request {
  display: inline-flex;
}

/* ===========================================
   Responsives Layout
   =========================================== */

@media (max-width: 780px) {
  main.container {
    padding: 0.8rem;
  }

  article.repo-block {
    padding: 0.8rem;
    border-radius: 0.6rem;
  }

  .repo-title-row td {
    border-radius: 0.35rem;
  }

  table.repo-table,
  table.repo-table thead,
  table.repo-table tbody,
  table.repo-table tr,
  table.repo-table td,
  table.repo-table th {
    display: block;
    width: 100%;
  }

  table.repo-table tr.repo-header {
    display: none !important;
  }

  table.repo-table thead {
    position: absolute;
    height: 0;
    width: 0;
    overflow: hidden;
  }

  table.repo-table tbody tr.archive-row {
    border: 1px solid #e2e8f0;
    border-radius: 0.45rem;
    margin-bottom: 0.8rem;
    padding: 0.45rem 0.55rem;
    background: #fff;
  }

  table.repo-table tbody tr.archive-row td {
    border: none;
    padding: 0.35rem 0;
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
  }

  table.repo-table tbody tr.archive-row td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #475569;
  }

  .archive-detail {
    flex-direction: column;
  }

  .repo-actions {
    justify-content: flex-start;
  }

  .repo-footer td {
    text-align: left;
  }

  .modal-content,
  .modal-content-wide {
    width: 100vw;
    height: 100vh;
    margin: 0;
    border-radius: 0;
  }

  .modal-body-scroll {
    max-height: calc(100vh - 120px);
  }

  .archive-content-table-wrapper {
    max-height: none;
  }

  .archive-content-table thead {
    display: none;
  }

  .archive-content-table tr {
    display: block;
    border: 1px solid #e2e8f0;
    border-radius: 0.4rem;
    margin-bottom: 0.75rem;
    padding: 0.4rem 0.5rem;
  }

  .archive-content-table td {
    display: flex;
    justify-content: space-between;
    gap: 0.6rem;
    border: none;
    padding: 0.25rem 0;
  }

  .archive-content-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #475569;
  }

  .act-path,
  .act-type,
  .act-mtime,
  .act-size,
  .act-dl {
    width: auto;
    text-align: left;
  }

  .archive-filter {
    width: 100%;
  }

  .archive-filter .acf-input {
    flex: 1;
    min-width: 0;
  }

  .archive-content-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

/* ===========================================
   Footer
   =========================================== */

footer {
  margin-top: 2rem;
  text-align: center;
  color: #94a3b8;
  font-size: 0.78rem;
}

/* ===========================================
   Globaler Spinner
   =========================================== */

.global-spinner {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  flex-direction: column;
  background: rgba(15, 23, 42, 0.32);
  backdrop-filter: blur(2px);
  z-index: 9999;
  color: #e2e8f0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.global-spinner.is-active {
  display: flex;
}

/* Fallback: anzeigen, wenn HTMX selbst die Klasse setzt */
.global-spinner.htmx-request {
  display: flex;
}

.spinner-circle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 4px solid rgba(226, 232, 240, 0.35);
  border-top-color: #38bdf8;
  animation: spin 0.9s linear infinite;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.05);
}

.spinner-label {
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
