/* ---------- reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e0e4ea;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 12px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 24px; min-height: 56px;
}
.topbar-brand { font-weight: 700; font-size: 1.05rem; flex: 1; min-width: 160px; }
.topbar-brand a { color: inherit; text-decoration: none; }
.topbar-brand a:hover { color: var(--primary); }
.topbar-nav { display: flex; align-items: center; gap: 18px; }
.topbar-nav a { color: var(--text-muted); font-weight: 500; font-size: .9rem; text-decoration: none; }
.topbar-nav a:hover { color: var(--primary); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.topbar-user { color: var(--text-muted); font-size: .9rem; }

/* ---------- container ---------- */
.container { max-width: 1100px; margin: 0 auto; padding: 32px 20px 64px; }
.container-wide { max-width: min(1680px, 96vw); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 20px; border: none; border-radius: var(--radius);
  font-size: .925rem; font-weight: 600; cursor: pointer;
  transition: background .15s, box-shadow .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }
.btn-outline {
  background: transparent; border: 1px solid var(--border); color: var(--text);
}
.btn-outline:hover { background: var(--bg); text-decoration: none; }
.btn-block { width: 100%; margin-top: 8px; }
.btn-sm { padding: 6px 14px; font-size: .82rem; }

/* ---------- forms ---------- */
label {
  display: block; font-size: .85rem; font-weight: 600;
  margin-bottom: 4px; margin-top: 14px; color: var(--text);
}
.label-hint { font-weight: 400; color: var(--text-muted); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
input[type="text"], input[type="password"], input[type="url"], input[type="number"] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .925rem;
  transition: border-color .15s;
}
input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }

.row { display: flex; gap: 12px; }
.col { flex: 1; }

/* ---------- auth card ---------- */
.auth-card {
  max-width: 400px; margin: 80px auto 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 36px 32px;
  box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 1.5rem; margin-bottom: 2px; }
.subtitle { color: var(--text-muted); margin-bottom: 20px; font-size: .95rem; }
.auth-footer { text-align: center; margin-top: 20px; font-size: .9rem; color: var(--text-muted); }

/* ---------- alerts ---------- */
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: .9rem; margin-bottom: 18px;
}
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: var(--danger); }

/* ---------- page title ---------- */
.page-title { font-size: 1.6rem; margin-bottom: 12px; }
.page-intro { color: var(--text-muted); font-size: .92rem; margin-bottom: 28px; max-width: 52rem; line-height: 1.55; }
.page-intro code { font-size: .85em; background: var(--bg); padding: 2px 6px; border-radius: 4px; }
.muted { color: var(--text-muted); }

/* ---------- job UI ---------- */
.job-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  flex-wrap: wrap; gap: 16px; margin-bottom: 20px;
}
.job-header-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.job-meta-line { color: var(--text-muted); font-size: .9rem; margin-top: 6px; }
.job-id { font-size: .82rem; background: var(--bg); padding: 2px 8px; border-radius: 4px; }
.job-params { margin-top: 10px; padding-left: 1.2rem; color: var(--text-muted); font-size: .88rem; }
.job-params li { margin-bottom: 4px; }

.status-badge {
  display: inline-block; margin-left: 8px; padding: 2px 10px; border-radius: 999px;
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
.status-running { background: #fef3c7; color: #92400e; }
.status-completed { background: #d1fae5; color: #065f46; }
.status-failed { background: #fee2e2; color: #991b1b; }
.status-cancelled { background: #e5e7eb; color: #374151; }

.job-named { font-weight: 500; color: var(--text-muted); font-size: 1rem; }

.jobs-search {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin-bottom: 20px; max-width: 40rem;
}
.jobs-search-input {
  flex: 1; min-width: 200px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .925rem;
}
.toolbar-row { margin-bottom: 16px; }

.td-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-actions { white-space: nowrap; text-align: right; }
.inline-form, .inline-form-header { display: inline; margin: 0; padding: 0; }
.inline-form button, .inline-form-header button { margin-left: 8px; }
.btn-link {
  background: none; border: none; padding: 0; margin: 0;
  font: inherit; color: var(--primary); cursor: pointer; text-decoration: underline;
}
.btn-link.danger { color: var(--danger); }
.btn-link:hover { opacity: .85; }

.danger-outline { border-color: #fca5a5; color: #b91c1c; }
.danger-outline:hover { background: #fef2f2; }

.alert-muted {
  padding: 12px 16px; border-radius: var(--radius);
  background: #f3f4f6; border: 1px solid var(--border); color: var(--text-muted);
  margin-bottom: 18px; font-size: .9rem;
}

.section-title { font-size: 1rem; margin: 20px 0 10px; color: var(--text-muted); }

.log-panel {
  background: #1e293b; color: #e2e8f0; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px; line-height: 1.45; padding: 16px; border-radius: var(--radius);
  max-height: min(480px, 60vh); overflow: auto; white-space: pre-wrap; word-break: break-word;
  border: 1px solid var(--border);
}

.job-done { margin-top: 20px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.job-done.hidden { display: none; }
.job-done p { margin-bottom: 10px; }
.job-done p:last-child { margin-bottom: 0; }
.job-done-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ---------- results viewer (CSV table) ---------- */
.results-view-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  flex-wrap: wrap; gap: 16px; margin-bottom: 24px;
}
.results-view-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.results-view-meta { margin-top: 6px; font-size: .9rem; }

.results-filter-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin-bottom: 16px; padding: 14px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.results-filter-input {
  flex: 1; min-width: 200px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .925rem;
}
.results-per-select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .9rem; background: var(--surface);
}

.results-count-line { font-size: .9rem; color: var(--text-muted); margin-bottom: 14px; line-height: 1.5; }
.results-warning { display: block; margin-top: 8px; color: #92400e; font-size: .88rem; }

.results-table-shell {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.results-table-scroll {
  max-height: min(75vh, 880px); overflow: auto;
  overscroll-behavior: contain;
}
.results-data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.results-data-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: #f1f5f9; color: var(--text-muted);
  font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  text-align: left; padding: 12px 14px; border-bottom: 2px solid var(--border);
  white-space: nowrap; box-shadow: 0 1px 0 var(--border);
}
.results-data-table tbody td {
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  vertical-align: top; max-width: 22rem; word-break: break-word;
}
.results-data-table tbody tr:nth-child(even) { background: #f8fafc; }
.results-data-table tbody tr:hover { background: #eff6ff; }
.results-col-idx {
  width: 3.5rem; text-align: right; font-size: 12px; color: var(--text-muted) !important;
  white-space: nowrap; max-width: 4rem !important;
}
.results-cell-link { word-break: break-all; }

.results-pagination {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 20px;
}
.results-page-status { font-size: .9rem; color: var(--text-muted); }

/* ---------- tool grid ---------- */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 24px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 24px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 1.15rem; margin-bottom: 6px; }
.card p { color: var(--text-muted); font-size: .88rem; margin-bottom: 8px; }
.card-icon { font-size: 2rem; margin-bottom: 10px; }

/* ---------- results ---------- */
.results-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  flex-wrap: wrap; gap: 16px; margin-bottom: 24px;
}
.results-header h1 { font-size: 1.4rem; }
.results-meta { color: var(--text-muted); font-size: .92rem; margin-top: 4px; }
.results-actions { display: flex; gap: 10px; flex-shrink: 0; }

.table-wrap {
  overflow-x: auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead { background: var(--bg); }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 700; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); white-space: nowrap; }
td { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td a { word-break: break-all; white-space: normal; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f9fafb; }

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  .tool-grid { grid-template-columns: 1fr; }
  .results-header { flex-direction: column; }
  .row { flex-direction: column; gap: 0; }
  .auth-card { margin-top: 40px; padding: 24px 20px; }
}
