:root {
  color-scheme: light;
  --bg: #f7f9fb;
  --surface: #ffffff;
  --ink: #17201c;
  --muted: #65716c;
  --line: #dfe7e2;
  --primary: #1f7a5a;
  --primary-strong: #145f45;
  --coral: #dd6b52;
  --gold: #d69f36;
  --shadow: 0 18px 50px rgba(25, 42, 35, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(31, 122, 90, 0.12), transparent 32%),
    linear-gradient(280deg, rgba(221, 107, 82, 0.11), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  background: var(--primary);
  color: #fff;
  font-weight: 760;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

button:hover:not(:disabled) {
  background: var(--primary-strong);
  box-shadow: 0 10px 24px rgba(31, 122, 90, 0.18);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(31, 122, 90, 0.12);
}

label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 720;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: calc(100vh - 80px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  align-items: center;
  gap: 48px;
}

.login-copy h1,
.topbar h1 {
  margin: 0;
  font-size: clamp(42px, 7vw, 82px);
  line-height: 0.96;
  letter-spacing: 0;
}

.lead {
  max-width: 520px;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 20px;
  line-height: 1.65;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 820;
}

.login-panel,
.tool-panel,
.stat-panel,
.history-section {
  border: 1px solid rgba(31, 122, 90, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.login-panel {
  padding: 28px;
}

.login-row,
.record-row,
.control-row {
  display: flex;
  gap: 10px;
}

.login-row input,
.record-row input {
  flex: 1 1 auto;
}

.record-row button {
  flex: 0 0 auto;
}

.form-message {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.form-message.error {
  color: #ba392b;
}

.form-message.success {
  color: var(--primary-strong);
}

.dashboard {
  display: grid;
  gap: 22px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-top: 10px;
}

.topbar h1 {
  font-size: clamp(34px, 5vw, 58px);
}

.ghost-button,
.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.ghost-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled) {
  background: #f0f5f2;
  box-shadow: none;
}

.camera-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-panel {
  min-height: 96px;
  padding: 18px;
  box-shadow: none;
}

.stat-panel span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.stat-panel strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
  line-height: 1;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.86fr);
  gap: 18px;
  align-items: start;
}

.tool-panel,
.history-section {
  padding: 18px;
}

.panel-heading,
.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.panel-heading h2,
.section-heading h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.2;
}

.panel-heading p,
.section-heading span {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.compact-heading {
  margin-bottom: 10px;
}

.camera-stage,
.replay-stage {
  position: relative;
  width: 100%;
  overflow: hidden;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #18221d;
  aspect-ratio: 4 / 3;
}

.camera-stage video,
.camera-stage img,
.replay-stage img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.camera-stage video.mirrored {
  transform: scaleX(-1);
}

.empty-camera,
.replay-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.72);
  font-weight: 820;
}

.empty-camera span {
  display: inline-grid;
  place-items: center;
  width: min(42%, 230px);
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.42);
  letter-spacing: 0;
}

.control-row {
  margin-top: 12px;
}

.control-row button {
  flex: 1 1 0;
}

.record-form {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.replay-stage {
  background: #101615;
}

.replay-stage img {
  opacity: 0;
  transition: opacity 180ms ease;
}

.replay-stage.has-image img {
  opacity: 1;
}

.replay-caption {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  min-height: 48px;
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(14, 20, 18, 0.74);
  color: #fff;
  font-weight: 720;
  display: none;
}

.replay-stage.has-image .replay-caption {
  display: block;
}

.trend-panel {
  margin-top: 16px;
}

.weight-chart {
  min-height: 210px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.weight-chart svg {
  width: 100%;
  height: 210px;
  display: block;
}

.chart-empty {
  height: 210px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.history-section {
  box-shadow: none;
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.history-item {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) auto auto;
  gap: 14px;
  align-items: center;
  min-height: 86px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.history-thumb {
  width: 86px;
  height: 66px;
  border-radius: 7px;
  background: #edf3ef;
  object-fit: cover;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.history-time {
  margin: 0;
  font-weight: 780;
}

.history-note {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.history-weight {
  color: var(--primary-strong);
  font-size: 20px;
  font-weight: 820;
  white-space: nowrap;
}

.delete-record-button {
  min-height: 38px;
  border: 1px solid rgba(186, 57, 43, 0.22);
  background: #fff;
  color: #ba392b;
  padding: 0 12px;
}

.delete-record-button:hover:not(:disabled) {
  background: #fff1ef;
  box-shadow: none;
}

@media (max-width: 900px) {
  .login-view,
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .login-view {
    align-content: center;
    gap: 28px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 22px, 1180px);
    padding: 18px 0 32px;
  }

  .topbar,
  .panel-heading,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .login-row,
  .record-row {
    flex-direction: column;
  }

  .login-copy h1 {
    font-size: 46px;
  }

  .lead {
    font-size: 17px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .history-item {
    grid-template-columns: 70px minmax(0, 1fr);
  }

  .history-thumb {
    width: 70px;
    height: 58px;
  }

  .history-weight {
    grid-column: 2;
    font-size: 18px;
  }

  .delete-record-button {
    grid-column: 1 / -1;
    width: 100%;
  }
}
