/* ═══════════════════════════════════════════════════════════
   ЙОЗЖ Scale · styles.css v3.9
   Tone: Friendly sci-fi · Robot companion + dark medical UI
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&family=JetBrains+Mono:wght@400;600&display=swap');

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --bg:      #080b10;
  --bg2:     #0d1117;
  --bg3:     #131922;
  --bg4:     #1a2233;
  --green:   #6ee7b7;
  --green2:  #34d399;
  --yellow:  #fde68a;
  --purple:  #c084fc;
  --blue:    #7dd3fc;
  --red:     #f87171;
  --text:    #e2e8f4;
  --dim:     #64748b;
  --border:  rgba(110,231,183,0.12);
  --border3: rgba(255,255,255,0.06);
  --font:    'Nunito', sans-serif;
  --mono:    'JetBrains Mono', monospace;
  --r:       10px;
}
*,*::before,*::after { box-sizing:border-box; margin:0; padding:0; }
html { font-size:14px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Subtle grid background */
body::before {
  content:'';
  position:fixed; inset:0;
  background-image:
    linear-gradient(rgba(110,231,183,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(110,231,183,.025) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events:none; z-index:0;
}

/* ── Layout ────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.left-panel {
  flex: 0 0 68%;
  padding: 24px 28px 48px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}

.right-panel {
  flex: 0 0 32%;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 24px 16px;
  overflow: hidden;
}

/* ── Header ────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border3);
}
.app-eyebrow {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--green);
  margin-bottom: 4px;
}
.app-title {
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  letter-spacing: -.3px;
}
.ws-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
}
.ws-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--dim);
  transition: all .3s;
}
.ws-dot.active {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}
.btn-reconnect {
  background: none;
  border: 1px solid var(--border3);
  color: var(--dim);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 14px;
  transition: all .2s;
}
.btn-reconnect:hover { color: var(--green); border-color: var(--border); }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border3);
  border-radius: var(--r);
  padding: 16px 20px;
  margin-bottom: 14px;
}
.card-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 14px;
}
.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

/* ── Profile ───────────────────────────────────────────────── */
.profile-card { margin-bottom: 14px; }
.profile-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--dim);
}
.form-input {
  background: var(--bg3);
  border: 1px solid var(--border3);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 14px;
  font-family: var(--font);
  transition: border-color .2s;
  width: 100%;
}
.form-input:focus { outline: none; border-color: rgba(110,231,183,.3); }
.form-input option { background: var(--bg3); }
.profile-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--dim);
  cursor: pointer;
}
.checkbox-label input { accent-color: var(--green); width: 15px; height: 15px; }
.btn-save {
  background: var(--green);
  color: #000;
  border: none;
  border-radius: 7px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 800;
  font-family: var(--font);
  cursor: pointer;
  transition: all .2s;
}
.btn-save:hover { background: var(--green2); transform: translateY(-1px); }

/* ── Step Buttons ──────────────────────────────────────────── */
.diag-btn-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 14px;
}
.diag-btn-small {
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid rgba(125,211,252,.2);
  background: rgba(125,211,252,.06);
  color: var(--blue);
  font-size: 11px;
  font-family: var(--mono);
  cursor: pointer;
  transition: all .2s;
}
.diag-btn-small:hover { background: rgba(125,211,252,.12); }

/* ── Engine Tabs ───────────────────────────────────────────── */
.engine-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg2);
  border: 1px solid var(--border3);
  border-radius: var(--r) var(--r) 0 0;
  padding: 6px 6px 0;
  border-bottom: none;
  margin-bottom: 0;
}
.engine-tab {
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font);
  padding: 9px 16px;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--dim);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .2s;
}
.engine-tab:hover { color: var(--text); background: var(--bg3); }
.engine-tab.active { background: var(--bg3); border-color: var(--border3); border-bottom-color: var(--bg3); color: #fff; }
.engine-tab[data-engine="xiaomi"].active    { color: var(--yellow); border-top: 2px solid var(--yellow); }
.engine-tab[data-engine="scientific"].active{ color: var(--green);  border-top: 2px solid var(--green); }
.engine-tab[data-engine="s400"].active      { color: var(--purple); border-top: 2px solid var(--purple); }

.engine-panels {
  background: var(--bg2);
  border: 1px solid var(--border3);
  border-radius: 0 0 var(--r) var(--r);
  border-top: none;
  padding: 16px;
  margin-bottom: 14px;
}
.engine-panel {}
.hidden { display: none !important; }

/* ── Metrics ───────────────────────────────────────────────── */
.metric-group { margin-bottom: 16px; }
.metric-group-title {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border3);
}
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}
.metric-card {
  background: var(--bg3);
  border: 1px solid var(--border3);
  border-radius: 8px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: all .2s;
}
.metric-card:hover { border-color: var(--border); transform: translateY(-1px); }
.metric-icon  { font-size: 16px; line-height: 1; }
.metric-label { font-size: 10px; color: var(--dim); font-family: var(--mono); }
.metric-value { font-size: 16px; font-weight: 800; color: #fff; font-family: var(--mono); }
.metric-badge { font-size: 10px; color: var(--dim); font-family: var(--mono); }
.metric-dim .metric-value { color: var(--dim); }
.raw-row {
  display: flex; gap: 16px; flex-wrap: wrap;
  padding: 8px 12px; background: var(--bg3);
  border-radius: 6px; margin-bottom: 14px;
  font-family: var(--mono); font-size: 12px; color: var(--dim);
}
.raw-row strong { color: var(--text); }
.range-bar { display: flex; gap: 3px; margin-top: 4px; }
.range-dot { height: 3px; border-radius: 2px; flex: 1; opacity: .3; transition: opacity .2s; }
.range-dot.active { opacity: 1; }

/* ── Compare Table ─────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }
.compare-table, .history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.compare-table thead tr, .history-table thead tr { background: var(--bg3); }
.compare-table th, .history-table th {
  padding: 9px 12px; text-align: left;
  font-family: var(--mono); font-size: 9px;
  letter-spacing: 1px; text-transform: uppercase;
  color: var(--dim); border-bottom: 1px solid var(--border3);
  white-space: nowrap;
}
.col-xiaomi { color: var(--yellow) !important; }
.col-sci    { color: var(--green)  !important; }
.col-s400   { color: var(--purple) !important; }
.col-delta  { color: var(--dim)    !important; }
.compare-table tbody tr, .history-table tbody tr {
  border-bottom: 1px solid rgba(255,255,255,.03);
  transition: background .15s;
}
.compare-table tbody tr:hover, .history-table tbody tr:hover { background: rgba(255,255,255,.02); }
.compare-table td, .history-table td { padding: 8px 12px; }
.cmp-label { color: var(--dim); font-size: 11px; }
.cmp-val   { font-family: var(--mono); font-weight: 700; }
.cmp-delta { font-family: var(--mono); font-size: 10px; color: var(--dim); }
.diff-high { background: rgba(248,113,113,.04) !important; }
.diff-high .cmp-delta { color: var(--red); }
.diff-med  { background: rgba(253,230,138,.03) !important; }
.diff-med  .cmp-delta { color: var(--yellow); }
.h-date { font-family: var(--mono); font-size: 10px; line-height: 1.4; color: var(--dim); }
.h-weight { font-family: var(--mono); font-weight: 800; color: var(--green); }
.empty-row { text-align: center; padding: 20px !important; color: var(--dim); font-size: 13px; }

/* ── History ───────────────────────────────────────────────── */
.history-btns { display: flex; gap: 8px; }
.btn-danger-sm {
  background: transparent; color: var(--red);
  border: 1px solid rgba(248,113,113,.2);
  border-radius: 6px; font-size: 11px; padding: 5px 10px;
  cursor: pointer; font-family: var(--font); transition: all .2s;
}
.btn-danger-sm:hover { background: rgba(248,113,113,.08); }
.history-chart-wrap { padding: 8px 0 12px; }
#weight-chart { width: 100%; height: 70px; display: block; }
.btn-delete-history {
  background: none; border: none; color: var(--dim);
  font-size: 12px; cursor: pointer; padding: 2px 6px; border-radius: 3px;
}
.btn-delete-history:hover { color: var(--red); }

/* ── Debug panel ───────────────────────────────────────────── */
.debug-panel {
  background: var(--bg2); border: 1px solid rgba(248,113,113,.2);
  border-radius: var(--r); margin-bottom: 14px;
  font-family: var(--mono); font-size: 11px;
}
.debug-header {
  padding: 8px 14px; background: rgba(248,113,113,.06);
  border-bottom: 1px solid rgba(248,113,113,.15);
  display: flex; justify-content: space-between;
  color: var(--red); font-size: 11px; border-radius: var(--r) var(--r) 0 0;
}
.debug-header button {
  background: none; border: none; color: var(--dim); cursor: pointer; font-size: 14px;
}

/* ── Footer ────────────────────────────────────────────────── */
.app-footer {
  margin-top: 32px; padding-top: 16px;
  border-top: 1px solid var(--border3);
  font-family: var(--mono); font-size: 10px;
  color: var(--dim); letter-spacing: .5px;
}

/* ═══════════════════════════════════════════════════════════
   RIGHT PANEL — ROBOT & SPEECH BUBBLE
   ═══════════════════════════════════════════════════════════ */

/* Speech bubble */
.bubble-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
  padding: 0 8px;
}

.speech-bubble {
  position: relative;
  background: var(--bg2);
  border: 3px solid var(--green);
  border-radius: 22px;
  padding: 22px 26px;
  max-width: 340px;
  min-height: 90px;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 0 32px rgba(110,231,183,.18), 0 6px 28px rgba(0,0,0,.45);
  transition: border-color .4s;
}

/* Bubble tail pointing down to robot */
.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: var(--green);
}
.speech-bubble::before {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: var(--bg2);
  z-index: 1;
}

.bubble-text {
  font-family: var(--font);
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.45;
}

.bubble-cursor {
  font-family: var(--mono);
  font-size: 20px;
  color: var(--green);
  animation: cursor-blink .7s infinite;
  flex-shrink: 0;
}
@keyframes cursor-blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* Bubble states */
.speech-bubble.state-error   { border-color: var(--red);    box-shadow: 0 0 20px rgba(248,113,113,.15); }
.speech-bubble.state-error::after { border-top-color: var(--red); }
.speech-bubble.state-measuring { border-color: var(--yellow); box-shadow: 0 0 24px rgba(253,230,138,.2); }
.speech-bubble.state-measuring::after { border-top-color: var(--yellow); }
.speech-bubble.state-done   { border-color: var(--green2);  box-shadow: 0 0 32px rgba(52,211,153,.3); }
.speech-bubble.state-done::after { border-top-color: var(--green2); }

/* Text blink after typewriter completes */
.bubble-text.blink { animation: text-blink .6s ease-in-out 3; }
@keyframes text-blink { 0%,100% { opacity: 1; } 50% { opacity: .2; } }

/* ── Robot SVG ─────────────────────────────────────────────── */
.robot-wrap {
  position: relative;
  width: 400px;
  max-width: 90%;
  flex-shrink: 0;
  margin-top: 24px;
}

.robot-svg {
  width: 100%;
  height: auto;
  filter: drop-shadow(0 0 30px rgba(110,231,183,.25));
}

/* Antenna pulse */
#antenna-ball {
  animation: antenna-pulse 2s ease-in-out infinite;
}
@keyframes antenna-pulse {
  0%,100% { r: 5; opacity: 1; }
  50%      { r: 7; opacity: .7; }
}

/* Heart glow pulse */
#heart-glow {
  animation: heart-pulse 1.8s ease-in-out infinite;
}
@keyframes heart-pulse {
  0%,100% { opacity: .9; r: 6; }
  50%      { opacity: .4; r: 4; }
}

/* Robot idle float */
.robot-wrap {
  animation: robot-float 4s ease-in-out infinite;
}
@keyframes robot-float {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}

/* Eye blink */
#eye-left, #eye-right { animation: eye-blink 5s ease-in-out infinite; }
#eye-right { animation-delay: .08s; }
@keyframes eye-blink {
  0%,92%,100% { scaleY: 1; }
  95%         { transform: scaleY(.1); }
}

/* Robot state animations */
.robot-svg.state-measuring #heart-glow {
  animation: heart-fast 0.5s ease-in-out infinite;
  fill: var(--yellow);
}
@keyframes heart-fast {
  0%,100% { opacity: 1; r: 8; }
  50%      { opacity: .3; r: 5; }
}
.robot-svg.state-measuring #antenna-ball { fill: var(--yellow); }
.robot-svg.state-measuring #eye-left,
.robot-svg.state-measuring #eye-right  { fill: var(--yellow); }

.robot-svg.state-done #heart-glow { fill: var(--green2); r: 9; animation: heart-done 0.4s ease-in-out 3 forwards; }
@keyframes heart-done { 0%,100% { r: 7; } 50% { r: 10; } }
.robot-svg.state-done #mouth-path { d: path("M 78 78 Q 100 96 122 78"); }
.robot-svg.state-done #antenna-ball { fill: var(--green2); animation: antenna-done .3s ease-in-out 3 alternate; }
@keyframes antenna-done { to { r: 8; } }

.robot-svg.state-error #heart-glow { fill: var(--red); }
.robot-svg.state-error #antenna-ball { fill: var(--red); }
.robot-svg.state-error #eye-left,
.robot-svg.state-error #eye-right  { fill: var(--red); opacity: .7; }
.robot-svg.state-error #mouth-path { d: path("M 78 88 Q 100 76 122 88"); }

/* ── Floating particles ────────────────────────────────────── */
.particle {
  position: absolute;
  border-radius: 50%;
  background: var(--green);
  opacity: 0;
  pointer-events: none;
}
.p1 { width: 6px; height: 6px; top: 20%; left: 5%;  animation: float-particle 4s 0s   infinite; }
.p2 { width: 4px; height: 4px; top: 45%; right: 8%; animation: float-particle 5s 1.5s infinite; }
.p3 { width: 5px; height: 5px; top: 70%; left: 15%; animation: float-particle 3.5s 3s infinite; }
@keyframes float-particle {
  0%         { opacity: 0; transform: translateY(0) scale(.5); }
  20%,80%    { opacity: .5; }
  100%       { opacity: 0; transform: translateY(-40px) scale(1.2); }
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-layout { flex-direction: column; }
  .left-panel  { flex: 1; border-right: none; border-bottom: 1px solid var(--border); }
  .right-panel { position: static; height: auto; flex-direction: row; justify-content: space-around; padding: 16px; }
  .bubble-wrap { flex: 1; }
  .robot-wrap  { width: 120px; margin-top: 0; }
  .profile-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .left-panel { padding: 16px; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .step-buttons { flex-wrap: wrap; }
}

/* ── Big Status Window (under robot) ───────────────────────── */
.status-window {
  width: 100%;
  max-width: 240px;
  margin-top: 28px;
  background: var(--bg2);
  border: 2px solid var(--border3);
  border-radius: 14px;
  padding: 16px 18px;
  font-family: var(--mono);
  transition: all .4s;
}
.sw-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
}
.sw-label {
  font-size: 12px;
  color: var(--dim);
  letter-spacing: .5px;
}
.sw-value {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
}
.sw-divider {
  height: 1px;
  background: var(--border3);
  margin: 4px 0;
}
.sw-badge {
  margin-top: 12px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  padding: 8px;
  border-radius: 8px;
  letter-spacing: .5px;
  background: rgba(100,116,139,.12);
  color: var(--dim);
  transition: all .4s;
}

/* Impedance OK state */
.status-window.imp-ok {
  border-color: rgba(52,211,153,.5);
  box-shadow: 0 0 24px rgba(52,211,153,.15);
}
.status-window.imp-ok .sw-impedance .sw-value { color: var(--green); }
.status-window.imp-ok .sw-badge {
  background: rgba(52,211,153,.15);
  color: var(--green2);
}

/* Impedance MISSING state */
.status-window.imp-missing {
  border-color: rgba(248,113,113,.5);
  box-shadow: 0 0 24px rgba(248,113,113,.15);
}
.status-window.imp-missing .sw-impedance .sw-value { color: var(--red); }
.status-window.imp-missing .sw-badge {
  background: rgba(248,113,113,.15);
  color: var(--red);
}

/* Measuring state */
.status-window.imp-waiting {
  border-color: rgba(253,230,138,.5);
}
.status-window.imp-waiting .sw-badge {
  background: rgba(253,230,138,.12);
  color: var(--yellow);
  animation: sw-pulse 1s ease-in-out infinite;
}
@keyframes sw-pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

@media (max-width: 900px) {
  .status-window { margin-top: 12px; max-width: 200px; }
  .sw-value { font-size: 16px; }
}

/* ── Connect Scale Button ──────────────────────────────────── */
.btn-connect-scale {
  display: block;
  width: 100%;
  padding: 16px;
  margin-bottom: 14px;
  border: none;
  border-radius: 10px;
  background: var(--green);
  color: #000;
  font-size: 16px;
  font-weight: 800;
  font-family: var(--font);
  cursor: pointer;
  transition: all .2s;
}
.btn-connect-scale:hover { background: var(--green2); transform: translateY(-1px); }
.btn-connect-scale:active { transform: translateY(0); }
.btn-connect-scale.connected {
  background: rgba(110,231,183,.1);
  color: var(--green);
  border: 1px solid var(--border);
}
