:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-strong: #f9fafb;
  --ink: #172033;
  --muted: #657084;
  --line: #d7dde6;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #e5f4f1;
  --blue: #2563eb;
  --amber: #b45309;
  --shadow: 0 18px 48px rgba(23, 32, 51, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo,
    system-ui, sans-serif;
}

body.keypad-open {
  padding-bottom: 300px;
}

button,
input,
select {
  font: inherit;
}

button,
input,
select,
.amount-keypad {
  touch-action: manipulation;
}

.amount-keypad,
.keypad-card,
.keypad-grid button,
.keypad-done {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(420px, 0.95fr);
  gap: 20px;
  align-items: stretch;
  margin-bottom: 22px;
}

.title-block {
  padding: 6px 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(1.75rem, 3vw, 2.65rem);
  line-height: 1.12;
  letter-spacing: 0;
}

.title-block h1 + p {
  max-width: 640px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.7;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.pdf-button {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  padding: 9px 16px;
  font-weight: 800;
  line-height: 1.2;
}

.pdf-button:hover {
  background: var(--accent-strong);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-strip article {
  display: grid;
  align-content: center;
  min-height: 84px;
  padding: 12px;
  border: 1px solid #e7ebf1;
  border-radius: 6px;
  background: var(--surface-strong);
}

.summary-strip span {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.summary-strip strong {
  font-size: clamp(1.05rem, 2.2vw, 1.55rem);
  line-height: 1.1;
  word-break: keep-all;
}

.quote-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.quote-panel {
  display: grid;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(23, 32, 51, 0.08);
}

.current-panel {
  border-top: 5px solid var(--blue);
}

.quote-panel[data-plan="change"] {
  border-top: 5px solid var(--accent);
}

.quote-panel[data-plan="mnp"] {
  border-top: 5px solid var(--amber);
}

.panel-header {
  display: flex;
  min-height: 48px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  line-height: 1;
}

.icon-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.field-stack {
  display: grid;
  gap: 12px;
}

.plan-picker,
.call-option-picker {
  display: grid;
  gap: 7px;
}

.plan-picker span,
.call-option-picker span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.35;
}

.plan-picker select,
.call-option-picker select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

.plan-picker select:focus,
.call-option-picker select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
  outline: none;
}

.plan-picker-meta,
.call-option-meta {
  margin: -1px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.form-field {
  display: grid;
  gap: 7px;
}

.form-field span,
.segmented-field legend {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.35;
}

.form-field input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  text-align: right;
}

.form-field input.keypad-active {
  border-color: var(--accent);
  background: #fbfefd;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.form-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
  outline: none;
}

.discount-field {
  display: grid;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.discount-field legend {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.35;
}

.discount-option {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-strong);
  cursor: pointer;
}

.discount-option input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.discount-option span {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.discount-option strong {
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.25;
}

.discount-option small {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.discount-option:has(input:checked) {
  border-color: rgba(15, 118, 110, 0.45);
  background: var(--accent-soft);
}

.discount-option.is-disabled {
  cursor: not-allowed;
  opacity: 0.64;
}

.discount-option.is-disabled input {
  cursor: not-allowed;
}

.check-option {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-strong);
  cursor: pointer;
}

.check-option input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.check-option span {
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.25;
}

.check-option:has(input:checked) {
  border-color: rgba(15, 118, 110, 0.45);
  background: var(--accent-soft);
}

.family-line-field.is-hidden,
.family-count-field.is-hidden {
  display: none;
}

.manual-discount-field {
  display: grid;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.manual-discount-field legend {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.35;
}

.manual-discount-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.segmented-field {
  display: grid;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  min-height: 42px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.segmented-control label {
  position: relative;
  min-width: 0;
}

.segmented-control input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented-control span {
  display: grid;
  min-height: 34px;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.segmented-control input:checked + span {
  background: var(--accent);
  color: #fff;
}

.payment-fields {
  display: grid;
  gap: 10px;
}

.payment-fields.is-hidden {
  display: none;
}

.field-note {
  margin: -2px 0 2px;
  padding: 8px 10px;
  border-left: 4px solid var(--amber);
  border-radius: 6px;
  background: #fff7ed;
  color: #7c2d12;
  font-size: 0.84rem;
  line-height: 1.45;
}

.result-block {
  display: grid;
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.result-line {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: #fff;
}

.result-line span {
  min-width: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.result-line strong {
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.15;
  text-align: right;
  white-space: nowrap;
}

.result-line.primary {
  background: var(--accent-soft);
}

.result-line.primary strong {
  color: var(--accent-strong);
  font-size: 1.25rem;
}

.amount-keypad {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  justify-content: center;
  padding: 0 12px 14px;
  pointer-events: none;
}

.keypad-card {
  width: min(420px, 100%);
  border: 1px solid rgba(215, 221, 230, 0.95);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 22px 60px rgba(23, 32, 51, 0.22);
  opacity: 0;
  transform: translateY(calc(100% + 18px));
  transition:
    opacity 180ms ease,
    transform 220ms ease;
}

.amount-keypad.is-open {
  pointer-events: auto;
}

.amount-keypad.is-open .keypad-card {
  opacity: 1;
  transform: translateY(0);
}

.keypad-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.keypad-header div {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.keypad-header span {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.keypad-header strong {
  color: var(--ink);
  font-size: 1.45rem;
  line-height: 1.1;
}

.keypad-done {
  min-width: 72px;
  min-height: 38px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
}

.keypad-grid button {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  cursor: pointer;
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1;
}

.keypad-grid button:active {
  transform: translateY(1px);
}

.keypad-grid button[data-keypad-action="clear"],
.keypad-grid button[data-keypad-action="backspace"] {
  color: var(--muted);
  font-size: 1.08rem;
}

.keypad-grid .wide-key {
  grid-column: span 2;
}

.keypad-grid .accent-key {
  grid-column: span 1;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.print-sheet {
  display: none;
}

@media (max-width: 1180px) {
  .app-header {
    grid-template-columns: 1fr;
  }

  .quote-grid {
    gap: 10px;
  }

  .quote-panel {
    gap: 14px;
    padding: 12px;
  }

  .panel-header h2 {
    font-size: 1.08rem;
  }

  .plan-picker select,
  .form-field input {
    padding-inline: 8px;
  }

  .result-line {
    padding-inline: 9px;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 6mm;
  }

  * {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  html,
  body {
    width: auto;
    min-width: 0;
    margin: 0;
    background: #fff;
    color: #172033;
  }

  .app-shell,
  .amount-keypad {
    display: none !important;
  }

  .print-sheet {
    display: block;
    width: 100%;
    font-size: 8pt;
    line-height: 1.28;
  }

  .print-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8mm;
    margin-bottom: 3mm;
    padding-bottom: 2.5mm;
    border-bottom: 1px solid #cbd5e1;
  }

  .print-eyebrow {
    margin: 0 0 1mm;
    color: #0f766e;
    font-size: 7pt;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
  }

  .print-header h1 {
    margin: 0;
    font-size: 14pt;
    line-height: 1.15;
  }

  .print-header time {
    color: #657084;
    font-size: 8pt;
    white-space: nowrap;
  }

  .print-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3mm;
    margin-bottom: 3mm;
  }

  .print-summary article {
    display: grid;
    gap: 1mm;
    min-height: 13mm;
    padding: 2mm 2.5mm;
    border: 1px solid #cbd5e1;
    border-radius: 2mm;
    background: #f8fafc;
  }

  .print-summary span {
    color: #657084;
    font-size: 7pt;
  }

  .print-summary strong {
    font-size: 12pt;
    line-height: 1.05;
  }

  .print-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3mm;
    align-items: start;
  }

  .print-card {
    overflow: hidden;
    border: 1px solid #cbd5e1;
    border-radius: 2mm;
    break-inside: avoid;
    background: #fff;
  }

  .print-card h2 {
    margin: 0;
    padding: 2.2mm 2.5mm;
    background: #e5f4f1;
    color: #115e59;
    font-size: 10pt;
    line-height: 1.15;
  }

  .print-section {
    padding: 2mm 2.5mm 2.5mm;
  }

  .print-section + .print-section {
    border-top: 1px solid #e2e8f0;
  }

  .print-section h3 {
    margin: 0 0 1.5mm;
    color: #657084;
    font-size: 7.2pt;
    line-height: 1.2;
  }

  .print-row {
    display: grid;
    grid-template-columns: minmax(22mm, 42%) minmax(0, 1fr);
    gap: 2mm;
    padding: 1mm 0;
    border-top: 1px solid #edf2f7;
    break-inside: avoid;
  }

  .print-row:first-of-type {
    border-top: 0;
  }

  .print-row span {
    color: #657084;
    overflow-wrap: anywhere;
  }

  .print-row strong {
    color: #172033;
    font-weight: 700;
    text-align: right;
    overflow-wrap: anywhere;
  }

  .print-row.is-result {
    background: #f8fafc;
    margin-inline: -1mm;
    padding-inline: 1mm;
  }

  .print-row.is-result strong {
    color: #115e59;
    font-size: 8.5pt;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 16px;
  }

  .summary-strip {
    grid-template-columns: 1fr;
  }

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

  .quote-panel {
    padding: 15px;
  }

  .manual-discount-grid {
    grid-template-columns: 1fr;
  }

  .result-line {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .result-line strong {
    width: 100%;
  }

  body.keypad-open {
    padding-bottom: 286px;
  }

  .amount-keypad {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}
