/* ErgoCoach theme — matches the "A / Your existing theme" concept */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ee;
  --text: #0f1f2e;
  --text-2: #4b5a6b;
  --muted: #8a97a6;
  --navy: #0f1f2e;
  --navy-2: #1b2f44;
  --green: #17a35a;
  --green-bg: #e7f7ee;
  --green-text: #0f6b3a;
  --amber: #d99a00;
  --amber-bg: #fff6de;
  --amber-text: #7a5600;
  --red: #d64541;
  --red-bg: #fdecec;
  --red-text: #8e2321;
  --blue: #2f8fe0;
  --blue-bg: #e8f2fc;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 31, 46, .05), 0 1px 8px rgba(15, 31, 46, .04);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  font-size: 15px;
  line-height: 1.4;
}
a { color: var(--blue); text-decoration: none; }
button { font-family: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p { margin: 0; }
.muted { color: var(--muted); }
.sub { color: var(--text-2); font-size: 14px; }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }

/* Layout */
#app { min-height: 100%; display: flex; flex-direction: column; }
.screen {
  flex: 1;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 18px 16px calc(var(--nav-h) + var(--safe-b) + 24px);
}
.screen.wide { max-width: 1200px; }
.screen.full { max-width: none; padding: 0; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 0 14px;
}
.topbar .title { flex: 1; text-align: center; font-weight: 700; font-size: 17px; }
.topbar .title .sub { display: block; font-weight: 500; font-size: 12.5px; }
.back {
  width: 38px; height: 38px; border-radius: 50%; border: none; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: var(--text);
}
.back:hover { background: rgba(15,31,46,.06); }
.header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.header h1 { font-size: 27px; }
.header .sub { margin-top: 2px; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card.pad-sm { padding: 12px; }
.card.pad-0 { padding: 0; overflow: hidden; }
.card + .card { margin-top: 12px; }
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-title { font-size: 16px; font-weight: 700; margin: 22px 0 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 700px) { .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 420px) { .grid-2.collapse { grid-template-columns: 1fr; } }

/* Buttons */
.btn {
  appearance: none; border: 1px solid transparent; cursor: pointer;
  border-radius: 12px; padding: 13px 18px; font-size: 15px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .12s, transform .05s, opacity .12s;
  line-height: 1.2; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.sm svg, .btn.xs svg { width: 15px; height: 15px; }
.back svg { width: 22px; height: 22px; }
.dodont h4 { display: flex; align-items: center; gap: 6px; margin: 0; }
.dodont h4 svg { width: 16px; height: 16px; }
.pill svg { width: 12px; height: 12px; }
.n svg { width: 14px; height: 14px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: rgba(15,31,46,.05); }
.btn.danger { background: var(--red-bg); color: var(--red-text); }
.btn.success { background: var(--green); color: #fff; }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 12px; font-size: 13.5px; border-radius: 10px; }
.btn.xs { padding: 5px 9px; font-size: 12.5px; border-radius: 8px; }
.btn.icon { width: 38px; height: 38px; padding: 0; border-radius: 50%; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* Badges / pills */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 999px;
  border: 1px solid transparent; white-space: nowrap;
}
.pill.green { background: var(--green-bg); color: var(--green-text); border-color: #bfe8d0; }
.pill.amber { background: var(--amber-bg); color: var(--amber-text); border-color: #f2dc9a; }
.pill.red { background: var(--red-bg); color: var(--red-text); border-color: #f2b9b7; }
.pill.blue { background: var(--blue-bg); color: #1c5f9c; border-color: #bcd9f5; }
.pill.gray { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }
.pill.navy { background: var(--navy); color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.green { background: var(--green); } .dot.amber { background: var(--amber); } .dot.red { background: var(--red); } .dot.gray { background: var(--muted); }

/* Lists */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px; border-bottom: 1px solid var(--border);
  cursor: pointer; background: transparent; border-left: none; border-right: none; border-top: none;
  width: 100%; text-align: left; font: inherit; color: inherit;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--surface-2); }
.list-item .li-title { font-weight: 600; font-size: 14.5px; }
.list-item .li-sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.list-item .li-right { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.chev { color: var(--muted); width: 16px; height: 16px; flex: none; }
.icon-box {
  width: 44px; height: 44px; border-radius: 11px; flex: none;
  display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--border);
}
.icon-box svg { width: 24px; height: 24px; }
.icon-box.lg { width: 84px; height: 84px; border-radius: 18px; }
.icon-box.lg svg { width: 48px; height: 48px; }

/* Metric rows (results) */
.metric-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid var(--border);
}
.metric-row:last-child { border-bottom: none; }
.metric-row .m-name { font-size: 14.5px; }
.metric-row .m-val { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.metric-row .m-val.nm { color: var(--muted); font-weight: 500; font-size: 13.5px; }
.metric-detail { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--text-2); margin: 4px 0 8px; display: none; }
.metric-detail.open { display: block; }

/* Stat tiles */
.stat { padding: 14px; }
.stat .s-val { font-size: 28px; font-weight: 700; letter-spacing: -.02em; display: flex; align-items: center; justify-content: space-between; }
.stat .s-label { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat svg { width: 22px; height: 22px; }

/* Notices */
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 13px 14px; border-radius: 12px; border: 1px solid transparent; }
.notice .n-icon { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.notice .n-icon svg { width: 16px; height: 16px; }
.notice .n-title { font-weight: 700; font-size: 14.5px; }
.notice .n-sub { color: var(--text-2); font-size: 13.5px; margin-top: 1px; }
.notice.good { background: var(--green-bg); border-color: #bfe8d0; }
.notice.good .n-icon { background: var(--green); color: #fff; }
.notice.good .n-title { color: var(--green-text); }
.notice.improve { background: var(--amber-bg); border-color: #f2dc9a; }
.notice.improve .n-icon { background: var(--amber); color: #fff; }
.notice.improve .n-title { color: var(--amber-text); }
.notice.bad { background: var(--red-bg); border-color: #f2b9b7; }
.notice.bad .n-icon { background: var(--red); color: #fff; }
.notice.bad .n-title { color: var(--red-text); }
.notice.info { background: var(--blue-bg); border-color: #bcd9f5; }
.notice.info .n-icon { background: var(--blue); color: #fff; }
.notice + .notice { margin-top: 10px; }

/* Forms */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.input, select, textarea {
  width: 100%; font: inherit; font-size: 15px; color: var(--text);
  padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47,143,224,.35); border-color: var(--blue); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%238a97a6' stroke-width='1.6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
select.sm { padding: 6px 28px 6px 10px; font-size: 13px; width: auto; border-radius: 8px; }
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14.5px; cursor: pointer; padding: 8px 0; }
.check input { width: 18px; height: 18px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button { border: none; background: transparent; padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 13.5px; color: var(--text-2); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Tabs bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(255,255,255,.96); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex; justify-content: center;
}
.tabbar .inner { display: flex; width: 100%; max-width: 980px; }
.tabbar button {
  flex: 1; border: none; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 11px; font-weight: 600; padding: 6px 0;
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button.on { color: var(--navy); }
.tabbar.hidden-tabs { display: none; }

/* Logo / brand */
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { height: 34px; max-width: 120px; object-fit: contain; border-radius: 6px; }
.brand .brand-name { font-weight: 700; font-size: 15px; }
.logo-box { width: 88px; height: 88px; border-radius: 14px; border: 1px dashed var(--border); background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.logo-box img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* Camera */
.cam-wrap { position: relative; background: #000; border-radius: 16px; overflow: hidden; aspect-ratio: 3 / 4; max-height: 70vh; }
.cam-wrap.landscape { aspect-ratio: 16 / 10; }
.cam-wrap video, .cam-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-wrap video.mirror, .cam-wrap canvas.mirror { transform: scaleX(-1); }
.cam-overlay { position: absolute; inset: 0; pointer-events: none; }
.cam-badge { position: absolute; top: 12px; left: 12px; display: flex; gap: 6px; }
.cam-badge .pill { background: rgba(255,255,255,.92); }
.cam-phase { position: absolute; top: 12px; right: 12px; }
.cam-cue {
  position: absolute; left: 12px; right: 12px; bottom: 12px;
  background: rgba(255,255,255,.95); border-radius: 12px; padding: 12px 14px;
  display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow);
}
.cam-cue .cue-icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.cam-cue .cue-icon svg { width: 22px; height: 22px; }
.cam-cue.good .cue-icon { background: var(--green-bg); color: var(--green); }
.cam-cue.warn .cue-icon { background: var(--amber-bg); color: var(--amber); }
.cam-cue.info .cue-icon { background: var(--blue-bg); color: var(--blue); }
.cam-cue .cue-title { font-weight: 700; font-size: 15px; }
.cam-cue .cue-sub { color: var(--text-2); font-size: 13px; }
.cam-countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: 96px; font-weight: 800; color: #fff; text-shadow: 0 2px 20px rgba(0,0,0,.5); }
.privacy-line { display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-size: 12.5px; margin-top: 10px; }
.privacy-line svg { width: 13px; height: 13px; }

/* Score */
.score-big { font-size: 46px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.score-big small { font-size: 22px; font-weight: 600; color: var(--text-2); }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.progress > div { height: 100%; border-radius: 99px; background: var(--green); }
.progress > div.amber { background: var(--amber); } .progress > div.red { background: var(--red); } .progress > div.blue { background: var(--blue); }

/* Table */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 8px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-wrap { overflow-x: auto; }

/* Guide */
.guide-step { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.guide-step:last-child { border-bottom: none; }
.guide-step .n { width: 28px; height: 28px; border-radius: 50%; background: var(--navy); color: #fff; font-weight: 700; font-size: 13px; display: grid; place-items: center; flex: none; }
.guide-step .g-title { font-weight: 600; }
.guide-step .g-sub { color: var(--text-2); font-size: 13.5px; margin-top: 2px; }
.figure-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.figure { border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); padding: 10px; text-align: center; }
.figure svg { width: 100%; height: auto; max-height: 220px; }
.figure .f-label { font-weight: 700; font-size: 13px; margin-top: 6px; }
.figure.ok .f-label { color: var(--green-text); }
.figure.bad .f-label { color: var(--red-text); }
.figure .f-sub { color: var(--text-2); font-size: 12.5px; }
.dodont { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .dodont { grid-template-columns: 1fr; } }
.dodont ul { margin: 6px 0 0; padding-left: 18px; font-size: 14px; color: var(--text-2); }
.dodont li { margin: 4px 0; }
.dodont .do h4 { color: var(--green-text); } .dodont .dont h4 { color: var(--red-text); }

/* Chart */
.chart { width: 100%; height: 150px; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .lbl { font-size: 10px; fill: var(--muted); }
.chart .line { fill: none; stroke: var(--blue); stroke-width: 2; stroke-linejoin: round; }
.chart .area { fill: rgba(47,143,224,.1); }
.chart .pt { fill: var(--blue); }
.chart .bar { fill: var(--blue); }

/* Toast / modal */
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 600; z-index: 50; box-shadow: 0 6px 24px rgba(0,0,0,.2); opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
.modal-bg { position: fixed; inset: 0; background: rgba(15,31,46,.45); z-index: 40; display: grid; place-items: end center; padding: 0; }
@media (min-width: 700px) { .modal-bg { place-items: center; padding: 20px; } }
.modal { background: var(--surface); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + var(--safe-b)); max-height: 92vh; overflow: auto; }
@media (min-width: 700px) { .modal { border-radius: 18px; } }
.modal h2 { margin-bottom: 12px; }

/* Empty */
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; margin-bottom: 8px; color: var(--border); }

/* Auth */
.auth-wrap { max-width: 400px; margin: 40px auto; }

/* Print report */
@media print {
  body { background: #fff; }
  .tabbar, .no-print { display: none !important; }
  .screen { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  .report-page { break-after: page; }
}
.report { font-size: 13px; }
.report .r-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; border-bottom: 2px solid var(--navy); padding-bottom: 12px; margin-bottom: 14px; }
.report .r-head img { height: 54px; max-width: 200px; object-fit: contain; }
.report h1 { font-size: 22px; }
.report .r-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 16px; margin-bottom: 14px; }
.report .r-meta div span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.report .r-sig { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 28px; }
.report .r-sig div { border-top: 1px solid var(--text); padding-top: 6px; font-size: 12px; color: var(--text-2); }
.report .r-foot { margin-top: 16px; color: var(--muted); font-size: 11px; }
.score-chip { display: inline-block; min-width: 42px; text-align: center; padding: 3px 8px; border-radius: 8px; font-weight: 700; font-size: 13px; }
.score-chip.g { background: var(--green-bg); color: var(--green-text); }
.score-chip.a { background: var(--amber-bg); color: var(--amber-text); }
.score-chip.r { background: var(--red-bg); color: var(--red-text); }
.score-chip.n { background: var(--surface-2); color: var(--muted); font-weight: 500; }

.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--navy); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync-dot.online { background: var(--green); } .sync-dot.pending { background: var(--amber); }
