:root {
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #20272e;
  background: #f2f4f5;
  font-size: 14px;
  --surface: #ffffff;
  --surface-subtle: #f7f8f8;
  --border: #d5dadd;
  --border-strong: #aeb8bd;
  --text-muted: #66737b;
  --charcoal: #222a30;
  --green: #187a50;
  --green-hover: #12623f;
  --green-pale: #e9f5ef;
  --amber: #966500;
  --amber-pale: #fff5d6;
  --red: #b42318;
  --red-pale: #fff0ee;
  --blue: #246a8d;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 900px; background: #f2f4f5; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, input, select, textarea { border-radius: 4px; }
input, select, textarea {
  min-height: 34px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--charcoal);
  padding: 7px 9px;
}
textarea { width: 100%; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid #6aa88d;
  outline-offset: 1px;
}
button {
  min-height: 34px;
  border: 1px solid #87949b;
  background: var(--surface);
  color: var(--charcoal);
  padding: 7px 12px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--green); color: var(--green); }
button:disabled { cursor: not-allowed; opacity: .48; }
button.primary { background: var(--green); border-color: var(--green); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--green-hover); border-color: var(--green-hover); color: #fff; }
button.small { min-height: 28px; padding: 4px 9px; font-size: 12px; }
.danger-text { color: var(--red); }
.icon-like { min-width: 56px; }

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 20px;
  background: var(--charcoal);
  color: #f8fafb;
  border-bottom: 3px solid var(--green);
}
.brand-block { min-width: 250px; }
.topbar h1 { margin: 0 0 4px; font-size: 20px; font-weight: 650; letter-spacing: 0; }
.topbar input { background: #303a40; border-color: #64727a; color: #fff; }
.topbar input::placeholder { color: #b9c1c5; }
.topbar button:not(.primary) { background: #303a40; border-color: #64727a; color: #fff; }
.topbar .compact-field { color: #c5ced2; }
.muted { color: var(--text-muted); font-size: 12px; }
.topbar .muted { color: #aebbc1; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar-actions { justify-content: flex-end; }
.compact-field { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.compact-field input { width: 145px; }

.tabs {
  display: flex;
  gap: 3px;
  min-height: 46px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tab {
  min-height: 45px;
  padding: 10px 17px;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: #4a565d;
}
.tab:hover { color: var(--green); }
.tab.active { border-bottom-color: var(--green); color: var(--green); font-weight: 650; }

main { padding: 16px 20px 28px; }
.view { display: none; }
.view.active { display: block; }
.view-toolbar, .section-heading, .panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.view-toolbar { min-height: 44px; margin-bottom: 10px; }
.log-filter-toolbar { flex: 1 1 auto; }
.log-filter-toolbar input[type="date"] { width: 142px; }
.log-filter-toolbar input[type="time"] { width: 112px; }
.log-filter-toolbar input[type="search"] { width: min(260px, 28vw); min-width: 180px; }
.log-pagination { flex: 0 0 auto; flex-wrap: nowrap; }
.section-heading { margin: 2px 0 10px; }
.section-heading h2, .panel-heading h3 { margin: 0; font-size: 15px; letter-spacing: 0; }
.section-heading > div:first-child { display: flex; align-items: baseline; gap: 10px; }
.section-gap { margin-top: 22px; }
.panel-heading { min-height: 36px; margin-bottom: 8px; }

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 10px;
}
.stat { min-height: 70px; padding: 11px 14px; border-right: 1px solid var(--border); }
.stat:last-child { border-right: 0; }
.stat span { color: var(--text-muted); font-size: 12px; }
.stat b { display: block; margin-top: 3px; font-size: 23px; line-height: 1.25; }
.stat.attention b { color: var(--red); }
.stat.running b { color: var(--amber); }
.stat.completed b, .stat.online b { color: var(--green); }
.inline-stats { color: var(--text-muted); font-size: 12px; }
.inline-stats b { color: var(--charcoal); }

.table-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; }
.machine-table-wrap { max-height: calc(100vh - 242px); }
.discovery-table-wrap { max-height: 360px; }
.logs-table-wrap { max-height: calc(100vh - 180px); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid #e5e8e9; text-align: left; vertical-align: middle; white-space: nowrap; }
th { position: sticky; z-index: 1; top: 0; background: #f4f6f6; color: #526068; font-size: 12px; font-weight: 650; }
tbody tr:hover { background: #f3f8f5; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.needs-attention { background: #fff8f1; }
tbody tr.needs-attention:hover { background: #fff1e3; }
.select-cell { width: 38px; text-align: center; }
.select-cell input { min-height: 0; }
.empty-cell { height: 70px; text-align: center; color: var(--text-muted); }
.mono { font-family: Consolas, "SFMono-Regular", monospace; font-size: 12px; }
.attention-cell, .reason-cell, .module-cell, .source-cell, .log-message { max-width: 330px; overflow: hidden; text-overflow: ellipsis; }
.attention-reason { color: var(--red); font-weight: 650; }
.status { display: inline-flex; align-items: center; min-height: 22px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.status.online, .status.completed, .status.run, .status.imported { color: var(--green); }
.status.offline, .status.failed, .status.stopped, .status.stop, .status.attention { color: var(--red); }
.status.leased, .status.running, .status.pending, .status.warning { color: var(--amber); }
.status.paused, .status.pause, .status.preview { color: var(--blue); }
.status.control { color: #7d3aa6; }
.status.neutral { color: var(--text-muted); }
.log-ERROR, .log-CRITICAL { color: var(--red); font-weight: 700; }
.log-WARN { color: var(--amber); font-weight: 650; }
.json-cell { margin: 0; max-width: 520px; max-height: 180px; overflow: auto; white-space: pre-wrap; font-family: Consolas, monospace; font-size: 11px; }
details summary { cursor: pointer; color: var(--green); }

.check-field { display: inline-flex; align-items: center; gap: 7px; color: #4f5c63; white-space: nowrap; }
.check-field input { min-height: 0; margin: 0; }
.editor-grid { display: grid; align-items: end; gap: 10px; margin: 2px 0 14px; }
.editor-grid label:not(.check-field), .settings-grid label:not(.check-field), .control-panel label { display: grid; gap: 5px; color: #58656c; font-size: 12px; }
.target-grid { grid-template-columns: minmax(180px, 2fr) 110px minmax(180px, 2fr) 100px auto auto; }
.editor-check { min-height: 34px; }
.profile-grid { grid-template-columns: 1fr 1fr auto; }
.profile-grid .wide { grid-column: span 3; }
.import-layout { display: grid; grid-template-columns: minmax(390px, .8fr) minmax(560px, 1.2fr); gap: 14px; }
.band { margin-top: 8px; }

dialog { padding: 0; border: 0; border-radius: 6px; box-shadow: 0 18px 70px #0007; }
dialog::backdrop { background: #11181dcc; }
.dialog-shell { background: var(--surface); }
.dialog-header { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 15px; border-bottom: 1px solid var(--border); }
.dialog-header h2 { margin: 0 0 3px; font-size: 17px; letter-spacing: 0; }
.machine-dialog { width: min(1480px, 96vw); max-height: 94vh; }
.machine-dialog .dialog-shell { max-height: 94vh; overflow: auto; }
.task-dialog { width: min(1100px, 92vw); max-height: 84vh; }
.task-details { margin: 14px; max-height: calc(84vh - 88px); }
.machine-meta { display: grid; grid-template-columns: repeat(7, minmax(110px, 1fr)); border-bottom: 1px solid var(--border); background: var(--surface-subtle); }
.machine-meta > div { min-height: 58px; padding: 9px 12px; border-right: 1px solid var(--border); }
.machine-meta > div:last-child { border-right: 0; }
.machine-meta span { display: block; color: var(--text-muted); font-size: 11px; margin-bottom: 4px; }
.machine-meta b { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }

.control-layout { display: grid; grid-template-columns: minmax(560px, 1fr) 310px; gap: 14px; padding: 14px; border-bottom: 1px solid var(--border); }
.snapshot-panel { min-width: 0; }
.snapshot-stage {
  position: relative;
  min-height: 390px;
  max-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  background: #15191c;
  border: 1px solid #343c40;
}
.snapshot-stage img { display: block; width: auto; height: auto; max-width: 100%; max-height: 68vh; user-select: none; }
.snapshot-stage img.clickable { cursor: crosshair; }
.snapshot-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #aab4b9; pointer-events: none; }
.snapshot-empty[hidden] { display: none; }
.snapshot-meta { min-height: 28px; padding-top: 7px; }
.click-marker { position: absolute; width: 18px; height: 18px; border: 2px solid #f5c542; border-radius: 50%; transform: translate(-50%, -50%); opacity: 0; pointer-events: none; }
.click-marker.pulse { animation: marker-pulse .7s ease-out; }
@keyframes marker-pulse { 0% { opacity: 1; transform: translate(-50%, -50%) scale(.45); } 100% { opacity: 0; transform: translate(-50%, -50%) scale(1.65); } }

.control-panel { padding-left: 14px; border-left: 1px solid var(--border); }
.control-panel fieldset { display: grid; gap: 14px; margin: 0; padding: 0; border: 0; }
.field-block { display: grid; gap: 6px; }
.field-label { color: #58656c; font-size: 12px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); }
.segmented button { border-radius: 0; margin-left: -1px; }
.segmented button:first-child { margin-left: 0; border-radius: 4px 0 0 4px; }
.segmented button:last-child { border-radius: 0 4px 4px 0; }
.segmented button.active { position: relative; border-color: var(--green); background: var(--green-pale); color: var(--green); }
.input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.modifier-row { display: flex; align-items: center; gap: 12px; min-height: 28px; }
.modifier-row label { display: inline-flex; align-items: center; gap: 5px; color: #4f5c63; }
.modifier-row input { min-height: 0; }
.command-status { min-height: 38px; margin-top: 14px; padding: 8px 9px; border: 1px solid var(--border); background: var(--surface-subtle); line-height: 1.35; }
.terminal-panel { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.terminal-panel textarea { width: 100%; resize: vertical; min-height: 78px; font-family: Consolas, "Courier New", monospace; }
.terminal-output { min-height: 84px; max-height: 220px; overflow: auto; margin: 8px 0 0; padding: 9px; border: 1px solid var(--border); background: #11171b; color: #dce7ec; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.4 Consolas, "Courier New", monospace; }

.settings-band { padding: 12px 14px 14px; border-bottom: 1px solid var(--border); }
.settings-grid { display: grid; grid-template-columns: 150px 120px minmax(180px, 1fr) minmax(180px, 1fr) auto auto auto; align-items: end; gap: 12px; }
.setting-check { min-height: 34px; }
.advanced-settings { margin-top: 11px; border-top: 1px solid #e3e7e8; padding-top: 9px; }
.advanced-settings summary { display: inline-block; }
.advanced-settings-grid { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)); gap: 10px; margin-top: 10px; }
.advanced-settings-grid label { display: grid; gap: 5px; color: #58656c; font-size: 12px; }
.advanced-settings-grid .wide-setting { grid-column: span 3; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 14px; }
.compact-table { max-height: 270px; }

#toast { position: fixed; z-index: 1000; right: 20px; bottom: 20px; max-width: 440px; padding: 10px 14px; border-radius: 4px; background: var(--charcoal); color: #fff; box-shadow: 0 8px 28px #0005; opacity: 0; transform: translateY(8px); transition: .16s; pointer-events: none; }
#toast.show { opacity: 1; transform: none; }
#toast.error { background: #8f2119; }

@media (max-width: 1180px) {
  .view-toolbar { align-items: flex-start; flex-direction: column; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat { border-bottom: 1px solid var(--border); }
  .import-layout { grid-template-columns: 1fr; }
  .target-grid { grid-template-columns: 1fr 1fr 1fr; }
  .settings-grid { grid-template-columns: repeat(3, 1fr); }
  .advanced-settings-grid { grid-template-columns: repeat(3, 1fr); }
  .machine-meta { grid-template-columns: repeat(3, 1fr); }
}
