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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", sans-serif;
  background: #f5f7f5;
  color: #1a1a1a;
  min-height: 100vh;
}

header {
  background: #2e7d32;
  color: white;
  padding: 16px;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

main {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

/* フォームセクション */
.form-section {
  background: white;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.form-section h2 {
  font-size: 1rem;
  color: #2e7d32;
  margin-bottom: 14px;
  font-weight: 600;
}

.form-group {
  margin-bottom: 12px;
  flex: 1;
}

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

.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: #2e7d32;
}

.form-row {
  display: flex;
  gap: 12px;
}

#addBtn {
  width: 100%;
  background: #2e7d32;
  color: white;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 4px;
}

#addBtn:hover {
  background: #1b5e20;
}

#addBtn:active {
  background: #1b5e20;
  transform: scale(0.98);
}

.error {
  color: #e53935;
  font-size: 0.85rem;
  margin-top: 8px;
  min-height: 1.2em;
}

/* サマリーセクション */
.summary-section {
  margin-bottom: 16px;
}

.summary-cards {
  display: flex;
  gap: 10px;
}

.summary-card {
  flex: 1;
  background: white;
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.summary-card.highlight {
  background: #e8f5e9;
  border: 1.5px solid #81c784;
}

.summary-label {
  display: block;
  font-size: 0.72rem;
  color: #777;
  margin-bottom: 4px;
}

.summary-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: #2e7d32;
  line-height: 1.1;
}

.summary-value.small {
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.summary-unit {
  font-size: 0.75rem;
  color: #888;
}

/* リストセクション */
.list-section {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.list-header h2 {
  font-size: 1rem;
  color: #2e7d32;
  font-weight: 600;
}

.sort-buttons {
  display: flex;
  gap: 6px;
}

.sort-btn {
  padding: 5px 10px;
  border: 1.5px solid #ccc;
  background: white;
  border-radius: 6px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
  color: #555;
}

.sort-btn.active {
  background: #2e7d32;
  color: white;
  border-color: #2e7d32;
}

.sort-btn:hover:not(.active) {
  border-color: #2e7d32;
  color: #2e7d32;
}

/* 商品カード */
.product-card {
  border: 1px solid #e8e8e8;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
  position: relative;
  transition: box-shadow 0.2s;
}

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

.product-card.rank-1 {
  border-left: 4px solid #f9a825;
  background: #fffde7;
}

.product-card.rank-2 {
  border-left: 4px solid #78909c;
  background: #eceff1;
}

.product-card.rank-3 {
  border-left: 4px solid #bf8f5b;
  background: #fdf6ee;
}

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

.product-name {
  font-size: 0.95rem;
  font-weight: 600;
  flex: 1;
  padding-right: 8px;
}

.rank-badge {
  font-size: 0.75rem;
  font-weight: 700;
  background: #e8f5e9;
  color: #2e7d32;
  padding: 2px 8px;
  border-radius: 12px;
  white-space: nowrap;
}

.card-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 70px;
  background: #f9f9f9;
  border-radius: 6px;
  padding: 6px 4px;
}

.stat-label {
  font-size: 0.68rem;
  color: #888;
  margin-bottom: 2px;
}

.stat-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1a1a1a;
}

.stat-value.profit {
  color: #2e7d32;
}

.stat-value.negative {
  color: #e53935;
}

.margin-bar-wrap {
  margin-top: 8px;
  background: #e8e8e8;
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
}

.margin-bar {
  height: 100%;
  background: #4caf50;
  border-radius: 4px;
  transition: width 0.4s;
}

.margin-bar.negative-bar {
  background: #e53935;
}

.delete-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.2s;
}

.delete-btn:hover {
  color: #e53935;
}

/* 空状態 */
.empty-section {
  text-align: center;
  padding: 40px 20px;
  color: #aaa;
  font-size: 0.9rem;
}

/* レスポンシブ */
@media (max-width: 400px) {
  .form-row {
    flex-direction: column;
  }
  .summary-cards {
    flex-direction: column;
  }
  .card-stats {
    gap: 6px;
  }
}
