/* Dragino OTA Console
   Design tokens + light/dark themes. Dense admin dashboard layout. */

:root {
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --surface-3: #E2E8F0;
  --border: #E2E8F0;
  --text: #0F172A;
  --text-2: #475569;
  --text-3: #94A3B8;

  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --primary-soft: #EFF6FF;
  --on-primary: #FFFFFF;

  --ok: #059669;
  --ok-soft: #ECFDF5;
  --warn: #D97706;
  --warn-soft: #FFFBEB;
  --bad: #DC2626;
  --bad-soft: #FEF2F2;
  --muted: #64748B;
  --muted-soft: #F1F5F9;

  --ring: #2563EB;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, .12);
  --radius: 10px;
  --radius-sm: 8px;
  --space: 4px;
  --font: "Fira Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0B1220;
  --surface: #111A2C;
  --surface-2: #182338;
  --surface-3: #243352;
  --border: #22304A;
  --text: #E6EDF7;
  --text-2: #A9B7CC;
  --text-3: #64748B;
  --primary: #3B82F6;
  --primary-hover: #60A5FA;
  --primary-soft: #16233F;
  --ok: #34D399;
  --ok-soft: #0D2B22;
  --warn: #FBBF24;
  --warn-soft: #2B210D;
  --bad: #F87171;
  --bad-soft: #321520;
  --muted: #7C8BA3;
  --muted-soft: #1B2740;
  --ring: #60A5FA;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
code, pre, .mono { font-family: var(--mono); }

:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: 4px;
}

.hidden { display: none !important; }

/* ---------------- top bar ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--primary);
  color: var(--on-primary);
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; font-weight: 700; }
.brand-text small { color: var(--text-3); font-size: 11px; letter-spacing: .04em; }

.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-weight: 600;
  padding: 8px 14px;
  min-height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--primary-soft); color: var(--primary); }

.top-actions { display: flex; align-items: center; gap: 8px; }
#token-input {
  width: 200px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
#token-input:focus { border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 18%, transparent); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
}
.icon-btn:hover { color: var(--text); border-color: var(--surface-3); background: var(--surface-2); }
.icon-btn .icon { width: 18px; height: 18px; }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ---------------- layout ---------------- */
.container { max-width: 1280px; margin: 0 auto; padding: 24px; }
.view { animation: fade-in .2s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.view-head h1 { margin: 0; font-size: 22px; line-height: 1.2; letter-spacing: -.01em; }
.subtitle { margin: 4px 0 0; color: var(--text-2); font-size: 13px; }

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

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .1s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.small { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn.ghost:hover { background: var(--bad-soft); color: var(--bad); }
.btn svg { width: 16px; height: 16px; }
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- panels ---------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.panel-head h2 { margin: 0; font-size: 16px; }
.panel h3 { margin: 0 0 12px; font-size: 16px; }
.panel h4 { margin: 20px 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.count { color: var(--text-3); font-weight: 500; font-size: 13px; }

/* ---------------- stats ---------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.stat-card strong { display: block; font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat-card span { color: var(--text-2); font-size: 12px; }
.stat-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stat-icon.info { background: var(--primary-soft); color: var(--primary); }
.stat-icon.ok { background: var(--ok-soft); color: var(--ok); }
.stat-icon.warn { background: var(--warn-soft); color: var(--warn); }
.stat-icon.bad { background: var(--bad-soft); color: var(--bad); }
.stat-icon.muted { background: var(--muted-soft); color: var(--muted); }

/* ---------------- tables ---------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.table { width: 100%; border-collapse: collapse; min-width: 560px; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th {
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s ease; }
.table tbody tr:hover { background: color-mix(in srgb, var(--primary-soft) 45%, transparent); }
.table .row-link { color: var(--primary); cursor: pointer; font-weight: 600; }
.table .row-link:hover { text-decoration: underline; }

/* ---------------- badges ---------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge svg { width: 12px; height: 12px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--primary-soft); color: var(--primary); }
.badge.muted { background: var(--muted-soft); color: var(--muted); }
.badge.solid.ok { background: var(--ok); color: #fff; }
.badge.solid.bad { background: var(--bad); color: #fff; }
.badge.solid.warn { background: var(--warn); color: #fff; }
.badge.solid.info { background: var(--primary); color: #fff; }
.badge.solid.muted { background: var(--muted); color: #fff; }

/* ---------------- forms ---------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.field { display: block; font-weight: 600; font-size: 13px; }
.field input, .field select, .field textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  font-weight: 400;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 18%, transparent);
}
.field input[type="file"] { padding: 6px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; min-height: 40px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.req { color: var(--bad); }
.hint { margin: 6px 0 0; color: var(--text-3); font-size: 12px; }
.form-error { margin: 10px 0 0; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--bad-soft); color: var(--bad); font-size: 13px; font-weight: 500; }

/* ---------------- publish form sections ---------------- */
.form-section {
  padding: 20px 0;
  border-top: 1px solid var(--border);
}
.form-section:first-of-type { border-top: 0; padding-top: 0; }
.form-section:last-of-type { padding-bottom: 0; }
.section-title { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.section-title h3 { margin: 0; font-size: 15px; }
.section-title .hint { margin: 2px 0 0; }
.step {
  display: grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 13px;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 28px 16px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-2);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .1s ease;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--primary); background: var(--primary-soft); }
.dropzone p { margin: 0; font-weight: 600; }
.dropzone svg { width: 28px; height: 28px; color: var(--text-3); }
.dropzone .hint { margin: 0; }

.file-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 13px;
}
.file-list li .file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list li.file-empty { color: var(--text-3); font-family: var(--font); }
.file-list .type-select {
  width: auto;
  margin: 0;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--font);
  font-size: 13px;
}
.file-list .comp-input {
  width: 150px;
  margin: 0;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--mono);
  font-size: 13px;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  cursor: pointer;
}
.switch-row input.switch { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  position: relative;
  flex: none;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-3);
  transition: background .15s ease;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
  transition: transform .15s ease;
}
.switch-row input.switch:checked + .switch-track { background: var(--primary); }
.switch-row input.switch:checked + .switch-track::after { transform: translateX(18px); }
.switch-row input.switch:focus-visible + .switch-track { outline: 2px solid var(--ring); outline-offset: 2px; }
.switch-row strong { display: block; font-size: 14px; }
.switch-row small { display: block; color: var(--text-3); font-size: 12px; }

.target-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.target-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.target-card:hover { border-color: var(--surface-3); background: var(--surface-2); }
.target-card.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 1px var(--primary);
}
.target-card input { position: absolute; opacity: 0; pointer-events: none; }
.target-card strong { font-size: 14px; }
.target-card small { color: var(--text-3); font-size: 12px; }
.target-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  margin-bottom: 4px;
}
.target-icon svg { width: 18px; height: 18px; }
.target-icon.muted { background: var(--muted-soft); color: var(--muted); }
.target-icon.ok { background: var(--ok-soft); color: var(--ok); }
.target-icon.info { background: var(--primary-soft); color: var(--primary); }
.target-icon.warn { background: var(--warn-soft); color: var(--warn); }

.target-input { margin-top: 14px; }
.percent-field { display: flex; align-items: center; gap: 14px; }
.percent-field input[type="range"] { flex: 1; accent-color: var(--primary); margin-top: 6px; }
.percent-value {
  font-family: var(--mono);
  font-weight: 700;
  color: var(--primary);
  min-width: 44px;
  text-align: right;
}

.confirm-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.publish-summary {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.publish-summary strong { font-family: var(--mono); font-size: 14px; }
.publish-summary span { color: var(--text-2); font-size: 12px; }
.publish-summary .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
}
.chip em { font-style: normal; color: var(--primary); font-weight: 700; }
.chip.muted { font-family: var(--font); color: var(--text-3); }

textarea { resize: vertical; min-height: 72px; }

/* ---------------- result / manifest ---------------- */
.result-box { margin-top: 14px; }
.result-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
pre.manifest {
  margin: 0;
  padding: 14px;
  background: #0B1220;
  color: #C9D9EC;
  border-radius: var(--radius-sm);
  overflow: auto;
  max-height: 340px;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---------------- empty ---------------- */
.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

/* ---------------- toast ---------------- */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.err { background: var(--bad); color: #fff; }

/* ---------------- search ---------------- */
.search-box { position: relative; }
.search-box svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-3); pointer-events: none; }
.search-box input {
  padding: 8px 12px 8px 32px;
  width: 240px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.search-box input:focus { border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 18%, transparent); }

/* ---------------- responsive ---------------- */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .top-actions { margin-left: auto; }
  #token-input { width: 150px; }
  .container { padding: 16px; }
  .view-head { flex-direction: column; align-items: flex-start; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .search-box input { width: 100%; }
  .search-box { flex: 1; min-width: 160px; }
  .btn, .tab { min-height: 44px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .top-actions { width: 100%; }
  #token-input { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
