/* ==================== リセット & 基本設定 ==================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #006aff;
  --primary-hover: #0052cc;
  --success-color: #00d26a;
  --warning-color: #ffb800;
  --danger-color: #ff4d4d;
  --text-primary: #1a1a2e;
  --text-secondary: #666;
  --bg-main: #f5f7fa;
  --bg-card: #ffffff;
  --border-color: #e0e6ed;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.6;
}

/* ==================== モーダル ==================== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-card);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  text-align: center;
  max-width: 400px;
  width: 90%;
}

.modal-content h2 {
  margin-bottom: 1rem;
  color: var(--primary-color);
}

.modal-content p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.modal-content input {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  margin-bottom: 1rem;
  transition: border-color 0.2s;
}

.modal-content input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.error-text {
  color: var(--danger-color);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

/* ==================== ボタン ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-main);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--border-color);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-outline:hover {
  background: var(--bg-main);
}

/* ==================== ヘッダー ==================== */
.header {
  background: var(--bg-card);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-left h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.header-left h1 i {
  color: var(--primary-color);
}

.header-right {
  display: flex;
  gap: 0.75rem;
}

.badge {
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-sandbox {
  background: #fff3cd;
  color: #856404;
}

.badge-production {
  background: #d4edda;
  color: #155724;
}

/* ==================== フィルター ==================== */
.filters {
  background: var(--bg-card);
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border-color);
}

.filter-row {
  display: flex;
  gap: 1.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.filter-actions {
  display: flex;
  gap: 0.75rem;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.filter-group label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.filter-group label i {
  margin-right: 0.25rem;
}

.filter-group select,
.filter-group input[type="date"] {
  padding: 0.625rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  min-width: 150px;
  background: white;
}

.filter-group select:focus,
.filter-group input[type="date"]:focus {
  outline: none;
  border-color: var(--primary-color);
}

/* ==================== 決済方法別サマリー ==================== */
.payment-type-summary {
  display: flex;
  gap: 1rem;
  padding: 1.5rem 2rem;
  background: var(--bg-main);
  overflow-x: auto;
}

.payment-type-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-card);
  padding: 1rem 1.5rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  min-width: 200px;
  flex: 1;
}

.payment-type-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.payment-type-card.cash .payment-type-icon {
  background: #e8f5e9;
  color: #2e7d32;
}

.payment-type-card.card .payment-type-icon {
  background: #e3f2fd;
  color: #1565c0;
}

.payment-type-card.wallet .payment-type-icon {
  background: #fff3e0;
  color: #ef6c00;
}

.payment-type-info {
  display: flex;
  flex-direction: column;
}

.payment-type-label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.payment-type-amount {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.payment-type-count {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ==================== サマリーカード ==================== */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  padding: 2rem;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}

.card:hover {
  box-shadow: var(--shadow-hover);
}

.summary-card {
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.card-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.card-icon.sales {
  background: #e8f4fd;
  color: var(--primary-color);
}

.card-icon.transactions {
  background: #e8fdf4;
  color: var(--success-color);
}

.card-icon.average {
  background: #fff8e8;
  color: var(--warning-color);
}

.card-icon.completed {
  background: #f0e8fd;
  color: #6c5ce7;
}

.card-content h3 {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.card-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ==================== グラフセクション ==================== */
.charts-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 1.5rem;
  padding: 0 2rem 2rem;
}

.chart-card {
  padding: 1.5rem;
}

.chart-card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.chart-card h3 i {
  color: var(--primary-color);
  margin-right: 0.5rem;
}

.chart-card canvas {
  width: 100% !important;
  height: 280px !important;
}

/* ==================== 店舗別売上 ==================== */
.location-section {
  padding: 0 2rem 2rem;
}

.location-section .card {
  padding: 1.5rem;
}

.location-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.location-section h3 i {
  color: var(--primary-color);
  margin-right: 0.5rem;
}

.location-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.location-item {
  background: var(--bg-main);
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.location-item .name {
  font-weight: 500;
  color: var(--text-primary);
}

.location-item .count {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.location-item .amount {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary-color);
}

/* ==================== 取引テーブル ==================== */
.transactions-section {
  padding: 0 2rem 2rem;
}

.transactions-section .card {
  padding: 1.5rem;
}

.transactions-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.transactions-section h3 i {
  color: var(--primary-color);
  margin-right: 0.5rem;
}

.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 0.875rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-main);
}

td {
  font-size: 0.9375rem;
}

tr:hover td {
  background: var(--bg-main);
}

.status-badge {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  border-radius: 1rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-completed {
  background: #d4edda;
  color: #155724;
}

.status-pending {
  background: #fff3cd;
  color: #856404;
}

.status-failed {
  background: #f8d7da;
  color: #721c24;
}

.pagination {
  margin-top: 1rem;
  text-align: center;
}

/* ==================== ローディング ==================== */
.loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.loading.hidden {
  display: none;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading p {
  margin-top: 1rem;
  color: var(--text-secondary);
}

/* ==================== ユーティリティ ==================== */
.hidden {
  display: none !important;
}

/* ==================== レスポンシブ ==================== */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
  }

  .header-left {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }

  .header-left h1 {
    font-size: 1.25rem;
  }

  .filters {
    padding: 1rem;
  }

  .filter-row {
    flex-direction: column;
    gap: 1rem;
  }

  .filter-group {
    width: 100%;
  }

  .filter-group select,
  .filter-group input[type="date"] {
    width: 100%;
  }

  .filter-actions {
    width: 100%;
  }

  .filter-actions .btn {
    flex: 1;
  }

  .payment-type-summary {
    flex-direction: column;
    padding: 1rem;
  }

  .payment-type-card {
    min-width: auto;
  }

  .summary-cards {
    padding: 1rem;
    gap: 1rem;
  }

  .charts-section {
    grid-template-columns: 1fr;
    padding: 0 1rem 1rem;
  }

  .location-section,
  .transactions-section {
    padding: 0 1rem 1rem;
  }

  .card-value {
    font-size: 1.5rem;
  }
}

/* ==================== エンプティステート ==================== */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-secondary);
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state p {
  font-size: 1rem;
}

/* ==================== トースト通知 ==================== */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 1rem 1.5rem;
  background: var(--text-primary);
  color: white;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-hover);
  animation: slideIn 0.3s ease;
  z-index: 1000;
}

.toast.error {
  background: var(--danger-color);
}

.toast.success {
  background: var(--success-color);
}

@keyframes slideIn {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ==================== 取引詳細モーダル ==================== */
.modal-large {
  max-width: 700px;
  width: 95%;
  max-height: 90vh;
  overflow-y: auto;
  text-align: left;
  padding: 0;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 10;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}

.btn-close:hover {
  background: var(--bg-main);
  color: var(--text-primary);
}

#order-detail-content {
  padding: 1.5rem;
}

/* 取引概要 */
.order-summary {
  background: var(--bg-main);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.order-info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.order-info-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.order-info-item .label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.order-info-item .value {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-primary);
  word-break: break-all;
}

/* 商品内訳 */
.order-items-section {
  margin-bottom: 1.5rem;
}

.order-items-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.order-items-section h3 i {
  color: var(--primary-color);
  margin-right: 0.5rem;
}

.order-items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.order-items-table th {
  background: var(--bg-main);
  padding: 0.75rem 1rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.order-items-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

.order-items-table .text-center {
  text-align: center;
}

.order-items-table .text-right {
  text-align: right;
}

.order-items-table .item-name {
  font-weight: 500;
}

.order-items-table .item-variation {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* 合計 */
.order-totals {
  background: var(--bg-main);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.total-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  font-size: 0.9375rem;
}

.total-row:not(:last-child) {
  border-bottom: 1px solid var(--border-color);
}

.total-final {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--primary-color);
  padding-top: 0.75rem;
}

/* アクション */
.order-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

/* ローディング・エラー */
.modal-loading,
.modal-error {
  padding: 3rem;
  text-align: center;
}

.modal-loading .spinner {
  margin: 0 auto 1rem;
}

.modal-error i {
  font-size: 3rem;
  color: var(--danger-color);
  margin-bottom: 1rem;
}

.modal-error p {
  color: var(--text-secondary);
}

/* クリック可能な行 */
.clickable-row {
  cursor: pointer;
  transition: background 0.2s;
}

.clickable-row td {
  cursor: pointer;
}

.clickable-row:hover td {
  background: #e8f4fd;
}

.clickable-row td * {
  pointer-events: none;
}

/* ==================== 商品別売上 ==================== */
.products-section {
  padding: 0 2rem 2rem;
}

.products-section .card {
  padding: 1.5rem;
}

.products-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.products-section h3 i {
  color: var(--primary-color);
  margin-right: 0.5rem;
}

/* 商品検索・ソート */
.products-filters {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.products-search {
  flex: 1;
  min-width: 200px;
  max-width: 400px;
  position: relative;
}

.products-search i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
}

.products-search input {
  width: 100%;
  padding: 0.625rem 0.75rem 0.625rem 38px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.products-search input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(0, 106, 255, 0.1);
}

.products-filters select {
  padding: 0.625rem 2rem 0.625rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: white;
  cursor: pointer;
  min-width: 160px;
}

.products-filters select:focus {
  outline: none;
  border-color: var(--primary-color);
}

.filtered-info {
  color: var(--primary-color) !important;
}

.filtered-info.hidden {
  display: none !important;
}

/* 検索ハイライト */
#products-table mark {
  background: #fff3cd;
  padding: 0 2px;
  border-radius: 2px;
}

.products-summary {
  margin-bottom: 1rem;
}

.products-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  padding: 1rem;
  background: var(--bg-main);
  border-radius: var(--radius-sm);
}

.products-stats span {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.products-stats span i {
  color: var(--primary-color);
}

.products-stats strong {
  color: var(--text-primary);
  font-weight: 600;
}

#products-table {
  width: 100%;
  border-collapse: collapse;
}

#products-table th,
#products-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

#products-table th {
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-main);
}

#products-table .text-right {
  text-align: right;
}

.product-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary-color);
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 0.75rem;
}

#products-table tr:nth-child(1) .product-rank { background: #ffd700; color: #333; }
#products-table tr:nth-child(2) .product-rank { background: #c0c0c0; color: #333; }
#products-table tr:nth-child(3) .product-rank { background: #cd7f32; color: white; }

.product-name {
  font-weight: 500;
}

.percentage-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 120px;
}

.percentage-fill {
  height: 8px;
  background: linear-gradient(90deg, var(--primary-color), var(--success-color));
  border-radius: 4px;
  flex-shrink: 0;
  min-width: 4px;
  max-width: 80px;
}

.percentage-bar span {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.text-center {
  text-align: center;
}

.text-muted {
  color: var(--text-secondary);
  font-size: 0.875rem;
  padding: 1rem !important;
}

/* レスポンシブ */
@media (max-width: 600px) {
  .modal-large {
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  .order-info-grid {
    grid-template-columns: 1fr;
  }

  .order-items-table th,
  .order-items-table td {
    padding: 0.5rem;
    font-size: 0.8125rem;
  }

  .products-stats {
    flex-direction: column;
    gap: 0.75rem;
  }

  .percentage-bar {
    min-width: 80px;
  }

  .percentage-fill {
    max-width: 50px;
  }
}
