* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  margin: 0;
  padding: 0;
  background: #f5f6fa;
  color: #2c3e50;
}
.container { max-width: 1280px; margin: 0 auto; padding: 20px; }
.hidden { display: none !important; }
.muted { color: #666; font-size: 13px; }
.diff { color: #cf222e; }

/* ===== Auth views (login/setup) ===== */
.auth-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.auth-card {
  background: #fff;
  border-radius: 12px;
  padding: 40px;
  width: 360px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
  text-align: center;
}
.auth-card h1 {
  margin: 0 0 4px;
  font-size: 28px;
  color: #0969da;
}
.auth-card .subtitle {
  margin: 0 0 28px;
  color: #666;
  font-size: 14px;
}
.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.auth-card input {
  padding: 10px 14px;
  border: 1px solid #d0d7de;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
.auth-card input:focus { border-color: #0969da; }

/* ===== Buttons ===== */
.btn {
  padding: 6px 14px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  background: #f6f8fa;
  cursor: pointer;
  font-size: 13px;
  transition: background .15s;
}
.btn:hover { background: #eaeef2; }
.btn.active { background: #0969da; color: #fff; border-color: #0969da; }
.btn-primary {
  background: #0969da;
  color: #fff;
  border-color: #0969da;
  padding: 10px 14px;
  font-size: 14px;
}
.btn-primary:hover { background: #0860c7; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger {
  background: #fff;
  color: #cf222e;
  border-color: #cf222e;
}
.btn-danger:hover { background: #ffebe9; }

/* ===== App header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 32px;
}
.header-left h1 {
  margin: 0;
  font-size: 20px;
  color: #0969da;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-info { font-size: 13px; color: #666; }
nav { display: flex; gap: 4px; }
.nav-btn {
  padding: 6px 16px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  color: #666;
  border-radius: 6px;
  transition: all .15s;
}
.nav-btn:hover { background: #f0f0f0; }
.nav-btn.active {
  background: #eef5ff;
  color: #0969da;
  font-weight: 500;
}

/* ===== Cards ===== */
.card {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.card h2 { margin: 0 0 12px; font-size: 17px; }

/* ===== Picker ===== */
.picker-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 12px;
}
.picker-row label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; font-weight: 500;
}
.picker-row select {
  padding: 8px 10px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
}
.dropzone {
  border: 2px dashed #d0d7de;
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  color: #666;
  font-size: 13px;
  transition: background .15s, border-color .15s;
}
.dropzone.dragover {
  background: #eef5ff;
  border-color: #0969da;
  color: #0969da;
}
.dropzone p { margin: 0; }
.link { color: #0969da; cursor: pointer; text-decoration: underline; }
.link input[type=file] { display: none; }

/* ===== Meta ===== */
.meta {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 16px;
  align-items: center;
}
.meta h3 { margin: 0 0 6px; font-size: 15px; }
.meta-summary { font-size: 14px; text-align: right; }
.meta-summary b { font-size: 18px; }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 5;
}
.toolbar .filters { display: flex; gap: 6px; }
.toolbar input[type=search] {
  margin-left: auto;
  padding: 6px 10px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  font-size: 13px;
  width: 260px;
}

/* ===== Tables ===== */
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #eaeef2;
  font-size: 13px;
  vertical-align: top;
}
th { background: #f6f8fa; font-weight: 600; user-select: none; }
tbody tr:hover td { background: #f6f8fa; }
tr.mismatch td { background: #fff5f5; }
tr.mismatch:hover td { background: #ffebeb; }
tr.match td.val { color: #888; }
col.c-idx     { width: 56px; }
col.c-status  { width: 84px; }
col.c-section { width: 110px; }
col.c-item    { width: 200px; }
td.idx { color: #999; text-align: right; }
td.section { color: #0969da; font-weight: 500; }
td.item { overflow-wrap: anywhere; }
td.val {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-height: 140px;
  overflow-y: auto;
  white-space: pre-wrap;
}
td.status { text-align: center; white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}
.badge.ok  { background: #dafbe1; color: #1a7f37; }
.badge.bad { background: #ffebe9; color: #cf222e; }

.section-header td {
  background: #eef3fb !important;
  font-weight: 600;
  color: #0969da;
  cursor: pointer;
  user-select: none;
}
.section-header .arrow {
  display: inline-block;
  width: 14px;
  transition: transform .15s;
}
.section-header.collapsed .arrow { transform: rotate(-90deg); }
tr.hidden { display: none; }
.section-diff-count { color: #cf222e; font-weight: 400; font-size: 12px; margin-left: 8px; }

.empty { text-align: center; color: #888; padding: 40px 20px; }

/* ===== Script card ===== */
.script-card { max-width: 800px; }
.robot-dir-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
}
.robot-dir-box label { font-size: 13px; color: #444; }
.robot-dir-box input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  font-size: 13px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
.command-box {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin: 12px 0;
}
.command-box code {
  flex: 1;
  padding: 12px 16px;
  background: #1e1e2e;
  color: #cdd6f4;
  border-radius: 8px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  word-break: break-all;
  white-space: pre-wrap;
  line-height: 1.5;
}
.command-box .btn { white-space: nowrap; align-self: center; }
.command-box-hidden {
  align-items: center;
}
.command-placeholder {
  flex: 1;
  padding: 12px 16px;
  background: #f0f0f0;
  color: #888;
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
}
.hint { color: #888; font-size: 12px; margin: 8px 0 0; }
.hint a { color: #0969da; }

/* ===== Users table ===== */
.add-user-form {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.add-user-form input,
.add-user-form select {
  padding: 8px 12px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  font-size: 13px;
}
.users-table { table-layout: auto; }
.users-table th, .users-table td { white-space: nowrap; }

/* ===== Reports management ===== */
.reports-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.reports-toolbar #reports-summary {
  margin-left: auto;
}
.reports-table { table-layout: auto; }
.reports-table th, .reports-table td { white-space: nowrap; }
.reports-table td.machine-id {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  color: #096;
}
.reports-table td.filename {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  color: #666;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reports-table tr.group-head td {
  background: #f0f4f8;
  font-weight: 600;
  color: #444;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.reports-table tr.group-head td::before {
  content: "▸ ";
  display: inline-block;
  transition: transform .15s;
}
.reports-table tr.group-head.collapsed td::before { content: "▸ "; }
.reports-table tr.group-head:not(.collapsed) td::before { content: "▾ "; }
.reports-table tr.hidden { display: none; }
.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}
.role-badge.admin { background: #fff1e5; color: #bc4c00; }
.role-badge.user { background: #ddf4ff; color: #0969da; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.4);
}
.modal-window {
  position: relative;
  background: #fff;
  border-radius: 10px;
  width: min(1280px, 96vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 48px rgba(0,0,0,.25);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid #eaeef2;
  font-size: 16px;
  font-weight: 600;
}
.modal-close {
  border: none;
  background: transparent;
  font-size: 24px;
  cursor: pointer;
  color: #888;
  padding: 0 8px;
  line-height: 1;
}
.modal-close:hover { color: #cf222e; }
.modal-meta {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid #eaeef2;
  background: #fafbfc;
}
.modal-meta h3 { margin: 0 0 6px; font-size: 15px; }
.modal-meta .meta-summary { font-size: 14px; text-align: right; }
.modal-meta .meta-summary b { font-size: 18px; }
.modal-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 20px;
  border-bottom: 1px solid #eaeef2;
  flex-wrap: wrap;
}
.modal-toolbar .filters { display: flex; gap: 6px; }
.modal-toolbar input[type=search] {
  margin-left: auto;
  padding: 6px 10px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  font-size: 13px;
  width: 200px;
}
.modal-result {
  flex: 1;
  overflow: auto;
  padding: 0 20px 20px;
}
.modal-result table { width: 100%; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #2c3e50;
  color: #fff;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  z-index: 100;
}
.toast.error { background: #cf222e; }
.toast.success { background: #1a7f37; }
