:root {
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --bg-inset: #eceef1;
  --text: #1b1f24;
  --text-muted: #5b6570;
  --border: #d9dee3;
  --accent: #1d5fd6;
  --accent-contrast: #ffffff;
  --danger: #a6291d;
  --danger-bg: #fbe9e7;
  --success: #146c2e;
  --success-bg: #e6f4ea;
  --warning-bg: #fff6dd;
  --tombstone: #8a6d00;
  --tombstone-bg: #fff3cd;
  --shadow: 0 1px 3px rgba(20, 24, 28, 0.12);
  --radius: 8px;
  --font-sans:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --bg-elevated: #1d2126;
    --bg-inset: #23282e;
    --text: #e7eaee;
    --text-muted: #9aa4af;
    --border: #33393f;
    --accent: #6ea0ff;
    --accent-contrast: #0b1220;
    --danger: #ff8a80;
    --danger-bg: #3a1512;
    --success: #7bd88f;
    --success-bg: #12301c;
    --warning-bg: #3a2f0c;
    --tombstone: #e8c766;
    --tombstone-bg: #3a2f0c;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

body {
  margin: 0;
  padding-inline: 16px;
  padding-block-start: max(16px, env(safe-area-inset-top, 0px));
  padding-block-end: max(16px, env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
}

h1,
h2,
h3 {
  line-height: 1.25;
  font-weight: 600;
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 0.75rem;
}

h2 {
  font-size: 1.1rem;
  margin: 1.75rem 0 0.5rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

h3 {
  font-size: 1rem;
  margin: 0 0 0.4rem;
}

.subtitle {
  color: var(--text-muted);
  margin-top: 0;
}

[hidden] {
  display: none !important;
}

/* ----- layout ----- */

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-inline: -16px;
  padding: 0.6rem 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.topbar-title {
  font-weight: 700;
}

.topbar-hostname {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.topbar-nav {
  margin-inline-start: auto;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.main {
  max-width: 960px;
  margin: 0 auto;
  padding-block: 1.25rem 3rem;
}

.view {
  display: block;
}

.panel + .panel {
  margin-top: 1.5rem;
}

/* ----- forms and buttons ----- */

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

input[type="password"],
input[type="text"] {
  width: 100%;
  max-width: 24rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1rem;
}

input[type="password"]:focus,
input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.login-form {
  max-width: 24rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.filter-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.6rem;
  margin: 0.75rem 0;
}

.filter-form label {
  margin-bottom: 0.35rem;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid transparent;
}

.button-primary {
  padding: 0.55rem 1rem;
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
  font-weight: 600;
}

.button-secondary {
  padding: 0.45rem 0.85rem;
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
}

.button-secondary:hover,
.button-primary:hover {
  filter: brightness(1.05);
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  font-size: 0.95rem;
}

#back-to-overview-button,
#back-to-folders-button {
  display: inline-block;
  margin-bottom: 0.75rem;
}

/* ----- status messages ----- */

.status-message {
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  margin: 0.5rem 0;
  font-size: 0.92rem;
}

.status-loading {
  background: var(--bg-inset);
  color: var(--text-muted);
}

.status-empty {
  background: var(--bg-inset);
  color: var(--text-muted);
  font-style: italic;
}

.status-error {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ----- facts and health ----- */

.fact-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1rem;
  margin: 0;
}

.fact-list dt {
  color: var(--text-muted);
}

.fact-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 0.75rem;
}

.health-card {
  padding: 0.75rem 0.9rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.health-value {
  margin: 0;
  padding: 0.3rem 0.55rem;
  border-radius: var(--radius);
  display: inline-block;
  font-size: 0.9rem;
}

.health-ok {
  background: var(--success-bg);
  color: var(--success);
}

.health-down {
  background: var(--danger-bg);
  color: var(--danger);
  overflow-wrap: anywhere;
}

/* ----- lists ----- */

.entity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.entity-list li {
  border-bottom: 1px solid var(--border);
}

.entity-list .link-button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.2rem;
  text-decoration: none;
}

.entity-list .link-button:hover {
  color: var(--accent);
  text-decoration: underline;
}

.entity-name {
  font-family: var(--font-mono);
}

.counts-line {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ----- tables ----- */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.5rem 0.7rem;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

.data-table thead th {
  color: var(--text-muted);
  font-weight: 600;
  background: var(--bg-inset);
  position: sticky;
  top: 0;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.files-table .file-name {
  font-family: var(--font-mono);
  /* `pre`, not `pre-wrap`: a name is one token an operator scans down a
     column, and breaking it mid-character at phone width makes a path
     unreadable. The table scrolls sideways inside `.table-scroll` instead.
     `pre` still preserves the leading and trailing spaces a name may
     legitimately carry. */
  white-space: pre;
}

.file-deleted td {
  color: var(--text-muted);
}

.tombstone-marker,
.invalid-marker {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.tombstone-marker {
  background: var(--tombstone-bg);
  color: var(--tombstone);
}

.invalid-marker {
  background: var(--danger-bg);
  color: var(--danger);
}

#load-more-button {
  margin-top: 0.9rem;
}

/* ----- phone width ----- */

@media (max-width: 480px) {
  body {
    font-size: 14px;
  }

  .topbar-nav {
    margin-inline-start: 0;
    width: 100%;
    justify-content: flex-end;
  }

  input[type="password"],
  input[type="text"] {
    max-width: none;
  }
}
