﻿/* ==========================================================
   Keywords Tab — Redesigned for fit & clarity
   ========================================================== */

#tab-keywords{
  --kw-bg: #F6F7F9;
  --kw-card: #ffffff;
  --kw-border: rgba(0,0,0,0.06);
  --kw-shadow: 0 8px 24px rgba(0,0,0,0.06);
  --kw-radius: 18px;
  --kw-text: #111827;
  --kw-muted: #6b7280;
  --kw-up: #16a34a;
  --kw-down: #dc2626;
  /* Override rankflow blue so .rf-metric etc have no blue bg */
  --rf-primary: transparent;
  --rf-primary-light: transparent;

  background: var(--kw-bg);
  padding: 24px 0 40px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* Page header */
#tab-keywords .kw-page-header{
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--kw-border);
  flex-wrap: wrap;
}
#tab-keywords .kw-page-header-title{
  font-size: 20px;
  font-weight: 600;
  color: var(--kw-text);
  margin: 0;
  letter-spacing: -0.02em;
}
#tab-keywords .kw-page-header-sub{
  font-size: 13px;
  color: var(--kw-muted);
  margin: 4px 0 0 0;
  line-height: 1.5;
  max-width: 560px;
}

/* Cards */
#tab-keywords .card{
  background: var(--kw-card);
  border: 1px solid var(--kw-border);
  border-radius: var(--kw-radius);
  box-shadow: var(--kw-shadow);
  padding: 18px 20px;
  position: relative;
  overflow: visible;
  margin-right: 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
#tab-keywords .card::before{ display: none; }

/* Card header */
#tab-keywords .kw-card-header{
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
#tab-keywords .kw-card-title{
  font-size: 16px;
  font-weight: 600;
  color: var(--kw-text);
  margin: 0;
  letter-spacing: -0.02em;
}

/* Filter bar - compact, wraps cleanly */
#tab-keywords .kw-filters{
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 12px 16px;
  background: #f9fafb;
  border: 1px solid var(--kw-border);
  border-radius: 12px;
  margin-bottom: 16px;
  font-size: 12px;
}
#tab-keywords .kw-filters .input,
#tab-keywords .kw-filters select{
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #fff;
  font-size: 12px;
  min-height: 32px;
  outline: none;
  transition: border-color .15s ease;
}
#tab-keywords .kw-filters .input{ 
  min-width: 0;
  flex: 1 1 140px;
  max-width: 200px;
}
#tab-keywords .kw-filters .kw-input-sm{
  flex: 0 0 auto;
  width: 72px;
  max-width: 72px;
}
#tab-keywords .kw-filters select{ 
  min-width: 0;
  max-width: 120px;
}
#tab-keywords .kw-filters .input:focus,
#tab-keywords .kw-filters select:focus{
  border-color: #94a3b8;
}
#tab-keywords .kw-filters-label{
  color: var(--kw-muted);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
#tab-keywords .kw-filters .divider{
  width: 1px;
  height: 18px;
  background: #e5e7eb;
  margin: 0 2px;
  align-self: center;
}

/* Controls (pagination, alert actions) */
#tab-keywords .controls{
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 14px;
  padding-top: 4px;
}
#tab-keywords .card .kw-filters + .controls{ margin-top: 14px; }

/* Alert card (cache not found) */
#tab-keywords #kwAlert{
  border-radius: var(--kw-radius);
  padding: 18px 20px;
}

#tab-keywords .input,
#tab-keywords select{
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 36px;
  font-size: 13px;
  outline: none;
}
#tab-keywords .input:focus,
#tab-keywords select:focus{ border-color: #94a3b8; }

#tab-keywords .btn{
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  background: #D8B15A !important;
  border: none !important;
  color: #1a1a1a !important;
  box-shadow: 0 2px 8px rgba(216, 177, 90, 0.3) !important;
  transition: background 0.2s ease !important;
}
#tab-keywords .btn:hover{
  background: #C49A4A !important;
  color: #1a1a1a !important;
}
#tab-keywords .btn.primary{
  background: #D8B15A !important;
  border: none !important;
  color: #1a1a1a !important;
  font-weight: 600 !important;
}

#tab-keywords .divider{
  width: 1px;
  height: 24px;
  background: #e5e7eb;
  margin: 0 8px;
}

/* Typography */
#tab-keywords .muted{ color: var(--kw-muted) !important; }
#tab-keywords .title{
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 600;
  color: var(--kw-text);
  letter-spacing: -0.02em;
}

/* Table: contained, no page scroll - table scrolls inside wrapper if needed */
#tab-keywords .mirolabs-table-wrap{
  margin-top: 0;
  border-radius: 12px;
  overflow-x: auto;
  overflow-y: visible;
  border: 1px solid var(--kw-border);
  background: var(--kw-card);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}
#tab-keywords .mirolabs-table-wrap::-webkit-scrollbar{
  height: 8px;
}
#tab-keywords .mirolabs-table-wrap::-webkit-scrollbar-track{
  background: #f1f5f9;
  border-radius: 4px;
}
#tab-keywords .mirolabs-table-wrap::-webkit-scrollbar-thumb{
  background: #cbd5e1;
  border-radius: 4px;
}
#tab-keywords .mirolabs-table-wrap::-webkit-scrollbar-thumb:hover{
  background: #94a3b8;
}
  
/* Table - flexible layout, min 720px to fit typical admin viewports */
#tab-keywords .mirolabs-table-wrap table{
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: transparent;
  table-layout: fixed;
}
  
#tab-keywords thead{
  background: #f9fafb;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--kw-border);
}
#tab-keywords th{
  padding: 10px 8px;
  font-size: 11px;
  font-weight: 600;
  color: #374151;
  text-align: left;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  text-overflow: ellipsis;
  background: #f9fafb !important;
}
  
/* Column widths - compact, fit ~960px */
#tab-keywords th:nth-child(1),
#tab-keywords td:nth-child(1){
  width: 14%;
  min-width: 100px;
}
#tab-keywords td:nth-child(1){
  white-space: normal !important;
  word-break: break-word;
}

#tab-keywords th:nth-child(2),
#tab-keywords td:nth-child(2){
  width: 9%;
  min-width: 70px;
}
#tab-keywords th:nth-child(2) .kw-resizer{ display: none; }
#tab-keywords th:nth-child(2),
#tab-keywords td:nth-child(2){
  white-space: normal !important;
  word-break: break-word;
}

#tab-keywords th:nth-child(3),
#tab-keywords td:nth-child(3){
  width: 18%;
  min-width: 120px;
}
#tab-keywords th:nth-child(3) .kw-resizer{ display: none; }
#tab-keywords td:nth-child(3) .mirolabs-page-cell{
  max-width: 100%;
}
#tab-keywords td:nth-child(3) .mirolabs-page-cell a{
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  display: block;
  max-width: 100%;
}

/* Numeric columns */
#tab-keywords th:nth-child(4),
#tab-keywords td:nth-child(4){ width: 7%; min-width: 56px; }
#tab-keywords th:nth-child(5),
#tab-keywords td:nth-child(5){ width: 7%; min-width: 56px; }
#tab-keywords th:nth-child(6),
#tab-keywords td:nth-child(6){ width: 6%; min-width: 50px; }
#tab-keywords th:nth-child(7),
#tab-keywords td:nth-child(7){ width: 6%; min-width: 50px; }
#tab-keywords th:nth-child(8),
#tab-keywords td:nth-child(8){ width: 5%; min-width: 44px; text-align: center; }
#tab-keywords th:nth-child(9),
#tab-keywords td:nth-child(9){ width: 5%; min-width: 44px; text-align: center; }

#tab-keywords th:nth-child(10),
#tab-keywords td:nth-child(10){
  width: 15%;
  min-width: 130px;
}
#tab-keywords td.kwTrendCell{
  overflow: visible;
}
#tab-keywords th:nth-child(10) .kw-resizer{ display: none; }

#tab-keywords th:nth-child(11),
#tab-keywords td:nth-child(11){
  width: 9%;
  min-width: 72px;
  padding-right: 12px !important;
}
  
#tab-keywords td{
  padding: 10px 8px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
  font-size: 12px;
  color: var(--kw-text);
}
#tab-keywords tbody tr{ transition: background .15s ease; }
#tab-keywords tbody tr:hover td{ background: #f9fafb; }
  
  #tab-keywords .kw-q{
    font-weight: 500;
    letter-spacing: .01em;
  }
  
#tab-keywords .badge{
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  color: #374151;
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 500;
  font-size: 11px;
}
#tab-keywords .mirolabs-delta{
  margin-top: 6px;
  font-size: 11px;
  font-weight: 500;
}
#tab-keywords .mirolabs-delta-up{ color: var(--kw-up) !important; }
#tab-keywords .mirolabs-delta-down{ color: var(--kw-down) !important; }
#tab-keywords .mirolabs-delta-zero{ color: #94a3b8; }
  
  /* Spark title */
  #tab-keywords .rf-trend-title{
    font-size: 11px;
    font-weight: 500;
    color: #334155;
    margin-bottom: 7px;
    opacity:.9;
  }
  
/* Trend cell wrapper - sparkline on top, compact details below */
#tab-keywords .rf-trend-cell-wrapper{
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
  width: 100%;
}

#tab-keywords .rf-spark-wrap{
  position: relative;
  width: 130px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #f9fafb;
  border: 1px solid var(--kw-border);
  overflow: visible;
}
#tab-keywords .rf-spark{
  width: 130px;
  height: 36px;
  display: block;
  overflow: visible;
}

/* Sparkline path - gray, no gradient fill (removed underline) */
#tab-keywords .rf-spark path{
  stroke-dasharray: 600;
  stroke-dashoffset: 600;
  animation: rfDraw .85s ease-out forwards;
  stroke: #6b7280 !important;
  stroke-width: 2;
  fill: none;
}
#tab-keywords .rf-spark-wrap:hover .rf-spark path{
  stroke: #374151 !important;
}

/* Spark dot - subtle gray */
#tab-keywords .rf-spark-dot{
  fill: #6b7280 !important;
}
#tab-keywords .rf-spark-wrap:hover .rf-spark-dot{
  fill: #374151 !important;
  opacity: 0.8 !important;
}

/* Trend details - compact, under sparkline */
#tab-keywords .rf-trend-details{
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  width: 100%;
  padding-top: 0;
  margin-top: 0;
}
#tab-keywords .rf-metric{
  font-size: 10px;
  color: #9ca3af;
  white-space: nowrap;
  margin: 0;
  background: none !important;
  padding: 0 !important;
  box-shadow: none !important;
}
#tab-keywords .rf-trend-details{
  background: none !important;
}
@keyframes rfDraw{
  from{ stroke-dashoffset: 600; opacity: .25; }
  to  { stroke-dashoffset: 0;   opacity: 1; }
}
/* Hover dot - subtle */
#tab-keywords .rf-dot{
  fill: #6b7280;
  stroke: #fff;
  stroke-width: 1.5;
  opacity: 0;
  transition: opacity .15s ease;
}
#tab-keywords .rf-spark-wrap:hover .rf-dot{
  opacity: 1;
}

/* Trend pill - compact */
#tab-keywords .rf-trend{
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 500;
  background: #f9fafb;
  border: 1px solid var(--kw-border);
  width: fit-content;
  cursor: default;
  outline: none;
  user-select: none;
}
#tab-keywords .rf-trend:focus,
#tab-keywords .rf-trend:active,
#tab-keywords .rf-trend:focus-visible{
  outline: none !important;
  box-shadow: none !important;
  border-color: var(--kw-border) !important;
}
#tab-keywords .rf-trend.rf-up{
  color: #047857;
  background: #dcfce7;
  border-color: #bbf7d0;
}
#tab-keywords .rf-trend.rf-down{
  color: #b91c1c;
  background: #fee2e2;
  border-color: #fecaca;
}
#tab-keywords .rf-trend.rf-flat{
  color: #475569;
  background: #f3f4f6;
  border-color: #e5e7eb;
}
#tab-keywords .rf-tip{
  position: absolute;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.25;
  background: #fff;
  color: var(--kw-text);
  border-radius: 10px;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -120%);
  transition: opacity 0.12s ease;
  z-index: 30;
  white-space: nowrap;
  border: 1px solid var(--kw-border);
  box-shadow: var(--kw-shadow);
}
  
  #tab-keywords .rf-tip strong{
    display:block;
    font-size: 12px;
    margin-bottom: 3px;
    color: #111827;
    font-weight: 500;
  }
  
  /* Tiny button */
  #tab-keywords .btn.tiny{
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
  }
  
  /* Resizable columns (Excel-like) */
  #tab-keywords .kw-resizer{
    position:absolute; top:0; right:-3px;
    width:6px; height:100%;
    cursor: col-resize;
    user-select:none;
    z-index: 15;
  }
  #tab-keywords .kw-resizer::before{
    content:"";
    position:absolute;
    top:10%; bottom:10%;
    left:50%;
    width:1px;
    transform: translateX(-50%);
    background: rgba(148,163,184,0.8);
    opacity:0;
    transition: opacity .12s ease;
  }
  #tab-keywords th:hover .kw-resizer::before{ opacity:1; }
#tab-keywords th.kw-resizing,
#tab-keywords th.kw-resizing *{ cursor: col-resize !important; }

/* Full width: no squeeze (match Overview) */
.mirolabs-ana-wrap #tab-keywords,
#tab-keywords{
  width: 100% !important;
  max-width: none !important;
}
.mirolabs-ana-wrap #tab-keywords .grid{ width: 100% !important; max-width: none !important; }
.mirolabs-ana-wrap #tab-keywords .card.full{ grid-column: 1 / -1 !important; width: 100% !important; }

/* Responsive */
@media (max-width: 1024px){
  #tab-keywords .kw-filters{ padding: 10px 14px; gap: 6px 10px; }
  #tab-keywords .kw-filters .input{ max-width: 160px; }
  #tab-keywords .mirolabs-table-wrap table{ min-width: 720px; }
}
@media (max-width: 768px){
  #tab-keywords{ padding: 16px 0 32px; }
  #tab-keywords .kw-page-header{ margin-bottom: 16px; padding-bottom: 14px; }
  #tab-keywords .card{ padding: 14px 16px; }
  #tab-keywords .kw-filters-label{ display: none; }
  #tab-keywords .kw-filters .input[placeholder*="Search"]{ max-width: 100%; flex: 1 1 100%; }
  #tab-keywords .mirolabs-table-wrap{ border-radius: 10px; }
}
