:root {
  --bg: #f8f8f6;
  --surface: #ffffff;
  --border: #e8e8e4;
  --text: #1a1a1a;
  --text-sub: #666660;
  --accent: #2d6a4f;
  --up: #1a7f4b;
  --down: #c0392b;
  --new-badge: #e67e22;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.07);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

/* Hero */
.hero {
  background: linear-gradient(135deg, var(--accent) 0%, #1b4332 100%);
  color: #fff;
  padding: 56px 20px;
  text-align: center;
}

.hero h1 {
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  font-weight: 800;
  margin-bottom: 8px;
}

.hero-sub {
  font-size: 1.05rem;
  opacity: 0.85;
  margin-bottom: 12px;
}

.last-updated {
  font-size: 0.85rem;
  opacity: 0.6;
}

/* Intro */
.intro-section {
  margin-top: 32px;
  margin-bottom: 8px;
}

.intro-section h2 {
  font-size: 1.15rem;
  margin-bottom: 10px;
}

.intro-section p {
  color: var(--text-sub);
  font-size: 0.9rem;
  line-height: 1.6;
}

.intro-section p + p {
  margin-top: 16px;
}

.intro-more {
  position: relative;
  max-height: 30px;
  overflow: hidden;
  transition: max-height 0.35s ease-in-out;
  margin-top: 16px;
}

.intro-more > p:first-child {
  margin-top: 0;
}

.intro-more::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(transparent, var(--bg));
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.intro-expanded .intro-more::after {
  opacity: 0;
}

.intro-toggle {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}

.intro-toggle:hover {
  text-decoration: underline;
}

/* Highlights */
.highlights {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 32px;
  margin-bottom: 8px;
}

.highlight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
  overflow: hidden;
}

.highlight-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hl-icon {
  font-size: 0.7rem;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
}

.hl-icon--up { background: #e6f4ed; color: var(--up); }
.hl-icon--down { background: #fde8e8; color: var(--down); }
.hl-icon--climb { background: #e8edf5; color: #3b5998; }

.highlight-list {
  list-style: none;
}

.highlight-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  min-height: 38px;
  box-sizing: border-box;
  border-bottom: 1px solid var(--border);
}

.highlight-list li:last-child {
  border-bottom: none;
}

.hl-medal {
  font-size: 1rem;
  margin-right: 8px;
  flex-shrink: 0;
}

.hl-num {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-sub);
  margin-right: 8px;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.hl-name {
  font-weight: 600;
  font-size: 0.82rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hl-detail {
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  margin-left: 8px;
}

.hl-detail--up { color: var(--up); }
.hl-detail--down { color: var(--down); }
.hl-detail--climb { color: #3b5998; }

/* Comparison toggle */
.comparison-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 4px;
  font-size: 0.9rem;
}

.comparison-bar label {
  color: var(--text-sub);
  font-weight: 500;
  white-space: nowrap;
}

.toggle-group {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 40px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.toggle-btn {
  padding: 8px 20px;
  border: none;
  background: transparent;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-sub);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.toggle-btn:hover {
  color: var(--text);
}

.toggle-btn.active {
  background: var(--accent);
  color: #fff;
}

.toggle-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Table */
.table-wrap {
  margin: 24px 0 40px;
}

.hidden-row {
  display: none;
}

.table-fade {
  position: relative;
}

.table-fade::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: linear-gradient(transparent, var(--bg));
  pointer-events: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

.show-all-btn {
  display: block;
  margin: 16px auto 0;
  padding: 10px 28px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 40px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
}

.show-all-btn:hover {
  background: #245a42;
}

.ranking-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.ranking-table thead th {
  background: #f0efe9;
  text-align: left;
  padding: 12px 16px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-sub);
  font-weight: 600;
}

.ranking-table thead th.col-rank {
  text-align: center;
}
.ranking-table thead th.col-traffic {
  text-align: right;
}

.ranking-table td {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}

.ranking-table tbody tr:hover td {
  background: #fafaf8;
}

.col-rank {
  width: 70px;
  font-weight: 700;
  color: var(--text-sub);
  text-align: center;
  white-space: nowrap;
}
.rank-num {
  display: block;
}
.col-rank .change {
  display: block;
}

.name-row {
  display: flex;
  align-items: center;
  min-width: 0;
}

.col-name a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.col-name a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.col-name .domain {
  display: block;
  font-size: 0.78rem;
  color: var(--text-sub);
  font-weight: 400;
}

.table-badge {
  flex-shrink: 0;
  margin-left: 8px;
  padding: 1px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 40px;
  white-space: nowrap;
}

.table-badge--winner { background: #e6f4ed; color: var(--up); }
.table-badge--loser { background: #fde8e8; color: var(--down); }
.table-badge--climber { background: #e8edf5; color: #3b5998; }

.col-traffic {
  width: 160px;
  color: var(--text-sub);
  font-size: 0.88rem;
  text-align: right;
  white-space: nowrap;
}

.change {
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.change--up { color: var(--up); }
.change--down { color: var(--down); }
.change--same { color: var(--text-sub); }
.change--new { color: var(--new-badge); font-weight: 500; }

/* Traffic cell layout */
.traffic-top {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1px;
}

/* Traffic bottom row */
.traffic-bottom {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1px;
  margin-top: 2px;
}

/* Traffic change value */
.traffic-change-row {
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.traffic-change--up { color: var(--up); }
.traffic-change--down { color: var(--down); }

/* KPI change badge (percent pill) */
.kpi-change {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.6rem;
  font-weight: 600;
  padding: 0.1rem 0.3rem;
  border-radius: 5px;
  margin-right: 3px;
  margin-left: 0;
  white-space: nowrap;
  vertical-align: middle;
}
.kpi-arrow-svg {
  width: 10px;
  height: 10px;
}
.kpi-change.up {
  background: rgba(26, 127, 75, 0.1);
  color: var(--up);
}
.kpi-change.down {
  background: rgba(192, 57, 43, 0.1);
  color: var(--down);
}

.loading {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-sub);
}

/* Signup */
.signup {
  margin-bottom: 56px;
}

.signup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 500px;
  margin: 0 auto;
  text-align: center;
  box-shadow: var(--shadow);
}

.signup-card h2 {
  font-size: 1.2rem;
  margin-bottom: 6px;
}

.signup-card > p {
  color: var(--text-sub);
  margin-bottom: 14px;
  font-size: 0.92rem;
}

.signup-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.signup-form input {
  flex: 1 1 40%;
  min-width: 0;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 40px;
  font-size: 0.95rem;
  outline: none;
}

.signup-form .btn {
  width: 100%;
}

.signup-form input:focus {
  border-color: var(--accent);
}

.btn {
  padding: 10px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 40px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: #245a42;
}

.feedback {
  font-size: 0.88rem;
  margin-top: 8px;
}

.feedback:empty {
  display: none;
}

.feedback--ok { color: var(--up); }
.feedback--err { color: var(--down); }

.signup-note {
  font-size: 0.8rem;
  color: var(--text-sub);
  margin-top: 14px;
  opacity: 0.7;
}

/* Info sections */
.info-section {
  margin-bottom: 32px;
}

.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}

.info-card h2 {
  font-size: 1.15rem;
  margin-bottom: 12px;
}

.info-card h3 {
  font-size: 0.92rem;
  margin-top: 16px;
  margin-bottom: 6px;
}

.info-card p {
  color: var(--text-sub);
  font-size: 0.9rem;
  line-height: 1.6;
}

.info-card p + p {
  margin-top: 8px;
}

.info-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.info-link:hover {
  text-decoration: underline;
}

/* Footer */
.footer {
  text-align: center;
  padding: 28px 20px;
  font-size: 0.82rem;
  color: var(--text-sub);
  border-top: 1px solid var(--border);
}

.footer a {
  color: var(--text-sub);
  text-decoration: none;
  font-weight: 600;
}

.footer a:hover {
  color: var(--text);
}

/* Scroll to top */
.scroll-top {
  position: fixed;
  bottom: calc(25px + env(safe-area-inset-bottom, 0px));
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s, visibility 0.3s, transform 0.3s, background 0.3s;
  transform: translate3d(0, 15px, 0);
  z-index: 110;
}

.scroll-top.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate3d(0, 0, 0);
}

.scroll-top:hover {
  background: #245a42;
}

/* Mobile */
/* Confirmation popup */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.confirm-popup {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.confirm-popup h2 {
  font-size: 1.2rem;
  margin-bottom: 10px;
}

.confirm-popup p {
  color: var(--text-sub);
  font-size: 0.8rem;
  line-height: 1.6;
  margin-bottom: 10px;
}

.confirm-close {
  margin-top: 12px;
}

/* Blog detail popup */
.blog-detail-popup {
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  text-align: left;
  position: relative;
  padding: 36px 40px 32px;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}
.blog-detail-popup::-webkit-scrollbar { display: none; /* Chrome/Safari */ }

.blog-detail-popup h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0;
  padding-right: 32px;
}

.blog-detail-desc {
  font-size: 0.72rem;
  color: var(--text-sub);
  margin-top: 6px;
  line-height: 1.5;
}

.blog-detail-section-desc {
  font-size: 0.72rem;
  color: var(--text-sub);
  margin-top: 10px;
  margin-bottom: 12px;
  line-height: 1.5;
}

.blog-detail-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-sub);
  line-height: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.blog-detail-close:hover {
  color: var(--text);
  background: #eee;
  border-color: var(--text-sub);
}

.blog-detail-section {
  margin-top: 28px;
}

.blog-detail-section h3 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 14px;
  color: var(--text-sub);
}

.blog-detail-chart-wrap {
  height: 260px;
  position: relative;
  background: var(--bg);
  border-radius: 12px;
  padding: 20px 16px 8px;
}

/* Top pages table */
.blog-detail-pages table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.blog-detail-pages th {
  padding: 10px 14px;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 2px solid var(--border);
  text-align: right;
}

.blog-detail-pages .th-page {
  text-align: left;
  width: auto;
}
.blog-detail-pages .th-traffic { width: 70px; }
.blog-detail-pages .th-keyword { width: 130px; }
.blog-detail-pages .th-pos { width: 46px; }

.blog-detail-pages td {
  padding: 9px 14px;
  color: var(--text);
  vertical-align: middle;
  font-size: 0.72rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.blog-detail-pages tbody tr:last-child td {
  border-bottom: none;
}

.blog-detail-pages tbody tr:nth-child(even) {
  background: rgba(0,0,0,0.02);
}

.blog-detail-pages tbody tr:hover {
  background: rgba(0,0,0,0.04);
}

/* Page URL column */
.td-page {
  text-align: left !important;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.td-page a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.72rem;
}

.td-page a:hover {
  text-decoration: underline;
}

/* Numeric columns */
.blog-detail-pages .td-traffic {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.blog-detail-pages .td-keyword {
  color: var(--text-sub);
  white-space: nowrap;
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
}
.blog-detail-pages .td-keyword a {
  color: var(--text-sub);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.blog-detail-pages .td-keyword a:hover {
  color: var(--accent);
  text-decoration: underline;
}
.blog-detail-pages .td-keyword .kw-search-icon {
  flex-shrink: 0;
  font-size: 0.65rem;
  opacity: 0.4;
  text-decoration: none;
}
.blog-detail-pages .td-keyword .kw-search-icon:hover {
  opacity: 1;
}

.external-icon {
  margin-left: 4px;
  font-size: 0.65rem;
  opacity: 0.4;
}
a:hover .external-icon {
  opacity: 1;
}

.search-icon {
  margin-left: 4px;
  font-size: 0.6rem;
  opacity: 0.4;
}
a:hover .search-icon {
  opacity: 1;
}

.blog-detail-pages .td-pos {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Preview wrap with fade for locked state */
.pages-preview-wrap {
  position: relative;
  overflow: hidden;
  pointer-events: none;
}
.pages-preview-wrap::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60%;
  background: linear-gradient(to bottom, transparent 0%, var(--bg) 100%);
  pointer-events: none;
}

/* Password gate for top pages */
.blog-detail-pages-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0 20px;
  gap: 8px;
}

.blog-detail-pages-gate p {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-sub);
  margin: 0;
  text-align: center;
  line-height: 1.5;
}

.blog-detail-pages-gate .gate-ig-link {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}
.blog-detail-pages-gate .gate-ig-link:hover {
  text-decoration: underline;
}

.blog-detail-pages-gate .gate-row {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.blog-detail-pages-gate input {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 16px;
  outline: none;
  width: 150px;
}

.blog-detail-pages-gate input:focus {
  border-color: var(--accent);
}

.blog-detail-pages-gate button {
  padding: 6px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.75rem;
  cursor: pointer;
}

.blog-detail-pages-gate button:hover {
  background: #245a42;
}

.blog-detail-pages-gate .gate-error {
  font-size: 0.78rem;
  color: var(--down);
  font-weight: 500;
  margin: 0;
}
.blog-detail-pages-gate .gate-error:empty {
  display: none;
}

.blog-detail-loading {
  text-align: center;
  padding: 40px;
  color: var(--text-sub);
  font-size: 0.9rem;
}

.blog-detail-error {
  text-align: center;
  padding: 28px;
  color: var(--down);
  font-size: 0.9rem;
}

/* "se mere" button in traffic cell */
.blog-detail-btn {
  display: block;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.68rem;
  padding: 2px 0;
  margin-left: auto;
  opacity: 0.45;
  transition: opacity 0.2s;
  color: var(--text-sub);
  white-space: nowrap;
  text-align: right;
}

.blog-detail-btn:hover {
  opacity: 1;
  color: var(--accent);
}

@media (max-width: 600px) {
  .signup-form { flex-direction: column; }
  .highlights { grid-template-columns: 1fr; }
  .comparison-bar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .scroll-top { width: 40px; height: 40px; font-size: 0.9rem; }
  .blog-detail-popup { max-width: 95vw; padding: 24px 20px; }
  .blog-detail-chart-wrap { height: 200px; padding: 12px 8px 4px; }
  .blog-detail-pages .td-keyword { display: none; }
  .blog-detail-pages .th-keyword { display: none; }
  .blog-detail-pages th,
  .blog-detail-pages td { padding: 7px 10px; }

  /* Remove ALL cell borders and padding on mobile */
  .ranking-table td,
  .ranking-table td.col-rank,
  .ranking-table td.col-name,
  .ranking-table td.col-traffic {
    border: none !important;
    border-top: none !important;
    font-size: 0.75rem;
  }

  /* Card-style ranking rows */
  .ranking-table thead { display: none; }
  .ranking-table tbody tr {
    display: grid;
    grid-template-columns: auto 1fr 100px;
    align-items: start;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    gap: 0;
  }
  .ranking-table tbody tr.hidden-row { display: none; }

  /* Left: rank + change stacked */
  .col-rank {
    grid-column: 1;
    grid-row: 1 / 3;
    width: auto;
    min-width: 32px;
    padding: 0 10px 0 0 !important;
    font-size: 0.72rem;
    font-weight: 700;
    align-self: center;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
  }
  .col-rank .rank-num { font-size: 0.82rem; }
  .col-rank .change {
    font-size: 0.68rem;
    display: block;
  }

  /* Middle: name + domain + badge */
  .col-name {
    grid-column: 2;
    grid-row: 1 / 3;
    padding: 0 8px 0 0 !important;
    min-width: 0;
    align-self: center;
  }

  /* Right: traffic stacked */
  .col-traffic {
    grid-column: 3;
    grid-row: 1 / 3;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 0 !important;
    font-size: 0.75rem;
    gap: 1px;
    align-self: center;
    width: 100px;
    max-width: 100px;
  }
  .col-traffic .traffic-top {
    display: flex;
    align-items: center;
    gap: 2px;
  }
  .col-traffic .traffic-bottom {
    margin-top: 1px;
    gap: 2px;
  }
  .col-traffic .traffic-change-row {
    font-size: 0.75rem;
  }
  .col-traffic .blog-detail-btn {
    font-size: 0.65rem;
    padding: 1px 2px;
  }
  .ranking-table thead .col-traffic { display: none; }
  .ranking-table tbody tr:hover td { background: none; }
  .confirm-overlay { z-index: 999; padding: 0; position: fixed; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; align-items: flex-start; }
  .confirm-popup { border-radius: 0; max-width: 100vw; width: 100vw; min-height: auto; max-height: none; overflow-y: visible; }
  .blog-detail-close { position: sticky; top: 12px; float: right; z-index: 10; margin-right: 4px; }
}
