:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --border: #e6e8ef;
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-50: #eef2ff;
  --success: #059669;
  --success-50: #ecfdf5;
  --warn: #d97706;
  --warn-50: #fffbeb;
  --danger: #dc2626;
  --danger-50: #fef2f2;
  --info: #0284c7;
  --info-50: #f0f9ff;
  --side: #0b1020;
  --side-2: #151b31;
  --side-text: #c7cbe0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 50px -12px rgba(16, 24, 40, .25);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
[x-cloak] { display: none !important; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -0.01em; }
code, .mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }

/* ---------- layout */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 16px; color: #fff; font-weight: 700; font-size: 17px; }
.brand-logo { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, #6366f1, #06b6d4); display: grid; place-items: center; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: #8b91ad; letter-spacing: .04em; text-transform: uppercase; }
.nav { flex: 1; overflow-y: auto; padding: 8px 12px; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6b7190; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--side-text); font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: var(--side-2); color: #fff; }
.nav a.active { background: #232a4a; color: #fff; }
.nav a svg { width: 18px; height: 18px; opacity: .85; flex-shrink: 0; }
.nav .badge-count { margin-left: auto; background: #ef4444; color: #fff; font-size: 11px; padding: 0 7px; border-radius: 99px; font-weight: 600; }
.userbox { border-top: 1px solid #1f2643; padding: 14px 16px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #2b3358; color: #fff; display: grid; place-items: center; font-weight: 600; flex-shrink: 0; }
.userbox .who { flex: 1; min-width: 0; }
.userbox .who b { display: block; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.userbox .who span { font-size: 12px; color: #8b91ad; text-transform: capitalize; }
.icon-btn { background: transparent; border: 0; color: inherit; cursor: pointer; padding: 6px; border-radius: 6px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: rgba(127, 127, 127, .15); }
.icon-btn svg { width: 18px; height: 18px; }

main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 18px 28px; background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar h1 { font-size: 19px; font-weight: 650; }
.topbar .sub { color: var(--muted); font-size: 13px; }
.topbar .spacer { flex: 1; }
.content { padding: 24px 28px 60px; max-width: 1500px; }
.menu-toggle { display: none; }

/* ---------- primitives */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-h h3 { font-size: 15px; font-weight: 600; }
.card-h .spacer { flex: 1; }
.card-b { padding: 18px; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-21 { grid-template-columns: 2fr 1fr; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.mt { margin-top: 16px; }
.mt-l { margin-top: 24px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strong { font-weight: 600; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 7px 13px; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--panel-2); border-color: #d5d9e3; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-50); border-color: #fecaca; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #047857; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 4px 9px; font-size: 12.5px; border-radius: 7px; }
.btn-lg { padding: 11px 18px; font-size: 15px; }
.btn-block { width: 100%; }

input, select, textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid #d6dae3; border-radius: 8px; padding: 8px 11px; width: 100%; outline: none; transition: border-color .12s, box-shadow .12s; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--primary); }
label.field, div.field { display: flex; flex-direction: column; gap: 6px; font-weight: 550; font-size: 13px; }
label.field > span.hint, div.field > span.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-toggle { border: 1px solid var(--border); border-radius: 99px; padding: 4px 11px; cursor: pointer; user-select: none; font-weight: 500; font-size: 13px; background: var(--panel); }
.chip-toggle.on { background: var(--primary-50); border-color: #c7d2fe; color: var(--primary-600); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; min-width: 160px; }
.filters input[type=search] { min-width: 240px; }

/* ---------- table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--panel-2); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid #f0f1f5; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbff; }
td .actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .4; margin-bottom: 8px; }
.pager { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.pager .spacer { flex: 1; }

/* ---------- badges */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: #f1f5f9; color: #475569; white-space: nowrap; text-transform: capitalize; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.plain::before { display: none; }
.b-green { background: var(--success-50); color: var(--success); }
.b-amber { background: var(--warn-50); color: var(--warn); }
.b-red { background: var(--danger-50); color: var(--danger); }
.b-blue { background: var(--info-50); color: var(--info); }
.b-indigo { background: var(--primary-50); color: var(--primary-600); }
.b-gray { background: #f1f5f9; color: #64748b; }
.pulse::before { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* ---------- KPIs */
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 550; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; }
.kpi .foot { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; float: right; }
.kpi .ic svg { width: 17px; height: 17px; }
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }
.bar-list .bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin-bottom: 10px; font-size: 13px; }
.bar-list .bar { grid-column: 1 / -1; height: 6px; border-radius: 99px; background: #eef0f6; overflow: hidden; }
.bar-list .bar > i { display: block; height: 100%; background: linear-gradient(90deg, #6366f1, #06b6d4); border-radius: 99px; }

/* ---------- modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); z-index: 100; display: grid; place-items: center; padding: 20px; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; }
.modal.wide { max-width: 860px; }
.modal-h { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-h h3 { font-size: 16px; flex: 1; }
.modal-b { padding: 20px; overflow-y: auto; }
.modal-f { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--panel-2); border-radius: 0 0 14px 14px; }

/* ---------- toasts */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); min-width: 260px; max-width: 420px; font-weight: 500; display: flex; gap: 10px; align-items: flex-start; }
.toast.error { background: #991b1b; }
.toast.success { background: #065f46; }

/* ---------- media cards */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.media-card { overflow: hidden; display: flex; flex-direction: column; }
.media-thumb { aspect-ratio: 16 / 9; background: #0b1020; display: grid; place-items: center; overflow: hidden; position: relative; }
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-thumb .dur { position: absolute; right: 8px; bottom: 8px; background: rgba(0, 0, 0, .7); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 6px; font-weight: 600; }
.media-body { padding: 12px 14px; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.media-body h4 { font-size: 14px; font-weight: 600; }
.media-actions { display: flex; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--border); }

/* ---------- slot cards (marketplace) */
.slot-card { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.slot-card .when { font-size: 15px; font-weight: 650; }
.slot-card .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.slot-card .stat { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; }
.slot-card .stat b { display: block; font-size: 14px; }
.slot-card .stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.slot-card.winning { border-color: #a7f3d0; box-shadow: 0 0 0 3px #ecfdf5; }
.slot-card.outbid { border-color: #fde68a; box-shadow: 0 0 0 3px #fffbeb; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { background: none; border: 0; padding: 9px 14px; font: inherit; font-weight: 550; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--info-50); color: #075985; border: 1px solid #bae6fd; font-size: 13px; }
.notice.warn { background: var(--warn-50); color: #92400e; border-color: #fde68a; }
.progress { height: 8px; background: #eef0f6; border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--primary); transition: width .2s; }
.tree-indent { display: inline-block; width: 18px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.spinner { width: 18px; height: 18px; border: 2px solid #c7d2fe; border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- auth pages */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero { background: radial-gradient(1200px 600px at 10% 10%, #312e81 0%, #0b1020 60%); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-hero h2 { font-size: 40px; line-height: 1.1; font-weight: 750; letter-spacing: -0.03em; max-width: 520px; }
.auth-hero p { color: #b6bbd6; font-size: 16px; max-width: 480px; }
.auth-hero ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; color: #d6d9ee; }
.auth-hero li { display: flex; gap: 10px; align-items: center; }
.auth-hero li i { width: 22px; height: 22px; border-radius: 6px; background: rgba(255, 255, 255, .1); display: grid; place-items: center; font-style: normal; font-size: 12px; }
.auth-form { display: grid; place-items: center; padding: 40px 24px; }
.auth-form .box { width: 100%; max-width: 400px; }
.auth-form h1 { font-size: 26px; margin-bottom: 6px; }
.demo-creds { margin-top: 22px; font-size: 12.5px; border: 1px dashed var(--border); border-radius: 10px; padding: 12px 14px; color: var(--muted); }
.demo-creds button { all: unset; cursor: pointer; color: var(--primary); font-weight: 600; }

@media (max-width: 1100px) {
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-3, .g-21 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; width: 260px; left: -270px; transition: left .2s; }
  .sidebar.open { left: 0; }
  .menu-toggle { display: inline-grid; }
  .content { padding: 16px; }
  .topbar { padding: 14px 16px; }
  .g-2, .form-grid { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .filters input, .filters select, .filters input[type=search] { min-width: 0; width: 100%; }
}

/* ---------- schedules */
.modal.xwide { max-width: 1080px; }
.ic-inline svg { width: 14px; height: 14px; vertical-align: -2px; margin-right: 5px; color: var(--muted); }
.sched-card { display: grid; grid-template-columns: auto 1fr auto auto; gap: 18px; align-items: center; padding: 14px 16px; }
.sched-card.paused, .sched-card.ended { opacity: .7; }
.sched-card.live { border-left: 3px solid var(--success); }
.sched-thumbs { display: flex; align-items: center; }
.sched-thumb { width: 72px; aspect-ratio: 16/9; border-radius: 8px; overflow: hidden; background: #0b1020; border: 2px solid var(--panel); margin-left: -18px; box-shadow: var(--shadow); }
.sched-thumb:first-child { margin-left: 0; }
.sched-thumb img, .sched-thumb video { width: 100%; height: 100%; object-fit: cover; }
.sched-thumbs .more { margin-left: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.sched-name { font-size: 15px; }
.sched-reach { text-align: right; min-width: 110px; }
.sched-reach .value { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.sched-actions { display: flex; gap: 6px; }
.target-chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 550; background: var(--panel-2); border: 1px solid var(--border); }
.target-chip.region { background: var(--primary-50); border-color: #c7d2fe; color: var(--primary-600); }
.target-chip.store { background: var(--info-50); border-color: #bae6fd; color: #075985; }
.target-chip.device { background: var(--success-50); border-color: #a7f3d0; color: #065f46; }
.target-chip button { all: unset; cursor: pointer; font-weight: 700; padding: 0 2px; opacity: .6; }
.target-chip button:hover { opacity: 1; }

.builder { display: flex; flex-direction: column; gap: 26px; }
.builder .step { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; margin-bottom: 12px; }
.builder .step > span { width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 12px; }
.builder .step em { font-style: normal; font-weight: 500; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; max-height: 300px; overflow-y: auto; padding: 2px; }
.pick { border: 2px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer; background: var(--panel); transition: border-color .12s, box-shadow .12s; }
.pick:hover { border-color: #c7d2fe; }
.pick.on { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); }
.pick-media { aspect-ratio: 16/9; background: #0b1020; position: relative; }
.pick-media img, .pick-media video { width: 100%; height: 100%; object-fit: cover; display: block; }
.pick-media .dur { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.7); color: #fff; font-size: 10.5px; padding: 1px 6px; border-radius: 5px; font-weight: 600; }
.pick-check { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: #fff; display: none; place-items: center; }
.pick-check svg { width: 14px; height: 14px; }
.pick.on .pick-check { display: grid; }
.pick-title { font-size: 12.5px; font-weight: 600; padding: 7px 9px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-sub { font-size: 11.5px; color: var(--muted); padding: 0 9px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; margin-bottom: 10px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font: inherit; font-weight: 550; color: var(--muted); cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.seg button b { background: var(--primary); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 6px; }
.small-seg { margin-bottom: 6px; }
.small-seg button { padding: 4px 10px; font-size: 13px; }
.target-pane { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.check-list { border: 1px solid var(--border); border-radius: 10px; margin-top: 8px; max-height: 260px; overflow-y: auto; }
.check-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px; border-bottom: 1px solid #f1f2f6; cursor: pointer; }
.check-row:last-child { border-bottom: 0; }
.check-row:hover { background: var(--panel-2); }
.check-row input { margin-top: 3px; }
.check-row span { display: flex; flex-direction: column; min-width: 0; }
.check-row small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.selected-pane { display: flex; flex-direction: column; gap: 12px; }
.reach-box { border-radius: 12px; padding: 14px 16px; background: linear-gradient(135deg, #eef2ff, #ecfeff); border: 1px solid #c7d2fe; }
.reach-box .value { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; color: var(--primary-600); }
.mode-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mode-card { border: 2px solid var(--border); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; }
.mode-card input { display: none; }
.mode-card.on { border-color: var(--primary); background: var(--primary-50); }
.modal-f .summary { margin-right: auto; font-size: 13px; color: var(--muted); max-width: 640px; }
@media (max-width: 860px) {
  .sched-card { grid-template-columns: 1fr; }
  .sched-reach { text-align: left; }
  .target-pane, .mode-cards { grid-template-columns: 1fr; }
}
