/* ============================================================
   O2 Marketing — original design system
   Warm neutral canvas + O2 terracotta accent + clear hierarchy.
   ============================================================ */

:root {
	--bg: #f7f5f1;
	--bg-2: #f1ede6;
	--surface: #ffffff;
	--surface-2: #fbfaf7;
	--line: #e7e2d9;
	--line-strong: #d8d1c5;
	--text: #1c1a17;
	--text-2: #4b463f;
	--muted: #726c62;
	--faint: #9c958a;
	--accent: #b0532f;
	--accent-ink: #8d3f21;
	--accent-soft: #fbf0ea;
	--accent-line: #ecc9b9;
	--good: #18794e;
	--good-bg: #e8f6ee;
	--warn: #9a5b00;
	--warn-bg: #fdf3df;
	--error: #b42318;
	--error-bg: #fdecea;
	--neutral: #5f5a52;
	--neutral-bg: #f2efe9;
	--radius: 14px;
	--radius-sm: 9px;
	--shadow: 0 1px 2px rgba(28, 26, 23, .04), 0 10px 30px rgba(28, 26, 23, .04);
	--font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
	--mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font-family: var(--font);
	font-size: 14px;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.02em; }
h1 { font-size: 23px; }
h2 { font-size: 16px; }
p { margin: 0; }
code { font-family: var(--mono); font-size: 12px; background: var(--bg-2); padding: 2px 5px; border-radius: 5px; }

/* ---------- Auth ---------- */
.auth-body { background: var(--bg); min-height: 100dvh; }
.auth-shell { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); min-height: 100dvh; }
.auth-brand {
	position: relative;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 56px;
	background:
		radial-gradient(900px 500px at 85% 15%, rgba(176, 83, 47, .28), transparent 60%),
		linear-gradient(145deg, #171512 0%, #2a211b 55%, #3b281f 100%);
	color: #fff;
}
.auth-brand-inner { position: relative; z-index: 2; max-width: 520px; }
.auth-brand img { height: 34px; filter: brightness(0) invert(1); opacity: .95; }
.auth-brand .eyebrow { margin-top: 42px; color: #e9b79e; }
.auth-brand h1 { margin-top: 12px; font-size: clamp(30px, 3.6vw, 48px); line-height: 1.08; letter-spacing: -.04em; }
.auth-copy { margin-top: 16px; color: #d8cec5; font-size: 15px; max-width: 430px; }
.auth-points { margin: 30px 0 0; padding: 0; list-style: none; display: grid; gap: 12px; }
.auth-points li { position: relative; padding-left: 24px; color: #e6ddd5; font-size: 13.5px; }
.auth-points li::before {
	content: ""; position: absolute; left: 0; top: 6px; width: 9px; height: 9px;
	border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(176, 83, 47, .18);
}
.auth-orbit i {
	position: absolute; border-radius: 50%; filter: blur(2px); opacity: .4;
	border: 1px solid rgba(233, 183, 158, .35);
}
.auth-orbit i:nth-child(1) { width: 420px; height: 420px; right: -140px; bottom: -120px; }
.auth-orbit i:nth-child(2) { width: 240px; height: 240px; right: -40px; bottom: -40px; border-color: rgba(255, 255, 255, .12); }
.auth-orbit i:nth-child(3) { width: 90px; height: 90px; right: 90px; bottom: 90px; background: rgba(176, 83, 47, .18); border: 0; }
.auth-card-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 38px; box-shadow: var(--shadow); }
.auth-card h2 { font-size: 26px; letter-spacing: -.03em; }
.auth-lead { margin: 6px 0 24px; }
.auth-form { display: grid; gap: 16px; }
.auth-form .btn { margin-top: 6px; }
.auth-help { margin-top: 20px; color: var(--muted); font-size: 12px; }
.auth-foot { margin-top: 18px; color: var(--faint); font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; }

/* ---------- Shell ---------- */
.app-shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
	position: sticky; top: 0; height: 100dvh; overflow-y: auto;
	display: flex; flex-direction: column; gap: 18px;
	padding: 22px 14px 16px;
	background: var(--surface);
	border-right: 1px solid var(--line);
	z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 10px; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand img { height: 26px; width: auto; }
.brand-tag {
	font-size: 10px; font-weight: 750; letter-spacing: .12em; text-transform: uppercase;
	color: var(--accent); background: var(--accent-soft); border: 1px solid var(--accent-line);
	padding: 3px 7px; border-radius: 999px;
}
.nav { display: grid; gap: 3px; }
.nav-label {
	margin: 14px 8px 6px; font-size: 10px; font-weight: 750; letter-spacing: .14em;
	text-transform: uppercase; color: var(--faint);
}
.nav-link {
	display: flex; align-items: center; gap: 10px;
	padding: 9px 10px; border-radius: 9px;
	color: var(--text-2); font-size: 13.5px; font-weight: 550;
	text-decoration: none; transition: background .15s ease, color .15s ease;
}
.nav-link svg { width: 17px; height: 17px; flex: none; color: var(--muted); }
.nav-link:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 650; }
.nav-link.is-active svg { color: var(--accent); }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; padding-top: 16px; border-top: 1px solid var(--line); }
.user-card { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.avatar {
	width: 32px; height: 32px; border-radius: 50%;
	display: grid; place-items: center;
	background: var(--accent-soft); color: var(--accent-ink);
	font-weight: 750; font-size: 13px; border: 1px solid var(--accent-line);
}
.user-card strong { display: block; font-size: 12.5px; }
.user-card span { display: block; font-size: 11px; color: var(--muted); }
.logout-link { padding: 7px 8px; color: var(--muted); font-size: 12px; }
.logout-link:hover { color: var(--error); text-decoration: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
	position: sticky; top: 0; z-index: 20;
	display: flex; align-items: center; gap: 16px;
	padding: 18px 32px;
	background: rgba(247, 245, 241, .88);
	backdrop-filter: blur(10px);
	border-bottom: 1px solid var(--line);
}
.page-title { min-width: 0; }
.page-title h1 { font-size: 22px; }
.page-title p { margin-top: 2px; color: var(--muted); font-size: 12.5px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.menu-toggle {
	display: none; width: 38px; height: 38px; border: 1px solid var(--line);
	background: var(--surface); border-radius: 9px; color: var(--text); cursor: pointer;
	place-items: center; padding: 0;
}
.menu-toggle svg { width: 20px; height: 20px; }
.content { padding: 26px 32px 48px; display: grid; gap: 18px; align-content: start; }

/* ---------- Controls ---------- */
.segmented {
	justify-self: start;
	display: inline-flex; gap: 2px; padding: 3px;
	background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px;
}
.segmented-item {
	padding: 6px 13px; border-radius: 999px; color: var(--muted);
	font-size: 12px; font-weight: 650; text-decoration: none;
}
.segmented-item:hover { color: var(--text); text-decoration: none; }
.segmented-item.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(28, 26, 23, .08); }
.btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 7px;
	height: 38px; padding: 0 15px; border-radius: 9px; border: 1px solid transparent;
	font: inherit; font-size: 13px; font-weight: 650; cursor: pointer; text-decoration: none;
	transition: transform .12s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-ink); color: #fff; }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }
.field { display: grid; gap: 6px; }
.field span { font-size: 11px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.field input, .field select {
	height: 40px; width: 100%; padding: 0 12px;
	border: 1px solid var(--line-strong); border-radius: 9px;
	background: var(--surface-2); color: var(--text); font: inherit;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent-line); outline-offset: 1px; border-color: var(--accent); }
.sync-form { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
.sync-form .field { min-width: 180px; }
.text-link { font-size: 12px; font-weight: 650; }

/* ---------- Alerts / notices ---------- */
.alert {
	padding: 11px 14px; border-radius: 10px; border: 1px solid transparent;
	font-size: 13px; font-weight: 550;
}
.alert.is-ok { background: var(--good-bg); border-color: #c6e9d5; color: var(--good); }
.alert.is-error { background: var(--error-bg); border-color: #f4c7c3; color: var(--error); }
.notice {
	display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline;
	padding: 12px 15px; border-radius: 11px;
	background: var(--accent-soft); border: 1px solid var(--accent-line);
	color: var(--accent-ink); font-size: 12.5px;
}
.notice strong { font-weight: 750; }
.notice span { color: var(--text-2); }

/* ---------- KPIs ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi-grid-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.kpi-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi-card {
	position: relative; overflow: hidden;
	background: var(--surface); border: 1px solid var(--line);
	border-radius: var(--radius); padding: 17px 18px 15px;
	box-shadow: 0 1px 2px rgba(28, 26, 23, .03);
}
.kpi-card::before {
	content: ""; position: absolute; top: 0; left: 18px; width: 26px; height: 3px;
	border-radius: 0 0 4px 4px; background: var(--line-strong);
}
.kpi-card.tone-accent::before { background: var(--accent); }
.kpi-card.tone-good::before { background: var(--good); }
.kpi-label { display: block; font-size: 10.5px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.kpi-value { display: block; margin: 9px 0 3px; font-size: 27px; font-weight: 700; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.kpi-sub { display: block; color: var(--muted); font-size: 11.5px; }

/* ---------- Panels ---------- */
.panel {
	background: var(--surface); border: 1px solid var(--line);
	border-radius: var(--radius); padding: 20px;
	box-shadow: 0 1px 2px rgba(28, 26, 23, .03);
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; }
.panel-head h2 { margin-top: 3px; }
.panel-head p { margin-top: 3px; color: var(--muted); font-size: 12.5px; }
.eyebrow { font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.chart-panel { padding-bottom: 14px; }
.chart-wrap { position: relative; height: 320px; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11.5px; font-weight: 650; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-sessions { background: var(--accent); }
.dot-revenue { background: var(--text); }
.dot-events { background: #2f6f8f; }

/* ---------- Sources ---------- */
.source-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.source-list li { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 11px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.source-list li:last-child { border-bottom: 0; }
.source-icon {
	width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
	background: var(--bg-2); color: var(--text-2); font-weight: 800; font-size: 13px;
}
.source-list strong { display: block; font-size: 13px; }
.source-list small { display: block; color: var(--muted); font-size: 11.5px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px -20px; padding: 0 20px 4px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th {
	text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line);
	font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--faint);
	white-space: nowrap;
}
.data-table td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table.compact td { padding: 9px 6px; }
.data-table .muted { color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.page-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.error-cell { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--error); }
.share-cell { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.share { flex: 1; height: 5px; border-radius: 999px; background: var(--bg-2); overflow: hidden; }
.share i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.share-cell small { color: var(--muted); font-size: 10.5px; min-width: 38px; text-align: right; }

/* ---------- Badges / details ---------- */
.badge {
	display: inline-flex; align-items: center; gap: 5px;
	padding: 3px 8px; border-radius: 999px;
	font-size: 10.5px; font-weight: 750; letter-spacing: .02em;
	background: var(--neutral-bg); color: var(--neutral); white-space: nowrap;
}
.badge.is-ok { background: var(--good-bg); color: var(--good); }
.badge.is-warn { background: var(--warn-bg); color: var(--warn); }
.badge.is-error { background: var(--error-bg); color: var(--error); }
.badge.is-neutral { background: var(--neutral-bg); color: var(--neutral); }
.detail-list { display: grid; gap: 10px; margin: 0; }
.detail-list > div { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.detail-list > div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); font-size: 12px; }
.detail-list dd { margin: 0; font-size: 12.5px; font-weight: 650; text-align: right; }
.hint { margin-top: 12px; color: var(--muted); font-size: 11.5px; }
.migration-log { margin-top: 14px; background: #1c1a17; color: #e8e2d9; padding: 14px; border-radius: 10px; overflow: auto; font: 12px/1.6 var(--mono); }
.empty { padding: 26px 8px; color: var(--muted); text-align: center; font-size: 12.5px; }
.error-page { max-width: 520px; margin: 12vh auto; text-align: center; display: grid; gap: 10px; }

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: no-preference) {
	.kpi-card, .panel { animation: rise .35s ease both; }
	.kpi-card:nth-child(2) { animation-delay: .03s; }
	.kpi-card:nth-child(3) { animation-delay: .06s; }
	.kpi-card:nth-child(4) { animation-delay: .09s; }
	@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
	.kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
	.kpi-grid-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
	.app-shell { grid-template-columns: 1fr; }
	.sidebar {
		position: fixed; inset: 0 auto 0 0; width: 260px; transform: translateX(-104%);
		transition: transform .2s ease; box-shadow: 0 20px 60px rgba(28, 26, 23, .18);
	}
	body.nav-open .sidebar { transform: translateX(0); }
	body.nav-open::after {
		content: ""; position: fixed; inset: 0; background: rgba(28, 26, 23, .28);
		z-index: 25;
	}
	.menu-toggle { display: grid; }
	.topbar { padding: 14px 20px; }
	.content { padding: 20px; }
	.grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
	.auth-shell { grid-template-columns: 1fr; }
	.auth-brand { display: none; }
	.auth-card-wrap { padding: 24px 16px; min-height: 100dvh; }
	.auth-card { padding: 28px 22px; }
	h1 { font-size: 20px; }
	.page-title h1 { font-size: 19px; }
	.page-title p { display: none; }
	.kpi-grid, .kpi-grid-6, .kpi-grid-3 { grid-template-columns: 1fr; }
	.panel { padding: 16px; }
	.panel-head { flex-direction: column; align-items: flex-start; }
	.table-wrap { margin: 0 -16px -16px; padding: 0 16px 4px; }
	.topbar-actions { display: none; }
	.content { padding: 16px; gap: 14px; }
}
