/* ============================================================
   TEME
   ============================================================ */
:root {
  --bg: #0f1117;
  --bg2: #1a1d2e;
  --bg3: #1e2235;
  --border: rgba(255,255,255,.08);
  --border2: rgba(255,255,255,.13);
  --text: #e8e8f0;
  --c-muted: #7a7a9a;
  --c-hint: #4a4a6a;
  --teal: #1D9E75;
  --teal-light: rgba(29,158,117,.15);
  --blue: #378ADD;
  --blue-light: rgba(55,138,221,.15);
  --amber: #EF9F27;
  --red: #D85A30;
  --purple: #7F77DD;
  --sidebar-w: 220px;
  --radius: 10px;
  --radius-sm: 6px;
}


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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
  transition: background .2s, color .2s;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform .2s, background .2s;
}
.sidebar-head { padding: 20px 18px 16px; border-bottom: 1px solid var(--border); }
.logo { display: flex; align-items: center; gap: 9px; }
.logo-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--teal); }
.logo-text { font-size: 16px; font-weight: 600; color: var(--text); }

.nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--c-muted); font-size: 14px; cursor: pointer;
  text-decoration: none; transition: all .15s; margin-bottom: 2px;
  user-select: none;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--teal-light); color: var(--teal); }
.nav-item svg { flex-shrink: 0; }

.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }
.user-info { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--teal-light); color: var(--teal);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 11px; color: var(--c-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout-btn {
  width: 100%; padding: 7px; border-radius: var(--radius-sm);
  border: 1px solid var(--border2); background: transparent;
  color: var(--c-muted); font-size: 13px; cursor: pointer; transition: all .15s;
}
.logout-btn:hover { background: rgba(216,90,48,.1); color: var(--red); border-color: var(--red); }

/* ============================================================
   MAIN
   ============================================================ */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; border-bottom: 1px solid var(--border);
  background: var(--bg2); position: sticky; top: 0; z-index: 50;
  flex-wrap: wrap; gap: 10px; transition: background .2s;
}
.topbar-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.menu-btn { display: none; background: none; border: none; color: var(--text); font-size: 18px; cursor: pointer; padding: 4px; }

.site-select, .period-select, .kw-search {
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text);
  padding: 7px 12px; font-size: 14px; transition: background .2s, color .2s;
}
.site-select { min-width: 200px; max-width: 300px; }
.period-select { min-width: 130px; }
.kw-search { width: 100%; }
.kw-search:focus, .site-select:focus, .period-select:focus {
  outline: none; border-color: var(--teal); box-shadow: 0 0 0 2px rgba(29,158,117,.2);
}

.refresh-btn, .theme-btn {
  background: none; border: 1px solid var(--border2); border-radius: var(--radius-sm);
  color: var(--c-muted); padding: 7px 12px; font-size: 13px; cursor: pointer; transition: all .15s;
}
.refresh-btn:hover, .theme-btn:hover { border-color: var(--teal); color: var(--teal); }
.theme-btn { font-size: 16px; padding: 6px 10px; }

/* ============================================================
   LOADING
   ============================================================ */
.loading-overlay {
  display: none; position: fixed; inset: 0; background: rgba(15,17,23,.5);
  align-items: center; justify-content: center; flex-direction: column;
  z-index: 200; gap: 16px;
}

.loading-overlay.show { display: flex; }
.loading-spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--teal); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--c-muted); font-size: 14px; }

/* ============================================================
   TABS
   ============================================================ */
.tab-content { display: none; padding: 24px; }
.tab-content.active { display: block; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px; margin-bottom: 16px;
  transition: background .2s;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.card-title { font-size: 15px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }

/* ============================================================
   METRICS
   ============================================================ */
.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.metric-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  transition: background .2s;
}
.metric-label { font-size: 12px; color: var(--c-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.metric-val { font-size: 28px; font-weight: 700; color: var(--text); }
.metric-chg { font-size: 13px; margin-top: 4px; }
.up { color: var(--teal); }
.down { color: var(--red); }
.neu { color: var(--c-muted); }

/* ============================================================
   CHARTS
   ============================================================ */
.charts-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 16px; }
.chart-wrap { position: relative; height: 240px; }

.chart-legend {
  display: flex; gap: 16px; flex-wrap: wrap;
  margin-bottom: 12px; font-size: 13px; color: var(--c-muted);
}
.chart-legend-item { display: flex; align-items: center; gap: 6px; }
.chart-legend-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.data-table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--c-muted);
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: .03em; white-space: nowrap;
}
.data-table td { padding: 11px 12px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg3); }

.empty-msg { color: var(--c-muted); font-size: 14px; padding: 24px 0; text-align: center; }

/* ============================================================
   BADGES
   ============================================================ */
.badge-gsc { font-size: 11px; padding: 2px 8px; border-radius: var(--radius-sm); background: var(--teal-light); color: var(--teal); font-weight: 500; }
.badge-dfs { font-size: 11px; padding: 2px 8px; border-radius: var(--radius-sm); background: var(--blue-light); color: var(--blue); font-weight: 500; }
.badge-pos {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 24px; border-radius: 5px; font-size: 13px; font-weight: 600; padding: 0 7px;
}
.pos-top3 { background: rgba(29,158,117,.15); color: var(--teal); }
.pos-top10 { background: rgba(55,138,221,.15); color: var(--blue); }
.pos-top20 { background: rgba(239,159,39,.15); color: var(--amber); }
.pos-low { background: rgba(122,122,154,.1); color: var(--c-muted); }

.kd-badge { font-size: 12px; padding: 3px 8px; border-radius: var(--radius-sm); }
.kd-easy { background: rgba(29,158,117,.15); color: var(--teal); }
.kd-med { background: rgba(239,159,39,.15); color: var(--amber); }
.kd-hard { background: rgba(216,90,48,.15); color: var(--red); }
.df-badge { background: rgba(29,158,117,.1); color: var(--teal); font-size: 12px; padding: 3px 8px; border-radius: 4px; }
.nf-badge { background: rgba(122,122,154,.1); color: var(--c-muted); font-size: 12px; padding: 3px 8px; border-radius: 4px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary {
  background: var(--teal); color: white; border: none;
  padding: 8px 18px; border-radius: var(--radius-sm); font-size: 14px;
  font-weight: 500; cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn-primary:hover { background: #0F6E56; }
.btn-outline {
  background: none; color: var(--c-muted); border: 1px solid var(--border2);
  padding: 8px 16px; border-radius: var(--radius-sm); font-size: 14px; cursor: pointer; transition: all .15s;
}
.btn-outline:hover { border-color: var(--teal); color: var(--teal); }

.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-btn {
  font-size: 13px; padding: 5px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: transparent; color: var(--c-muted); cursor: pointer; transition: all .15s;
}
.filter-btn:hover { border-color: var(--border2); color: var(--text); }
.filter-btn.active { background: var(--teal-light); border-color: var(--teal); color: var(--teal); }

/* ============================================================
   BARS
   ============================================================ */
.bar-wrap { display: flex; align-items: center; gap: 8px; }
.bar-bg { flex: 1; height: 5px; background: var(--bg3); border-radius: 3px; min-width: 50px; }
.bar-fill { height: 5px; border-radius: 3px; background: var(--blue); }
.bar-fill.teal { background: var(--teal); }
.bar-fill.purple { background: var(--purple); }
.bar-num { font-size: 13px; color: var(--c-muted); white-space: nowrap; }

/* ============================================================
   REPORTS
   ============================================================ */
.reports-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.report-form { display: flex; flex-direction: column; gap: 8px; }
.report-form label { font-size: 13px; color: var(--c-muted); margin-top: 4px; }
.report-form input[type=checkbox] { margin-right: 6px; }
.email-status { font-size: 13px; padding: 8px 12px; border-radius: var(--radius-sm); margin-top: 8px; display: none; }
.email-status.ok { display: block; background: var(--teal-light); color: var(--teal); }
.email-status.err { display: block; background: rgba(216,90,48,.15); color: var(--red); }

/* ============================================================
   KW IDEA
   ============================================================ */
.kw-idea-input { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.kw-idea-input .kw-search { flex: 1; min-width: 200px; }
.kw-search-wrap { margin-bottom: 12px; }

/* ============================================================
   COMP
   ============================================================ */
.comp-input-row { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.comp-input-row .kw-search { flex: 1; min-width: 150px; }

/* ============================================================
   TREND
   ============================================================ */
.trend { display: inline-flex; align-items: center; gap: 3px; font-size: 13px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-btn { display: block; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .reports-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .tab-content { padding: 16px; }
  .metric-val { font-size: 22px; }
}
