:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --up: #16a34a;
  --down: #dc2626;
  --unknown: #9ca3af;
  --warn: #d97706;
  --accent: #2563eb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card-bg: #1e2126;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #2d3138;
    --unknown: #6b7280;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

.topbar h1 { font-size: 18px; margin: 0; }

.topbar-actions {
  display: flex;
  gap: 8px;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

main h2 {
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0;
}

/* Grid view is meant to pack as many monitors as possible on a wide
   monitor (up to ~50 targets), so it opts out of the page's normal
   1200px reading-width cap while active. */
#main-content.wide {
  max-width: none;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.list-header h2 {
  margin-bottom: 0;
}

.list-view-toggle {
  display: flex;
  gap: 6px;
}

.view-toggle-btn {
  font-size: 12px;
  padding: 6px 12px;
}

.view-toggle-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

#add-monitor-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#add-monitor-form input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

#add-monitor-form input[name="name"] { flex: 1; min-width: 140px; }
#add-monitor-form input[name="target"] { flex: 2; min-width: 220px; }
#add-monitor-form input[name="repo_path"] { flex: 2; min-width: 220px; }
#add-monitor-form input[name="tags"] { flex: 1; min-width: 160px; }

#add-monitor-form select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 14px;
  cursor: pointer;
}

button.secondary {
  background: transparent;
  color: var(--text);
}

button.danger {
  background: transparent;
  color: var(--down);
  border-color: var(--down);
}

.monitor-search {
  margin-bottom: 12px;
}

.monitor-search-input {
  width: 100%;
  max-width: 320px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.tag-chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
}

.middleware-row {
  align-items: center;
}

.middleware-row-name {
  flex: 0 0 auto;
  min-width: 70px;
  font-size: 13px;
}

.middleware-version-input {
  max-width: 140px;
}

.middleware-row button {
  font-size: 12px;
  padding: 6px 10px;
}

.middleware-item {
  margin-bottom: 12px;
}

.middleware-item:last-child {
  margin-bottom: 0;
}

.middleware-item .middleware-row {
  margin-bottom: 6px;
}

.middleware-vuln summary {
  font-weight: 400;
}

.middleware-vuln-list {
  margin: 0 0 10px;
  padding-left: 18px;
  font-size: 13px;
}

.middleware-vuln-list li {
  margin-bottom: 8px;
}

.middleware-vuln-list li:last-child {
  margin-bottom: 0;
}

.middleware-manage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.middleware-manage-row:last-child {
  border-bottom: none;
}

.middleware-manage-row button {
  font-size: 12px;
  padding: 4px 10px;
  flex-shrink: 0;
}

.api-key-reveal {
  background: var(--bg);
  border: 1px solid var(--warn);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.api-key-reveal .modal-row {
  margin-bottom: 0;
}

button.filter-chip {
  font-family: inherit;
  cursor: pointer;
}

button.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

button.filter-chip.clear {
  color: var(--muted);
}

.monitor-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.monitor-table-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
}

.monitor-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

.monitor-table th,
.monitor-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.monitor-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
}

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

.monitor-table-url {
  white-space: normal;
  overflow-wrap: anywhere;
}

.monitor-table-actions {
  text-align: right;
  white-space: nowrap;
}

.monitor-table-actions button {
  font-size: 12px;
  padding: 4px 8px;
  margin-left: 6px;
}

/* Dense alternative to the table for ~50 monitors on a large monitor —
   fits as many columns as the viewport allows rather than a fixed count. */
.monitor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

/* Fixed (not max-) height, tuned so 3 rows of cards fit a 1080px-tall
   screen above the grid (topbar + heading + search + tag filter ≈ 205px,
   so (1080 - 205 - 2*10px gap) / 3 ≈ 280px). Cards vary a lot in content
   now that problem-free rows are hidden (see gridCardHtml) — rather than
   let a content-heavy card stretch the whole grid row taller, the body
   scrolls internally (see .grid-card-body) so every card in a row stays
   the same height. */
.grid-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-size: 12px;
  height: 280px;
}

.grid-card-screenshot {
  height: 100px;
  background: var(--bg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.grid-card-screenshot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  display: block;
}

.grid-card-noshot {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  padding: 8px;
}

.grid-card-body {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.grid-card-url {
  font-weight: 600;
  overflow-wrap: anywhere;
  margin-bottom: 2px;
}

.grid-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  color: var(--muted);
}

.grid-card-actions {
  display: flex;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.grid-card-actions button {
  flex: 1;
  border: none;
  border-radius: 0;
  font-size: 11px;
  padding: 6px 4px;
}

.grid-card-actions button:first-child {
  border-right: 1px solid var(--border);
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.card-top {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.url-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.url-text {
  overflow-wrap: anywhere;
}

.url-row button {
  flex-shrink: 0;
  font-size: 12px;
  padding: 6px 10px;
}

.ssl-row,
.domain-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.domain-refresh-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.domain-refresh-row button {
  flex-shrink: 0;
  font-size: 12px;
  padding: 6px 10px;
}

.screenshot-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.screenshot-image-wrap {
  flex: 0 0 auto;
  max-width: 220px;
}

.screenshot-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.screenshot-actions button {
  font-size: 12px;
  padding: 6px 10px;
  white-space: nowrap;
}

.screenshot-thumb {
  display: block;
  width: 100%;
  max-width: 220px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.screenshot-caption {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.card-top .card-detail {
  width: 100%;
}

/* Same divider treatment as .card-detail-response-history, applied between
   every item inside 詳細表示 (URL/最終チェック/SSL/ドメイン/メモ/タグ/撮影パネル)
   so each section reads as a distinct block, not just the response-history one. */
.card-detail > * + * {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.card > .actions {
  justify-content: flex-end;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 8px;
}

.card-header .name { font-weight: 600; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: white;
}

.badge.up { background: var(--up); }
.badge.down { background: var(--down); }
.badge.unknown { background: var(--unknown); }
.badge.warn { background: var(--warn); }

.meta {
  font-size: 13px;
  color: var(--muted);
}

.card .meta {
  margin-bottom: 12px;
}

.locations {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 12px;
  margin-bottom: 12px;
}

.location-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.actions button { font-size: 12px; padding: 6px 10px; }

.modal-row {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.repo-path-input,
.tags-input {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
}

.card-memo {
  margin-bottom: 16px;
}

.card-memo-input {
  display: block;
  width: 100%;
  resize: vertical;
  font-family: inherit;
  margin-bottom: 6px;
}

.card-memo-actions {
  text-align: right;
}

.modal-row button {
  font-size: 12px;
  padding: 6px 10px;
}

.lambda-locations-textarea {
  display: block;
  width: 100%;
  min-height: 80px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-bottom: 8px;
}

.api-docs-code {
  display: block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 0 0 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
}

.settings-group-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
  background: var(--bg);
  padding: 1px 4px;
  border-radius: 4px;
}

.modal-row .unit {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}

.toggle-row {
  align-items: center;
}

.toggle-row input[type="number"]:disabled {
  opacity: 0.5;
}

.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s;
}

.switch-track::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: white;
  border-radius: 50%;
  transition: transform 0.15s;
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::before {
  transform: translateX(16px);
}

.hidden { display: none; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: min(420px, calc(100% - 32px));
  max-height: calc(100vh - 64px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  flex-shrink: 0;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-footer:empty {
  display: none;
}

.settings-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
}

.settings-group:last-child {
  margin-bottom: 0;
}

.settings-group summary {
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.settings-group summary::before {
  content: "▶";
  font-size: 9px;
  color: var(--muted);
  transition: transform 0.15s;
}

.settings-group[open] summary::before {
  transform: rotate(90deg);
}

.settings-group summary::-webkit-details-marker {
  display: none;
}

.settings-group-body {
  padding: 4px 12px 12px;
}

.settings-group-body .modal-row:last-child {
  margin-bottom: 0;
}

.screenshot-modal {
  width: min(700px, calc(100% - 32px));
}

.card-detail-modal {
  width: min(900px, calc(100% - 32px));
  max-height: calc(100vh - 32px);
}

.card-detail-modal .card {
  border: none;
  padding: 0;
}

.card-detail-response-history {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.modal-section-title {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 10px;
}

.response-history-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.response-history-header .modal-section-title {
  margin: 0 0 10px;
}

.response-time-modal {
  width: min(700px, calc(100% - 32px));
}

.response-time-chart {
  width: 100%;
  height: auto;
  display: block;
  margin-bottom: 16px;
}

.screenshot-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.screenshot-item img {
  display: block;
  width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.screenshot-item .screenshot-caption {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  text-align: center;
}

.modal-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
