/* =========================================================
   3033 → BT11 Weight Sender — single stylesheet
   (no external fonts / CDNs: works 100% offline)
   ========================================================= */

:root {
  --bg: #0f172a;
  --bg-2: #111c35;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --err: #dc2626;
  --err-bg: #fee2e2;
  --idle: #94a3b8;
  --radius: 16px;
  --shadow: 0 20px 45px -20px rgba(15, 23, 42, 0.45);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(1200px 600px at 10% -10%, #1e3a8a 0%, transparent 60%),
              radial-gradient(900px 500px at 110% 10%, #0e7490 0%, transparent 55%),
              linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- Auth (login / register) ---------------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.brand-logo {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #0891b2);
  display: grid;
  place-items: center;
  color: #fff;
  flex-shrink: 0;
}
.brand-logo svg { width: 26px; height: 26px; }

.brand h1 { font-size: 1.2rem; margin: 0; }
.brand p { margin: 0; font-size: 0.85rem; color: var(--muted); }

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s, opacity 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-success { background: var(--ok); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }

.btn-ghost { background: #f1f5f9; color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: #e2e8f0; }

.btn-danger-ghost { background: var(--err-bg); color: var(--err); }

.btn-block { width: 100%; }

.alert {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  margin-bottom: 16px;
}
.alert-error { background: var(--err-bg); color: #991b1b; }
.alert-success { background: var(--ok-bg); color: #166534; }
.alert-info { background: #e0f2fe; color: #075985; }
.alert-warn { background: var(--warn-bg); color: #92400e; }

.auth-footer {
  margin-top: 18px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
}

.hint {
  margin-top: 14px;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

/* ---------------- Dashboard ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  color: #e2e8f0;
}
.topbar .brand { margin: 0; }
.topbar .brand h1 { color: #fff; font-size: 1.05rem; }
.topbar .brand p { color: #94a3b8; }

.user-box {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}
.user-box form { margin: 0; }
.user-box .btn { padding: 8px 12px; font-size: 0.85rem; }

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px 40px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 14px;
}

/* USB status */
.usb-status {
  display: flex;
  align-items: center;
  gap: 16px;
}

.usb-icon {
  width: 68px;
  height: 68px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: #f1f5f9;
  color: var(--idle);
  transition: background 0.25s, color 0.25s;
  position: relative;
}
.usb-icon svg { width: 38px; height: 38px; }

.usb-icon::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--idle);
  border: 2px solid #fff;
}

.usb-icon.state-connected { background: var(--ok-bg); color: var(--ok); }
.usb-icon.state-connected::after { background: var(--ok); }

.usb-icon.state-connecting { background: var(--warn-bg); color: var(--warn); }
.usb-icon.state-connecting::after { background: var(--warn); animation: pulse 1s infinite; }

.usb-icon.state-error { background: var(--err-bg); color: var(--err); }
.usb-icon.state-error::after { background: var(--err); }

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

.usb-text { flex: 1; min-width: 0; }
.usb-text strong { display: block; font-size: 1.05rem; }
.usb-text span { display: block; font-size: 0.85rem; color: var(--muted); word-break: break-word; }

.usb-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.usb-actions .btn { flex: 1; min-width: 140px; }

/* Weight sender */
.weight-row {
  display: flex;
  gap: 10px;
}

.weight-input-wrap {
  position: relative;
  flex: 1;
}

.weight-input {
  font-size: 1.6rem;
  font-weight: 700;
  font-family: var(--mono);
  padding: 14px 52px 14px 16px;
  letter-spacing: 0.02em;
}

.weight-unit {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-weight: 700;
  color: var(--muted);
  pointer-events: none;
}

.weight-row .btn { padding: 0 24px; font-size: 1.05rem; }

.form-msg {
  min-height: 1.4em;
  margin-top: 10px;
  font-size: 0.9rem;
}
.form-msg.ok { color: var(--ok); }
.form-msg.err { color: var(--err); }

/* Settings */
details.settings {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
details.settings summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  user-select: none;
}
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}
.settings-grid .form-group { margin: 0; }
.settings-grid select.input,
.settings-grid input.input { padding: 9px 10px; font-size: 0.9rem; }
.settings-note { font-size: 0.78rem; color: var(--muted); margin-top: 10px; }

/* Flow diagram */
.flow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}
.flow .node {
  flex: 1;
  padding: 8px 4px;
  border-radius: 10px;
  background: #f1f5f9;
  transition: background 0.3s, color 0.3s;
}
.flow .node.active { background: var(--primary); color: #fff; }
.flow .arrow { color: #cbd5e1; flex-shrink: 0; }

/* Logs */
.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
}
.log-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
}
.log-list li:last-child { border-bottom: none; }
.log-list .w { font-family: var(--mono); font-weight: 700; }
.log-list .meta { color: var(--muted); font-size: 0.78rem; }
.log-empty { color: var(--muted); font-size: 0.88rem; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}
.badge-ok { background: var(--ok-bg); color: #166534; }
.badge-err { background: var(--err-bg); color: #991b1b; }

.rx-box {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: #0f172a;
  color: #a7f3d0;
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 60px;
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

@media (max-width: 480px) {
  .topbar { padding: 12px 14px; }
  .topbar .brand p { display: none; }
  .weight-row { flex-direction: column; }
  .weight-row .btn { padding: 14px; }
  .settings-grid { grid-template-columns: 1fr; }
}
