*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e2e8f0;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --text: #1e293b;
  --text-sub: #64748b;
  --success: #16a34a;
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 20px 16px 60px;
}

header {
  text-align: center;
  margin-bottom: 28px;
}
header h1 {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary);
}
header p {
  color: var(--text-sub);
  margin-top: 4px;
  font-size: 0.9rem;
}

main {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* カード */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}
.card-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-sub);
  margin-bottom: 16px;
}

/* プロジェクト情報グリッド */
.project-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px 20px;
}
.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field-group label {
  font-size: 0.8rem;
  color: var(--text-sub);
  font-weight: 600;
}
.field-group input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
  background: var(--bg);
}
.field-group input:focus {
  border-color: var(--primary);
  background: var(--surface);
}

/* テーブル */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 14px;
}
.table-scroll-hint {
  display: none;
}
table {
  width: 100%;
  min-width: 700px;
  border-collapse: collapse;
  font-size: 0.88rem;
}
thead th {
  background: var(--bg);
  padding: 8px 10px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-sub);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td {
  border-bottom: none;
}

/* テーブル列幅 */
.col-name   { min-width: 160px; }
.col-qty    { width: 70px; }
.col-unit   { width: 80px; }
.col-price  { width: 110px; }
.col-factor { width: 90px; }
.col-sub    { width: 110px; }
.col-note   { min-width: 120px; }
.col-del    { width: 40px; }

/* テーブル入力 */
.td-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-family: inherit;
  font-size: 0.88rem;
  color: var(--text);
  background: transparent;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.td-input:focus {
  border-color: var(--primary);
  background: var(--surface);
}
.td-input[type="number"] {
  text-align: right;
}
select.td-input {
  cursor: pointer;
}

/* 小計セル */
.subtotal-cell {
  text-align: right;
  font-weight: 600;
  color: var(--text);
  padding-right: 10px;
  white-space: nowrap;
}

/* 削除ボタン */
.btn-delete {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.btn-delete:hover {
  color: var(--error, #dc2626);
  background: #fee2e2;
}

/* 行追加ボタン */
.btn-add {
  background: none;
  border: 1px dashed var(--border);
  border-radius: 7px;
  padding: 8px 20px;
  font-family: inherit;
  font-size: 0.88rem;
  color: var(--text-sub);
  cursor: pointer;
  width: 100%;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.btn-add:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #eef2ff;
}

/* 合計・操作 */
.total-layout {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.total-table {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 200px;
}
.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.92rem;
  gap: 16px;
}
.total-label { color: var(--text-sub); }
.total-value { font-weight: 600; text-align: right; }
.total-row-grand {
  border-top: 2px solid var(--border);
  padding-top: 10px;
  margin-top: 4px;
}
.grand {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
button {
  font-family: inherit;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  padding: 11px 28px;
  font-size: 0.92rem;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
  background: var(--bg);
  color: var(--text-sub);
  padding: 11px 28px;
  font-size: 0.92rem;
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #e2e8f0; color: var(--text); }

/* ======= 印刷ビュー ======= */
.print-view {
  display: none;
}

@media print {
  body > header,
  body > main {
    display: none !important;
  }

  .print-view {
    display: block;
    padding: 24px;
    font-family: 'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
    color: #000;
  }

  .print-title {
    text-align: center;
    font-size: 1.6rem;
    font-weight: 700;
    border-bottom: 2px solid #000;
    padding-bottom: 8px;
    margin-bottom: 20px;
  }

  .print-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 16px;
    font-size: 0.9rem;
  }

  .print-meta-left {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.6;
  }
  .print-honorific { font-size: 0.85rem; font-weight: normal; }

  .print-meta-right {
    text-align: right;
    font-size: 0.85rem;
    line-height: 1.8;
  }

  .print-project {
    margin-bottom: 12px;
    font-size: 0.9rem;
  }

  .print-grand-total {
    display: flex;
    justify-content: space-between;
    background: #f0f0f0;
    padding: 10px 16px;
    border: 1px solid #ccc;
    margin-bottom: 20px;
    font-size: 0.9rem;
    font-weight: 700;
  }
  .print-grand-value {
    font-size: 1.2rem;
  }

  .print-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    font-size: 0.82rem;
  }
  .print-table th,
  .print-table td {
    border: 1px solid #ccc;
    padding: 6px 8px;
    text-align: left;
  }
  .print-table th {
    background: #f0f0f0;
    font-weight: 700;
  }
  .print-table td:nth-child(2),
  .print-table td:nth-child(4),
  .print-table td:nth-child(5),
  .print-table td:nth-child(6) {
    text-align: right;
  }

  .print-totals {
    width: 220px;
    margin-left: auto;
    font-size: 0.85rem;
  }
  .print-total-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid #e0e0e0;
  }
  .print-total-grand {
    border-top: 2px solid #000;
    border-bottom: none;
    font-weight: 700;
    font-size: 0.95rem;
    padding-top: 8px;
    margin-top: 4px;
  }
}

/* モバイル */
@media (max-width: 640px) {
  header h1 { font-size: 1.4rem; }
  .card { padding: 16px; }
  .project-grid { grid-template-columns: 1fr; }
  .total-layout { flex-direction: column; }
  .action-buttons { flex-direction: row; width: 100%; }
  .btn-primary, .btn-secondary { flex: 1; }

  /* テーブル横スクロールヒント */
  .table-scroll-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--text-sub);
    text-align: right;
    margin-bottom: 6px;
  }

  /* 各列の最小幅を明示して折りたたみを防ぐ */
  .col-name   { min-width: 130px; }
  .col-qty    { min-width: 60px; }
  .col-unit   { min-width: 70px; }
  .col-price  { min-width: 90px; }
  .col-factor { min-width: 75px; }
  .col-sub    { min-width: 90px; }
  .col-note   { min-width: 90px; }
  .col-del    { min-width: 36px; }
}
