/* ──────────────────────────────────────────────
   TV Ratings Page — ratings.html
   ────────────────────────────────────────────── */

/* ── Page wrapper ── */
.ratings-page {
  background: var(--artifact-navy);
  color: var(--artifact-white);
  min-height: 100vh;
  padding-top: 78px; /* header height (is-scrolled) */
}

/* ── Hero / title area ── */
.ratings-hero {
  padding: 56px 0 40px;
  border-bottom: 1px solid var(--artifact-line-dark);
}

.ratings-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--artifact-muted-dark);
  margin-bottom: 20px;
}
.ratings-breadcrumb a {
  color: var(--artifact-muted-dark);
  transition: color 0.2s;
}
.ratings-breadcrumb a:hover {
  color: var(--artifact-aqua);
}
.ratings-breadcrumb .bc-sep {
  opacity: 0.4;
}

.ratings-hero h1 {
  font-family: var(--artifact-display);
  font-size: clamp(32px, 4vw, 48px);
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 1.2;
  margin-bottom: 10px;
}

.ratings-hero .ratings-subtitle {
  font-size: 15px;
  color: var(--artifact-muted-dark);
  line-height: 1.7;
  max-width: 520px;
}

/* ── Tab navigation → Sidebar tree ── */
.ratings-content {
  padding: 0 0 80px;
}

.ratings-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 36px;
  padding-top: 28px;
}

/* 사이드바 */
.ratings-sidebar {
  position: sticky;
  top: 90px;
  align-self: start;
}

.ratings-tree {
  border: 1px solid var(--artifact-line-dark);
  border-radius: 8px;
  padding: 12px 0;
  background: rgba(255,255,255,0.03);
}

.tree-group {
  padding: 0;
}
.tree-group + .tree-group {
  border-top: 1px solid rgba(255,255,255,0.06);
}

.tree-group-title {
  padding: 14px 20px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--artifact-aqua);
  margin: 0;
}

.tree-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 20px 10px 32px;
  font-size: 14px;
  font-weight: 400;
  background: transparent;
  color: var(--artifact-muted-dark);
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  position: relative;
}
.tree-item::before {
  content: '';
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--artifact-muted-dark);
  opacity: 0.4;
  transition: opacity 0.15s, background 0.15s;
}

.tree-item:hover {
  background: rgba(255,255,255,0.05);
  color: var(--artifact-white);
}
.tree-item:hover::before {
  opacity: 0.8;
}

.tree-item.active {
  background: rgba(110,55,250,0.15);
  color: var(--artifact-white);
  font-weight: 600;
}
.tree-item.active::before {
  background: var(--artifact-purple);
  opacity: 1;
  width: 6px;
  height: 6px;
}

.tree-item:focus-visible {
  outline: 2px solid var(--artifact-aqua);
  outline-offset: -2px;
}

/* 우측 메인 콘텐츠 */
.ratings-main {
  min-width: 0;
}

/* ── Filter bar ── */
.ratings-filters {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 20px 24px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--artifact-line-dark);
  border-radius: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--artifact-muted-dark);
  white-space: nowrap;
}

/* Date picker trigger styled via calendar.css */

.market-toggle {
  display: flex;
  border: 1px solid var(--artifact-line-dark);
  border-radius: 6px;
  overflow: hidden;
}

/* Weekly display handled by NKCalendar trigger */

.market-btn {
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  color: var(--artifact-muted-dark);
  border: none;
  border-right: 1px solid var(--artifact-line-dark);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}
.market-btn:last-child {
  border-right: none;
}
.market-btn:hover {
  color: var(--artifact-white);
}
.market-btn.active {
  background: var(--artifact-aqua-ink);
  color: var(--artifact-white);
}

/* ── Select dropdowns (Target / Variable) ── */
.nk-select {
  height: 40px;
  padding: 0 36px 0 14px;
  background-color: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.24);
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  line-height: 40px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23ffffff' d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  transition: border-color 0.2s;
  white-space: nowrap;
}
.nk-select:hover {
  border-color: rgba(255,255,255,0.4);
}
.nk-select:focus {
  outline: none;
  border-color: var(--artifact-aqua);
}
.nk-select option {
  background: #1a1a2e;
  color: #fff;
}

/* ── Data table ── */
.ratings-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  border: 1px solid var(--artifact-line-dark);
}

.ratings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 480px;
}

.ratings-table thead {
  background: rgba(255,255,255,0.06);
}

.ratings-table th {
  padding: 14px 16px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--artifact-muted-dark);
  text-align: left;
  border-bottom: 1px solid var(--artifact-line-dark);
  white-space: nowrap;
}
.ratings-table th.col-rank,
.ratings-table td.col-rank {
  text-align: center;
  width: 64px;
}
.ratings-table th.col-rating,
.ratings-table td.col-rating {
  text-align: right;
  width: 120px;
}
.ratings-table th.col-channel,
.ratings-table td.col-channel {
  width: 120px;
}

.ratings-table tbody tr {
  border-bottom: 1px solid rgba(255,255,255,0.06);
  transition: background 0.15s;
}
.ratings-table tbody tr:last-child {
  border-bottom: none;
}
.ratings-table tbody tr:hover {
  background: rgba(255,255,255,0.04);
}

.ratings-table td {
  padding: 13px 16px;
  color: var(--artifact-white);
  vertical-align: middle;
}

/* Rank number styling */
.rank-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 13px;
  font-weight: 700;
  border-radius: 6px;
}
.rank-top3 {
  background: var(--artifact-purple);
  color: var(--artifact-white);
}

/* Rating bar */
.rating-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ── Status states ── */
.ratings-status {
  padding: 60px 20px;
  text-align: center;
  font-size: 15px;
  color: var(--artifact-muted-dark);
  line-height: 1.8;
}
.ratings-status.is-loading::before {
  content: "";
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--artifact-line-dark);
  border-top-color: var(--artifact-aqua);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 10px;
  vertical-align: middle;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.ratings-status.is-error {
  color: var(--artifact-red, #F40953);
}

/* ── Footnote ── */
.ratings-footnote {
  margin-top: 20px;
  font-size: 12px;
  color: var(--artifact-muted-dark);
  line-height: 1.8;
}

/* ── Load-more button ── */
.ratings-loadmore {
  text-align: center;
  padding: 24px 0;
}
.loadmore-btn {
  padding: 12px 32px;
  font-size: 14px;
  background: transparent;
  color: var(--artifact-muted-dark);
  border: 1px solid var(--artifact-line-dark);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.loadmore-btn:hover {
  color: var(--artifact-white);
  border-color: rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.05);
}
.loadmore-btn:focus-visible {
  outline: 2px solid var(--artifact-aqua);
  outline-offset: 2px;
}

/* ── Responsive ──────────────────────────── */

/* --- Desktop narrow (≤1100px) --- */
@media screen and (max-width: 1100px) {
  .ratings-page { padding-top: 72px; }
}

/* --- Tablet landscape (≤1024px) --- */
@media screen and (max-width: 1024px) {
  .ratings-layout {
    grid-template-columns: 190px minmax(0, 1fr);
    gap: 28px;
  }
}

/* --- Tablet / Fold open (≤768px) — sidebar → pills --- */
@media screen and (max-width: 768px) {
  .ratings-hero { padding: 36px 0 28px; }
  .ratings-hero h1 { font-size: 28px; }

  .ratings-layout {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  /* Sidebar → horizontal scrollable pills */
  .ratings-sidebar {
    position: static;
  }
  .ratings-tree {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 8px;
    gap: 6px;
    border-radius: 8px;
    align-items: center;
  }
  .ratings-tree::-webkit-scrollbar { display: none; }
  .tree-group {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    border-top: none;
  }
  .tree-group + .tree-group {
    padding-left: 8px;
    margin-left: 2px;
    border-left: 1px solid rgba(255,255,255,0.1);
    border-top: none;
  }
  .tree-group-title {
    padding: 0 6px;
    font-size: 10px;
    white-space: nowrap;
    line-height: 1;
  }
  .tree-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-height: 44px;
    padding: 0 14px;
    font-size: 12px;
    white-space: nowrap;
    border-radius: 22px;
    background: rgba(255,255,255,0.06);
    text-align: center;
  }
  .tree-item::before { display: none; }
  .tree-item.active {
    background: rgba(110,55,250,0.25);
    border-radius: 22px;
  }
  .tree-item:hover {
    background: rgba(255,255,255,0.1);
  }

  /* Filter bar → 2-column grid */
  .ratings-filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    padding: 16px 18px;
  }
  .filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
  }
  .filter-group label {
    min-width: 32px;
    flex-shrink: 0;
  }
  .filter-group .nk-cal-wrap,
  .filter-group .market-toggle,
  .filter-group .nk-select {
    flex: 1;
    min-width: 0;
  }
  .nk-select {
    font-size: 12px;
    height: 44px;
    line-height: 44px;
    padding: 0 30px 0 12px;
  }
  .market-btn {
    padding: 8px 14px;
    min-height: 44px;
  }

  /* Table: sticky rank column + smaller font */
  .ratings-table {
    font-size: 13px;
    min-width: 420px;
  }
  .ratings-table th {
    font-size: 11px;
    padding: 12px 14px;
  }
  .ratings-table td {
    padding: 11px 14px;
  }
  .ratings-table th.col-rank,
  .ratings-table td.col-rank {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--artifact-navy);
    width: 52px;
  }
  .ratings-table thead th.col-rank {
    z-index: 3;
    background: #0a2d4d;
  }
  .ratings-table tbody tr:hover td.col-rank {
    background: #0b3050;
  }
  .ratings-table th.col-channel,
  .ratings-table td.col-channel {
    width: 100px;
  }
  .ratings-table th.col-rating,
  .ratings-table td.col-rating {
    width: 100px;
  }

  /* Footnote */
  .ratings-footnote {
    font-size: 11px;
    word-break: keep-all;
    overflow-wrap: break-word;
  }
}

/* --- Filter stacking (≤650px) --- */
@media screen and (max-width: 650px) {
  .ratings-page { padding-top: 66px; }
  .ratings-hero { padding: 28px 0 20px; }
  .ratings-hero h1 { font-size: 24px; }
  .ratings-hero .ratings-subtitle {
    font-size: 13px;
  }

  /* Filter bar → single column */
  .ratings-filters {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 14px 16px;
  }
  .filter-group {
    justify-content: space-between;
  }
  .filter-group .nk-cal-wrap {
    flex: 1;
  }
  .market-toggle {
    flex: 1;
  }
  .market-btn {
    flex: 1;
    text-align: center;
  }
  .nk-select {
    flex: 1;
    min-width: 0;
  }

  /* Table tighter */
  .ratings-table th,
  .ratings-table td {
    padding: 10px 10px;
    font-size: 13px;
  }
  .ratings-table th {
    font-size: 11px;
  }
  .ratings-table th.col-rank,
  .ratings-table td.col-rank {
    width: 46px;
    padding: 10px 6px;
  }
  .ratings-table th.col-channel,
  .ratings-table td.col-channel {
    width: 80px;
  }
  .ratings-table th.col-rating,
  .ratings-table td.col-rating {
    width: 80px;
    padding-right: 12px;
  }

  /* Load-more full-width */
  .loadmore-btn {
    width: 100%;
    padding: 14px 20px;
  }

  .ratings-footnote {
    font-size: 11px;
  }
}

/* --- Standard mobile (≤430px) --- */
@media screen and (max-width: 430px) {
  .ratings-hero h1 { font-size: 22px; }

  .tree-item {
    padding: 0 10px;
    font-size: 11px;
    min-height: 40px;
  }
  .tree-group-title {
    font-size: 9px;
    padding: 0 4px;
  }

  .ratings-table {
    min-width: 380px;
  }
  .rank-num {
    width: 24px;
    height: 24px;
    font-size: 11px;
    border-radius: 4px;
  }
}

/* --- Small mobile (≤360px) --- */
@media screen and (max-width: 360px) {
  .ratings-hero { padding: 22px 0 16px; }
  .ratings-hero h1 { font-size: 20px; }
  .ratings-breadcrumb { font-size: 11px; }

  .ratings-tree {
    padding: 6px;
    gap: 4px;
  }
  .tree-item {
    padding: 0 8px;
    min-height: 38px;
    font-size: 11px;
  }

  .ratings-filters {
    padding: 12px;
    gap: 10px;
  }
  .filter-group label {
    font-size: 11px;
  }
  .nk-select {
    font-size: 11px;
    padding: 0 26px 0 10px;
    height: 40px;
    line-height: 40px;
  }
  .market-btn {
    font-size: 11px;
    padding: 6px 10px;
  }

  .ratings-table {
    font-size: 12px;
    min-width: 340px;
  }
  .ratings-table th {
    font-size: 10px;
    padding: 8px 6px;
  }
  .ratings-table td {
    padding: 8px 6px;
  }
}

/* --- Galaxy Fold closed (≤280px) --- */
@media screen and (max-width: 280px) {
  .ratings-page { padding-top: 60px; }
  .ratings-hero { padding: 16px 0 12px; }
  .ratings-hero h1 { font-size: 18px; letter-spacing: -0.03em; }
  .ratings-hero .ratings-subtitle {
    font-size: 12px;
    line-height: 1.5;
  }
  .ratings-breadcrumb {
    font-size: 10px;
    gap: 4px;
  }

  .ratings-layout {
    gap: 14px;
    padding-top: 16px;
  }

  .ratings-tree {
    padding: 4px;
    gap: 3px;
  }
  .tree-group + .tree-group {
    padding-left: 4px;
    margin-left: 1px;
  }
  .tree-group-title {
    font-size: 8px;
    padding: 0 3px;
  }
  .tree-item {
    padding: 0 7px;
    min-height: 36px;
    font-size: 10px;
    border-radius: 18px;
  }

  .ratings-filters {
    padding: 10px;
    gap: 8px;
    border-radius: 6px;
  }
  .filter-group label {
    font-size: 10px;
    min-width: 24px;
  }
  .nk-select {
    font-size: 10px;
    height: 38px;
    line-height: 38px;
    padding: 0 22px 0 8px;
    background-position: right 6px center;
    background-size: 12px;
  }
  .market-btn {
    font-size: 10px;
    padding: 6px 8px;
    min-height: 38px;
  }

  .ratings-table-wrap {
    border-radius: 6px;
  }
  .ratings-table {
    font-size: 11px;
    min-width: 300px;
  }
  .ratings-table th {
    font-size: 9px;
    padding: 7px 4px;
  }
  .ratings-table td {
    padding: 7px 4px;
  }
  .ratings-table th.col-rank,
  .ratings-table td.col-rank {
    width: 36px;
    padding: 7px 2px;
  }
  .rank-num {
    width: 20px;
    height: 20px;
    font-size: 10px;
    border-radius: 3px;
  }

  .ratings-footnote {
    font-size: 10px;
    line-height: 1.6;
  }
  .ratings-loadmore {
    padding: 16px 0;
  }
  .loadmore-btn {
    font-size: 12px;
    padding: 12px 16px;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .ratings-status.is-loading::before {
    animation: none;
  }
  .tree-item,
  .market-btn,
  .loadmore-btn,
  .ratings-table tbody tr {
    transition: none;
  }
}

/* ── Print ── */
@media print {
  .ratings-page {
    background: #fff;
    color: #000;
    padding-top: 0;
  }
  .ratings-hero {
    padding: 20px 0 10px;
    border-bottom-color: #ccc;
  }
  .ratings-hero h1 {
    color: #000;
    font-size: 24px;
  }
  .ratings-hero .ratings-subtitle,
  .ratings-breadcrumb,
  .ratings-breadcrumb a {
    color: #555;
  }
  .ratings-sidebar {
    display: none;
  }
  .ratings-layout {
    display: block;
  }
  .ratings-filters {
    background: none;
    border-color: #ccc;
  }
  .filter-group label,
  .market-btn,
  .nk-select {
    color: #000;
    border-color: #ccc;
    background: #fff;
  }
  .ratings-table-wrap {
    border-color: #ccc;
    overflow: visible;
  }
  .ratings-table {
    min-width: 0;
    color: #000;
  }
  .ratings-table th {
    color: #333;
    border-bottom-color: #ccc;
    background: #f5f5f5;
  }
  .ratings-table td {
    color: #000;
  }
  .ratings-table tbody tr {
    border-bottom-color: #eee;
  }
  .ratings-table th.col-rank,
  .ratings-table td.col-rank {
    position: static;
    background: transparent;
  }
  .rank-top3 {
    background: #333;
    color: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .ratings-loadmore {
    display: none;
  }
  .ratings-footnote {
    color: #555;
  }
}
