:root {
  --bg: #0f1117;
  --panel: #161a23;
  --panel-2: #1e2433;
  --border: #2a3142;
  --text: #e6e9ef;
  --muted: #8b94a8;
  --accent: #5ea0ff;
  --accent-2: #9b6cff;
  --p0: #ff5d6c;
  --p1: #ffb547;
  --p2: #5ee0a0;
  --p3: #7aa0c4;
  --error: #ff8b94;
  --ok: #5ee0a0;
  --shadow: 0 4px 18px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}

.brand a { color: var(--text); font-weight: 600; }
.brand .badge {
  margin-left: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 99px;
}

.topnav { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.topnav a { color: var(--muted); font-size: 12.5px; padding: 2px 6px; border-radius: 4px; }
.topnav a:hover { color: var(--text); background: var(--panel-2); }
.topnav a.active { color: var(--text); background: var(--panel-2); font-weight: 600; }

.usermenu { display: flex; align-items: center; gap: 10px; }
.usermenu .user { color: var(--muted); font-size: 13px; }

.link-button {
  background: none; border: none; color: var(--accent);
  cursor: pointer; padding: 0; font-size: 13px;
}
.link-button:hover { text-decoration: underline; }

.content { padding: 22px; max-width: min(95vw, 1700px); margin: 0 auto; }
.footer { text-align: center; padding: 28px 12px; color: var(--muted); font-size: 12px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.card.narrow { max-width: 440px; margin: 60px auto; }
.card + .card { margin-top: 16px; }

h1, h2, h3 { margin-top: 0; }
.muted { color: var(--muted); }
.error { color: var(--error); }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 180px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
}
textarea { min-height: 72px; resize: vertical; }

button.primary, .btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white; border: none; border-radius: 8px;
  padding: 9px 14px; cursor: pointer; font-weight: 600;
}
button.primary:hover { filter: brightness(1.05); }

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font: inherit;
}
.btn:hover { border-color: var(--accent); }
.btn.danger { color: var(--error); border-color: rgba(255,139,148,.4); }
.btn.btn-mini {
  padding: 4px 6px;
  font-size: 11px;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
  white-space: nowrap;
}
.btn.btn-mini.disabled,
span.btn.btn-mini.disabled {
  color: var(--muted);
  opacity: 0.45;
  cursor: not-allowed;
  border-style: dashed;
}
.btn.btn-mini.disabled:hover { border-color: var(--border); }
.links-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
  min-width: 220px;
}
/* Row 1 = 2 wide buttons (span 3 cols of 6), Row 2 = 3 buttons (span 2 cols of 6).
   Implemented by switching to a 6-column grid where the first two children take
   3 cols each, and the next three take 2 cols each. */
.links-grid.links-grid-2x3 {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  min-width: 240px;
}
.links-grid.links-grid-2x3 > *:nth-child(1),
.links-grid.links-grid-2x3 > *:nth-child(2) {
  grid-column: span 3;
}
.links-grid.links-grid-2x3 > *:nth-child(3),
.links-grid.links-grid-2x3 > *:nth-child(4),
.links-grid.links-grid-2x3 > *:nth-child(5) {
  grid-column: span 2;
}

.cluster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.cluster-tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  transition: border-color 120ms;
  /* Make all tiles in a row equal in height; thumb sits flush at the bottom. */
  display: flex;
  flex-direction: column;
}
.cluster-tile:hover { border-color: var(--accent); }
.cluster-tile h3 { margin: 0 0 4px; }
.cluster-tile .slug { color: var(--muted); font-size: 12px; }
.cluster-tile .summary {
  font-size: 13px; color: var(--muted); margin: 8px 0;
  flex-grow: 1;                 /* fill leftover space so layout is uniform */
}
.tile-stats { display: flex; gap: 10px; margin-top: 8px; font-size: 12px; flex-wrap: wrap;}
.tile-status {
  margin-top: 10px;
  padding: 4px 10px;
  background: rgba(255,181,71,.10);
  border: 1px solid rgba(255,181,71,.35);
  color: #ffb547;
  border-radius: 6px;
  font-size: 12px;
  text-align: center;
}
.tile-thumb {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}
.tile-thumb img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}
.tile-thumb-cap {
  font-size: 10.5px;
  color: var(--muted);
  text-align: center;
  padding: 4px 0;
  background: var(--panel-2);
  border-top: 1px solid var(--border);
}

/* Per-card MSA-schedule strip (under the priority pills). */
.tile-schedule {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
  font-size: 11.5px;
}
.tile-schedule .pill.schedule {
  background: var(--panel-2);
  border-color: var(--border);
  color: var(--muted);
}
.tile-schedule .pill.schedule strong {
  color: var(--text);
  font-weight: 600;
  margin-left: 2px;
}
.tile-schedule .pill.schedule-urgent {
  background: rgba(255, 77, 109, 0.10);
  border-color: rgba(255, 77, 109, 0.55);
  color: #ffd0d8;
}
.tile-schedule .pill.schedule-urgent strong { color: #ffb7c3; }

/* Card highlight for clusters with a near-term filler deadline. */
.cluster-tile.urgent {
  border-color: rgba(255, 77, 109, 0.55);
  box-shadow: 0 0 0 1px rgba(255, 77, 109, 0.25) inset,
              0 6px 18px -8px rgba(255, 77, 109, 0.35);
}
.cluster-tile.urgent:hover {
  border-color: #ff4d6d;
}
.urgent-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: #ff4d6d;
  color: #fff;
  border-radius: 99px;
  vertical-align: 1px;
}
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 99px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted);
}
.pill.P0 { color: var(--p0); border-color: rgba(255,93,108,.4); }
.pill.P1 { color: var(--p1); border-color: rgba(255,181,71,.4); }
.pill.P2 { color: var(--p2); border-color: rgba(94,224,160,.4); }
.pill.P3 { color: var(--p3); border-color: rgba(122,160,196,.4); }

.tabs { display: flex; gap: 4px; margin: 18px 0 8px; flex-wrap: wrap; }
.tabs a, .tabs button {
  padding: 7px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  color: var(--muted);
  cursor: pointer;
}
.tabs a.active, .tabs button.active { color: var(--text); border-bottom-color: var(--accent); background: var(--panel); }
.tab-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0 12px 12px 12px;
  padding: 16px;
}

table.targets {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.targets th, table.targets td {
  text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
table.targets th { color: var(--muted); font-weight: 500; }
table.targets tr:hover td { background: var(--panel-2); }

/* Row-cutout (Generating Catalog) — hide Aladin Lite chrome that's noisy at 80×80 */
.row-cutout .aladin-logo,
.row-cutout .aladin-location,
.row-cutout .aladin-fov,
.row-cutout .aladin-coordinates,
.row-cutout .aladin-cooFrame,
.row-cutout .aladin-frameChoice,
.row-cutout .aladin-frame-info,
.row-cutout .aladin-status,
.row-cutout .aladin-toolbox,
.row-cutout .aladin-stack-control,
.row-cutout .aladin-imageQuality-control,
.row-cutout .aladin-simbadPointer-control {
  display: none !important;
}
.row-cutout .aladin-container { background: #000 !important; }

.aladin-wrap { aspect-ratio: 1 / 1; max-width: 820px; max-height: 820px; margin: 0 auto; }
#aladin-lite-div { width: 100%; height: 100%; border-radius: 8px; overflow: hidden; }
.fitsmap-iframe { width: 100%; height: 680px; border: 0; border-radius: 8px; background: #000; }

.split { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
@media (max-width: 1080px) { .split { grid-template-columns: 1fr; } }

.comment {
  background: var(--panel-2);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.comment .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* Custom file-input wrapper — replaces browser-locale text ("ファイルを選択" / "選択されていません")
   with English-only "Choose file" + "No file selected". */
.file-input {
  display: flex; align-items: center; gap: 8px;
}
.file-input input[type="file"] {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.file-input .file-btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; font: inherit;
  white-space: nowrap;
}
.file-input .file-btn:hover { border-color: var(--accent); }
.file-input .file-name {
  color: var(--muted); font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.flash.ok { background: rgba(94,224,160,.12); border: 1px solid rgba(94,224,160,.3); color: var(--ok); }
.flash.err { background: rgba(255,139,148,.10); border: 1px solid rgba(255,139,148,.3); color: var(--error); }
