:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --ok: #166534;
  --ok-bg: #dcfce7;
  --warn: #92400e;
  --warn-bg: #fef3c7;
  --latest: #ecfeff;
}

* { box-sizing: border-box; }

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

a { color: inherit; }

header.app-header {
  background: #0f172a;
  color: #fff;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

header .brand { font-weight: 700; letter-spacing: 0.02em; }
header .meta { color: #94a3b8; font-size: 13px; }
header .logout {
  color: #fff;
  text-decoration: none;
  border: 1px solid #334155;
  padding: 8px 12px;
  border-radius: 8px;
}

main {
  max-width: 1200px;
  margin: 28px auto;
  padding: 0 20px 48px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
}

.stat .label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat .value {
  margin-top: 8px;
  font-size: 20px;
  font-weight: 700;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.toolbar h1 {
  margin: 0;
  font-size: 22px;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: 700;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }

.btn-download {
  background: #0ea5e9;
  color: #fff;
}

.btn-download:hover:not(:disabled) {
  background: #0284c8;
}

.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-ghost {
  background: #e2e8f0;
  color: var(--ink);
}

.btn-small {
  padding: 7px 10px;
  font-size: 13px;
  border-radius: 8px;
}

.flash {
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  white-space: pre-wrap;
}

.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: #fee2e2; color: #991b1b; }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tr.latest {
  background: var(--latest);
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 600; }

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: #fee2e2; color: #991b1b; }
.badge.ret { background: #e0e7ff; color: #3730a3; }
.badge.run { background: var(--warn-bg); color: var(--warn); }

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

.empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
}

.log-box {
  margin-top: 18px;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 12px;
  padding: 14px;
  max-height: 280px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 40;
}

.modal.show { display: flex; }

.modal-card {
  background: #fff;
  width: 100%;
  max-width: 540px;
  border-radius: 16px;
  padding: 22px;
}

.modal-card h3 { margin-top: 0; color: var(--danger); }

.warning {
  background: var(--danger-bg);
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 12px;
  border-radius: 10px;
  margin: 14px 0;
}

.confirm-input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.details-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 14px;
}

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

@media (max-width: 700px) {
  .cards { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  table { display: block; overflow-x: auto; }
}
