:root {
  --bg: #f6f7f9;
  --fg: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-fg: #fff;
  --danger: #dc2626;
  --ok: #16a34a;
}
* { box-sizing: border-box; }
body { margin:0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
       background: var(--bg); color: var(--fg); line-height: 1.5; }
.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px; }
.center { display: flex; align-items: center; justify-content: center; min-height: 100vh; }

.topbar {
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 12px 24px; display: flex; justify-content: space-between; align-items: center;
}
.topbar .brand { font-weight: 600; color: var(--fg); text-decoration: none; }
.topbar .link { background: none; border: none; color: var(--muted); cursor: pointer; font: inherit; }

h1, h2, h3 { margin: 0 0 12px; }
h1 { font-size: 22px; }
h2 { font-size: 18px; margin-top: 24px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 12px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
  display: inline-block; padding: 8px 14px; border: 1px solid var(--border);
  background: #fff; color: var(--fg); border-radius: 8px; text-decoration: none;
  font: inherit; font-size: 14px; cursor: pointer; transition: 0.1s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.1); color: var(--accent-fg); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.xs { padding: 2px 8px; font-size: 14px; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px;
        background: #e2e8f0; font-size: 12px; }
.pill.ok { background: #dcfce7; color: var(--ok); }

table.t { width: 100%; border-collapse: collapse; background: #fff;
          border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
table.t th, table.t td { padding: 12px; text-align: left; border-bottom: 1px solid var(--border);
                          vertical-align: top; }
table.t th { background: #f8fafc; font-weight: 600; font-size: 13px; color: var(--muted); }
table.t tr:last-child td { border-bottom: 0; }

.bar { background: #e2e8f0; border-radius: 999px; height: 8px; overflow: hidden;
       margin: 8px 0; max-width: 240px; }
.bar > span { display: block; height: 100%; background: var(--accent);
              transition: width 0.3s; }

.form { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.form label { display: block; font-size: 13px; color: var(--muted); }
.form input[type=text], .form input:not([type]), .form input[type=password],
.form input[type=file], .form textarea, .form select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 6px; font: inherit;
}

.stage {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 20px; margin: 16px 0;
}
.stage > header { display: flex; justify-content: space-between; align-items: flex-start;
                  gap: 16px; margin-bottom: 12px; }
.stage.done { background: #f8fafc; opacity: 0.85; }
.stage .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
               gap: 12px; margin: 12px 0; }
.stage .grid figure { margin: 0; position: relative; aspect-ratio: 1; overflow: hidden;
                      border-radius: 8px; background: #e2e8f0; }
.stage .grid img, .stage .grid video {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.stage .grid figcaption { font-size: 12px; padding: 6px 8px; background: rgba(255,255,255,0.9);
                          position: absolute; bottom: 0; left: 0; right: 0; }
.stage .grid form { position: absolute; top: 4px; right: 4px; }

.add-stage, .upload, details > summary { cursor: pointer; }
details { margin: 8px 0; }
details > summary { padding: 8px 12px; background: #f1f5f9; border-radius: 6px;
                    font-size: 14px; color: var(--muted); }

.comments { list-style: none; padding: 0; margin: 12px 0; }
.comments li { background: #f1f5f9; border-radius: 8px; padding: 10px 12px; margin: 6px 0;
                display: flex; gap: 12px; align-items: flex-start; }
.comments li .body { flex: 1; white-space: pre-wrap; }

.err { background: #fee2e2; color: #b91c1c; padding: 8px 12px; border-radius: 6px;
       margin: 8px 0; }

input[name=stage_names] { width: 100%; padding: 8px 10px; border: 1px solid var(--border);
                            border-radius: 6px; margin: 4px 0; font: inherit; }

.stage .grid figure.pdf {
  aspect-ratio: auto; padding: 12px;
  display: flex; align-items: center; justify-content: center; text-align: center;
}
.stage .grid figure.pdf .pdf-link {
  font-size: 13px; color: var(--accent); text-decoration: none; flex: 1;
  word-break: break-all;
}
