:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d7dde5;
  --text: #18202a;
  --muted: #657386;
  --accent: #1769aa;
  --danger: #b42318;
  --ok: #16703a;
}

* { box-sizing: border-box; }
html { overflow-x: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  background: #101820;
  color: #fff;
}
header a { color: #fff; }
.brand-link {
  color: #fff;
  font-weight: 800;
  min-width: 0;
}
.brand-link strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.portal-links {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.portal-links a {
  padding: 6px 9px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-weight: 700;
  font-size: 0.92rem;
  white-space: nowrap;
}
.portal-links a:hover {
  background: rgba(255, 255, 255, 0.16);
}
.header-spacer { flex: 1; }
.user-menu {
  position: relative;
  margin-left: auto;
}
.user-menu summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
  font-weight: 700;
  padding: 6px 8px;
  border-radius: 6px;
}
.user-menu[open] summary { background: rgba(255, 255, 255, 0.12); }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu-panel {
  position: fixed;
  top: 58px;
  right: 22px;
  z-index: 1000;
  width: min(340px, calc(100vw - 20px));
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 12px 32px rgba(16, 24, 32, 0.2);
  display: grid;
  gap: 6px;
}
.user-menu-panel a,
.user-menu-panel button {
  width: 100%;
  display: block;
  text-align: left;
  border-radius: 6px;
}
.user-menu-panel a {
  color: var(--text);
  padding: 8px 10px;
  background: #fff;
  border: 1px solid transparent;
}
.user-menu-panel a:hover {
  background: #eef2f6;
  border-color: var(--line);
}
.user-menu-panel form { margin: 6px 0 0; }
nav { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.nav-feedback {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  line-height: 1.05;
}
.nav-badge {
  display: inline-block;
  min-width: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #ffcc4d;
  color: #101820;
  font-weight: 800;
  text-align: center;
}
main { padding: 20px; max-width: 1800px; margin: 0 auto; }
.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}
.dashboard-side {
  position: sticky;
  top: 16px;
}
.side-toolbar {
  justify-content: space-between;
}
.side-toolbar h2 { margin: 0; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.grid { display: grid; gap: 12px; }
.grid.cols { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
label { display: block; font-weight: 600; margin-bottom: 4px; }
input, select, button, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
input, select, textarea { width: 100%; background: #fff; }
.compact-input,
.compact-select {
  min-width: 150px;
}
.check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-weight: 400;
  white-space: nowrap;
}
.check-label input {
  width: auto;
}
button, .button {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  cursor: pointer;
}
button.secondary, .button.secondary { background: #fff; color: var(--accent); }
.small-button { padding: 5px 8px; border-radius: 6px; white-space: nowrap; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #eef2f6; }
.muted { color: var(--muted); }
.status-pending, .status-running { color: #8a5a00; font-weight: 700; }
.status-finished { color: var(--ok); font-weight: 700; }
.status-failed { color: var(--danger); font-weight: 700; }
.progress-block {
  margin: 12px 0 4px;
}
.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.95rem;
}
.progress-bar {
  position: relative;
  height: 14px;
  overflow: hidden;
  border: 1px solid #b9d7fb;
  border-radius: 999px;
  background: #e8f2ff;
}
.progress-bar-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -35%;
  width: 35%;
  border-radius: 999px;
  background: linear-gradient(90deg, #1769aa, #2ea3f2);
  animation: progress-slide 1.25s ease-in-out infinite;
}
@keyframes progress-slide {
  0% { left: -35%; }
  100% { left: 100%; }
}
.source-progress-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.source-progress-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
.source-progress-item small {
  grid-column: 2 / 4;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.source-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #8a5a00;
}
.source-finished .source-dot { background: var(--ok); }
.source-failed .source-dot { background: var(--danger); }
.source-running .source-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(23, 105, 170, 0.14);
}
.tabs { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.tab { padding: 8px 12px; background: #e7edf4; border-radius: 6px; cursor: pointer; }
.tab.active { background: var(--accent); color: #fff; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.inner-tabs { margin-top: 4px; }
.inner-tab {
  padding: 8px 12px;
  background: #eef2f6;
  color: var(--accent);
  border-radius: 6px;
  cursor: pointer;
}
.inner-tab.active {
  background: var(--accent);
  color: #fff;
}
.inner-tab-panel { display: none; }
.inner-tab-panel.active { display: block; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.inline-label { margin: 0 0 0 8px; }
.toolbar-search { flex: 1 1 360px; min-width: 220px; }
.labor-summary { display: none; }
.selected-row { background: #eaf5ff; }
.error { color: var(--danger); font-weight: 700; }
.setup-note {
  background: #fff7df;
  border: 1px solid #f2d27a;
  border-radius: 8px;
  padding: 10px 12px;
  color: #5f4700;
}
.portal-warning,
.portal-info {
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.portal-warning {
  background: #fdeceb;
  border: 1px solid #efb3ad;
  color: #681d17;
}
.portal-info {
  background: #e8f2ff;
  border: 1px solid #b9d7fb;
  color: #173d63;
}
.portal-warning p,
.portal-info p { margin: 6px 0; }
.portal-warning ul { margin: 8px 0 12px 18px; padding: 0; }
.feedback-status {
  display: inline-block;
  min-width: 82px;
  text-align: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 700;
}
.feedback-open { background: #fff4ce; color: #6b4d00; }
.feedback-reviewing { background: #e4f0ff; color: #174a7c; }
.feedback-done { background: #e7f5e7; color: var(--ok); }
.text-preview {
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #f7f9fb;
}
.version-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.version-grid > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}
@media (max-width: 1050px) {
  .dashboard-layout { grid-template-columns: 1fr; }
  .dashboard-side { position: static; }
}
.recall-done { background: #e9f7ef; }
.recall-open { background: #fdeceb; }
.recall-badge {
  display: inline-block;
  min-width: 92px;
  text-align: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 700;
}
.recall-done .recall-badge { background: #cfeedd; color: var(--ok); }
.recall-open .recall-badge { background: #f8d0cc; color: var(--danger); }
.table-wrap { max-height: 70vh; overflow: auto; border: 1px solid var(--line); background: #fff; }
.labor-tree-table { min-width: 1100px; }
.labor-tree-table thead th { position: sticky; top: 0; z-index: 1; }
.labor-hidden { display: none; }
.labor-category { background: #f6f8fb; font-weight: 700; }
.labor-category[data-open="true"] { background: #eef4fa; }
.tree-cell { padding-left: calc(10px + (var(--depth) * 22px)); white-space: nowrap; }
.tree-toggle {
  width: 22px;
  height: 22px;
  padding: 0;
  margin-right: 6px;
  line-height: 20px;
  text-align: center;
  background: #fff;
  color: var(--accent);
}
.static-toggle {
  display: inline-block;
  cursor: default;
}
.service-config-wrap {
  max-height: 42vh;
  margin-bottom: 16px;
}
.service-config-table th:first-child,
.service-config-table td:first-child { width: 30%; }
.service-config-table th:nth-child(2),
.service-config-table td:nth-child(2) { width: 28%; }
.service-config-table th:last-child,
.service-config-table td:last-child { width: 42%; text-align: left; }
.node-count {
  color: var(--muted);
  font-weight: 600;
  margin-left: 8px;
}
.pick-button { min-width: 86px; padding: 5px 8px; }
.selected-row .pick-button { background: var(--ok); color: #fff; border-color: var(--ok); }
.labor-tree-table th:first-child,
.labor-tree-table td:first-child { width: 31%; }
.labor-tree-table th:nth-child(2),
.labor-tree-table td:nth-child(2) { width: 100px; text-align: center; }
.labor-tree-table th:nth-child(3),
.labor-tree-table td:nth-child(3) { width: 150px; }
.labor-tree-table th:last-child,
.labor-tree-table td:last-child,
.number-cell { width: 110px; text-align: right; }

@media (max-width: 760px) {
  header {
    padding: 10px 12px;
    gap: 8px;
  }
  .brand-link {
    flex: 1 1 auto;
    max-width: calc(100vw - 118px);
    font-size: 0.95rem;
  }
  .portal-links {
    order: 3;
    flex: 1 0 100%;
    gap: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-top: 2px;
    scrollbar-width: thin;
  }
  .portal-links a {
    flex: 0 0 auto;
    font-size: 0.86rem;
    padding: 6px 8px;
  }
  .header-spacer { display: none; }
  .user-menu summary {
    max-width: 46vw;
    font-size: 0.9rem;
  }
  .user-menu summary span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .user-menu-panel {
    top: 54px;
    left: 10px;
    right: 10px;
    width: auto;
  }
  main {
    width: 100%;
    padding: 10px;
  }
  .panel,
  .portal-warning,
  .portal-info {
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 6px;
  }
  h1 { font-size: 1.45rem; }
  h2 { font-size: 1.2rem; }
  h3 { font-size: 1.05rem; }
  .grid.cols {
    grid-template-columns: 1fr;
  }
  input,
  select,
  textarea,
  button,
  .button {
    min-height: 42px;
  }
  .toolbar {
    align-items: stretch;
  }
  .toolbar > * {
    flex: 1 1 100%;
  }
  .toolbar .inline-label {
    flex-basis: auto;
    margin-left: 0;
  }
  .toolbar-search {
    min-width: 0;
    flex-basis: 100%;
  }
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }
  .tab,
  .inner-tab {
    flex: 0 0 auto;
    white-space: nowrap;
  }
  table {
    display: block;
    overflow-x: auto;
    max-width: 100%;
    white-space: nowrap;
  }
  th,
  td {
    padding: 8px;
    max-width: 72vw;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .table-wrap {
    max-width: 100%;
    max-height: 62vh;
    overflow: auto;
  }
  .labor-tree-table {
    min-width: 820px;
  }
  .labor-tree-table th:first-child,
  .labor-tree-table td:first-child { width: 260px; }
  .labor-tree-table th:nth-child(2),
  .labor-tree-table td:nth-child(2) { width: 95px; }
  .labor-tree-table th:nth-child(3),
  .labor-tree-table td:nth-child(3) { width: 120px; }
  .tree-cell {
    white-space: normal;
    min-width: 230px;
  }
  .tree-toggle {
    min-width: 28px;
    height: 28px;
    line-height: 26px;
  }
  .pick-button,
  .small-button {
    width: 100%;
    min-width: 0;
    white-space: normal;
  }
  .service-config-wrap {
    max-height: 56vh;
  }
  .version-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 761px) and (max-width: 1180px) {
  main { padding: 14px; }
  .dashboard-layout {
    grid-template-columns: minmax(0, 1fr) 300px;
  }
  .labor-tree-table {
    min-width: 980px;
  }
}
