:root {
  font-family: system-ui, -apple-system, "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif;
  color: #172d46;
  background: #f5f8fc;
  font-size: 16px;
}

* { box-sizing: border-box; }

body { margin: 0; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid #58a4ff; outline-offset: 2px; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 210px minmax(0, 1fr); }
.side-nav { background: #112e51; color: #fff; padding: 24px 14px; display: flex; flex-direction: column; gap: 12px; }
.brand { font-size: 1.22rem; font-weight: 700; padding: 8px 12px 24px; letter-spacing: .04em; }
.nav-button { border: 0; border-radius: 10px; padding: 13px 14px; text-align: left; background: transparent; color: inherit; font-weight: 600; min-height: 46px; }
.nav-button[aria-current="page"] { background: #dcecff; color: #103b70; }
.nav-button:not(:disabled):hover { background: #2c4b6f; color: #fff; }
.main-content { width: min(100%, 1050px); margin-inline: auto; padding: 30px 34px 48px; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 22px; margin-bottom: 24px; }
.page-heading h1 { font-size: clamp(1.55rem, 2.5vw, 2rem); margin: 3px 0 7px; }
.eyebrow { color: #225e9b; font-size: .83rem; font-weight: 700; letter-spacing: .1em; margin: 0; }
.supporting { color: #4b6076; margin: 0; line-height: 1.5; }
.heading-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.primary-button, .secondary-button { min-height: 46px; border-radius: 9px; padding: 10px 17px; font-weight: 700; }
.primary-button { border: 1px solid #0a5aa6; background: #0a5aa6; color: #fff; }
.primary-button:hover { background: #084b8b; }
.secondary-button { border: 1px solid #90aac7; background: #fff; color: #16446f; }
.secondary-button:hover { background: #eaf3ff; }
.save-status { display: inline-flex; align-items: center; min-height: 35px; border-radius: 18px; padding: 5px 12px; background: #e8f5ed; color: #145b32; font-weight: 700; white-space: nowrap; }
.save-status[data-state="saving"] { background: #fff1d6; color: #795000; }
.save-status[data-state="error"] { background: #fff0ef; color: #a02523; }
.message, .error-box { background: #fff0ef; color: #8a2323; border: 1px solid #d89792; border-radius: 10px; padding: 14px 16px; margin-bottom: 20px; }
.local-notice { background: #eaf2fb; border: 1px solid #bad1e9; border-radius: 10px; padding: 12px 16px; line-height: 1.5; }
.account-link { display: block; text-decoration: none; }
.account-shell { width: min(100% - 32px, 680px); margin: 0 auto; padding: 24px 0 64px; }
.account-header, .account-profile { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.account-header { padding-bottom: 22px; font-weight: 700; }
.account-shell h1 { margin: 0 0 8px; }
.account-shell > .supporting { margin-bottom: 18px; }
.account-status { padding: 12px 14px; background: #eaf2fb; border-radius: 9px; line-height: 1.5; }
.account-form { display: grid; gap: 14px; margin-top: 18px; }
.account-form button { justify-self: start; }
.account-extra { margin-top: 22px; border-top: 1px solid #d1ddea; padding-top: 18px; }
.account-extra summary { cursor: pointer; font-weight: 700; }
.account-extra form + form { border-top: 1px solid #d1ddea; padding-top: 18px; }
.account-profile h2 { margin-bottom: 4px; }
.account-profile p { margin: 0; overflow-wrap: anywhere; }
.account-profile button { flex: none; white-space: nowrap; }
.company-name { font-size: 1.2rem; font-weight: 700; }
.invite-result { margin-top: 18px; padding: 14px; border-radius: 9px; background: #eaf2fb; overflow-wrap: anywhere; }
.invite-result input { width: 100%; min-width: 0; padding: 10px; margin-bottom: 10px; }
.error-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.estimate-list { display: grid; gap: 12px; }
.list-filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.company-group { min-width: 0; }
.company-group > h2 { margin: 12px 0; font-size: 1.25rem; }
.site-group { margin: 10px 0 20px; padding-left: 14px; border-left: 3px solid #bfd4ea; }
.site-group > h3 { margin: 12px 0; font-size: 1.08rem; }
.estimate-row { min-width: 0; border: 1px solid #d1ddea; background: #fff; color: inherit; border-radius: 12px; padding: 15px; display: grid; gap: 10px; box-shadow: 0 1px 3px #dbe4ed80; }
.estimate-open { width: 100%; border: 0; padding: 4px; color: #16446f; background: transparent; display: flex; justify-content: space-between; gap: 12px; text-align: left; font-weight: 700; }
.estimate-open:hover { text-decoration: underline; }
.estimate-row-summary, .estimate-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
.estimate-row-summary span { color: #4b6076; }
.estimate-actions select { min-height: 44px; margin-left: 5px; max-width: 100%; }
.estimate-actions .secondary-button { min-height: 44px; }
.empty-state { background: #fff; border: 1px dashed #adc2d8; border-radius: 12px; padding: 32px 22px; color: #4b6076; }
.summary-card { display: flex; flex-wrap: wrap; gap: 28px; padding: 16px 20px; margin-bottom: 18px; border-radius: 11px; background: #eaf2fb; }
.summary-card > div { display: flex; gap: 10px; align-items: baseline; }
.summary-label { color: #536b83; }
.form-card { background: #fff; border: 1px solid #d1ddea; border-radius: 12px; margin: 0 0 18px; padding: 20px; }
.form-card legend { float: left; width: 100%; font-size: 1.14rem; font-weight: 700; padding: 0 0 16px; }
.field-grid { clear: both; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; }
.field { min-width: 0; display: flex; flex-direction: column; gap: 7px; font-weight: 600; }
.field-wide { grid-column: 1 / -1; }
.field input, .field textarea, .field select { width: 100%; border: 1px solid #91a8c0; border-radius: 8px; background: #fff; color: #172d46; padding: 10px 12px; min-height: 44px; }
.field textarea { resize: vertical; }
.field small { color: #536b83; font-weight: 400; }
.date-controls { display: grid; grid-template-columns: minmax(0, 1fr) 155px; gap: 8px; }
.bottom-nav { display: none; }
.asset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 18px 0; }
.asset-card { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 9px; padding: 14px; border: 1px solid #d1ddea; border-radius: 10px; }
.asset-card img { max-width: 100%; max-height: 120px; object-fit: contain; }
.asset-card input { max-width: 100%; }
.heading-card { margin-top: 18px; }
.heading-card h2, .form-card h2 { margin: 0 0 14px; font-size: 1.22rem; }
.detail-card { min-width: 0; border: 1px solid #cbd9e8; border-radius: 10px; padding: 16px; margin: 15px 0; background: #fbfdff; }
.detail-card h3, .detail-card h4 { margin: 0 0 13px; }
.internal-card { background: #f3f7fb; border-left: 4px solid #4777a6; }
.internal-card summary { cursor: pointer; font-weight: 700; line-height: 1.5; }
.internal-card[open] summary { margin-bottom: 16px; }
.internal-table-scroll { overflow-x: auto; }
.internal-compare { width: 100%; min-width: 680px; border-collapse: collapse; margin-top: 14px; background: #fff; }
.internal-compare th, .internal-compare td { text-align: left; border: 1px solid #cbd9e8; padding: 9px; }
.internal-compare th { background: #e9f2fc; }
.internal-compare .secondary-button { padding: 7px 10px; }
.card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 14px 0; }
.card-actions select { min-height: 44px; max-width: 100%; }
.amount-summary { background: #e9f2fc; border-radius: 8px; padding: 10px; line-height: 1.5; }
.submission-preview { background: #fff; border: 1px dashed #9eb9d5; border-radius: 8px; padding: 10px; line-height: 1.5; }
.submission-row { border: 1px solid #d1ddea; border-radius: 9px; padding: 12px; margin: 12px 0; }
.submission-row .secondary-button { margin-top: 12px; }
.finance-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.finance-metric { min-width: 0; display: flex; flex-direction: column; gap: 4px; border: 1px solid #d1ddea; border-radius: 9px; padding: 12px; background: #f7fbff; }
.finance-metric span, .finance-metric small { color: #4b6076; }
.finance-metric strong { font-size: 1.18rem; overflow-wrap: anywhere; }
.finance-proposal { margin-top: 18px; padding: 16px; border: 1px solid #a9c6e5; border-radius: 10px; background: #eaf3ff; }
.finance-proposal h3, .finance-item-list h3 { margin: 0 0 10px; }
.finance-proposal p { line-height: 1.5; }
.finance-item-list { margin-top: 22px; }
.finance-item-card, .finance-item-summary { display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid #d1ddea; padding: 14px 0; }
.finance-item-summary span, .finance-item-summary small { line-height: 1.5; }
.backup-reminder { color: #795000; font-weight: 700; line-height: 1.5; }
.import-confirm { display: grid; gap: 10px; line-height: 1.5; margin: 12px 0; }
.import-confirm[hidden] { display: none; }
.import-confirm label:first-child { display: flex; align-items: center; gap: 10px; }
.import-confirm input[type="checkbox"] { width: 24px; height: 24px; flex: none; }
.import-confirm input[type="text"] { display: block; width: min(100%, 340px); min-height: 44px; margin-top: 5px; border: 1px solid #91a8c0; border-radius: 8px; padding: 8px; }
.backup-file-label { display: inline-flex; align-items: center; cursor: pointer; }
.backup-file-label input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.backup-file-label:focus-within { outline: 3px solid #58a4ff; outline-offset: 2px; }
.restore-row { min-width: 0; padding: 14px 0; border-bottom: 1px solid #d1ddea; display: grid; gap: 8px; }
.restore-row p { margin: 0; line-height: 1.5; overflow-wrap: anywhere; }
.restore-row select, .restore-row input { width: min(100%, 340px); min-height: 44px; border: 1px solid #91a8c0; border-radius: 8px; padding: 8px; }
.restore-row label { display: grid; gap: 5px; }
.restore-conflict { color: #a02523; font-weight: 700; }
.restore-row details { border: 1px solid #d1ddea; border-radius: 8px; padding: 10px; }
.restore-row summary { cursor: pointer; font-weight: 700; }
.restore-difference { display: grid; gap: 5px; padding: 8px 0; border-bottom: 1px solid #e1e8f0; overflow-wrap: anywhere; }
.restore-images { display: flex; flex-wrap: wrap; gap: 14px; }
.restore-images > div { display: grid; gap: 5px; }
.restore-images img { max-width: 160px; max-height: 100px; object-fit: contain; border: 1px solid #d1ddea; }
.cloud-conflict { border: 2px solid #a02523; }
.cloud-conflict[hidden] { display: none; }
.cloud-conflict .restore-difference { grid-template-columns: minmax(0, 1fr); }
.cloud-conflict pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font: inherit; }
.cloud-conflict .conflict-values { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.cloud-conflict .conflict-values > div { min-width: 0; padding: 10px; background: #f3f7fb; border-radius: 8px; }
@media (max-width: 600px) { .cloud-conflict .conflict-values { grid-template-columns: 1fr; } }
#restore-preview h3, #restore-preview h4 { margin-bottom: 10px; }
#apply-restore { margin-top: 16px; }

.submission-pages { display: grid; gap: 20px; justify-content: center; overflow-x: auto; padding: 4px; }
.submission-page { width: 210mm; height: 297mm; padding: 15mm; background: white; color: #182537; box-shadow: 0 3px 16px #172d4630; flex: none; font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif; font-size: 10pt; }
.paper-inner { width: 180mm; height: 267mm; display: flex; flex-direction: column; }
.paper-header { flex: none; border-bottom: 1px solid #315b84; padding-bottom: 3mm; margin-bottom: 3mm; overflow-wrap: anywhere; }
.paper-header.first { display: grid; grid-template-columns: 1.45fr 1fr; gap: 4mm; }
.paper-header h2 { margin: 0 0 2mm; font-size: 17pt; }
.paper-header p { margin: 1mm 0; line-height: 1.35; }
.paper-header .paper-remarks { grid-column: 1 / -1; }
.paper-header.compact { display: flex; justify-content: space-between; gap: 3mm; font-size: 9pt; }
.paper-seller { display: flex; gap: 2mm; justify-content: flex-end; text-align: right; min-width: 0; }
.paper-seller-text { min-width: 0; flex: 1; }
.paper-seller-name { display: flex; gap: 2mm; align-items: center; justify-content: flex-end; }
.paper-logo { width: 28mm; height: 17mm; object-fit: contain; }
.paper-stamp { width: 15mm; height: 15mm; object-fit: contain; }
.paper-totals { flex: none; border: 1px solid #bacddd; padding: 2mm 3mm; margin-bottom: 3mm; }
.paper-totals h3 { font-size: 10pt; margin: 0 0 1mm; }
.paper-total-line { display: flex; justify-content: space-between; gap: 3mm; padding: .45mm 0; }
.paper-total-line.grand { border-top: 1px solid #315b84; margin-top: 1mm; padding-top: 1.2mm; font-size: 12pt; }
.paper-flow { flex: 1; min-height: 0; overflow: hidden; }
.paper-section-heading { font-size: 11pt; margin: 2mm 0 1mm; padding: 1mm 2mm; background: #e8f1fa; overflow-wrap: anywhere; }
.paper-item-heading { font-size: 9pt; font-weight: 600; margin: 1.5mm 0 .8mm; overflow-wrap: anywhere; }
.paper-item-block { break-inside: avoid; }
.paper-item-row { display: grid; grid-template-columns: minmax(0, 1fr) 15mm 15mm 25mm 28mm; gap: 1.5mm; padding: 1.2mm 1mm; border-bottom: 1px solid #d9e3ec; align-items: start; break-inside: avoid; overflow-wrap: anywhere; }
.paper-item-row > :not(:first-child) { text-align: right; }
.paper-item-note { margin: 1mm 1mm 2mm; line-height: 1.45; overflow-wrap: anywhere; }
.paper-flow > .paper-totals { margin-top: 4mm; }
.paper-footer { flex: none; display: flex; justify-content: space-between; border-top: 1px solid #9eb3c8; padding-top: 2mm; margin-top: 2mm; font-size: 8pt; }
@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { background: white !important; }
  .app-shell, .main-content { display: block; width: auto; margin: 0; padding: 0 !important; }
  .side-nav, .bottom-nav, #app-message, #list-view, #editor-view, #details-view, #financial-view, #submission-view > :not(.submission-pages) { display: none !important; }
  #submission-view, .submission-pages { display: block !important; padding: 0; margin: 0; overflow: visible; }
  .submission-pages { zoom: 1 !important; }
  .submission-page { box-shadow: none; margin: 0; break-after: page; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .submission-page:last-child { break-after: auto; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .side-nav { display: none; }
  .main-content { padding: 22px 16px 100px; }
  .page-heading { flex-direction: column; align-items: stretch; gap: 15px; }
  .heading-actions { justify-content: space-between; }
  .field-grid { grid-template-columns: 1fr; }
  .list-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-wide { grid-column: auto; }
  .bottom-nav { position: fixed; z-index: 10; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); background: #112e51; color: #fff; box-shadow: 0 -3px 15px #172d4640; }
  .bottom-nav .nav-button { text-align: center; padding: 8px 3px; font-size: .78rem; line-height: 1.2; overflow-wrap: anywhere; }
  .asset-grid { grid-template-columns: 1fr; }
  .detail-card { padding: 12px; }
  .internal-table-scroll { display: none; }
  .finance-metrics { grid-template-columns: 1fr; }
  .bottom-nav { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .submission-pages { justify-content: start; }
}

@media (max-width: 420px) {
  .list-filters { grid-template-columns: 1fr; }
  .estimate-open { flex-direction: column; }
  .date-controls { grid-template-columns: minmax(0, 1fr) 132px; }
  .date-controls input { min-width: 0; }
  .error-box { flex-direction: column; align-items: stretch; }
}
