:root {
  --bg: #f2f5f7;
  --surface: #ffffff;
  --border: #dde4ea;
  --text: #1b2633;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #eef2ff;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.brand-mark svg {
  width: 20px;
  height: 20px;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.base-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.base-picker select {
  height: 36px;
  padding: 0 30px 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  outline: none;
  cursor: pointer;
}

.base-picker select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}
  text-decoration: none;

.btn:hover {
  border-color: var(--border);
}

.btn svg {
  width: 17px;
  height: 17px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--accent);
  border-color: #b9c8f2;
  background: #f6f8ff;
}

.icon-btn.danger:hover {
  color: var(--red);
  border-color: #f3c4c4;
  background: #fef5f5;
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-head {
  padding: 16px 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0;
}

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

.upload-grid {
  display: grid;
  grid-template-columns: 1.05fr 1.15fr;
  gap: 20px;
  padding: 16px 20px 20px;
}

.dropzone {
  border: 1.5px dashed #b6c2d1;
  border-radius: 8px;
  min-height: 232px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #fafbfc;
  cursor: pointer;
  text-align: center;
  padding: 20px;
  outline: none;
}

.dropzone:hover,
.dropzone.dragover,
.dropzone:focus-visible {
  border-color: var(--accent);
  background: #f5f8ff;
}

.dropzone svg {
  width: 34px;
  height: 34px;
  color: var(--accent);
}

.dropzone-main {
  font-weight: 600;
}

.dropzone-sub {
  color: var(--muted);
  font-size: 12px;
}

.file-meta {
  margin-top: 8px;
  padding: 8px 10px;
  background: #eef4ff;
  color: var(--accent-strong);
  border-radius: 8px;
  font-size: 12px;
  word-break: break-all;
  max-width: 100%;
}

.form-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span {
  font-size: 12px;
  color: #334155;
  font-weight: 500;
}

.field em {
  color: var(--red);
  font-style: normal;
}

.field input,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  outline: none;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.field textarea {
  resize: vertical;
  min-height: 78px;
}

.password-input {
  display: flex;
  gap: 8px;
}

.password-input input {
  flex: 1;
  min-width: 0;
}

.password-input .icon-btn {
  flex: none;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-track {
  flex: 1;
  height: 8px;
  background: #e6ebf1;
  border-radius: 8px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.15s;
}

#progressText {
  font-size: 12px;
  color: var(--muted);
  min-width: 38px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.list-panel {
  padding-bottom: 6px;
}

.list-head {
  padding-bottom: 14px;
}

.list-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.search-box svg {
  width: 15px;
  height: 15px;
  color: var(--muted);
  flex: none;
}

.search-box input {
  border: 0;
  outline: 0;
  width: 190px;
  background: transparent;
}

.count-label {
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
}

.firmware-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1160px;
}

.firmware-table th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  white-space: nowrap;
}

.firmware-table td {
  padding: 11px 14px;
  border-bottom: 1px solid #eef2f5;
  vertical-align: middle;
  font-size: 13px;
}

.firmware-table tbody tr:hover {
  background: #f8fafc;
}

.firmware-table tbody tr.active-row {
  background: #f3faf6;
}

.version-badge {
  display: inline-block;
  font-family: Consolas, monospace;
  font-weight: 600;
  background: #eef4ff;
  color: var(--accent-strong);
  border: 1px solid #cddcff;
  border-radius: 6px;
  padding: 3px 8px;
  white-space: nowrap;
}

.device-code {
  display: inline-block;
  font-family: Consolas, monospace;
  font-size: 12px;
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #d7dee6;
  border-radius: 6px;
  padding: 2px 8px;
  white-space: nowrap;
}

.file-name {
  display: block;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hash {
  font-family: Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
}

.num {
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  background: #eef1f4;
  color: #475569;
  white-space: nowrap;
}

.badge-active {
  background: #dcfce7;
  color: #15803d;
}

.actions-col {
  width: 232px;
}

.actions-cell {
  white-space: nowrap;
}

.actions-cell .icon-btn {
  margin-right: 4px;
}

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
}

.empty-state svg {
  width: 34px;
  height: 34px;
  color: #9aa7b5;
}

.empty-state p {
  margin: 8px 0 0;
}

.latest-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 20px;
  flex-wrap: wrap;
}

.latest-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
}

.latest-icon {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #ecfdf5;
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.latest-icon svg {
  width: 19px;
  height: 19px;
}

.latest-info h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0;
}

.latest-info p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.latest-info code {
  background: #eef1f4;
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 12px;
}

.latest-urls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  flex: 1;
  max-width: 640px;
}

.url-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
}

.url-row span {
  width: 110px;
  flex: none;
  font-size: 12px;
  color: var(--muted);
}

.url-row code {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-family: Consolas, monospace;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(16px);
  background: #16202c;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: 0.2s;
  max-width: min(90vw, 560px);
  word-break: break-all;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: min(680px, 100%);
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0;
}

.modal-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  word-break: break-all;
}

.modal-body {
  padding: 16px 20px 20px;
  display: grid;
  gap: 16px;
}

.modal-password-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.modal-password-row .field {
  flex: 1;
  min-width: 0;
}

.modal-urls {
  display: grid;
  gap: 8px;
}

.modal .url-row span {
  width: 110px;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-head {
  text-align: center;
  margin-bottom: 20px;
}

.auth-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: 8px;
  background: #eef2ff;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-icon svg {
  width: 24px;
  height: 24px;
}

.auth-head h1 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0;
}

.auth-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-error {
  min-height: 18px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--red);
  text-align: center;
}

.docs-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 20px;
  flex-wrap: wrap;
}

.docs-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
}

.docs-icon {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #fef3c7;
  color: #b45309;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.docs-icon svg {
  width: 19px;
  height: 19px;
}

.docs-info h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0;
}

.docs-info p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.docs-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.docs-actions .btn svg {
  width: 17px;
  height: 17px;
}

.devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  padding: 16px 20px 20px;
}

.device-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafbfc;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.device-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.device-count {
  font-size: 12px;
  color: var(--muted);
}

.device-card-versions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.device-card-versions > div {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}

.device-card-versions span {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.device-card-versions strong {
  font-family: Consolas, monospace;
  font-size: 13px;
  word-break: break-all;
}

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

.device-card-actions .btn {
  flex: 1;
  height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.device-filter {
  height: 34px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  outline: none;
}

@media (max-width: 860px) {
  .topbar-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .upload-grid {
    grid-template-columns: 1fr;
  }

  .latest-panel {
    flex-direction: column;
    align-items: flex-start;
  }

  .latest-urls {
    max-width: 100%;
    width: 100%;
  }

  .search-box input {
    width: 150px;
  }
}

.app-shell {
  display: flex;
  align-items: flex-start;
  min-height: calc(100vh - 69px);
}

.sidebar {
  width: 220px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 12px;
  min-height: calc(100vh - 69px);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  text-align: left;
}

.nav-btn:hover {
  background: #f1f5f9;
  color: var(--text);
}

.nav-btn.active {
  background: #eef2ff;
  color: var(--accent-strong);
  font-weight: 500;
}

.nav-btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.main-content {
  flex: 1;
  min-width: 0;
  padding: 20px;
}

.view {
  display: none;
  flex-direction: column;
  gap: 16px;
}

.view.active {
  display: flex;
}

.panel-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

@media (max-width: 860px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
  }
  .side-nav {
    flex-direction: row;
    overflow-x: auto;
  }
  .nav-btn {
    flex: none;
    width: auto;
    padding: 0 12px;
  }
  .main-content {
    padding: 14px;
  }
}
