:root {
  --bg: #ffffff;
  --panel: #f3efe4;
  --text: #333333;
  --muted: #666666;
  --primary: #ca9f85;
  --primary-hover: #b88f74;
  --border: #c4cbd7;
  --danger: #c45c4a;
  --panel-shadow: 0 0 30px 20px rgba(0, 0, 0, 0.12);
  --radius-panel: 10px;
  --radius: 6px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(1rem + var(--safe-top)) calc(1rem + var(--safe-right))
    calc(1rem + var(--safe-bottom)) calc(1rem + var(--safe-left));
}

body.portal-landing {
  justify-content: center;
}

main {
  width: min(520px, 100%);
  background: var(--panel);
  border-radius: var(--radius-panel);
  box-shadow: var(--panel-shadow);
  padding: 2rem 1.5rem 1.5rem;
  text-align: center;
}

main.portal-wide {
  width: min(960px, 100%);
  text-align: left;
}

@media (max-width: 520px) {
  main {
    padding: 1.5rem 1rem 1.25rem;
    box-shadow: 0 0 20px 10px rgba(0, 0, 0, 0.08);
  }
}

.logo {
  display: block;
  width: min(200px, 65%);
  height: auto;
  margin: 0 auto 1.25rem;
}

h1 {
  font-size: clamp(1.125rem, 4vw, 1.35rem);
  font-weight: 600;
  margin: 0 0 0.5rem;
}

h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
}

p.sub {
  color: var(--muted);
  margin: 0 0 1.5rem;
  font-size: 0.9375rem;
  line-height: 1.5;
  word-break: break-word;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.875rem;
  margin-bottom: 1.5rem;
}

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

a.app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 7.5rem;
  padding: 1rem 0.75rem;
  background: var(--bg);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

a.app:active,
a.app:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

a.app img,
a.app svg {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
}

a.app span {
  font-size: 0.975rem;
  font-weight: 500;
  text-align: center;
}

a.app.hidden,
.grid.hidden {
  display: none;
}

.host-list {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.host-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.host-card summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.875rem 1rem;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}

.host-card summary::-webkit-details-marker {
  display: none;
}

.host-card summary::after {
  content: "▾";
  color: var(--muted);
  font-size: 0.875rem;
  transition: transform 0.15s ease;
}

.host-card:not([open]) summary::after {
  transform: rotate(-90deg);
}

.host-name {
  font-size: 0.975rem;
}

.host-summary {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
}

.host-body {
  padding: 0 1rem 1rem;
}

.host-section + .host-section {
  margin-top: 1rem;
}

.host-section h3 {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  line-height: 1.4;
  min-width: 28rem;
}

.data-table th,
.data-table td {
  padding: 0.5rem 0.625rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

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

@media (max-width: 520px) {
  .data-table {
    font-size: 0.75rem;
    min-width: 24rem;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar .back-link {
    width: 100%;
  }
}

.auth-link,
.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 7.5rem;
  min-height: 2.75rem;
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #ffffff;
  text-decoration: none;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

.auth-link.login,
.back-link.secondary {
  background: transparent;
  color: var(--primary);
}

.auth-link.login:hover,
.back-link.secondary:hover {
  background: rgba(202, 159, 133, 0.12);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.toolbar .meta {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.4;
}

.report-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  margin-bottom: 1.25rem;
  padding: 0.875rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 9rem;
}

.filter-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.filter-group select {
  min-height: 2.5rem;
  padding: 0.4rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
}

.filter-group.is-disabled label,
.filter-group.is-disabled select {
  color: #9a9a9a;
}

.filter-group.is-disabled select {
  background: #f0f0f0;
  cursor: not-allowed;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 640px) {
  .stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem;
}

.stat-card .label {
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 0.25rem;
}

.stat-card .value {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.2;
}

.charts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 720px) {
  .charts.two-col {
    grid-template-columns: 1fr 1fr;
  }
}

.chart-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem;
}

.chart-wrap {
  position: relative;
  height: 220px;
}

@media (max-width: 520px) {
  .chart-wrap {
    height: 200px;
  }
}

.chart-wrap.tall {
  height: 260px;
}

.error-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--muted);
  word-break: break-word;
}

.error-list li {
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}

.error-list li:last-child {
  border-bottom: none;
}

.status-msg {
  color: var(--muted);
  font-size: 0.9375rem;
  padding: 2rem 0;
  text-align: center;
}

footer {
  margin-top: 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.6;
}

footer a {
  color: var(--primary);
  text-decoration: none;
}

.deluge-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.deluge-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 0.75rem;
  font-size: 0.975rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0.1rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  background: #eeeeee;
}

.pill.on {
  background: #e5f2e6;
  color: #2d6a32;
}

.pill.off {
  background: #f3e6e2;
  color: #8a3d32;
}

.pill.starting {
  background: #f6efd8;
  color: #7a5b12;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

button.auth-link {
  cursor: pointer;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
}

button.auth-link.secondary {
  background: transparent;
  color: var(--primary);
}

button.auth-link:disabled,
a.auth-link.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.deluge-note {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
  margin: 0.75rem 0 0;
}

.deluge-error {
  color: var(--danger);
  font-size: 0.875rem;
  margin: 0.75rem 0 0;
}
