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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: #f5f5f5;
  color: #333;
  line-height: 1.6;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

h1 {
  color: #2c3e50;
  margin-bottom: 30px;
  font-size: 28px;
}

h2 {
  color: #34495e;
  margin-bottom: 15px;
  font-size: 20px;
}

.section {
  background: white;
  padding: 20px;
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.loading {
  text-align: center;
  padding: 40px;
  font-size: 18px;
  color: #666;
}

.error {
  background-color: #fee;
  color: #c33;
  padding: 15px;
  border-radius: 4px;
  margin-bottom: 20px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}

.data-table th,
.data-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #ddd;
}

.data-table th {
  background-color: #f8f9fa;
  font-weight: 600;
  color: #495057;
}

.data-table tr:hover {
  background-color: #f8f9fa;
}

#estimateTable td:nth-child(4) {
  color: #dc3545;
  font-weight: 600;
}

input[type="date"] {
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
}

.actions {
  margin-top: 30px;
  text-align: center;
}

.btn {
  padding: 10px 24px;
  font-size: 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-primary {
  background-color: #3498db;
  color: white;
}

.btn-primary:hover {
  background-color: #2980b9;
}

.btn-primary:disabled {
  background-color: #bdc3c7;
  cursor: not-allowed;
}

.invoice-group {
  margin-bottom: 20px;
  padding: 15px;
  background-color: #f8f9fa;
  border-radius: 4px;
}

.invoice-group h3 {
  margin-bottom: 10px;
  color: #2c3e50;
}

.invoice-item {
  padding: 8px 0;
  border-bottom: 1px solid #e0e0e0;
}

.invoice-item:last-child {
  border-bottom: none;
}

.monthly-invoice-dates {
  margin-top: 10px;
  padding: 10px;
  background-color: #e8f4f8;
  border-radius: 4px;
  font-size: 14px;
}

.date-list {
  list-style: none;
  padding-left: 20px;
}

.date-list li {
  padding: 2px 0;
}

.estimate-details {
  margin-top: 10px;
}

.estimate-row {
  display: flex;
  gap: 30px;
  flex-wrap: wrap;
}

.estimate-col {
  flex: 1;
  min-width: 250px;
}

.estimate-col p {
  margin-bottom: 8px;
  font-size: 14px;
}

.estimate-col strong {
  color: #2c3e50;
  min-width: 120px;
  display: inline-block;
}

@media (max-width: 768px) {
  .estimate-row {
    flex-direction: column;
    gap: 15px;
  }
  
  .estimate-col {
    min-width: auto;
  }
}

.invoice-date-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tentative-checkbox-container {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: 14px;
}

.tentative-checkbox {
  cursor: pointer;
}

.tooltip-container {
  position: relative;
  display: inline-block;
}

.tooltip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background-color: #e0e0e0;
  color: #666;
  border-radius: 50%;
  font-size: 12px;
  font-weight: bold;
  cursor: help;
  transition: background-color 0.2s;
}

.tooltip-icon:hover {
  background-color: #d0d0d0;
}

.tooltip-text {
  visibility: hidden;
  opacity: 0;
  width: 280px;
  background-color: #333;
  color: #fff;
  text-align: left;
  border-radius: 6px;
  padding: 10px 12px;
  position: absolute;
  z-index: 1000;
  bottom: 125%;
  left: 50%;
  margin-left: -140px;
  font-size: 13px;
  line-height: 1.4;
  transition: opacity 0.3s, visibility 0.3s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.tooltip-text::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: #333 transparent transparent transparent;
}

.tooltip-container:hover .tooltip-text {
  visibility: visible;
  opacity: 1;
}

input[type="date"] {
  min-width: 140px;
}

.tentative-badge {
  display: inline-block;
  background-color: #8e44ad !important;
  color: white !important;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: normal;
  margin-left: 8px;
}

.tentative-badge-small {
  display: inline-block;
  background-color: #8e44ad !important;
  color: white !important;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: normal;
  margin-left: 6px;
}

.btn-outline {
  background-color: white;
  color: #3498db;
  border: 1px solid #3498db;
}

.btn-outline:hover {
  background-color: #3498db;
  color: white;
}

.btn-required {
  border: 2px solid #dc3545;
  color: #dc3545;
  animation: pulse 1.5s infinite;
}

.btn-required:hover {
  background-color: #dc3545;
  color: white;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(220, 53, 69, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
  }
}

.selected-contacts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 15px;
  min-height: 40px;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #f9f9f9;
}

.contact-tag {
  display: inline-flex;
  align-items: center;
  background-color: #e3f2fd;
  color: #1976d2;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.contact-tag:hover {
  background-color: #bbdefb;
}

.contact-tag .remove {
  margin-left: 8px;
  font-weight: bold;
  cursor: pointer;
}

.modal {
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.5);
}

.modal-content {
  background-color: white;
  margin: 5% auto;
  padding: 0;
  border-radius: 8px;
  width: 80%;
  max-width: 800px;
  max-height: 80%;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #ddd;
  background-color: #f8f9fa;
}

.modal-header h3 {
  margin: 0;
  flex-grow: 1;
}

.close {
  color: #aaa;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  line-height: 1;
}

.close:hover {
  color: #000;
}

.modal-body {
  padding: 20px;
}

.search-box {
  margin-bottom: 20px;
}

.search-box input {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 16px;
}

.contact-list {
  max-height: 400px;
  overflow-y: auto;
}

.contact-list .data-table tbody tr {
  cursor: pointer;
}

.contact-list .data-table tbody tr:hover {
  background-color: #f0f0f0;
}

.negative-invoice {
  border: 2px solid #dc3545;
  background-color: #f8d7da;
}

.error-message {
  color: #dc3545;
  font-weight: bold;
  margin: 10px 0;
}

.alert {
  padding: 10px 15px;
  margin-bottom: 20px;
  border: 1px solid transparent;
  border-radius: 4px;
}

.alert-danger {
  color: #721c24;
  background-color: #f8d7da;
  border-color: #f5c6cb;
}

/* 請求プレビューカード */
.invoice-preview-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 20px;
}

.invoice-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  width: 100%;
}

.invoice-card:hover {
  transform: translateX(2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.invoice-card-header {
  padding: 12px 16px;
  background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
  color: white;
  position: relative;
  width: 320px;
  flex-shrink: 0;
  display: flex;
  gap: 20px;
  align-items: center;
}

.invoice-card-header.tentative {
  background: linear-gradient(135deg, #8e44ad 0%, #9b59b6 100%);
}

.invoice-card-header.not-created {
  background: linear-gradient(135deg, #ffc107 0%, #ffb300 100%);
}

.invoice-card-header.error {
  background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
}

.invoice-card-header.negative {
  background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
}

.invoice-header-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 140px;
}

.invoice-card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 20px;
}

.invoice-status-badge {
  display: inline-block;
  background: rgba(255,255,255,0.3);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.invoice-header-right {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.invoice-date-compact {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
}

.date-item {
  opacity: 0.9;
  white-space: nowrap;
}

.invoice-amount-large {
  font-size: 18px;
  font-weight: bold;
  letter-spacing: -0.5px;
  margin-top: 2px;
}

.invoice-card-body {
  padding: 12px 16px;
  flex: 1;
  display: flex;
  align-items: center;
}


.invoice-items-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  flex: 1;
}

.invoice-item-row {
  padding: 4px 10px;
  background-color: #f8f9fa;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.2s;
  font-size: 12px;
}

.invoice-item-row:hover {
  background-color: #e9ecef;
}

.invoice-item-name {
  color: #495057;
  font-size: 12px;
  white-space: nowrap;
}

.invoice-item-price {
  font-weight: 600;
  color: #2c3e50;
  font-size: 13px;
  white-space: nowrap;
}

.invoice-item-badge {
  display: inline-block;
  background: #d4edda;
  color: #28a745;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 10px;
  margin-left: 6px;
}

.invoice-item-badge.tentative {
  background: #e8daef;
  color: #8e44ad;
}

.invoice-item-badge.waiting {
  background: #f8f9fa;
  color: #6c757d;
}

.invoice-item-badge.not-created {
  background: #fff3cd;
  color: #856404;
}

.negative-warning {
  background: #fff5f5;
  border: 1px solid #ffdddd;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #c0392b;
  font-size: 12px;
}

.invoice-preview-empty {
  text-align: center;
  padding: 60px 20px;
  color: #6c757d;
}

.invoice-preview-empty-icon {
  font-size: 48px;
  margin-bottom: 15px;
  opacity: 0.5;
}

@media (max-width: 768px) {
  .invoice-card {
    flex-direction: column;
  }
  
  .invoice-card-header {
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .invoice-header-left {
    min-width: auto;
  }
  
  .invoice-header-right {
    width: 100%;
  }
  
  .invoice-date-compact {
    flex-direction: row;
    gap: 12px;
    font-size: 10px;
  }
  
  .invoice-card-body {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .invoice-amount-large {
    font-size: 16px;
  }
}