:root {
  color-scheme: light;
  --navy: #14213d;
  --navy-2: #1f3158;
  --orange: #f59e0b;
  --orange-dark: #d97706;
  --blue-soft: #eef4ff;
  --green: #087f5b;
  --green-soft: #e8f7f1;
  --red: #c92a2a;
  --ink: #152033;
  --muted: #6b7280;
  --line: #dfe4ec;
  --page: #f3f5f8;
  --card: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }

.app-header {
  min-height: 116px;
  padding: max(18px, env(safe-area-inset-top)) 20px 26px;
  color: white;
  background: linear-gradient(135deg, var(--navy), var(--navy-2));
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-header h1 { font-size: 24px; margin: 2px 0 0; letter-spacing: .02em; }
.eyebrow { font-size: 12px; opacity: .72; margin: 0; }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.28); font-weight: 700; }
.session-user { border: 0; background: transparent; color: white; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 0; }
.session-user small { max-width: 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; opacity: .8; }

main { width: min(100%, 760px); margin: -16px auto 0; padding: 0 12px 48px; }
.summary { display: grid; grid-template-columns: 1fr 1fr 1.35fr; background: white; border-radius: 14px; box-shadow: 0 8px 28px rgba(20,33,61,.11); overflow: hidden; margin-bottom: 12px; }
.summary div { min-height: 72px; display: flex; flex-direction: column; align-items: center; justify-content: center; border-right: 1px solid var(--line); }
.summary div:last-child { border-right: 0; }
.summary strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.summary span { color: var(--muted); font-size: 11px; margin-top: 3px; }

.card { background: var(--card); border: 1px solid rgba(20,33,61,.07); border-radius: 14px; padding: 18px; margin-bottom: 12px; box-shadow: 0 2px 12px rgba(20,33,61,.05); }
.section-heading { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.section-heading h2, .manual-fields h2 { font-size: 18px; margin: 2px 0 0; }
.step { margin: 0; font-size: 10px; letter-spacing: .12em; font-weight: 800; color: var(--orange-dark); }
.status-pill { white-space: nowrap; border-radius: 999px; background: #eef0f4; color: var(--muted); padding: 5px 9px; font-size: 11px; font-weight: 700; }
.status-pill.success { color: var(--green); background: var(--green-soft); }
.status-pill.pending { color: #875300; background: #fff4d6; }
.status-pill.submitted { color: #285ba8; background: var(--blue-soft); }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.camera-button { min-height: 142px; border: 2px dashed #b8c2d3; border-radius: 12px; background: #f8fafc; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--navy); font-weight: 800; }
.camera-button small { color: var(--muted); font-weight: 400; font-size: 12px; }
.camera-icon { width: 42px; height: 31px; border-radius: 7px; background: var(--navy); position: relative; margin-bottom: 5px; }
.camera-icon::before { content: ""; position: absolute; width: 16px; height: 7px; background: var(--navy); border-radius: 4px 4px 0 0; top: -5px; left: 13px; }
.camera-icon::after { content: ""; position: absolute; width: 14px; height: 14px; border: 3px solid white; border-radius: 50%; top: 6px; left: 11px; }

.sample-tools { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); font-size: 11px; }
.sample-tools button { border: 1px solid var(--line); background: white; color: var(--navy); border-radius: 999px; padding: 5px 8px; font-size: 11px; }
.preview-area { margin-top: 16px; }
.preview-frame { min-height: 240px; max-height: 420px; border-radius: 12px; overflow: hidden; background: #e9edf3; display: grid; place-items: center; }
.preview-frame img { display: block; width: 100%; height: 100%; max-height: 420px; object-fit: contain; }
.preview-fallback { padding: 42px 20px; display: flex; flex-direction: column; align-items: center; color: var(--muted); gap: 6px; }
.preview-fallback span { font-size: 12px; overflow-wrap: anywhere; }
.preview-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 2px 14px; color: var(--muted); font-size: 12px; }
.preview-meta span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-button { border: 0; background: transparent; color: #285ba8; padding: 4px; white-space: nowrap; }
.primary-button, .save-button { border: 0; width: 100%; min-height: 50px; border-radius: 10px; color: white; background: var(--navy); font-weight: 800; box-shadow: 0 5px 14px rgba(20,33,61,.2); }
.danger-button { border: 1px solid #c92a2a; width: 100%; min-height: 46px; margin-top: 10px; border-radius: 10px; color: #c92a2a; background: #fff; font-weight: 800; }
.primary-button[disabled] { opacity: .62; cursor: wait; }

.notice { padding: 10px 12px; margin: -4px 0 14px; border-radius: 9px; background: #fff7e6; color: #875300; font-size: 12px; line-height: 1.55; }
.capture-card > .notice { margin: 0 0 12px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid .wide { grid-column: 1 / -1; }
.field-grid > label { min-width: 0; }
.field-grid > label > input,
.field-grid > label > select,
.field-grid > label > .money-input { width: 100%; height: 44px; min-height: 44px; }
.field-grid > label > input[type="date"] {
  display: block;
  width: 100% !important;
  min-width: 0;
  max-width: 100%;
  height: 44px !important;
  min-height: 44px !important;
  -webkit-appearance: none;
  appearance: none;
}
label { display: flex; flex-direction: column; gap: 5px; color: #4b5563; font-size: 12px; font-weight: 700; }
.label-caption { min-height: 18px; display: flex; align-items: center; gap: 5px; }
input, select, textarea { width: 100%; min-height: 44px; border: 1px solid #cfd6e2; border-radius: 8px; background: #fff; color: var(--ink); padding: 9px 10px; outline: none; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: #315f9f; box-shadow: 0 0 0 3px rgba(49,95,159,.12); }
.money-input { display: flex; align-items: center; height: 44px; min-height: 44px; border: 1px solid #cfd6e2; border-radius: 8px; padding: 0 10px; background: white; }
.money-input input { border: 0; box-shadow: none; height: 42px; min-height: 42px; padding: 9px 0; }
.money-input:focus-within { border-color: #315f9f; box-shadow: 0 0 0 3px rgba(49,95,159,.12); }

.tax-box { border: 1px solid var(--line); border-radius: 10px; margin: 14px 0 20px; overflow: hidden; }
.tax-row { display: grid; grid-template-columns: 54px 1fr 1fr; gap: 8px; align-items: center; padding: 8px 10px; border-top: 1px solid var(--line); }
.tax-row:first-child { border-top: 0; }
.tax-row input { min-height: 38px; text-align: right; padding: 6px 8px; }
.tax-head { color: var(--muted); background: #f7f8fa; font-size: 10px; font-weight: 700; }
.tax-head span:not(:first-child) { text-align: right; }
.ai-account-box { margin: 0 0 20px; padding: 14px; border: 1px solid #cfdcf0; border-radius: 10px; background: var(--blue-soft); }
.ai-account-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.ai-account-heading h2 { margin: 2px 0 0; color: var(--navy); font-size: 17px; }
.ai-account-heading > span { color: #285ba8; font-size: 10px; font-weight: 800; background: white; border-radius: 999px; padding: 5px 8px; white-space: nowrap; }
.ai-account-box input[readonly], .ai-account-box textarea[readonly] { background: #f8fbff; color: var(--ink); }
.ai-account-box > p { margin: 10px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.manual-fields { padding-top: 2px; }
.manual-fields h2 { margin-bottom: 14px; }
.manual-fields label { margin-top: 12px; }
.required { display: inline-block; align-self: flex-start; background: #fff0f0; color: var(--red); border-radius: 4px; padding: 1px 4px; font-size: 9px; }
.save-button { background: var(--orange); color: #2a1c00; margin-top: 18px; box-shadow: 0 5px 14px rgba(245,158,11,.23); }
.validation-message { margin-top: 12px; color: var(--red); background: #fff2f2; padding: 9px 11px; border-radius: 8px; font-size: 12px; }

.empty-state { text-align: center; color: var(--muted); padding: 22px 0 10px; font-size: 13px; }
.draft-list { display: grid; gap: 8px; }
.draft-item { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fbfcfe; }
.draft-detail { min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.draft-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.draft-title strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.draft-item .amount { font-weight: 800; font-variant-numeric: tabular-nums; }
.draft-item small { color: var(--muted); }
.draft-sync { display: flex; align-items: center; gap: 7px; min-width: 0; }
.draft-sync .status-pill { padding: 3px 7px; flex: 0 0 auto; }
.reshoot-notice { margin-top: 8px; padding: 9px 10px; border-radius: 8px; background: #fff4d6; color: #704900; font-size: 12px; line-height: 1.55; }
.primary-inline { background: var(--navy); color: white; border-color: var(--navy); }
.sync-error { color: var(--red); font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draft-thumb { width: 72px; height: 82px; border: 1px solid var(--line); border-radius: 8px; padding: 0; overflow: hidden; background: #e9edf3; color: var(--muted); font-size: 11px; }
.draft-thumb img { width: 100%; height: 100%; object-fit: cover; }
.draft-actions { display: flex; gap: 12px; }
.draft-actions button { border: 0; background: transparent; color: #285ba8; padding: 2px 0; font-size: 12px; }
.draft-actions .danger-text { color: var(--red); }
.outline-button { border: 1px solid #315f9f; border-radius: 8px; background: white; color: #285ba8; padding: 7px 10px; font-size: 11px; font-weight: 800; white-space: nowrap; }

dialog { width: min(calc(100% - 24px), 600px); border: 0; border-radius: 14px; padding: 16px; box-shadow: 0 24px 70px rgba(15, 23, 42, .28); }
dialog::backdrop { background: rgba(15, 23, 42, .62); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dialog-heading button { width: 36px; height: 36px; border: 0; border-radius: 50%; background: #eef0f4; color: var(--ink); font-size: 22px; line-height: 1; }
.image-dialog img { display: block; width: 100%; max-height: 72vh; object-fit: contain; border-radius: 8px; background: #e9edf3; }
.monthly-dialog p { line-height: 1.6; }
.monthly-dialog #monthlySummary { font-size: 18px; font-weight: 800; }
.monthly-selector { display: grid; gap: 6px; font-size: 13px; font-weight: 700; margin: 14px 0; }
.monthly-selector select { min-height: 44px; font-size: 16px; }
.dialog-note { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.outline-dialog-button { border: 1px solid #315f9f; width: 100%; min-height: 46px; margin: 0 0 10px; border-radius: 10px; color: #285ba8; background: white; font-weight: 800; }
.monthly-dialog .primary-button + .dialog-note { margin-top: 18px; }
.login-dialog { width: min(calc(100% - 32px), 420px); }
.login-dialog h2 { margin: 4px 0 10px; }
.login-dialog label { margin-bottom: 18px; }
.login-dialog .validation-message { margin: 0 0 12px; }
.toast { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #101827; color: white; border-radius: 999px; padding: 10px 18px; font-size: 13px; transition: .2s ease; z-index: 100; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 680px) {
  .app-header { padding-left: max(24px, calc((100vw - 760px) / 2)); padding-right: max(24px, calc((100vw - 760px) / 2)); }
  main { padding-left: 0; padding-right: 0; }
  .card { padding: 22px; }
}

@media (max-width: 370px) {
  .field-grid { grid-template-columns: 1fr; }
  .field-grid .wide { grid-column: auto; }
  .tax-row { grid-template-columns: 42px 1fr 1fr; gap: 5px; padding: 7px; }
}
