:root {
  --ink: #1e2a31;
  --muted: #65767e;
  --paper: #f5f7f4;
  --surface: #ffffff;
  --line: #dbe3df;
  --teal: #0f6675;
  --teal-dark: #0a4c58;
  --morning: #d26a32;
  --evening: #3569a8;
  --danger: #b32828;
  --shadow: 0 10px 25px rgb(20 45 47 / 8%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Hiragino Sans", "Yu Gothic", Meiryo, system-ui, sans-serif;
  line-height: 1.5;
}

button, input { font: inherit; }
button { cursor: pointer; }

.site-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem max(1.25rem, calc((100% - 1120px) / 2));
  color: #fff;
  background: var(--teal-dark);
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.35rem, 3vw, 1.8rem); font-weight: 700; letter-spacing: .04em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
.eyebrow { margin-bottom: .15rem; color: var(--teal); font-size: .7rem; font-weight: 700; letter-spacing: .13em; }
.site-header .eyebrow { color: #bce5e6; }
.header-note { color: #dceff0; font-size: .85rem; }
.header-actions { display: flex; align-items: center; gap: .8rem; }
.header-logout { padding: .35rem .65rem; color: #fff; background: transparent; border: 1px solid #bce5e6; border-radius: 6px; font-size: .8rem; }
.login-panel { display: grid; gap: .8rem; width: min(420px, calc(100% - 2rem)); margin: 4rem auto; padding: 1.5rem; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.login-panel[hidden] { display: none; }
.login-panel > p:not(.eyebrow):not(.form-error) { color: var(--muted); font-size: .9rem; }
#login-form { display: grid; gap: .8rem; }
#login-form label { display: grid; gap: .35rem; font-size: .9rem; font-weight: 700; }
#login-password { min-height: 46px; padding: .5rem .7rem; }
.password-visibility { display: flex !important; align-items: center; gap: .4rem; font-size: .82rem !important; font-weight: 400 !important; }
.password-visibility input { width: auto; }
.password-dialog { width: min(440px, calc(100% - 2rem)); padding: 0; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.password-dialog::backdrop { background: rgb(10 40 45 / 45%); }
#password-change-form { display: grid; gap: .9rem; padding: 1.25rem; }
#password-change-form > label { display: grid; gap: .35rem; font-size: .9rem; font-weight: 700; }
#password-change-form input { min-height: 44px; padding: .45rem .65rem; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.dialog-close { width: 2rem; height: 2rem; color: var(--muted); background: transparent; border: 0; border-radius: 50%; font-size: 1.5rem; line-height: 1; }
.dialog-close:hover { background: #edf4f2; }

main { display: grid; gap: 1.25rem; width: min(1120px, calc(100% - 2rem)); margin: 1.5rem auto 3rem; }
.entry-panel, .chart-panel, .records-panel { padding: clamp(1rem, 3vw, 1.5rem); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.period-chip { padding: .35rem .75rem; color: var(--teal-dark); background: #e3f1ef; border-radius: 999px; font-size: .85rem; font-weight: 700; }

#entry-form { display: grid; gap: 1rem; }
.datetime-field { display: grid; gap: .35rem; max-width: 360px; font-size: .92rem; font-weight: 700; }
input { width: 100%; color: var(--ink); background: #fff; border: 1px solid #b9c9c5; border-radius: 8px; }
.datetime-field input { min-height: 48px; padding: .5rem .7rem; }
.measurement-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
.measurement-field { position: relative; display: grid; gap: .25rem; padding: .75rem; border-radius: 10px; }
.measurement-field span { font-size: .86rem; font-weight: 700; }
.measurement-field input { min-height: 66px; padding: .35rem 2.2rem .35rem .45rem; border-width: 0 0 2px; border-radius: 0; font-size: clamp(1.8rem, 7vw, 2.5rem); font-weight: 700; text-align: right; }
.measurement-field small { position: absolute; right: .82rem; bottom: 1.2rem; color: var(--muted); font-size: .75rem; }
.systolic { background: #fdf0e9; }.systolic input { border-color: var(--morning); }
.diastolic { background: #edf4fa; }.diastolic input { border-color: var(--evening); }
.pulse { background: #eef5ef; }.pulse input { border-color: #579467; }
.form-actions { display: flex; gap: .6rem; }.save-button { min-height: 52px; padding: 0 1.1rem; color: #fff; background: var(--teal); border: 0; border-radius: 9px; font-weight: 700; }.form-actions .save-button:only-child { width: 100%; }
.save-button:hover { background: var(--teal-dark); }
.form-help { margin-top: 1rem; color: var(--muted); font-size: .78rem; }
.form-error { color: var(--danger); font-weight: 700; }

.chart-heading { align-items: end; }
.chart-actions { display: flex; align-items: center; gap: .8rem; }
.chart-date-range { margin-top: .15rem; color: var(--muted); font-size: .82rem; }
.legend { display: flex; gap: 1rem; color: var(--muted); font-size: .85rem; }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend-dot { width: .7rem; height: .7rem; border-radius: 50%; }.morning { background: var(--morning); }.evening { background: var(--evening); }
.plot-section + .plot-section { margin-top: 1.4rem; }
.plot-labels { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .3rem; }
.plot-labels h3 span, .plot-labels p { color: var(--muted); font-size: .78rem; font-weight: 400; }
.pressure-info { display: flex; align-items: baseline; justify-content: end; gap: .9rem; color: var(--muted); text-align: right; white-space: nowrap; }
.average-summary { color: var(--ink); font-size: .78rem; font-variant-numeric: tabular-nums; }
.chart { min-height: 210px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .normal-pressure-band { fill: #e5f5fa; }.chart .grid { stroke: #dfe6e3; stroke-width: 1; }.chart .sunday-line { stroke: #9eb7af; stroke-width: 1.25; }.chart .axis { stroke: #aebdb8; stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 13px; }.chart .axis-unit { fill: var(--ink); font-weight: 700; }
.empty-state { display: grid; justify-items: center; gap: .45rem; padding: 2.7rem 1rem; text-align: center; background: #f7faf8; border: 1px dashed #bfd0ca; border-radius: 10px; }
.empty-state[hidden] { display: none; }
.empty-state p { font-weight: 700; }.empty-state span { color: var(--muted); font-size: .85rem; }
.text-button { padding: .3rem; color: var(--teal); background: none; border: 0; border-bottom: 1px solid currentColor; font-weight: 700; }

.data-actions { display: flex; gap: .5rem; }
.secondary-button, .delete-button { color: var(--teal-dark); background: #fff; border: 1px solid #afc6c0; border-radius: 7px; }
.secondary-button { padding: .48rem .7rem; font-size: .82rem; font-weight: 700; }.file-button { display: inline-flex; align-items: center; cursor: pointer; }.file-button input { display: none; }
.table-scroll { overflow-x: auto; } table { width: 100%; border-collapse: collapse; white-space: nowrap; } th, td { padding: .7rem .6rem; border-bottom: 1px solid var(--line); text-align: left; font-size: .88rem; } th { color: var(--muted); font-size: .75rem; } .record-number { text-align: right; font-variant-numeric: tabular-nums; } .record-period { display: inline-block; min-width: 2.5rem; padding: .15rem .45rem; border-radius: 99px; text-align: center; font-size: .75rem; font-weight: 700; }.record-period.morning { color: #96451e; background: #fdf0e9; }.record-period.evening { color: #274e80; background: #edf4fa; }.row-actions { display: flex; justify-content: end; gap: .35rem; }.edit-button, .delete-button { padding: .28rem .45rem; background: #fff; border-radius: 6px; font-size: .75rem; }.edit-button { color: var(--teal-dark); border: 1px solid #afc6c0; }.delete-button { color: var(--danger); border: 1px solid #e4b7b7; }.table-empty { padding: 1.5rem; color: var(--muted); text-align: center; }.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

@media (min-width: 800px) { main { grid-template-columns: minmax(260px, 340px) 1fr; align-items: start; }.entry-panel { position: sticky; top: 1rem; }.chart-panel, .records-panel { grid-column: 2; }.measurement-fields { grid-template-columns: 1fr; }.measurement-field input { font-size: 2rem; } }
@media (max-width: 480px) { .site-header { align-items: start; flex-direction: column; }.header-note { display: none; }.header-actions { width: 100%; justify-content: space-between; } main { width: min(100% - 1.25rem, 1120px); margin-top: .75rem; }.measurement-fields { gap: .45rem; }.measurement-field { padding: .55rem; }.measurement-field input { min-height: 58px; }.measurement-field small { right: .6rem; bottom: 1rem; }.chart { min-height: 185px; }.plot-labels { align-items: start; flex-direction: column; gap: .1rem; }.pressure-info { align-items: start; flex-direction: column; gap: .1rem; text-align: left; white-space: normal; }.data-actions { gap: .25rem; }.secondary-button { padding: .45rem .5rem; } }

@page { size: 297mm 210mm; margin: 0; }
@media print {
  html, body { width: auto; height: auto; }
  body { margin: 0; padding: 10mm; background: #fff; }
  .site-header, .login-panel, .password-dialog, .entry-panel, .records-panel, .print-button, .empty-state { display: none !important; }
  main { display: block; width: 100%; height: 170mm; margin: 0; overflow: hidden; }
  .chart-panel { display: flex; flex-direction: column; width: 100%; height: 170mm; padding: 0; border: 0; border-radius: 0; box-shadow: none; break-inside: avoid-page; page-break-inside: avoid; }
  .chart-heading { flex: 0 0 10mm; margin: 0; }
  .chart-heading .eyebrow { display: none; }
  .chart-date-range { margin-top: 0; }
  .chart text { font-size: 24px; }
  .chart-actions, .legend { display: flex !important; }
  .legend-dot { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #chart-area { display: grid; grid-template-rows: 3fr 2fr; gap: 2mm; height: 160mm; }
  .plot-labels { flex: 0 0 7mm; margin-bottom: 0; }
  .plot-section { display: flex; flex-direction: column; min-height: 0; break-inside: avoid; page-break-inside: avoid; }
  .plot-section + .plot-section { margin-top: 0; }
  .chart { flex: 1 1 0; min-height: 0; height: auto; }
  .chart svg { width: 100%; height: 100%; }
}

body.print-layout { margin: 0; padding: 10mm; background: #fff; }
body.print-layout .site-header, body.print-layout .login-panel, body.print-layout .password-dialog, body.print-layout .entry-panel, body.print-layout .records-panel, body.print-layout .print-button, body.print-layout .empty-state { display: none !important; }
body.print-layout main { display: block; width: 100%; height: 170mm; margin: 0; overflow: hidden; }
body.print-layout .chart-panel { display: flex; flex-direction: column; width: 100%; height: 170mm; padding: 0; border: 0; border-radius: 0; box-shadow: none; }
body.print-layout .chart-heading { flex: 0 0 10mm; margin: 0; }
body.print-layout .chart-heading .eyebrow { display: none; }
body.print-layout .chart-date-range { margin-top: 0; }
body.print-layout .chart text { font-size: 24px; }
body.print-layout .chart-actions, body.print-layout .legend { display: flex !important; }
body.print-layout #chart-area { display: grid; grid-template-rows: 3fr 2fr; gap: 2mm; height: 160mm; }
body.print-layout .plot-labels { flex: 0 0 7mm; margin-bottom: 0; }
body.print-layout .plot-section { display: flex; flex-direction: column; min-height: 0; }
body.print-layout .plot-section + .plot-section { margin-top: 0; }
body.print-layout .chart { flex: 1 1 0; min-height: 0; height: auto; }
body.print-layout .chart svg { width: 100%; height: 100%; }
