:root {
  --primary: #1a3a5c;
  --primary-light: #2d6099;
  --accent: #e67e22;
  --success: #27ae60;
  --danger: #e74c3c;
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --text: #2c3e50;
  --text-sub: #7f8c8d;
  --border: #dce3ea;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --radius: 10px;
  --header-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, 'Hiragino Sans', 'Meiryo', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ===== HEADER ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-h);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.header h1 { font-size: 18px; font-weight: 700; }
.record-count { font-size: 13px; opacity: 0.8; }

/* ===== FILTER BAR ===== */
.filter-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 99;
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 10px 12px 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.06);
}
.search-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.search-clear-btn {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: #dde3ea;
  color: #555;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.search-clear-btn:active { background: #c5cdd6; }
.search-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 24px;
  font-size: 15px;
  outline: none;
  background: var(--bg);
  -webkit-appearance: none;
}
.search-input:focus { border-color: var(--primary-light); background: white; }

.chip-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 4px;
  margin-bottom: 6px;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip-group { display: flex; gap: 4px; flex-shrink: 0; }

.chip {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: white;
  color: var(--text-sub);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  min-height: 30px;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: white; }

.sort-row { display: flex; align-items: center; gap: 8px; }
.sort-label { font-size: 12px; color: var(--text-sub); white-space: nowrap; }
.sort-select {
  flex: 1;
  padding: 6px 28px 6px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: white;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0l6 8 6-8z' fill='%237f8c8d'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.sort-dir-btn {
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: white;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 34px;
}

/* ===== CARD LIST ===== */
.card-list {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  cursor: pointer;
  border-left: 4px solid var(--primary-light);
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, box-shadow 0.1s;
  text-decoration: none;
  color: inherit;
  display: block;
}
.card:active { transform: scale(0.985); box-shadow: 0 1px 4px rgba(0,0,0,0.1); }
.card.kn { border-left-color: var(--accent); }

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 6px;
}
.card-id { font-size: 20px; font-weight: 700; color: var(--primary); letter-spacing: 1px; }
.card-badges { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge-js           { background: #dbeafe; color: #1d4ed8; }
.badge-kn           { background: #fef3c7; color: #92400e; }
.badge-hq           { background: #e0f2fe; color: #0369a1; }
.badge-kozoji       { background: #f0fdf4; color: #166534; }
.badge-chiyogaoka   { background: #fdf4ff; color: #7e22ce; }
.badge-paid         { background: #dcfce7; color: #166534; }
.badge-unpaid       { background: #fee2e2; color: #991b1b; }
.badge-done         { background: #d1fae5; color: #065f46; }
.badge-wip          { background: #fef9c3; color: #854d0e; }

.card-danchi {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-danchi-sub { font-size: 14px; color: var(--text-sub); font-weight: 400; }
.card-dates {
  font-size: 13px;
  color: var(--text-sub);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}
.card-date-item { display: flex; align-items: center; gap: 3px; }
.date-label { font-size: 11px; color: #aaa; }
.card-status { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.card-link-btn {
  margin-left: auto;
  padding: 3px 8px;
  border-radius: 5px;
  background: #eef3f8;
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.card-link-btn:active { background: #d2e3f0; }

/* ===== LOADING / ERROR ===== */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-sub);
  gap: 16px;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-msg {
  margin: 16px;
  padding: 14px 16px;
  background: #fee2e2;
  color: #991b1b;
  border-radius: var(--radius);
  font-size: 14px;
}
.empty-msg {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-sub);
  font-size: 15px;
}

/* ===== FAB（新規登録ボタン） ===== */
.fab {
  position: fixed;
  bottom: 24px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.28);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s, box-shadow 0.15s;
}
.fab:active { transform: scale(0.92); box-shadow: 0 2px 8px rgba(0,0,0,0.22); }

/* ===== EDIT PAGE ===== */
.edit-app { min-height: 100vh; background: var(--bg); }
.edit-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 12px;
  height: var(--header-h);
  gap: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.back-btn {
  background: none;
  border: none;
  color: white;
  font-size: 28px;
  cursor: pointer;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
}
.edit-title { flex: 1; font-size: 15px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-btn {
  background: var(--accent);
  border: none;
  color: white;
  font-size: 14px;
  font-weight: 700;
  padding: 8px 18px;
  border-radius: 6px;
  cursor: pointer;
  min-height: 38px;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.save-btn:disabled { background: #ccc; cursor: not-allowed; }

.edit-body { padding: 12px; padding-bottom: 40px; }

.section {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}
.section-title {
  background: var(--primary);
  color: white;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 16px;
  letter-spacing: 0.5px;
}

.field-row {
  display: flex;
  align-items: flex-start;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.field-row:last-child { border-bottom: none; }

.field-label {
  font-size: 12px;
  color: var(--text-sub);
  min-width: 72px;
  padding-top: 10px;
  flex-shrink: 0;
  line-height: 1.3;
}
.field-label.required::after { content: ' *'; color: var(--danger); }
.field-control { flex: 1; min-width: 0; }

.field-input, .field-select, .field-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
  font-family: inherit;
  background: white;
  color: var(--text);
  -webkit-appearance: none;
  outline: none;
  transition: border-color 0.2s;
}
.field-input:focus, .field-select:focus, .field-textarea:focus { border-color: var(--primary-light); }
.field-input.error, .field-select.error, .field-textarea.error { border-color: var(--danger); background: #fff8f8; }
.field-error { font-size: 12px; color: var(--danger); margin-top: 4px; min-height: 16px; }

.field-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0l6 8 6-8z' fill='%237f8c8d'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.field-textarea { min-height: 80px; resize: vertical; line-height: 1.5; }

.radio-group { display: flex; gap: 20px; padding: 8px 0; }
.radio-label { display: flex; align-items: center; gap: 8px; font-size: 16px; cursor: pointer; }
.radio-label input { width: 20px; height: 20px; accent-color: var(--primary); cursor: pointer; }

.field-readonly {
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-sub);
  word-break: break-all;
  line-height: 1.5;
}

.url-field-wrap { display: flex; gap: 8px; align-items: flex-start; }
.url-link-btn {
  padding: 8px 12px;
  background: #e8f4fd;
  border: 1.5px solid #bee3f8;
  border-radius: 6px;
  color: var(--primary-light);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 40px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

/* ===== DIFF MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  display: flex;
  align-items: flex-end;
}
.modal {
  background: white;
  border-radius: 18px 18px 0 0;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px 16px 36px;
  -webkit-overflow-scrolling: touch;
}
.modal-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
  text-align: center;
  color: var(--primary);
}
.modal-subtitle {
  font-size: 13px;
  color: var(--text-sub);
  text-align: center;
  margin-bottom: 14px;
}
.diff-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.diff-table th {
  background: var(--bg);
  padding: 8px;
  text-align: left;
  font-size: 11px;
  color: var(--text-sub);
  border-bottom: 1px solid var(--border);
}
.diff-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  word-break: break-all;
  font-size: 13px;
}
.diff-field { font-weight: 600; white-space: nowrap; }
.diff-before { color: #e74c3c; }
.diff-after  { color: #27ae60; font-weight: 600; }

.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.btn-cancel {
  flex: 1;
  padding: 14px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-confirm {
  flex: 1;
  padding: 14px;
  background: var(--primary);
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  color: white;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-confirm:disabled { background: #aaa; cursor: not-allowed; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20,20,20,0.88);
  color: white;
  padding: 12px 22px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 300;
  opacity: 1;
  transition: opacity 0.4s;
  white-space: nowrap;
  pointer-events: none;
}
.toast.hide { opacity: 0; }
