:root {
  color-scheme: light;
  --navy: #12233f;
  --blue: #1769aa;
  --blue-dark: #0d4d83;
  --pale-blue: #eaf4fb;
  --surface: #ffffff;
  --surface-muted: #f4f6f8;
  --border: #d8e0e8;
  --text-muted: #607086;
  --green: #137a49;
  --red: #b42318;
  --amber: #8a5200;
  --shadow: 0 12px 32px rgba(18, 35, 63, 0.08);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: #f7f9fb;
  color: var(--navy);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
  line-height: 1.6;
}

button, input, textarea { font: inherit; }

button { cursor: pointer; }

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

.app-header {
  padding: 0;
  background: linear-gradient(135deg, #102744, #1769aa);
  color: #fff;
}

.header-inner {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  width: min(1640px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.app-header h1 { margin: 4px 0; font-size: clamp(1.8rem, 3vw, 2.6rem); }
.app-header p { margin: 0; }
.eyebrow { font-weight: 700; letter-spacing: 0.08em; opacity: 0.82; }

.menu-toggle, .menu-close {
  display: none;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border: 0;
}

.menu-toggle {
  width: 46px;
  height: 46px;
  margin-top: 2px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
}

.menu-toggle span {
  position: absolute;
  width: 22px;
  height: 2px;
  border-radius: 999px;
  background: #fff;
}

.menu-toggle span:nth-child(1) { transform: translateY(-7px); }
.menu-toggle span:nth-child(3) { transform: translateY(7px); }

.site-layout {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 24px;
  width: min(1640px, calc(100% - 32px));
  margin: 28px auto;
  align-items: start;
}

.site-sidebar {
  position: sticky;
  top: 20px;
  z-index: 10;
  min-width: 0;
  padding: 16px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 8px 12px;
}

.site-navigation { display: grid; gap: 4px; }
.site-navigation a {
  display: block;
  padding: 10px 11px;
  border-radius: 9px;
  color: var(--navy);
  font-weight: 650;
  line-height: 1.4;
  text-decoration: none;
}
.site-navigation a:hover { background: var(--surface-muted); }
.site-navigation a[aria-current="page"] { background: var(--pale-blue); color: var(--blue-dark); }
.site-navigation a:focus-visible, .menu-toggle:focus-visible, .menu-close:focus-visible, .menu-overlay:focus-visible, .return-link:focus-visible {
  outline: 3px solid rgba(23, 105, 170, 0.3);
  outline-offset: 2px;
}
.sidebar-note { margin: 14px 8px 2px; color: var(--text-muted); font-size: 0.82rem; }
.site-content { min-width: 0; }
.site-view[hidden], .menu-overlay[hidden] { display: none !important; }

.page-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(420px, 0.95fr);
  gap: 24px;
  width: 100%;
  margin: 0;
  align-items: start;
}

.info-view { max-width: 940px; }
.info-panel {
  padding: clamp(24px, 4vw, 46px);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.info-panel h2 { margin: 2px 0 12px; font-size: clamp(1.65rem, 3vw, 2.25rem); }
.info-panel p { max-width: 72ch; }
.info-eyebrow { margin: 0; color: var(--blue); font-size: 0.88rem; font-weight: 750; letter-spacing: 0.06em; }
.guide-steps { display: grid; gap: 10px; margin: 24px 0; padding: 0; list-style: none; counter-reset: guide-step; }
.guide-steps li { display: grid; grid-template-columns: minmax(130px, 0.32fr) minmax(0, 1fr); gap: 12px; padding: 14px 16px; border-radius: 10px; background: var(--surface-muted); counter-increment: guide-step; }
.guide-steps strong::before { content: counter(guide-step) ". "; color: var(--blue); }
.info-list { display: grid; gap: 9px; padding-left: 1.4rem; }
.info-callout { margin-top: 22px; padding: 14px 16px; border-left: 4px solid var(--blue); border-radius: 8px; background: var(--pale-blue); }
.return-link { display: inline-flex; margin-top: 18px; color: var(--blue-dark); font-weight: 750; }
.faq-list { display: grid; gap: 10px; margin-top: 22px; }
.faq-list details { border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.faq-list summary { padding: 14px 16px; cursor: pointer; font-weight: 700; }
.faq-list p { margin: 0; padding: 0 16px 16px; color: var(--text-muted); }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 26px;
}

.panel h2, .panel h3 { margin-top: 0; }
.form-section { padding: 22px 0; border-top: 1px solid var(--border); }
.form-section:first-of-type { border-top: 0; }

.mode-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 22px;
  margin: 16px 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
}

.mode-switch legend { padding: 0 8px; font-weight: 700; }
.mode-switch label, .checkbox-field { display: flex; gap: 8px; align-items: center; }
.mode-switch input, .checkbox-field input, .saved-row input {
  flex: 0 0 auto;
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
}

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

.field { display: flex; flex-direction: column; gap: 7px; font-weight: 650; }
.field, .readout-field, .result-card, .saved-item { min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field small { color: var(--text-muted); font-weight: 400; }
.field-label { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.required-badge { display: inline-block; padding: 1px 7px; border-radius: 999px; background: #fdecec; color: var(--red); font-size: 0.75rem; font-weight: 750; }
.required-badge.optional-badge { background: #fff5dc; color: var(--amber); }
.field-error:empty { display: none; }
.field .field-error { color: var(--red); font-weight: 650; }
.field.has-error input { border-color: var(--red); background: #fffafa; }

input:not([type="radio"]):not([type="checkbox"]), textarea {
  width: 100%;
  border: 1px solid #b9c6d4;
  border-radius: 9px;
  padding: 11px 12px;
  background: #fff;
  color: var(--navy);
}

input:focus, textarea:focus {
  outline: 3px solid rgba(23, 105, 170, 0.16);
  border-color: var(--blue);
}

input[readonly] { background: var(--surface-muted); }
.readout-field { justify-content: center; padding: 12px; border-radius: 10px; background: var(--surface-muted); }
.readout-field strong { font-size: 1.28rem; }

.section-heading-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.section-heading-row h2, .section-heading-row h3 { margin-bottom: 0; }
.fee-summary, .saved-help, .rounding-note { color: var(--text-muted); }
.rounding-note { font-size: 0.88rem; }
.fee-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.notice, .message {
  margin-top: 14px;
  border-radius: 10px;
  padding: 12px 14px;
}

.notice { background: #fff5dc; color: var(--amber); }
.shipping-pending-notice { display: flex; flex-direction: column; gap: 2px; }
.message.success { background: #e8f7ef; color: var(--green); }
.message.warning { background: #fff5dc; color: var(--amber); }
.message.error { background: #fdecec; color: var(--red); }
.message { white-space: pre-line; }
.notice, .message, .result-card, .break-even-card, .saved-title, .saved-meta {
  overflow-wrap: anywhere;
}

.button-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 18px; }
.primary-button, .secondary-button, .danger-button, .text-button {
  border-radius: 9px;
  padding: 10px 16px;
  font-weight: 700;
}

.primary-button { border: 1px solid var(--blue); background: var(--blue); color: #fff; }
.primary-button:hover { background: var(--blue-dark); }
.secondary-button { border: 1px solid #9fb0c3; background: #fff; color: var(--navy); }
.danger-button { border: 1px solid #d92d20; background: #fff; color: var(--red); }
.text-button { padding: 4px 0; border: 0; background: transparent; color: var(--blue); }
.full-button { width: 100%; margin-top: 8px; }

.status-chip {
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--pale-blue);
  color: var(--blue-dark);
  font-weight: 700;
  font-size: 0.9rem;
}

.empty-state { margin-top: 18px; padding: 28px 16px; border-radius: 12px; background: var(--surface-muted); color: var(--text-muted); text-align: center; }
.result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 20px; }
.result-card { min-height: 92px; padding: 15px; border-radius: 12px; background: var(--surface-muted); display: flex; flex-direction: column; justify-content: center; }
.result-card span { color: var(--text-muted); }
.result-card strong { font-size: 1.35rem; }
.result-card.highlight { background: var(--pale-blue); }
.profit-card.positive strong { color: var(--green); }
.profit-card.negative strong, .profit-card.zero strong { color: var(--red); }
.break-even-card { margin: 18px 0 14px; padding: 16px 18px; border: 1px solid #b9d6ea; border-radius: 12px; background: #f3f9fd; }
.break-even-card > span { display: block; color: var(--blue-dark); font-weight: 750; }
.break-even-card > strong { display: block; margin-top: 4px; font-size: 1.35rem; }
.break-even-card p { margin: 5px 0 0; color: var(--text-muted); font-size: 0.9rem; }
.break-even-card .break-even-pending { color: var(--amber); font-weight: 700; }

.saved-section { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--border); }
.saved-list { display: grid; gap: 9px; margin-top: 14px; }
.saved-row { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px; min-width: 0; }
.saved-row input { width: auto; }
.saved-item { width: 100%; border: 1px solid var(--border); border-radius: 10px; background: #fff; padding: 11px 13px; text-align: left; color: var(--navy); }
.saved-item:hover { border-color: var(--blue); background: var(--pale-blue); }
.saved-title { display: block; font-weight: 750; }
.saved-meta { display: block; color: var(--text-muted); font-size: 0.88rem; }
.saved-empty { color: var(--text-muted); padding: 12px 0; }
.compact-buttons { margin-top: 12px; }

.hidden { display: none !important; }

footer { width: min(1380px, calc(100% - 48px)); margin: 0 auto 30px; color: var(--text-muted); text-align: center; }

@media (max-width: 1279px) {
  body.menu-open { overflow: hidden; }
  .menu-toggle { position: relative; display: inline-flex; }
  .site-layout { display: block; width: min(1380px, calc(100% - 48px)); }
  .site-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(310px, calc(100% - 48px));
    padding: 18px 14px;
    border-width: 0 1px 0 0;
    border-radius: 0 16px 16px 0;
    overflow-y: auto;
    transform: translateX(-105%);
    visibility: hidden;
    pointer-events: none;
    transition: transform 180ms ease, visibility 180ms ease;
  }
  .site-sidebar.is-open { transform: translateX(0); visibility: visible; pointer-events: auto; }
  .menu-close { display: inline-flex; width: 44px; height: 44px; border-radius: 9px; background: var(--surface-muted); color: var(--navy); font-size: 1.8rem; line-height: 1; }
  .site-navigation a { min-height: 44px; padding: 11px 12px; }
  .menu-overlay { position: fixed; inset: 0; z-index: 40; width: 100%; border: 0; background: rgba(9, 23, 42, 0.48); }
}

@media (max-width: 960px) {
  .page-shell { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .header-inner, .site-layout, footer { width: calc(100% - 24px); }
  .header-inner { gap: 12px; padding: 22px 0; }
  .page-shell { gap: 16px; }
  .app-header h1 { font-size: clamp(1.65rem, 8vw, 2rem); line-height: 1.35; overflow-wrap: anywhere; }
  .app-header .eyebrow { font-size: 0.8rem; }
  .site-layout { margin: 16px auto; }
  .info-panel { padding: 20px 18px; border-radius: 14px; }
  .guide-steps li { grid-template-columns: 1fr; gap: 4px; }
  .panel { padding: 18px; border-radius: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .mode-switch { flex-direction: column; gap: 8px; padding: 14px; }
  .mode-switch label, .checkbox-field { min-height: 44px; }
  .mode-switch input, .checkbox-field input, .saved-checkbox { width: 20px; height: 20px; }
  input:not([type="radio"]):not([type="checkbox"]), textarea { min-height: 46px; font-size: 16px; }
  textarea { min-height: 76px; }
  .button-row, .fee-actions { flex-direction: column; }
  .button-row > button, .fee-actions > button { width: 100%; min-height: 46px; }
  .section-heading-row { align-items: flex-start; flex-wrap: wrap; }
  .text-button { min-height: 44px; padding: 8px 0; }
  .result-card strong, .break-even-card > strong { overflow-wrap: anywhere; }
  .saved-row { align-items: start; gap: 8px; }
  .saved-row > input { margin-top: 13px; }
  .saved-item { padding: 12px; }
  .saved-meta { line-height: 1.55; }
  footer { margin-bottom: 22px; font-size: 0.92rem; }
}

@media (max-width: 430px) {
  .result-grid { grid-template-columns: 1fr; }
  .result-card { min-height: 82px; }
}

@media (max-width: 360px) {
  .header-inner, .site-layout, footer { width: calc(100% - 16px); }
  .header-inner { gap: 9px; padding: 18px 0; }
  .menu-toggle { width: 44px; height: 44px; }
  .panel { padding: 14px; border-radius: 12px; }
  .info-panel { padding: 18px 14px; border-radius: 12px; }
  .form-section { padding: 18px 0; }
  .break-even-card { padding: 14px; }
}
