/* ═══════════════════════════════════════════════════
   PaddleMate Nano — Calibration Tool
   Style aligned with paddlemate-ftp-calculator (slate-950 / sky)
   ═══════════════════════════════════════════════════ */

:root {
  --background: #020617;
  --foreground: #f8fafc;
  --bg:        #020617; /* slate-950 */
  --surface:   rgba(15, 23, 43, 0.5); /* slate-900/50 */
  --surface2:  #0f172a; /* slate-900 */
  --border:    #334155; /* slate-700 */
  --border-soft: #475569; /* slate-600 */
  --text:      #f1f5f9; /* slate-100 */
  --text-dim:  #94a3b8; /* slate-400 */
  --text-muted:#64748b; /* slate-500 */
  --accent:    #38bdf8; /* sky-400 */
  --accent2:   #7dd3fc; /* sky-300 */
  --accent-strong: #0ea5e9; /* sky-500 */
  --green:     #6ee7b7; /* emerald-300 */
  --green-strong: #10b981; /* emerald-500 */
  --orange:    #fbbf24; /* amber-500 */
  --red:       #fecaca; /* red-200 */
  --red-strong:#ef4444; /* red-500 */
  --radius:    0.75rem; /* rounded-xl */
  --radius-md: 0.5rem;  /* rounded-lg */
  --transition: 0.15s ease;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", "Noto Sans", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  line-height: 1.5;
}

/* ─── Header ─── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 24px 20px;
  background: rgba(2, 6, 23, 0.85);
  border-bottom: 1px solid rgba(51, 65, 85, 0.6);
  backdrop-filter: blur(12px);
}

.header-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #fff;
  text-decoration: none;
  transition: color var(--transition);
  width: fit-content;
}
.header-back:hover {
  color: var(--accent2);
}

.header-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: 100%;
  gap: 12px;
}

.header-center {
  grid-column: 2;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.paddlemate-logo {
  width: min(100%, 11rem);
  margin-inline: auto;
}
.paddlemate-logo img {
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  width: 100%;
  height: auto;
  display: block;
}

.header-center h1 {
  font-size: 1.875rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: #fff;
  line-height: 1.2;
}
.header-center .subtitle {
  font-size: 0.875rem;
  color: var(--text-dim);
  font-weight: 500;
}

.header-right {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Status pill */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.pill .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  transition: background var(--transition);
}
.pill.disconnected {
  background: rgba(15, 23, 43, 0.6);
  border-color: rgba(71, 85, 105, 0.6);
  color: var(--text-dim);
}
.pill.disconnected .dot { background: var(--text-muted); }
.pill.connecting {
  background: rgba(14, 165, 233, 0.1);
  border-color: rgba(14, 165, 233, 0.3);
  color: var(--accent2);
}
.pill.connecting .dot   { background: var(--accent); animation: pulse 1s infinite; }
.pill.connected {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
  color: var(--green);
}
.pill.connected .dot    { background: var(--green-strong); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .3; }
}

/* Battery */
.battery {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.875rem;
  color: var(--text-dim);
  transition: opacity var(--transition);
}
.battery.hidden { opacity: 0; pointer-events: none; }
.battery.charging { color: var(--green); }

/* ─── Main ─── */
main {
  max-width: 42rem;
  margin: 28px auto;
  padding: 0 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.compat-warning {
  margin: 0;
  padding: 12px 16px;
  font-size: 0.875rem;
  line-height: 1.5;
  color: rgba(254, 243, 198, 0.9); /* amber-100/90 */
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.2); /* amber-500/20 */
  border-radius: var(--radius);
  text-align: center;
}

/* ─── Insights (collapsible) ─── */
.insights-card {
  background: var(--surface);
  border: 1px solid rgba(51, 65, 85, 0.8);
  border-radius: var(--radius);
  overflow: hidden;
}

.insights-toggle {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.insights-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #f1f5f9;
}

.insights-action {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.insights-body {
  border-top: 1px solid rgba(51, 65, 85, 0.8);
  padding: 16px;
  font-size: 0.875rem;
  line-height: 1.6;
  color: #cbd5e1; /* slate-300 */
}

.insights-body.is-collapsed {
  display: none;
}

.insights-body p + p,
.insights-body p + ol {
  margin-top: 12px;
}

.insights-body strong {
  color: #f1f5f9;
  font-weight: 600;
}

.insights-steps {
  margin: 0;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.insights-steps li::marker {
  color: var(--accent);
  font-weight: 600;
}

/* ─── Cards ─── */
.card {
  background: var(--surface);
  border: 1px solid rgba(51, 65, 85, 0.8);
  border-radius: var(--radius);
  overflow: hidden;
  transition: opacity var(--transition), filter var(--transition), border-color var(--transition);
}
.card.locked {
  opacity: 0.45;
  pointer-events: none;
  filter: grayscale(0.35);
}

.card h2 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  padding: 12px 18px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.7);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.card-body {
  padding: 16px 18px;
}

/* ─── Grid / rows ─── */
.row-center {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.info-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 18px;
  font-size: 0.9375rem;
}
.info-grid label {
  color: var(--text-dim);
  font-weight: 500;
}
.info-grid span {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.serial-label {
  margin-left: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9375rem;
  color: var(--accent2);
  font-weight: 600;
}

/* ─── Buttons ─── */
.btn {
  padding: 8px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
    color var(--transition), transform 0.1s, opacity var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: rgba(14, 165, 233, 0.15);
  border-color: rgba(14, 165, 233, 0.45);
  color: var(--accent2);
}
.btn-primary:hover:not(:disabled) {
  background: rgba(14, 165, 233, 0.25);
  border-color: rgba(14, 165, 233, 0.7);
  color: #fff;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
  color: var(--red);
}
.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.22);
  border-color: rgba(239, 68, 68, 0.55);
}

.btn-accent {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.35);
  color: var(--green);
}
.btn-accent:hover:not(:disabled) {
  background: rgba(16, 185, 129, 0.22);
  border-color: rgba(16, 185, 129, 0.55);
  color: #fff;
}

.btn-small {
  padding: 4px 12px;
  font-size: 0.75rem;
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text-dim);
}
.btn-small:hover:not(:disabled) {
  border-color: var(--border-soft);
  color: #fff;
}

/* ─── Inputs ─── */
input[type="text"],
input[type="number"] {
  background: rgba(2, 6, 23, 0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9375rem;
  width: 120px;
  outline: none;
  transition: border-color var(--transition);
}
input:focus {
  border-color: rgba(14, 165, 233, 0.6);
}

input[type="checkbox"] {
  accent-color: var(--accent-strong);
}

.status-msg {
  font-size: 0.875rem;
  font-weight: 500;
  min-width: 80px;
  color: var(--text-dim);
}
.status-msg.ok   { color: var(--green); }
.status-msg.fail { color: var(--red); }

.is-hidden { display: none !important; }

/* ─── Log ─── */
#log-output {
  background: rgba(2, 6, 23, 0.7);
  border: 1px solid rgba(51, 65, 85, 0.8);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8125rem;
  color: var(--text-dim);
  max-height: 180px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ─── Force Calibration ─── */
.cal-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cal-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid rgba(51, 65, 85, 0.5);
  border-radius: var(--radius-md);
  transition: opacity var(--transition), border-color var(--transition);
}
.cal-step.done { opacity: 0.55; }
.cal-step.active {
  border-color: rgba(14, 165, 233, 0.5);
  border-left: 3px solid var(--accent);
}

.step-num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(51, 65, 85, 0.8);
  color: var(--text-dim);
  font-size: 0.8125rem;
  font-weight: 700;
  flex-shrink: 0;
}
.cal-step.active .step-num {
  background: rgba(14, 165, 233, 0.25);
  color: var(--accent2);
}
.cal-step.done .step-num {
  background: rgba(16, 185, 129, 0.25);
  color: var(--green);
}

.step-label {
  font-size: 0.875rem;
  color: var(--text);
  min-width: 120px;
}

.cal-badge {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 4px;
  margin-left: 8px;
  border: 1px solid transparent;
}
.cal-badge.idle {
  background: rgba(15, 23, 43, 0.6);
  border-color: rgba(71, 85, 105, 0.5);
  color: var(--text-dim);
}
.cal-badge.running {
  background: rgba(14, 165, 233, 0.12);
  border-color: rgba(14, 165, 233, 0.35);
  color: var(--accent2);
  animation: pulse 1s infinite;
}
.cal-badge.done {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.35);
  color: var(--green);
}
.cal-badge.fail {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
  color: var(--red);
}

.cal-results {
  padding-top: 10px;
  border-top: 1px solid rgba(51, 65, 85, 0.7);
}
.cal-results.hidden { display: none; }

#input-cal-weight { width: 100px; }

.card-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.625;
}

.input-unit {
  font-size: 0.875rem;
  color: var(--text-dim);
}

/* ─── Responsive ─── */
@media (max-width: 520px) {
  header { padding: 12px 14px 16px; }
  .header-row {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .header-center { grid-column: 1; }
  .header-right {
    grid-column: 1;
    justify-self: center;
  }
  .header-center h1 { font-size: 1.5rem; }
  .paddlemate-logo { width: min(100%, 9rem); }
  main { padding: 0 8px 48px; }
  .card-body { padding: 12px; }
  .serial-label { margin-left: 0; }
}
