:root {
    --ws-primary: #6366f1;
    --ws-primary-dark: #4f46e5;
    --ws-primary-soft: #eef2ff;
    --ws-sidebar: #0f172a;
    --ws-sidebar-hover: #1e293b;
    --ws-bg: #f8fafc;
    --ws-border: #e2e8f0;
    --ws-text: #0f172a;
    --ws-muted: #64748b;
    --ws-success: #16a34a;
    --ws-warning: #d97706;
    --ws-danger: #dc2626;
    --ws-sidebar-width: 238px;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', 'DM Sans', system-ui, sans-serif;
    background: var(--ws-bg);
    color: var(--ws-text);
    min-height: 100vh;
    font-size: 14px;
}

a { color: var(--ws-primary); text-decoration: none; }
a:hover { color: var(--ws-primary-dark); }

/* ---------- loading ---------- */
.loading-container {
    position: fixed; inset: 0; z-index: 9999;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: var(--ws-sidebar);
}
.loading-spinner {
    width: 44px; height: 44px; border-radius: 50%;
    border: 4px solid rgba(255,255,255,.2); border-top-color: var(--ws-primary);
    animation: spin 1s linear infinite;
}
.loading-text { margin-top: 14px; color: #cbd5e1; font-size: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.auth-container {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 60%, #312e81 100%);
    padding: 24px;
}
.auth-card {
    background: #fff; border-radius: 14px; padding: 36px; width: 100%; max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.auth-logo .logo-text { font-size: 1.25rem; font-weight: 700; }
.auth-badge {
    display: inline-block; font-size: .65rem; font-weight: 700; letter-spacing: .06em;
    background: var(--ws-danger); color: #fff; padding: 2px 7px; border-radius: 4px; margin-left: 6px;
}

/* ---------- app layout ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--ws-sidebar-width); flex-shrink: 0;
    background: var(--ws-sidebar); color: #cbd5e1;
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px;
    color: #fff; font-weight: 700; font-size: 1.05rem;
}
.sidebar-brand .brand-accent { color: #a5b4fc; font-weight: 500; }
.sidebar-brand svg { width: 28px; height: 28px; }
.nav-menu { list-style: none; margin: 0; padding: 4px 10px; flex: 1; overflow-y: auto; }
.nav-menu-link {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 12px; margin: 2px 0; border-radius: 8px;
    color: #cbd5e1; font-weight: 500; font-size: .92rem;
}
.nav-menu-link:hover { background: var(--ws-sidebar-hover); color: #fff; }
.nav-menu-link.active { background: var(--ws-primary); color: #fff; }
.nav-menu-link.disabled { opacity: .4; pointer-events: none; }
.nav-menu-icon { font-size: 1.05rem; width: 20px; text-align: center; }
.sidebar-footer { padding: 12px 18px; font-size: .72rem; color: #64748b; border-top: 1px solid #1e293b; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: 58px; background: #fff; border-bottom: 1px solid var(--ws-border);
    display: flex; align-items: center; gap: 14px; padding: 0 24px;
    position: sticky; top: 0; z-index: 100;
}
.topbar .search { flex: 1; max-width: 520px; position: relative; }
.topbar .search input {
    width: 100%; border: 1px solid var(--ws-border); border-radius: 8px;
    padding: 8px 12px 8px 36px; font-size: .9rem; background: #fff;
}
.topbar .search input:focus { outline: none; border-color: var(--ws-primary); box-shadow: 0 0 0 3px var(--ws-primary-soft); }
.topbar .search .bi-search { position: absolute; left: 12px; top: 9px; color: var(--ws-muted); }
.search-results {
    position: absolute; top: 42px; left: 0; right: 0; background: #fff;
    border: 1px solid var(--ws-border); border-radius: 10px; box-shadow: 0 12px 30px rgba(15,23,42,.12);
    max-height: 420px; overflow-y: auto; z-index: 200;
}
.search-result {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; color: var(--ws-text);
}
.search-result:hover { background: var(--ws-bg); }
.search-result .type { font-size: .68rem; text-transform: uppercase; color: var(--ws-muted); width: 62px; }
.search-result .sub { font-size: .78rem; color: var(--ws-muted); }
.env-badge {
    font-size: .72rem; font-weight: 700; letter-spacing: .05em; padding: 5px 10px; border-radius: 6px;
}
.env-badge.production { background: #fee2e2; color: #b91c1c; }
.env-badge.development { background: #dcfce7; color: #15803d; }
.env-badge.local { background: #e0e7ff; color: #3730a3; }
.topbar-user { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.topbar-user .avatar {
    width: 34px; height: 34px; border-radius: 50%; background: var(--ws-primary);
    color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.topbar-user .name { font-weight: 600; font-size: .88rem; line-height: 1.1; }
.topbar-user .role { font-size: .72rem; color: var(--ws-muted); }

.content { padding: 20px 24px 40px; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-header h1 { font-size: 1.6rem; font-weight: 700; margin: 0; }
.page-header .subtitle { color: var(--ws-muted); margin-top: 2px; }
.breadcrumb { font-size: .8rem; margin-bottom: 4px; }
.breadcrumb a { color: var(--ws-muted); }

/* ---------- cards / tiles ---------- */
.card { border: 1px solid var(--ws-border); border-radius: 12px; box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.card-header { background: transparent; border-bottom: 1px solid var(--ws-border); font-weight: 600; padding: 12px 16px; }
.card-title { font-weight: 600; font-size: 1rem; margin: 0; }

.kpi { display: flex; align-items: flex-start; gap: 14px; padding: 16px; }
.kpi .icon {
    width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; background: var(--ws-primary-soft); color: var(--ws-primary); flex-shrink: 0;
}
.kpi .icon.green { background: #dcfce7; color: var(--ws-success); }
.kpi .icon.amber { background: #fef3c7; color: var(--ws-warning); }
.kpi .icon.red { background: #fee2e2; color: var(--ws-danger); }
.kpi .label { font-size: .8rem; color: var(--ws-muted); }
.kpi .value { font-size: 1.55rem; font-weight: 700; line-height: 1.2; }
.kpi .delta { font-size: .78rem; margin-top: 2px; }
.kpi .delta.up { color: var(--ws-success); }
.kpi .delta.down { color: var(--ws-danger); }
.kpi .delta.muted { color: var(--ws-muted); }

/* ---------- tables ---------- */
.table { font-size: .88rem; margin-bottom: 0; }
.table thead th {
    font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ws-muted);
    font-weight: 600; background: #f8fafc; border-bottom: 1px solid var(--ws-border); white-space: nowrap;
}
.table thead th.sortable { cursor: pointer; user-select: none; }
.table thead th.sortable:hover { color: var(--ws-text); }
.table tbody td { vertical-align: middle; border-color: #f1f5f9; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: #f8fafc; }
.table .primary-cell { font-weight: 600; color: var(--ws-text); }
.table .sub-cell { font-size: .76rem; color: var(--ws-muted); }

.table-footer {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 16px; border-top: 1px solid var(--ws-border); font-size: .82rem; color: var(--ws-muted);
}
.pagination { margin: 0; }
.pagination .page-link { border-radius: 6px !important; margin: 0 2px; border-color: var(--ws-border); color: var(--ws-text); font-size: .82rem; }
.pagination .page-item.active .page-link { background: var(--ws-primary); border-color: var(--ws-primary); color: #fff; }

/* ---------- chips / badges ---------- */
.chip {
    display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 6px;
    font-size: .74rem; font-weight: 600; white-space: nowrap;
}
.chip.free { background: #f1f5f9; color: #475569; }
.chip.basic { background: #e0f2fe; color: #0369a1; }
.chip.pro { background: #ede9fe; color: #6d28d9; }
.chip.enterprise { background: #fee2e2; color: #b91c1c; }
.chip.lifetime_founder, .chip.lifetime { background: #e0e7ff; color: #3730a3; }
.chip.unknown { background: #f1f5f9; color: #64748b; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 500; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.status.active .dot, .status.online .dot, .status.done .dot { background: var(--ws-success); }
.status.trialing .dot, .status.warn .dot, .status.offline-recent .dot { background: var(--ws-warning); }
.status.past_due .dot, .status.unpaid .dot, .status.offline .dot, .status.error .dot { background: var(--ws-danger); }
.status.canceled .dot, .status.never .dot, .status.free .dot { background: #94a3b8; }

.usage { min-width: 90px; }
.usage .nums { font-weight: 600; font-size: .85rem; }
.usage .bar { height: 5px; border-radius: 3px; background: #e2e8f0; margin-top: 4px; overflow: hidden; }
.usage .bar > span { display: block; height: 100%; background: var(--ws-primary); }
.usage .bar.green > span { background: var(--ws-success); }
.usage .bar.amber > span { background: var(--ws-warning); }
.usage .bar.red > span { background: var(--ws-danger); }

.platform-icon {
    display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; font-weight: 600;
}
.platform-icon .pi {
    width: 22px; height: 22px; border-radius: 5px; display: inline-flex; align-items: center; justify-content: center;
    font-size: .62rem; font-weight: 700; color: #fff; letter-spacing: .02em;
}
.pi.roku { background: #6c3c97; }
.pi.android { background: #3ddc84; color: #0f172a; }
.pi.firetv { background: #f90; color: #0f172a; }
.pi.appletv { background: #111; }
.pi.samsung { background: #1428a0; }
.pi.lg { background: #a50034; }
.pi.web { background: #2563eb; }
.pi.chromecast { background: #4285f4; }
.pi.other { background: #64748b; }

/* ---------- filters ---------- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filter-bar .form-label { font-size: .74rem; color: var(--ws-muted); font-weight: 600; margin-bottom: 3px; }
.filter-bar .form-select, .filter-bar .form-control { font-size: .86rem; min-width: 150px; }

/* ---------- detail pages ---------- */
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.detail-header h1 { font-size: 1.5rem; font-weight: 700; margin: 0 0 6px; }
.detail-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--ws-muted); font-size: .86rem; }
.detail-meta .sep { color: #cbd5e1; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.detail-actions .btn { font-size: .84rem; }

.nav-tabs { border-bottom: 1px solid var(--ws-border); }
.nav-tabs .nav-link { color: var(--ws-muted); font-weight: 500; border: 0; border-bottom: 2px solid transparent; padding: 10px 16px; }
.nav-tabs .nav-link.active { color: var(--ws-primary); border-bottom-color: var(--ws-primary); background: transparent; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; font-size: .88rem; }
.kv dt { color: var(--ws-muted); font-weight: 500; margin: 0; }
.kv dd { margin: 0; word-break: break-word; }
.kv code { font-size: .78rem; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid #f1f5f9; font-size: .84rem; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--ws-muted); width: 110px; flex-shrink: 0; font-size: .78rem; }

.heartbeat-strip { display: flex; gap: 2px; height: 26px; }
.heartbeat-strip span { flex: 1; border-radius: 2px; background: #e2e8f0; }
.heartbeat-strip span.on { background: var(--ws-success); }
.heartbeat-strip span.off { background: var(--ws-danger); }

.empty { text-align: center; color: var(--ws-muted); padding: 36px 16px; }
.empty .bi { font-size: 2rem; display: block; margin-bottom: 8px; color: #cbd5e1; }

.btn-primary { background: var(--ws-primary); border-color: var(--ws-primary); }
.btn-primary:hover { background: var(--ws-primary-dark); border-color: var(--ws-primary-dark); }
.btn-outline-primary { color: var(--ws-primary); border-color: var(--ws-primary); }
.btn-outline-primary:hover { background: var(--ws-primary); border-color: var(--ws-primary); }

.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; }

.mock-banner {
    background: #fef3c7; color: #92400e; font-size: .78rem; text-align: center; padding: 4px; font-weight: 600;
}

@media (max-width: 991px) {
    .sidebar { position: fixed; left: calc(-1 * var(--ws-sidebar-width)); transition: left .2s; z-index: 300; }
    .sidebar.open { left: 0; }
    .content { padding: 16px; }
    .kv { grid-template-columns: 110px 1fr; }
}
