/* ========== Base ========== */
* { box-sizing: border-box; }
body { font-family: 'Hiragino Kana Gothic ProN', 'Hiragino Sans', 'Meiryo', sans-serif; }

/* ========== Sticky Header Wrapper ========== */
#stickyHeader {
  position: sticky;
  top: 0;
  z-index: 100;
  background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

/* ========== Header ========== */
.app-header {
  background: linear-gradient(135deg, #1a365d 0%, #2d5a8e 100%);
  color: white;
  padding: 12px 16px;
  /* position/top/z-index は #stickyHeader が担う */
}
.app-header h1 { font-size: 1.1rem; font-weight: 700; margin: 0; }
.app-header .subtitle { font-size: 0.7rem; opacity: 0.8; margin-top: 2px; }

/* ========== Navigation Tabs ========== */
.nav-tabs {
  display: flex;
  background: #f8fafc;
  border-bottom: 2px solid #e2e8f0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.nav-tab {
  padding: 10px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.nav-tab.active {
  color: #1e40af;
  border-bottom-color: #1e40af;
  background: white;
}
.nav-tab:hover { background: #e2e8f0; }

/* ========== Status Badges ========== */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  min-width: 52px;
}
.badge-A { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.badge-B { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.badge-C { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.badge-done { background: #dbeafe; color: #1e3a8a; border: 1px solid #93c5fd; }
.badge-ok { background: #d1fae5; color: #065f46; }
.badge-ng { background: #fee2e2; color: #991b1b; }
.badge-100 { background: #d1fae5; color: #065f46; }
.badge-partial { background: #fef3c7; color: #92400e; }
.badge-zero { background: #fee2e2; color: #991b1b; }

/* ========== Cards ========== */
.contract-card {
  background: white;
  border-radius: 12px;
  margin: 8px 12px;
  padding: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  cursor: pointer;
  transition: all 0.2s;
  border-left: 4px solid #e2e8f0;
}
.contract-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.12); transform: translateY(-1px); }
.contract-card.status-A { border-left-color: #10b981; }
.contract-card.status-B { border-left-color: #f59e0b; }
.contract-card.status-C { border-left-color: #ef4444; }
.contract-card.status-done { border-left-color: #3b82f6; }

.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.card-name { font-size: 1rem; font-weight: 700; color: #1e293b; }
.card-car { font-size: 0.82rem; color: #475569; margin-top: 2px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; font-size: 0.75rem; }
.card-meta-item { display: flex; align-items: center; gap: 3px; color: #64748b; }

/* ========== Detail Panel ========== */
.detail-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 100%;
  max-width: 480px;
  background: white;
  z-index: 200;
  overflow-y: auto;
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  transform: translateX(100%);
  transition: transform 0.3s ease;
}
.detail-panel.open { transform: translateX(0); }

.detail-header {
  background: linear-gradient(135deg, #1a365d 0%, #2d5a8e 100%);
  color: white;
  padding: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.detail-header h2 { font-size: 1.1rem; font-weight: 700; margin: 0 0 4px; }
.detail-header .car-info { font-size: 0.82rem; opacity: 0.9; }

.detail-section {
  padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9;
}
.section-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ========== Checklist ========== */
.checklist-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  transition: all 0.2s;
}
.checklist-item.checked {
  background: #f0fdf4;
  border-color: #86efac;
}
.checklist-item.unchecked {
  background: #fff7f7;
  border-color: #fca5a5;
}
.checklist-label { font-size: 0.85rem; color: #374151; font-weight: 500; }
.checklist-value { font-size: 0.8rem; font-weight: 600; }
.check-yes { color: #059669; }
.check-no { color: #dc2626; }
.check-empty { color: #94a3b8; }

/* ========== Input Fields ========== */
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid #f1f5f9;
}
.field-label { font-size: 0.82rem; color: #64748b; flex-shrink: 0; width: 100px; }
.field-value { font-size: 0.85rem; color: #1e293b; font-weight: 500; text-align: right; flex: 1; }
.field-input {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.83rem;
  width: 130px;
  text-align: right;
  background: white;
}
.field-input:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 2px rgba(59,130,246,0.2); }

.select-input {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.83rem;
  background: white;
  cursor: pointer;
}
.select-input:focus { outline: none; border-color: #3b82f6; }

/* ========== Payment rows ========== */
.payment-block {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}
.payment-block-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: #475569;
  margin-bottom: 8px;
}

/* ========== Progress Bar ========== */
.progress-bar-wrap { background: #e2e8f0; border-radius: 6px; height: 8px; overflow: hidden; margin-top: 6px; }
.progress-bar { height: 100%; border-radius: 6px; transition: width 0.3s; }
.progress-bar.p100 { background: #10b981; }
.progress-bar.p50 { background: #f59e0b; }
.progress-bar.p0 { background: #ef4444; }

/* ========== Filter Bar ========== */
.filter-bar {
  padding: 10px 12px;
  background: white;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.filter-btn {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1.5px solid #e2e8f0;
  background: white;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  color: #64748b;
}
.filter-btn.active { border-color: #1e40af; background: #1e40af; color: white; }

/* ========== Search ========== */
.search-wrap { padding: 10px 12px; background: white; border-bottom: 1px solid #e2e8f0; }
.search-input {
  width: 100%;
  padding: 8px 14px 8px 36px;
  border: 1.5px solid #e2e8f0;
  border-radius: 20px;
  font-size: 0.85rem;
  background: #f8fafc;
  position: relative;
}
.search-input:focus { outline: none; border-color: #3b82f6; background: white; }
.search-wrap-inner { position: relative; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #94a3b8; font-size: 0.85rem; }

/* ========== Overlay ========== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.overlay.show { opacity: 1; pointer-events: all; }

/* ========== Summary Cards ========== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  padding: 0;
  border-top: 1px solid #e2e8f0;
}
.summary-card {
  background: white;
  border-radius: 0;
  padding: 10px 8px;
  box-shadow: none;
  text-align: center;
  border-right: 1px solid #f1f5f9;
}
.summary-card:last-child { border-right: none; }
.summary-number { font-size: 1.5rem; font-weight: 800; line-height: 1; margin-bottom: 2px; }
.summary-label { font-size: 0.68rem; color: #64748b; }

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: #1e293b;
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.85rem;
  z-index: 999;
  transition: transform 0.3s;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #94a3b8;
}
.empty-state i { font-size: 3rem; margin-bottom: 16px; }
.empty-state p { font-size: 0.9rem; }

/* ========== Loading ========== */
.loading { text-align: center; padding: 40px; color: #94a3b8; }
.spinner { display: inline-block; width: 36px; height: 36px; border: 3px solid #e2e8f0; border-top-color: #3b82f6; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Responsive ========== */
@media (min-width: 768px) {
  .summary-grid { grid-template-columns: repeat(4, 1fr); }
  .detail-panel { width: 560px; }
  .contract-card { margin: 8px 16px; }
}
@media (min-width: 1100px) {
  .detail-panel { width: 620px; }
}

/* ========== Save Button ========== */
.save-btn {
  background: #1e40af;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.save-btn:hover { background: #1d3a9e; }
.save-btn:active { background: #1e3a8a; }

/* ========== Tabs inside detail ========== */
.detail-tabs {
  display: flex;
  border-bottom: 2px solid #e2e8f0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: #f8fafc;
}
.detail-tab {
  padding: 10px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}
.detail-tab.active { color: #1e40af; border-bottom-color: #1e40af; background: white; }

/* ========== Alert ========== */
.alert-banner {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.8rem;
  color: #92400e;
  margin: 8px 12px;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

/* スプレッドシート列バッジ */
.col-badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1.4;
  padding: 0 5px;
  margin-left: 4px;
  border-radius: 4px;
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
  white-space: nowrap;
  vertical-align: middle;
}

/* 入力チェック: 必須項目が未入力のとき赤くする */
.req-input:placeholder-shown,
.req-missing {
  border-color: #ef4444 !important;
  background: #fff1f2 !important;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.14) !important;
}
.req-missing-row {
  background: #fff1f2 !important;
  border: 1px solid #fca5a5 !important;
  border-radius: 8px;
}
.req-missing-text {
  color: #b91c1c !important;
  font-weight: 700 !important;
}
