/*
 * App shell: layout, topbar, sidebar, and shared UI components.
 * Loaded alongside application.css (tokens/reset) and landing.css.
 * Scoped under body.app-layout so landing page font-size is unaffected.
 */

body.app-layout {
  font-size: 14px;
}

/* ─── SHELL LAYOUT ──────────────────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 56px 1fr;
  min-height: 100vh;
}

/* ─── TOPBAR ─────────────────────────────────────────────────────────────────── */

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.02em;
  color: var(--t1);
  text-decoration: none;
}

.logo:hover {
  text-decoration: none;
}

.logo-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-icon svg {
  width: 16px;
  height: 16px;
}

.logo-suffix {
  color: var(--t2);
  font-weight: 400;
  margin-left: 2px;
  font-size: 13px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.plan-pill {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--accent-s);
  color: var(--accent);
  font-weight: 500;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}

/* ─── SIDEBAR ────────────────────────────────────────────────────────────────── */

.sidebar {
  grid-row: 2;
  border-right: 1px solid var(--border);
  background: var(--card);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--t3);
  padding: 8px 28px 6px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin: 0 8px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--t2);
  transition: all 0.15s;
  position: relative;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--surface);
  color: var(--t1);
  text-decoration: none;
}

.nav-item.active {
  background: var(--accent-s);
  color: var(--accent);
  font-weight: 500;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.nav-icon {
  width: 18px;
  height: 18px;
  opacity: 0.5;
  flex-shrink: 0;
}

.nav-item.active .nav-icon {
  opacity: 1;
}

.nav-badge {
  margin-left: auto;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--t3);
  font-weight: 500;
  font-family: var(--mono);
}

.nav-badge.live {
  background: var(--red-s);
  color: var(--red);
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--border);
}

.sidebar-footer-text {
  font-size: 11px;
  color: var(--t3);
  line-height: 1.7;
}

.sidebar-footer-text strong {
  color: var(--t2);
}

/* ─── MAIN CONTENT ───────────────────────────────────────────────────────────── */

.main {
  grid-row: 2;
  padding: 24px 28px;
  overflow-y: auto;
  background: var(--bg);
}

.screen-header {
  margin-bottom: 24px;
}

.screen-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}

.screen-header p {
  font-size: 13px;
  color: var(--t2);
}

/* ─── ANIMATION ──────────────────────────────────────────────────────────────── */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-up {
  animation: fadeUp 0.3s ease;
}

/* ─── CARD ───────────────────────────────────────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--rl);
  padding: 20px;
  transition: border-color 0.2s;
}

.card-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--t2);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--t2);
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-3);
}

.card-table {
  padding-bottom: 0;
}

.card-table .table-wrap {
  margin: var(--space-4) -20px 0;
  border-top: 1px solid var(--border);
}

/* ─── KPI ────────────────────────────────────────────────────────────────────── */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-label {
  font-size: 12px;
  color: var(--t2);
  font-weight: 500;
  margin-bottom: 10px;
}

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-family: var(--mono);
}

.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  margin-top: 8px;
}

.kpi-delta.up   { background: var(--green-s); color: var(--green); }
.kpi-delta.down { background: var(--red-s);   color: var(--red);   }

/* ─── PROFILE BANNER ─────────────────────────────────────────────────────────── */

.profile-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--input);
  border-radius: 10px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.profile-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.profile-name {
  font-size: 12px;
  font-weight: 600;
}

.profile-note {
  font-size: 9px;
  color: var(--t3);
  font-weight: 400;
  margin-left: 6px;
}

.profile-stats {
  display: flex;
  gap: 16px;
  margin-top: 3px;
}

.profile-stats span  { font-size: 11px; color: var(--t2); }
.profile-stats strong { color: var(--t4); font-family: var(--mono); }

/* ─── GRIDS / LAYOUT HELPERS ─────────────────────────────────────────────────── */

.grid-2   { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.grid-4   { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
}

.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }

.chart-container {
  position: relative;
  height: 200px;
  margin-top: var(--space-2);
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ─── DATA TABLE (in-card) ───────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead {
  background: var(--surface);
}

.data-table th {
  padding: 10px 16px;
  text-align: left;
  font-weight: 500;
  color: var(--t3);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover td {
  background: var(--card-hover);
}

.data-table .col-num,
.data-table th.col-num,
.data-table td.col-num {
  text-align: right;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--t4);
}

.data-table th.col-action,
.data-table td.col-action {
  text-align: right;
  width: 88px;
}

.kw-term {
  font-weight: 500;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.intent-tag {
  display: inline-flex;
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface);
  color: var(--t2);
  border: 1px solid var(--border);
  text-transform: capitalize;
  white-space: nowrap;
}

.data-table td.col-num .diff-inline {
  justify-content: flex-end;
}

.data-table td.col-num .opp-score {
  display: block;
}

.opp-score {
  display: inline-block;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  min-width: 2ch;
  text-align: right;
}

/* ─── FILTER BAR ─────────────────────────────────────────────────────────────── */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.fbtn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--t2);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
  font-weight: 500;
}

.fbtn:hover           { border-color: var(--border-h); color: var(--t1); }
.fbtn.active          { background: var(--accent-s); border-color: var(--accent); color: var(--accent); }
.fbtn.yt.active       { background: var(--yt-s); border-color: var(--yt); color: var(--yt); }
.fbtn.tt.active       { background: var(--tt-s); border-color: var(--tt); color: var(--tt); }

/* ─── SEARCH / SERP INPUTS ───────────────────────────────────────────────────── */

.search-wrap {
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--t3);
  pointer-events: none;
}

.search-input {
  padding: 7px 14px 7px 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input);
  color: var(--t1);
  font-size: 13px;
  font-family: var(--font);
  width: 220px;
  outline: none;
}

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

.serp-search-row {
  display: flex;
  align-items: stretch;
  gap: 12px;
}

.kw-seed-form .serp-search-row,
.serp-search-form .serp-search-row {
  flex-wrap: wrap;
}

@media (min-width: 640px) {
  .kw-seed-form .serp-search-row,
  .serp-search-form .serp-search-row {
    flex-wrap: nowrap;
  }
}

/* Shared text inputs + buttons (app screens) */
.text-input,
.serp-search-input,
.serp-input {
  flex: 1;
  min-width: 0;
  padding: 12px 18px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--input);
  color: var(--t1);
  font-size: 15px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.text-input::placeholder,
.serp-search-input::placeholder,
.serp-input::placeholder {
  color: var(--t3);
}

.text-input:focus,
.serp-search-input:focus,
.serp-input:focus {
  border-color: var(--accent);
}

.btn,
.serp-btn {
  padding: 12px 24px;
  border-radius: var(--r);
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  white-space: nowrap;
  transition: opacity 0.15s;
}

.btn:hover,
.serp-btn:hover {
  opacity: 0.88;
}

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

.btn:disabled,
.serp-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Inline action forms (e.g. table row Track buttons) */
td form {
  display: inline;
  margin: 0;
}

.platform-pills {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.platform-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--t2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.platform-pill input[type="radio"] { display: none; }

.platform-pill:hover               { border-color: var(--border-h); color: var(--t1); }
.platform-pill.yt.active           { background: var(--yt-s); border-color: var(--yt); color: var(--yt); }
.platform-pill.tt.active           { background: var(--tt-s); border-color: var(--tt); color: var(--tt); }

.serp-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 64px 24px;
  text-align: center;
  color: var(--t3);
}

.serp-empty svg  { opacity: 0.3; }
.serp-empty p    { font-size: 15px; font-weight: 500; color: var(--t2); }
.serp-empty span { font-size: 13px; max-width: 400px; line-height: 1.6; }

/* ─── TABLE ──────────────────────────────────────────────────────────────────── */

.tw {
  overflow-x: auto;
  border-radius: var(--rl);
  border: 1px solid var(--border);
  background: var(--card);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead { background: var(--surface); }

th {
  padding: 10px 16px;
  text-align: left;
  font-weight: 500;
  color: var(--t3);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td      { background: var(--card-hover); }

/* ─── PLATFORM TAG ───────────────────────────────────────────────────────────── */

.ptag {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
}

.ptag.yt { background: var(--yt-s); color: var(--yt); }
.ptag.tt { background: var(--tt-s); color: var(--tt); }

/* ─── DIFFICULTY SCORE ───────────────────────────────────────────────────────── */

.diff-ring {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 2px 6px 2px 2px;
  border-radius: 8px;
}

.diff-ring:hover { background: rgba(99, 102, 241, 0.08); }

.diff-ring-num {
  position: absolute;
  top: 50%;
  left: 16px;
  transform: translate(-50%, -50%);
  font-size: 9px;
  font-weight: 700;
  font-family: var(--mono);
}

.diff-ring-label { font-size: 11px; font-weight: 600; line-height: 1.2; }
.diff-ring-sub   { font-size: 9px; color: var(--t3); }

/* ─── DIFFICULTY INLINE ──────────────────────────────────────────────────────── */

.diff-inline { display: flex; align-items: center; gap: 5px; }

.diff-bar,
.diff-bar-track {
  width: 28px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
  flex-shrink: 0;
}

.diff-bar-fill {
  height: 100%;
  border-radius: 2px;
}

.diff-num {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
}

/* ─── POSITION / RANK ────────────────────────────────────────────────────────── */

.pos        { font-family: var(--mono); font-weight: 700; font-size: 14px; }
.pos-change { font-size: 11px; font-weight: 700; font-family: var(--mono); margin-left: 6px; }
.pos-change.up   { color: var(--green); }
.pos-change.down { color: var(--red); }
.pos-change.new  { color: var(--accent); }

/* ─── VOLUME BAR ─────────────────────────────────────────────────────────────── */

.vol-wrap { display: flex; align-items: center; gap: 8px; }
.vol-bar  { height: 4px; border-radius: 2px; background: var(--accent); opacity: 0.7; }
.vol-num  { font-family: var(--mono); font-size: 12px; color: var(--t2); }

/* ─── SPARKLINE ──────────────────────────────────────────────────────────────── */

.sparkline { display: block; }

/* ─── CONTENT THUMB ──────────────────────────────────────────────────────────── */

.thumb { display: flex; align-items: center; gap: 8px; }

.thumb-box {
  width: 40px;
  height: 28px;
  border-radius: 4px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.thumb-text {
  font-size: 12px;
  color: var(--t2);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── VELOCITY BADGE ─────────────────────────────────────────────────────────── */

.vel {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--mono);
  padding: 3px 9px;
  border-radius: 12px;
  white-space: nowrap;
}

.vel.hot     { background: var(--red-s);   color: var(--red);   }
.vel.rising  { background: var(--amber-s); color: var(--amber); }
.vel.steady  { background: var(--green-s); color: var(--green); }
.vel.new     { background: var(--accent-s); color: var(--accent); }

/* ─── TRACK BUTTON ───────────────────────────────────────────────────────────── */

.track-btn {
  padding: 5px 14px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  transition: all 0.15s;
}

.track-btn:hover        { background: var(--accent-s); }
.track-btn.tracked      { background: var(--accent-s); }

/* ─── TOGGLE ─────────────────────────────────────────────────────────────────── */

.toggle {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.toggle.on  { background: var(--green); border: 1px solid var(--green); }
.toggle.off { background: var(--surface); border: 1px solid var(--border); }

.toggle::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  transition: left 0.2s;
}

.toggle.on::after  { left: 18px; }
.toggle.off::after { left: 2px; }

/* ─── DIFF BREAKDOWN PANEL ───────────────────────────────────────────────────── */

.diff-panel {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--rl);
  background: var(--card);
  overflow: hidden;
  margin-bottom: 24px;
}

.diff-panel-left {
  width: 280px;
  border-right: 1px solid var(--border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.diff-panel-right { flex: 1; padding: 20px; }

.factor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.factor-card {
  padding: 10px;
  background: var(--input);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.factor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.factor-label  { font-size: 11px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.factor-score  { font-family: var(--mono); font-size: 11px; font-weight: 700; }

.factor-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  margin-bottom: 6px;
  overflow: hidden;
}

.factor-bar-fill { height: 100%; border-radius: 2px; }
.factor-detail   { font-size: 10px; color: var(--t3); line-height: 1.4; }
.factor-verdict  { font-weight: 500; margin-top: 2px; }

/* ─── SERP RESULTS ───────────────────────────────────────────────────────────── */

.serp-result {
  display: flex;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.serp-result:hover        { background: var(--card-hover); }
.serp-result:last-child   { border-bottom: none; }

.serp-pos {
  min-width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 14px;
}

.serp-pos.top { background: var(--accent-s); color: var(--accent); }
.serp-pos.mid { background: var(--surface);  color: var(--t2);     }

.serp-body   { flex: 1; min-width: 0; }
.serp-title  { font-weight: 500; font-size: 14px; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.serp-channel { font-size: 12px; color: var(--t2); margin-bottom: 5px; }
.serp-meta   { display: flex; gap: 16px; font-size: 12px; color: var(--t3); }
.serp-meta span { display: flex; align-items: center; gap: 4px; }

/* ─── KEYWORD CHIPS ──────────────────────────────────────────────────────────── */

.kw-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.kw-chip {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 12px;
  color: var(--t2);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  display: inline-block;
}

.kw-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-s); }

/* ─── TRENDING / MOVERS ──────────────────────────────────────────────────────── */

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

.trend-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.trend-item:hover { background: var(--card-hover); }

.trend-rank     { font-family: var(--mono); font-size: 12px; font-weight: 600; min-width: 22px; color: var(--t3); }
.trend-rank.top { color: var(--accent); }
.trend-kw       { flex: 1; font-size: 13px; font-weight: 500; }
.trend-vol      { font-family: var(--mono); font-size: 12px; color: var(--t2); }

.mover { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-top: 1px solid var(--border); }

.mover-badge {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
}

.mover-badge.up   { background: var(--green-s); color: var(--green); }
.mover-badge.down { background: var(--red-s);   color: var(--red);   }

.mover-info   { flex: 1; }
.mover-kw     { font-weight: 500; font-size: 12px; }
.mover-detail { font-size: 11px; color: var(--t3); }

/* ─── SCROLLBAR ──────────────────────────────────────────────────────────────── */

::-webkit-scrollbar       { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
