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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f5f5;
  color: #333;
  font-size: 15px;
  line-height: 1.5;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

/* ヘッダー */
header {
  background: #2c5f8a;
  color: white;
  padding: 20px 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  text-align: center;
}

header h1 {
  font-size: 1.5rem;
  margin-bottom: 4px;
}

.subtitle {
  font-size: 0.85rem;
  opacity: 0.85;
}

/* セクション共通 */
section {
  background: white;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

section h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: #2c5f8a;
  border-left: 4px solid #2c5f8a;
  padding-left: 8px;
}

/* フォーム */
.form-row {
  margin-bottom: 10px;
}

.form-row label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: #555;
}

.required {
  color: #e53e3e;
}

.form-row input[type="text"],
.form-row input[type="date"],
.form-row textarea,
.form-row select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.95rem;
  transition: border-color 0.2s;
}

.form-row input:focus,
.form-row textarea:focus {
  outline: none;
  border-color: #2c5f8a;
}

.form-row textarea {
  resize: vertical;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-add {
  display: block;
  width: 100%;
  padding: 10px;
  background: #2c5f8a;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 8px;
}

.btn-add:hover {
  background: #1e4266;
}

.btn-cancel {
  display: block;
  width: 100%;
  padding: 10px;
  background: #e2e8f0;
  color: #555;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  margin-top: 8px;
}

/* フィルター */
.filter-section {
  padding: 12px 16px;
}

.filter-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.filter-btn {
  padding: 6px 14px;
  border: 1px solid #ddd;
  border-radius: 20px;
  background: white;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.filter-btn.active,
.filter-btn:hover {
  background: #2c5f8a;
  color: white;
  border-color: #2c5f8a;
}

.sort-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #555;
}

.sort-bar select {
  padding: 5px 8px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.85rem;
}

/* サマリー */
.summary-section {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px;
}

.summary-card {
  text-align: center;
  padding: 10px 6px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.expired-card { background: #fff5f5; border: 1px solid #fed7d7; }
.warning-card  { background: #fffaf0; border: 1px solid #fbd38d; }
.normal-card   { background: #f0fff4; border: 1px solid #9ae6b4; }
.total-card    { background: #ebf8ff; border: 1px solid #90cdf4; }

.summary-num {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}

.expired-card .summary-num { color: #c53030; }
.warning-card .summary-num { color: #c05621; }
.normal-card  .summary-num { color: #276749; }
.total-card   .summary-num { color: #2b6cb0; }

.summary-label {
  font-size: 0.75rem;
  color: #666;
}

/* 契約一覧 */
.contract-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-msg {
  text-align: center;
  color: #999;
  padding: 30px 0;
  font-size: 0.9rem;
}

.contract-card {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px 14px;
  border-left: 5px solid #ccc;
  transition: box-shadow 0.2s;
}

.contract-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.contract-card.expired {
  border-left-color: #e53e3e;
  background: #fff5f5;
}

.contract-card.warning {
  border-left-color: #ed8936;
  background: #fffaf0;
}

.contract-card.normal {
  border-left-color: #38a169;
  background: #f0fff4;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
  gap: 8px;
}

.client-name {
  font-size: 1rem;
  font-weight: 700;
  color: #222;
}

.status-badge {
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-expired { background: #fed7d7; color: #c53030; }
.badge-warning { background: #fbd38d; color: #c05621; }
.badge-normal  { background: #9ae6b4; color: #276749; }

.contract-content {
  font-size: 0.9rem;
  color: #555;
  margin-bottom: 8px;
}

.card-dates {
  font-size: 0.82rem;
  color: #666;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 6px;
}

.date-item span {
  font-weight: 600;
  color: #444;
}

.renewal-date {
  font-size: 0.9rem;
  font-weight: 600;
}

.contract-card.expired .renewal-date { color: #c53030; }
.contract-card.warning .renewal-date { color: #c05621; }
.contract-card.normal  .renewal-date { color: #276749; }

.days-label {
  font-size: 0.8rem;
  margin-left: 6px;
}

.card-memo {
  font-size: 0.82rem;
  color: #777;
  background: rgba(0,0,0,0.03);
  padding: 4px 8px;
  border-radius: 4px;
  margin-bottom: 8px;
}

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

.btn-edit,
.btn-delete {
  padding: 5px 14px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.83rem;
  font-weight: 600;
  transition: opacity 0.2s;
}

.btn-edit   { background: #ebf8ff; color: #2b6cb0; }
.btn-delete { background: #fff5f5; color: #c53030; }

.btn-edit:hover,
.btn-delete:hover {
  opacity: 0.75;
}

/* モーダル */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: white;
  border-radius: 10px;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content h2 {
  font-size: 1.1rem;
  margin-bottom: 14px;
  color: #2c5f8a;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}

/* レスポンシブ */
@media (max-width: 480px) {
  .summary-section {
    grid-template-columns: repeat(2, 1fr);
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 360px) {
  .filter-bar {
    gap: 4px;
  }
  .filter-btn {
    padding: 5px 10px;
    font-size: 0.8rem;
  }
}
