:root {
  --bg: #101214;
  --surface: #181b1f;
  --surface-2: #20242a;
  --border: #30343b;
  --text: #f5f7f8;
  --muted: #9ca3ad;
  --accent: #78d6b0;
  --accent-dark: #10271f;
  --danger: #ff8a8a;
  --radius: 16px;
  --radius-sm: 10px;
  --space: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }

.app-shell { min-height: 100vh; }
.page { width: 100%; max-width: 760px; margin: 0 auto; padding: 18px 14px 118px; }
.page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.page-header h1 { margin: 0; font-size: 1.35rem; }
.history-page-header h1 { flex: 0 0 auto; white-space: nowrap; font-size: clamp(1.05rem, 4vw, 1.35rem); }
.fixed-page-header { position: fixed; z-index: 20; top: 0; left: 50%; width: 100%; max-width: 760px; transform: translateX(-50%); padding: calc(12px + env(safe-area-inset-top)) 14px 10px; border-bottom: 1px solid var(--border); background: rgba(16,18,20,.97); backdrop-filter: blur(12px); }
.fixed-page-header .page-header { margin-bottom: 12px; }
.input-fixed-header .weight-entry { margin-bottom: 0; }
.input-page { padding-top: calc(150px + env(safe-area-inset-top)); padding-bottom: calc(164px + env(safe-area-inset-bottom)); }
.detail-fixed-header .page-header { margin-bottom: 6px; }
.detail-fixed-header .eyebrow { margin-bottom: 0; }
.detail-page { padding-top: calc(106px + env(safe-area-inset-top)); padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
.back-button { width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 50%; background: var(--surface); color: var(--text); display: grid; place-items: center; font-size: 1.35rem; }
.header-spacer { flex: 1; }
.status-badge { border: 1px solid var(--border); border-radius: 999px; color: var(--muted); padding: 7px 10px; font-size: .78rem; }
.status-badge.online { color: var(--accent); border-color: #315d4d; }
.status-badge.offline { color: var(--danger); border-color: #6d3d3d; }

.home-page { min-height: 100vh; max-width: 760px; margin: 0 auto; padding: 24px 16px; display: flex; flex-direction: column; }
.home-header { display: flex; justify-content: space-between; align-items: flex-start; }
.eyebrow { color: var(--muted); margin: 0 0 4px; font-size: .82rem; }
.home-header h1 { margin: 0; font-size: 2rem; }
.home-menu { flex: 1; align-content: center; margin: 0; display: grid; gap: 12px; }
.menu-button { min-height: 92px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); display: grid; grid-template-columns: 52px 1fr 24px; align-items: center; gap: 12px; padding: 14px; }
.menu-button:active { background: var(--surface-2); }
.menu-icon { width: 52px; height: 52px; border-radius: 14px; background: var(--accent-dark); color: var(--accent); display: grid; place-items: center; font-weight: 800; }
.menu-button strong, .menu-button small { display: block; }
.menu-button strong { font-size: 1.12rem; margin-bottom: 4px; }
.menu-button small { color: var(--muted); }
.menu-arrow { color: var(--muted); font-size: 1.8rem; text-align: right; }

.primary-button, .secondary-button { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; border-radius: var(--radius-sm); border: 1px solid transparent; padding: 0 16px; font-weight: 750; line-height: 1; text-align: center; cursor: pointer; }
.primary-button { background: var(--accent); color: #102019; }
.primary-button:disabled { opacity: .55; cursor: not-allowed; }
.secondary-button { background: var(--surface); color: var(--text); border-color: var(--border); }
.header-action { min-height: 44px; white-space: nowrap; flex-shrink: 0; padding-inline: 12px; font-size: .84rem; }

.history-list { display: grid; gap: 10px; }
.history-item { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 14px; text-align: left; color: var(--text); cursor: pointer; transition: background .15s ease, border-color .15s ease; }
.history-item:hover, .history-item:focus-visible { background: var(--surface-2); border-color: #46504c; outline: none; }
.history-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-bottom: 12px; }
.history-date { min-width: 0; color: var(--muted); font-size: .82rem; }
.history-date time { display: block; margin-top: 5px; font-size: .75rem; color: var(--muted); font-weight: 400; }
.history-date .history-title { display: block; color: var(--text); font-size: .95rem; line-height: 1.25; overflow-wrap: anywhere; }
.history-grand { flex: 0 0 auto; text-align: right; }
.history-grand span { display: block; color: var(--muted); font-size: .7rem; margin-bottom: 3px; }
.history-grand strong { color: var(--accent); font-size: 1.2rem; line-height: 1.1; }
.history-meta { display: grid; grid-template-columns: .75fr 1fr 1.2fr; gap: 8px; border-top: 1px solid var(--border); padding-top: 10px; }
.history-meta > div { min-width: 0; }
.history-meta > div + div { border-left: 1px solid var(--border); padding-left: 10px; }
.history-meta span { color: var(--muted); font-size: .68rem; line-height: 1.2; display: block; }
.history-meta strong { display: block; color: var(--text); margin-top: 4px; font-size: .82rem; line-height: 1.2; white-space: nowrap; }
.empty-state { margin: 18vh auto 0; max-width: 280px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; color: var(--text); margin-bottom: 6px; }
.record-title { margin: 0 0 12px; color: var(--text); font-size: .95rem; font-weight: 650; line-height: 1.35; overflow-wrap: anywhere; }
.new-record-dialog { width: min(380px, calc(100% - 32px)); border: 1px solid var(--border); border-radius: 18px; padding: 22px; background: var(--surface); color: var(--text); }
.new-record-dialog::backdrop { background: rgba(0,0,0,.68); backdrop-filter: blur(3px); }
.new-record-dialog h2 { margin: 0; font-size: 1.2rem; }
.dialog-description { margin: 7px 0 18px; color: var(--muted); font-size: .88rem; }
.new-record-dialog label { display: block; margin-bottom: 7px; color: var(--muted); font-size: .8rem; }
.new-record-dialog input { width: 100%; height: 48px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #111317; color: var(--text); padding: 0 12px; outline: none; }
.new-record-dialog input:focus { border-color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dialog-actions .secondary-button, .dialog-actions .primary-button { min-height: 44px; }

.weight-entry { display: grid; grid-template-columns: 1fr 84px; gap: 8px; margin-bottom: 12px; }
.weight-entry input { width: 100%; min-width: 0; height: 52px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); padding: 0 13px; outline: none; }
.weight-entry input:focus { border-color: var(--accent); }
.weight-entry input::placeholder { color: #737a84; }

.grid-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.weight-grid { min-width: 590px; width: 100%; border-collapse: separate; border-spacing: 5px; padding: 5px; table-layout: fixed; }
.weight-grid th, .weight-grid td { height: 42px; text-align: center; }
.weight-grid th { color: var(--muted); font-size: .72rem; font-weight: 700; }
.weight-grid th.row-label, .weight-grid td.row-label { width: 34px; color: var(--muted); font-size: .75rem; }
.weight-grid th.row-total, .weight-grid td.row-total { width: 68px; }
.weight-grid input { width: 100%; height: 42px; border: 1px solid var(--border); border-radius: 7px; background: #111317; color: var(--text); text-align: center; outline: none; padding: 0 3px; }
.weight-grid input:focus { border-color: var(--accent); background: #141922; }
.row-total { color: var(--accent); font-weight: 800; font-size: .78rem; }

.summary { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; border-top: 1px solid var(--border); background: rgba(24,27,31,.97); backdrop-filter: blur(12px); }
.summary-inner { max-width: 760px; margin: 0 auto; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
.summary-primary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.summary-primary div { min-width: 0; }
.summary-primary span, .summary-secondary span { display: block; color: var(--muted); font-size: .68rem; line-height: 1.2; }
.summary-primary strong { display: block; font-size: clamp(1rem, 4vw, 1.2rem); line-height: 1.2; margin-top: 4px; white-space: nowrap; }
.summary-primary div:last-child { text-align: right; }
.summary-primary div:last-child strong { color: var(--accent); }
.summary-secondary { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; align-items: center; gap: 10px; }
.summary-secondary div { min-width: 0; padding-left: 2px; }
.summary-secondary strong { display: block; margin-top: 4px; font-size: .88rem; line-height: 1.2; white-space: nowrap; }
.summary-secondary .primary-button { min-width: 82px; height: 44px; padding-inline: 12px; }

.detail-scroll { overflow-x: auto; padding: 5px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.detail-grid { min-width: 590px; width: 100%; border-collapse: separate; border-spacing: 5px; table-layout: fixed; }
.detail-grid th, .detail-grid td { height: 38px; text-align: center; }
.detail-grid thead th { color: var(--muted); font-size: .72rem; font-weight: 700; }
.detail-grid tbody th.row-name, .detail-grid tbody td { border: 1px solid var(--border); border-radius: 7px; background: #111317; }
.detail-grid tbody th.row-name { width: 34px; border: 0; background: transparent; color: var(--muted); font-size: .75rem; }
.detail-grid thead th.row-name { width: 34px; }
.detail-grid thead th.detail-total-head, .detail-grid tbody td.detail-total { width: 68px; }
.detail-grid td.detail-total { color: var(--accent); font-weight: 800; }
.detail-summary-footer { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; border-top: 1px solid var(--border); background: rgba(24,27,31,.97); backdrop-filter: blur(12px); }
.detail-summary-footer .summary-inner { padding-top: 12px; }
.detail-footer-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: center; gap: 8px; }
.detail-footer-row > div { min-width: 0; }
.detail-footer-row > div + div { border-left: 1px solid var(--border); padding-left: 8px; }
.detail-footer-row span { display: block; color: var(--muted); font-size: .68rem; line-height: 1.2; white-space: nowrap; }
.detail-footer-row strong { display: block; margin-top: 5px; font-size: .9rem; line-height: 1.1; white-space: nowrap; }
.detail-footer-row > div:first-child strong, .detail-footer-row > div:nth-child(2) strong { color: var(--accent); }

.placeholder { min-height: 70vh; display: grid; place-content: center; text-align: center; color: var(--muted); }
.placeholder strong { color: var(--text); font-size: 1.2rem; margin-bottom: 8px; }
.toast { position: fixed; z-index: 30; left: 50%; bottom: 24px; transform: translate(-50%, 20px); max-width: calc(100% - 32px); border: 1px solid var(--border); border-radius: 999px; background: #262a30; color: var(--text); padding: 11px 16px; opacity: 0; pointer-events: none; transition: .18s ease; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  .page { padding-top: 28px; }
  .input-page { padding-top: calc(150px + env(safe-area-inset-top)); }
  .detail-page { padding-top: calc(106px + env(safe-area-inset-top)); }
  .home-page { padding: 32px 24px; }
  .weight-grid { min-width: 620px; }
  .summary-inner { padding-left: 20px; padding-right: 20px; }
  .history-item { padding: 16px 18px; }
}

@media (max-width: 360px) {
  .summary-inner { padding-left: 10px; padding-right: 10px; }
  .summary-primary { padding: 9px; }
  .summary-secondary { gap: 6px; }
  .summary-secondary span { font-size: .63rem; }
  .summary-secondary strong { font-size: .8rem; }
  .summary-secondary .primary-button { min-width: 72px; padding-inline: 8px; }
  .history-item { padding: 12px; }
  .history-meta { gap: 5px; }
  .history-meta > div + div { padding-left: 6px; }
  .history-meta span { font-size: .62rem; }
  .history-meta strong { font-size: .75rem; }
  .new-record-dialog { padding: 18px; }
  .detail-summary-footer .summary-inner { padding-left: 8px; padding-right: 8px; }
  .detail-footer-row { gap: 4px; }
  .detail-footer-row > div + div { padding-left: 4px; }
  .detail-footer-row span { font-size: .56rem; }
  .detail-footer-row strong { font-size: .7rem; }
}