:root {
  --bg: #f5f7fb;
  --nav: #071b3a;
  --primary: #2f6fd0;
  --primary-soft: #eef6ff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #dce3ef;
  --line-soft: #eef2f7;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --terminal: #0f172a;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1180px;
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 9px;
  padding: 0 16px;
  min-height: 34px;
  color: #fff;
  background: var(--primary);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button.danger {
  background: var(--danger);
}

.secondary {
  border: 1px solid var(--line);
  color: var(--primary);
  background: #fff;
}

.small {
  min-height: 26px;
  padding: 0 12px;
  font-size: 12px;
}

.app-shell {
  display: grid;
  grid-template-columns: 182px 1fr;
  min-height: 100vh;
}

.side-nav {
  min-height: 100vh;
  padding: 16px;
  background: var(--nav);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  margin-bottom: 8px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: var(--primary);
  background: #fff;
  font-size: 11px;
  font-weight: 700;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  color: #fff;
  font-size: 14px;
}

.brand small {
  color: #9fb3d1;
  font-size: 9px;
}

.nav-item {
  justify-content: flex-start;
  width: 100%;
  height: 38px;
  padding: 0 14px;
  color: #eaf2ff;
  background: rgb(255 255 255 / 12%);
  text-align: left;
}

.page {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 16px;
  padding: 16px;
}

.command-bar,
.bin-panel,
.status-card,
.log-panel {
  border: 1px solid var(--line-soft);
  border-radius: 20px;
  background: #fff;
}

.command-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  border-color: #d5dce8;
  border-radius: 10px;
  padding: 0 16px;
}

.command-device-summary {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.command-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

.command-button {
  min-width: 150px;
  min-height: 40px;
  border-radius: 10px;
}

.command-button.secondary {
  color: #334155;
  border-color: #d5dce8;
}

.section-heading h1,
.section-heading h2,
.status-title h2,
.log-title h2 {
  margin: 0;
  font-size: 20px;
}

.section-heading p,
.log-title p,
.bin-footer p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.section-heading.compact h1 {
  font-size: 20px;
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(780px, 1fr) 322px;
  gap: 16px;
}

.bin-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 500px;
  padding: 20px;
}

.bin-head,
.bin-footer,
.log-title,
.status-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.add-bin-button {
  display: grid;
  place-items: center;
  min-width: 150px;
  height: 38px;
  border: 1px solid var(--primary);
  border-radius: 9px;
  color: var(--primary);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}

.add-bin-button input {
  display: none;
}

.bin-table-wrap {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.bin-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}

.bin-table th,
.bin-table td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: middle;
}

.bin-table th:last-child,
.bin-table td:last-child {
  border-right: 0;
}

.bin-table tr:last-child td {
  border-bottom: 0;
}

.bin-table th {
  height: 44px;
  color: #334155;
  background: #f8fafc;
  font-weight: 600;
}

.bin-table td {
  height: 52px;
}

.enabled-col {
  width: 48px;
  text-align: center;
}

.file-path-col {
  width: 44%;
}

.start-address-col {
  width: 120px;
}

.length-col {
  width: 178px;
}

.replace-col {
  width: 74px;
}

.delete-col {
  width: 72px;
}

.file-path-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.start-address-cell,
.length-cell {
  color: var(--text);
  white-space: nowrap;
}

.editable-hex-field {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.hex-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 118px;
  min-width: 0;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 8px;
  background: transparent;
}

.hex-input-wrap input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  border: 0;
  padding: 0;
}

.hex-input-wrap span {
  color: #cbd5e1;
  font-size: 13px;
}

.editable-hex-field.invalid .hex-input-wrap span,
.editable-hex-field small {
  color: var(--danger);
}

.editable-hex-field small {
  font-size: 11px;
  line-height: 1.2;
}

.readonly-hex {
  display: inline-block;
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.bin-table input[type="text"] {
  height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 8px;
  background: transparent;
}

.bin-table input[type="text"]:focus {
  border-color: var(--primary);
  outline: none;
  background: #fff;
}

.bin-table .hex-input-wrap input[type="text"],
.bin-table .hex-input-wrap input[type="text"]:focus {
  width: auto;
  height: 100%;
  border: 0;
  padding: 0;
  background: transparent;
}

.hex-input-wrap:focus-within {
  border-color: var(--primary);
  background: #fff;
}

.hex-input-wrap input:focus {
  border-color: transparent;
}

.editable-hex-field.invalid .hex-input-wrap,
.editable-hex-field.invalid .hex-input-wrap:focus-within {
  border-color: var(--danger);
  color: var(--danger);
  background: #fff;
}

.editable-hex-field.invalid input {
  color: var(--danger);
}

.row-action {
  color: var(--primary);
  background: transparent;
  min-height: 28px;
  padding: 0 6px;
}

.row-action.delete {
  color: var(--danger);
}

.empty-row td {
  height: 156px;
  color: var(--muted);
  text-align: center;
}

.status-column {
  display: grid;
  grid-template-rows: 142px 106px 180px;
  gap: 14px;
}

.status-card {
  padding: 14px;
  overflow: hidden;
}

.status-title h2 {
  font-size: 15px;
}

.status-title span {
  color: var(--muted);
  font-size: 11px;
}

.check-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.check-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  border: 1px solid #e5eaf2;
  border-radius: 8px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.check-list li::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #cbd5e1;
}

.check-list li.ok {
  color: #10a85a;
}

.check-list li.ok::before {
  background: var(--ok);
}

.check-list li.warn::before {
  background: var(--warn);
}

.config-summary {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  font-size: 11px;
}

.config-summary div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.config-summary dt {
  color: var(--muted);
}

.config-summary dd {
  margin: 0;
  color: var(--text);
  text-align: right;
}

.task-snapshot {
  display: grid;
  gap: 6px;
  margin-top: 8px;
  font-size: 11px;
}

.task-progress-row,
.task-step-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2e8f0;
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.current-phase {
  display: grid;
  gap: 3px;
  border-radius: 10px;
  padding: 6px 10px;
  background: #f8fafc;
}

.current-phase strong {
  font-size: 12px;
  font-weight: 500;
}

.current-phase span,
.task-step-row {
  color: var(--muted);
}

.task-step-ok {
  color: #10a85a;
}

.task-step-active {
  color: var(--primary);
}

.task-step-pending {
  color: #94a3b8;
}

.task-step-failed {
  color: var(--danger);
}

.log-panel {
  border-radius: 0;
  padding: 12px;
}

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

#process-log {
  height: 178px;
  margin: 8px 0 0;
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
  color: #c7d2fe;
  background: var(--terminal);
  font-size: 12px;
  white-space: pre-wrap;
}

.config-dialog {
  width: min(600px, 92vw);
  border: 0;
  border-radius: 16px;
  padding: 0;
  background: #f3f6fc;
}

.config-dialog::backdrop {
  background: rgb(0 0 0 / 35%);
}

.config-dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  height: 56px;
  border-bottom: 1px solid var(--line);
  padding: 0 16px;
  background: #fff;
}

.config-dialog header h2 {
  margin: 0;
  font-size: 18px;
}

.config-dialog header button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  color: #111;
  background: transparent;
  font-size: 28px;
}

.dialog-field-list,
.config-option-group,
.config-preview {
  margin: 16px;
  border-radius: 10px;
  padding: 12px;
  background: #fff;
}

.dialog-field-list {
  padding: 0;
  overflow: hidden;
}

.dialog-field {
  display: grid;
  grid-template-columns: 170px 1fr;
  align-items: center;
  min-height: 68px;
  border-bottom: 1px solid #edf2f7;
  padding: 0 14px;
  font-size: 14px;
}

.dialog-field:last-child {
  border-bottom: 0;
}

.dialog-field span {
  color: var(--text);
}

.dialog-field strong {
  font-size: 14px;
  font-weight: 600;
}

.dialog-field select {
  height: 34px;
  border: 0;
  color: var(--text);
  background: transparent;
}

.dialog-hint {
  margin: 0 16px;
  color: var(--muted);
  font-size: 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 16px;
}

.config-option-group {
  display: grid;
  gap: 8px;
}

.config-option-group.compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.config-option-group h3 {
  margin: 0;
  font-size: 13px;
}

.config-option-group p,
.config-preview span {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 13px;
}

.config-preview {
  display: grid;
  gap: 6px;
  background: #ecfdf5;
}

.config-preview strong,
.config-preview span {
  color: #047857;
}

.switch input {
  display: none;
}

.switch span {
  display: block;
  width: 50px;
  height: 28px;
  border-radius: 999px;
  background: #cbd5e1;
  position: relative;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.16s ease;
}

.switch input:checked + span {
  background: #45ad52;
}

.switch input:checked + span::after {
  transform: translateX(22px);
}
