:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #667085;
  --line: #d7dde5;
  --panel: #ffffff;
  --field: #f7f9fb;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --warn: #b42318;
  --warn-bg: #fff1f0;
  --shadow: 0 18px 48px rgba(22, 34, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family:
    Inter, "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, sans-serif;
  background: #eef2f5;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.workbench {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

.title-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-actions form {
  margin: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.25;
}

h2 {
  font-size: 15px;
  line-height: 1.4;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) minmax(220px, 1.6fr) repeat(3, minmax(130px, 1fr)) minmax(150px, 0.9fr);
  gap: 12px;
  align-items: end;
  padding: 18px 24px 20px;
  border-bottom: 1px solid var(--line);
}

.template-grid {
  grid-template-columns: minmax(170px, 1fr) minmax(170px, 1fr) minmax(260px, 2fr) minmax(150px, 0.9fr);
}

.control-grid label:not(.file-picker) {
  display: grid;
  gap: 6px;
}

.control-grid label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.file-picker {
  position: relative;
  display: block;
  min-width: 0;
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-picker span,
.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  width: 100%;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.file-picker span {
  color: var(--accent);
  background: #e8f5f3;
  border-color: #a6d8d2;
}

input {
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
}

input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 118, 110, 0.16);
}

.file-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.file-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.primary-button {
  color: #ffffff;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  max-width: 160px;
  color: var(--accent);
  background: #ffffff;
  border-color: var(--accent);
}

.secondary-button:disabled {
  color: #98a2b3;
  border-color: var(--line);
  cursor: not-allowed;
}

.error-box {
  margin: 16px 24px 0;
  padding: 12px 14px;
  color: var(--warn);
  background: var(--warn-bg);
  border: 1px solid #f7b6b0;
  border-radius: 6px;
  font-weight: 700;
}

.warning-box {
  margin: 16px 24px 0;
  padding: 12px 14px;
  color: #8a4b00;
  background: #fff7e6;
  border: 1px solid #ffd591;
  border-radius: 6px;
  font-weight: 700;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 18px 24px 0;
}

.summary:empty {
  display: none;
}

.summary-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: #f7f9fb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.summary-item span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary-item strong {
  font-size: 24px;
}

.tables {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  padding: 18px 24px 24px;
}

.table-panel {
  min-width: 0;
}

.table-panel h2 {
  margin-bottom: 10px;
}

.table-wrap {
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #344054;
  background: #f2f5f8;
  font-size: 12px;
}

td {
  overflow-wrap: anywhere;
}

tbody tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 980px) {
  .control-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 640px) {
  .app-shell {
    width: min(100vw - 20px, 1180px);
    padding: 10px 0;
  }

  .title-row,
  .control-grid,
  .summary,
  .tables {
    padding-left: 14px;
    padding-right: 14px;
  }

  .title-row {
    align-items: stretch;
    flex-direction: column;
  }

  .secondary-button {
    max-width: none;
  }

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