/* ==========================================================
 * 注文商品ランキング専用CSS
 * - 外枠・ヘッダー・メニューは base.css / settings.css / admaster.css に合わせる
 * - このファイルではランキング画面の中身だけを調整する
 * ========================================================== */

.product-ranking-main {
  padding-bottom: 48px;
}

.ranking-lead {
  width: min(920px, calc(100% - 28px));
  margin: -10px auto 26px auto;
  text-align: center;
  color: var(--section-text-color, #333);
  line-height: 1.8;
  font-size: 0.98rem;
}

.ranking-section {
  width: min(1100px, calc(100% - 28px));
  max-width: 1100px;
  margin: 36px auto;
  padding: 22px 22px 26px 22px;
  background-color: var(--section-bg-color, #fff);
  color: var(--section-text-color, #222);
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.10);
  box-sizing: border-box;
}

.ranking-section-title {
  margin: 0 auto 18px auto !important;
  font-size: 1.28rem !important;
  line-height: 1.35;
  white-space: normal !important;
}

.ranking-section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 12px;
}

.ranking-section-head p {
  margin: 0;
  line-height: 1.7;
  color: var(--input-text-color, #555);
  opacity: 0.86;
}

.ranking-inline-loading {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
  font-size: 0.9rem;
  white-space: nowrap;
}

/* admaster.css の .styled-form を使いつつ、ランキング用に横幅を広げる */
.ranking-filter-form.styled-form {
  width: 100%;
  max-width: none;
  margin: 0 auto;
  padding: 18px;
  box-shadow: none;
  border: 1px solid var(--input-border-color, #ddd);
  box-sizing: border-box;
}

.ranking-filter-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr 1fr 1fr;
  gap: 14px;
  align-items: end;
}

.ranking-field {
  display: block;
  min-width: 0;
}

.ranking-field span {
  display: block;
  margin-bottom: 7px;
  color: var(--section-text-color, #333);
  font-weight: 700;
  font-size: 0.92rem;
}

.ranking-field input,
.ranking-field select {
  width: 100%;
  min-height: 44px;
  display: block;
  margin: 0;
  padding: 9px 10px;
  border: 1px solid var(--input-border-color, #ccc);
  border-radius: 6px;
  background-color: var(--input-bg-color, #fff);
  color: var(--input-text-color, #222);
  box-sizing: border-box;
}

.ranking-field.is-muted,
.date-field.is-muted {
  opacity: 0.55;
}

.ranking-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.ranking-primary-btn,
.ranking-secondary-btn {
  min-width: 170px;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.03em;
  transition: filter 0.18s ease, transform 0.18s ease, opacity 0.18s ease;
}

.ranking-primary-btn {
  color: #fff;
  border: none;
  background: linear-gradient(180deg, #63b3fa 0%, #007bff 60%, #20518d 100%);
  box-shadow:
    0 2px 10px 0 rgba(30, 80, 180, 0.13),
    0 1px 0 0 #fff6 inset,
    0 0.5px 1px 0 #20518d44;
}

.ranking-secondary-btn {
  color: var(--input-text-color, #333);
  border: 1px solid var(--input-border-color, #888);
  background: linear-gradient(to bottom, #cccccc, #999999);
}

.ranking-primary-btn:hover,
.ranking-secondary-btn:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

.ranking-primary-btn:disabled,
.ranking-secondary-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.ranking-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.ranking-summary-card {
  padding: 16px 14px 14px 14px;
  text-align: center;
  border: 1px solid var(--input-border-color, #ddd);
  border-radius: 10px;
  background: var(--input-bg-color, #fff);
  color: var(--input-text-color, #222);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  min-width: 0;
}

.ranking-summary-label {
  display: block;
  margin-bottom: 7px;
  font-size: 0.86rem;
  opacity: 0.82;
  font-weight: 700;
}

.ranking-summary-card strong {
  display: inline-block;
  max-width: 100%;
  font-size: clamp(1.22rem, 2.8vw, 1.85rem);
  line-height: 1.25;
  word-break: break-word;
}

.ranking-summary-card small {
  display: block;
  margin-top: 6px;
  opacity: 0.72;
  line-height: 1.35;
}

.bar-chart {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(180px, 270px) minmax(160px, 1fr) minmax(95px, auto);
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--input-border-color, #ddd);
  border-radius: 8px;
  background: var(--input-bg-color, #fff);
}

.bar-label {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.bar-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 50%;
  background: var(--menu-bg-color, #333);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
}

.bar-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.bar-track {
  position: relative;
  height: 16px;
  border-radius: 999px;
  background: rgba(120, 120, 120, 0.20);
  overflow: hidden;
}

.bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  min-width: 3px;
  border-radius: inherit;
  background: linear-gradient(90deg, #63b3fa, #007bff 65%, #20518d);
}

.bar-value {
  text-align: right;
  font-weight: 700;
  white-space: nowrap;
}

.ranking-empty,
.ranking-empty-cell {
  padding: 18px;
  text-align: center;
  color: var(--input-text-color, #555);
  opacity: 0.82;
}

.ranking-chart-note {
  margin-top: 8px;
  border: 1px dashed var(--input-border-color, #ddd);
  border-radius: 8px;
}

.ranking-scroll-hint {
  display: none;
  text-align: center;
  margin: 0 auto 8px auto;
  font-size: 0.86rem;
  color: var(--input-text-color, #555);
  opacity: 0.85;
}

.ranking-table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.ranking-table {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
  background-color: var(--input-bg-color, #fff);
  color: var(--input-text-color, #222);
}

.ranking-table th,
.ranking-table td {
  padding: 9px 10px;
  border: 1px solid var(--input-border-color, #ddd);
  vertical-align: middle;
  box-sizing: border-box;
}

.ranking-table th {
  text-align: center;
  background-color: var(--section-bg-color, #f7f7f7);
  color: var(--section-text-color, #222);
  white-space: nowrap;
}

.ranking-table td {
  text-align: left;
}

.ranking-table .num {
  text-align: right;
  white-space: nowrap;
}

.rank-cell {
  text-align: center !important;
  width: 64px;
  white-space: nowrap;
}

.product-name-cell {
  min-width: 220px;
  font-weight: 700;
  word-break: break-word;
}

.product-type {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 123, 255, 0.13);
  color: #135da7;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.product-type.custom {
  background: rgba(231, 76, 60, 0.12);
  color: #b03a2e;
}

#backToTop {
  display: none;
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 998;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--input-border-color, #aaa);
  background: var(--section-bg-color, #fff);
  color: var(--section-text-color, #222);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
  cursor: pointer;
}

.menu-content a[aria-current="page"] {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.dark-mode .ranking-primary-btn {
  background: linear-gradient(180deg, #8aa9c8 0%, #4d7fae 65%, #304b66 100%);
}

.dark-mode .ranking-secondary-btn {
  background: linear-gradient(to bottom, #a9a7a8, #7f7f82);
  color: #111;
}

.dark-mode .bar-rank {
  background: #a9a7a8;
  color: #111;
}

.dark-mode .bar-fill {
  background: linear-gradient(90deg, #a9c6e4, #76a6d2 65%, #52799e);
}

.dark-mode .product-type {
  color: #d8ecff;
  background: rgba(118, 166, 210, 0.25);
}

.dark-mode .product-type.custom {
  color: #ffd7d2;
  background: rgba(231, 76, 60, 0.22);
}

@media (max-width: 960px) {
  .ranking-filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ranking-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bar-row {
    grid-template-columns: minmax(150px, 220px) minmax(120px, 1fr) minmax(80px, auto);
  }
}

@media (max-width: 640px) {
  .product-ranking-main {
    padding-left: 0;
    padding-right: 0;
  }

  .ranking-lead {
    width: calc(100% - 26px);
    text-align: left;
    font-size: 0.92rem;
  }

  .ranking-section {
    width: calc(100% - 20px);
    margin: 26px auto;
    padding: 16px 12px 20px 12px;
  }

  .ranking-filter-form.styled-form {
    padding: 14px 12px;
  }

  .ranking-filter-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .ranking-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .ranking-primary-btn,
  .ranking-secondary-btn {
    width: 100%;
    min-width: 0;
  }

  .ranking-summary-grid {
    grid-template-columns: 1fr;
  }

  .ranking-section-head {
    display: block;
  }

  .ranking-inline-loading {
    display: inline-block;
    margin-top: 10px;
  }

  .bar-row {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .bar-value {
    text-align: left;
  }

  .bar-name {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  .ranking-scroll-hint {
    display: block;
  }

  .ranking-table th,
  .ranking-table td {
    padding: 8px 9px;
    font-size: 0.92rem;
  }
}

/* 「すべて」表示時の未注文商品用 */
.bar-row.no-value .bar-fill {
  min-width: 0;
  width: 0 !important;
}

.bar-row.no-value .bar-value {
  opacity: 0.72;
}

.product-type.no-orders {
  background: rgba(120, 120, 120, 0.16);
  color: #555;
}

.dark-mode .product-type.no-orders {
  color: #f0f0f0;
  background: rgba(180, 180, 180, 0.22);
}