/* ============================================================
   SpyTools System — sub-app overlay inside Order Manager
   Toggled via body[data-system="spytools"]
   ============================================================ */

/* ---------- Visibility switching ---------- */
body[data-system="commerce"] .sidebar-spy,
body[data-system="commerce"] .main-content-spy {
    display: none !important;
}
body[data-system="spytools"] .sidebar:not(.sidebar-spy),
body[data-system="spytools"] .main-content:not(.main-content-spy) {
    display: none !important;
}

/* ---------- Spy Sidebar (mirrors commerce sidebar dimensions) ---------- */
.sidebar-spy {
    width: 240px;
    background: #ffffff;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: calc(100vh - 56px);
    position: sticky;
    top: 56px;
    overflow-y: auto;
    font-family: 'Inter', sans-serif;
}
body.dark .sidebar-spy {
    background: #0f172a;
    border-right-color: #1e293b;
    color: #cbd5e1;
}

/* Back-to-commerce strip */
.spy-back-strip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    transition: filter 0.15s ease;
}
.spy-back-strip:hover { filter: brightness(1.05); }
.spy-back-strip i { width: 16px; height: 16px; }

/* Brand block */
.spy-brand {
    padding: 14px 16px 10px;
    border-bottom: 1px solid #f1f5f9;
}
.spy-brand-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
    color: #0f172a;
    letter-spacing: -0.01em;
}
.spy-brand-title i { color: #6366f1; width: 18px; height: 18px; }
.spy-brand-sub {
    margin-top: 4px;
    font-size: 11px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
body.dark .spy-brand-title { color: #e2e8f0; }
body.dark .spy-brand { border-bottom-color: #1e293b; }

/* Nav */
.spy-nav {
    flex: 1;
    padding: 8px 10px;
}
.spy-nav-section {
    margin-bottom: 14px;
}
.spy-nav-title {
    display: block;
    padding: 6px 12px 4px;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
    font-weight: 600;
}
.spy-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    color: #475569;
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    cursor: pointer;
}
.spy-nav-link i { width: 16px; height: 16px; flex-shrink: 0; }
.spy-nav-link:hover {
    background: #f1f5f9;
    color: #0f172a;
}
.spy-nav-link.active {
    background: #eef2ff;
    color: #4f46e5;
    font-weight: 600;
}
.spy-nav-link .spy-link-badge {
    margin-left: auto;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 999px;
    background: #fee2e2;
    color: #dc2626;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.spy-nav-link .spy-link-badge.cyan { background: #cffafe; color: #0e7490; }
.spy-nav-link .spy-link-badge.amber { background: #fef3c7; color: #b45309; }

body.dark .spy-nav-link { color: #94a3b8; }
body.dark .spy-nav-link:hover { background: #1e293b; color: #f1f5f9; }
body.dark .spy-nav-link.active { background: rgba(99,102,241,0.15); color: #a5b4fc; }

/* ---------- Main host ---------- */
.main-content-spy {
    flex: 1;
    background: #f8fafc;
    min-height: calc(100vh - 56px);
    overflow-x: hidden;
}
body.dark .main-content-spy { background: #020617; }

.spy-panel { display: none; padding: 24px 32px; max-width: 1400px; margin: 0 auto; }
.spy-panel.active { display: block; }

.spy-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e5e7eb;
}
.spy-panel-head h1 {
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.02em;
    margin: 0;
}
.spy-panel-head p {
    margin: 4px 0 0;
    font-size: 13px;
    color: #64748b;
}
body.dark .spy-panel-head { border-bottom-color: #1e293b; }
body.dark .spy-panel-head h1 { color: #f1f5f9; }
body.dark .spy-panel-head p { color: #94a3b8; }

/* ---------- Discover hero / KPI strip ---------- */
.spy-kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 24px;
}
.spy-kpi {
    padding: 16px 20px;
    border-right: 1px solid #f1f5f9;
}
.spy-kpi:last-child { border-right: none; }
.spy-kpi-label {
    display: block;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #94a3b8;
    font-weight: 600;
    margin-bottom: 6px;
}
.spy-kpi-value {
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.02em;
}
.spy-kpi-trend {
    margin-top: 4px;
    font-size: 11.5px;
    color: #16a34a;
    font-weight: 600;
}
.spy-kpi-trend.down { color: #dc2626; }
body.dark .spy-kpi-row { background: #0f172a; border-color: #1e293b; }
body.dark .spy-kpi { border-right-color: #1e293b; }
body.dark .spy-kpi-value { color: #f1f5f9; }

/* ---------- Filter bar ---------- */
.spy-filter-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 16px;
}
.spy-filter-search {
    flex: 1;
    min-width: 220px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 7px 10px;
}
.spy-filter-search input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 13px;
    color: #0f172a;
    font-family: inherit;
}
.spy-filter-search i { width: 14px; height: 14px; color: #94a3b8; }
.spy-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: #f1f5f9;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    color: #475569;
    cursor: pointer;
    transition: all 0.15s;
}
.spy-chip:hover { background: #e2e8f0; }
.spy-chip.active {
    background: #4f46e5;
    color: #fff;
}
body.dark .spy-filter-bar { background: #0f172a; border-color: #1e293b; }
body.dark .spy-filter-search { background: #020617; border-color: #1e293b; }
body.dark .spy-filter-search input { color: #f1f5f9; }
body.dark .spy-chip { background: #1e293b; color: #cbd5e1; }

/* ---------- Ads grid ---------- */
.spy-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.spy-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.spy-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(15,23,42,0.06);
}
.spy-card-media {
    position: relative;
    aspect-ratio: 9/16;
    background: linear-gradient(135deg, #1e293b, #0f172a);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #475569;
}
.spy-card-media i { width: 48px; height: 48px; opacity: 0.4; }
.spy-card-platform {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(15,23,42,0.85);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.spy-card-platform.tiktok { background: #000; }
.spy-card-platform.meta { background: #1877f2; }
.spy-card-score {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #16a34a;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 6px;
}
.spy-card-score.hot { background: #dc2626; }
.spy-card-body {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.spy-card-title {
    font-size: 13.5px;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.spy-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11.5px;
    color: #64748b;
}
.spy-card-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    margin-top: 4px;
    padding-top: 10px;
    border-top: 1px dashed #e5e7eb;
}
.spy-card-stat {
    text-align: center;
}
.spy-card-stat .v {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: #0f172a;
}
.spy-card-stat .l {
    display: block;
    font-size: 9.5px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 2px;
}
body.dark .spy-card { background: #0f172a; border-color: #1e293b; }
body.dark .spy-card-title { color: #f1f5f9; }
body.dark .spy-card-stats { border-top-color: #1e293b; }
body.dark .spy-card-stat .v { color: #f1f5f9; }

/* ---------- Empty / Coming-soon panel ---------- */
.spy-empty {
    text-align: center;
    padding: 64px 24px;
    background: #ffffff;
    border: 1px dashed #e5e7eb;
    border-radius: 12px;
    color: #64748b;
}
.spy-empty i {
    width: 48px;
    height: 48px;
    color: #cbd5e1;
    margin-bottom: 12px;
}
.spy-empty h3 {
    font-size: 18px;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 6px;
}
.spy-empty p { margin: 0 0 16px; font-size: 13px; }
.spy-empty .spy-empty-tag {
    display: inline-block;
    background: #eef2ff;
    color: #4f46e5;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
body.dark .spy-empty { background: #0f172a; border-color: #1e293b; }
body.dark .spy-empty h3 { color: #f1f5f9; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .spy-kpi-row { grid-template-columns: repeat(2, 1fr); }
    .spy-kpi { border-bottom: 1px solid #f1f5f9; }
    .spy-panel { padding: 16px; }
}
@media (max-width: 600px) {
    .sidebar-spy { width: 64px; }
    .sidebar-spy .spy-brand-sub,
    .sidebar-spy .spy-brand-title span,
    .sidebar-spy .spy-nav-title,
    .sidebar-spy .spy-nav-link span,
    .sidebar-spy .spy-link-badge,
    .sidebar-spy .spy-back-strip span { display: none; }
}
