:root {
  --bg: #f6f5f0;
  --surface: #ffffff;
  --surface-2: #f0f7f5;
  --line: #d8ddd7;
  --text: #18231f;
  --muted: #66736e;
  --green: #17745f;
  --blue: #2e5f92;
  --amber: #b56b15;
  --danger: #b33c32;
  --shadow: 0 18px 40px rgba(29, 43, 38, .11);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--bg);
  font-family: "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  letter-spacing: 0;
}

button, input {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--text);
  background: #fff;
  cursor: pointer;
}

button:hover { border-color: var(--green); }
button:disabled { cursor: not-allowed; opacity: .55; }

.primary {
  border-color: var(--green);
  color: #fff;
  background: var(--green);
}

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

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: end;
  padding: 14px 2px 16px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

h1, h2 {
  margin: 0;
  line-height: 1.22;
}

h1 { font-size: clamp(24px, 3vw, 36px); }
h2 { font-size: 18px; }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(96px, auto));
  gap: 8px;
  margin: 0;
}

.meta-grid div {
  min-width: 96px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255,255,255,.72);
}

.meta-grid dt {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 11px;
}

.meta-grid dd {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.flow {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.flow-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 118px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.flow-item b {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: #fff;
  background: var(--green);
}

.flow-line {
  height: 2px;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, .92fr) minmax(620px, 1.42fr);
  gap: 14px;
  align-items: start;
}

.pdf-panel, .form-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.pdf-panel {
  min-height: 740px;
  overflow: hidden;
}

.panel-head, .form-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.file-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  min-width: 52px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--blue);
  font-weight: 800;
  cursor: pointer;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

#pdfFrame {
  display: block;
  width: 100%;
  height: 640px;
  border: 0;
  background: #ebece7;
}

.pdf-status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 12px;
}

.form-panel {
  overflow: hidden;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.settings {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  padding: 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

label span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  color: var(--text);
  background: #fff;
}

input:focus {
  outline: 2px solid rgba(23,116,95,.2);
  border-color: var(--green);
}

.table-shell {
  overflow: auto;
  max-height: 500px;
}

table {
  width: 100%;
  min-width: 820px;
  border-collapse: separate;
  border-spacing: 0;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #f9faf7;
  font-size: 12px;
}

td:first-child, th:first-child {
  width: 48px;
  text-align: center;
}

td:last-child, th:last-child {
  width: 52px;
  text-align: center;
}

.row-delete {
  width: 34px;
  min-width: 34px;
  padding: 0;
  color: var(--danger);
}

.amount-input {
  text-align: right;
}

.account-input {
  width: 70px;
  text-align: center;
}

.summary-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.summary-bar div {
  min-width: 104px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfa;
}

.summary-bar span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.summary-bar strong {
  display: block;
  font-size: 18px;
}

.message {
  min-height: 38px;
  padding: 0 14px 14px;
  color: var(--muted);
  font-size: 13px;
}

.message.error { color: var(--danger); }
.message.success { color: var(--green); }

@media (max-width: 1040px) {
  .topbar {
    grid-template-columns: 1fr;
  }

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

  .pdf-panel {
    min-height: 560px;
  }

  #pdfFrame {
    height: 470px;
  }
}

@media (max-width: 720px) {
  .app {
    width: min(100% - 16px, 680px);
    padding-top: 10px;
  }

  .meta-grid,
  .settings {
    grid-template-columns: 1fr 1fr;
  }

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

  .flow-line {
    display: none;
  }

  .flow-item {
    min-width: 0;
  }

  .panel-head, .form-toolbar, .summary-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    justify-content: stretch;
  }

  .toolbar-actions button,
  .summary-bar button {
    width: 100%;
  }
}

@media (max-width: 460px) {
  .meta-grid,
  .settings {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 22px;
  }
}
