/* Bridge Core admin panel - one stylesheet, no external fonts or images.
   Layout uses logical properties (inline/block, start/end) so the same rules
   serve LTR English and RTL Persian. Theme follows prefers-color-scheme. */

:root {
	color-scheme: dark light;
	--bg: #0b1020;
	--bg-raised: #131a2e;
	--bg-input: #0e1527;
	--border: #243049;
	--text: #e6ebf5;
	--muted: #94a3b8;
	--accent: #4f8cff;
	--accent-contrast: #ffffff;
	--ok: #34d399;
	--warn: #fbbf24;
	--bad: #f87171;
	--radius: 10px;
	--shadow: 0 10px 30px rgb(0 0 0 / 35%);
	--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	--sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Naskh Arabic", Tahoma, sans-serif;
}

@media (prefers-color-scheme: light) {
	:root {
		--bg: #f5f7fb;
		--bg-raised: #ffffff;
		--bg-input: #ffffff;
		--border: #dbe2ee;
		--text: #0f172a;
		--muted: #5b6b82;
		--accent: #2563eb;
		--ok: #059669;
		--warn: #b45309;
		--bad: #dc2626;
		--shadow: 0 10px 24px rgb(15 23 42 / 10%);
	}
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	padding: 0;
	height: 100%;
}

body {
	background: var(--bg);
	color: var(--text);
	font-family: var(--sans);
	font-size: 15px;
	line-height: 1.55;
}

a { color: var(--accent); }

h1, h2, h3 { margin: 0 0 0.5rem; line-height: 1.3; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }

.boot {
	display: grid;
	place-items: center;
	height: 100vh;
	color: var(--muted);
}

/* --- shell --------------------------------------------------------------- */

/* The shell owns the viewport and scrolls in its own panes, so the sidebar and
   the header stay put on long pages. */
html, body { height: 100%; }
body { overflow: hidden; }
body.modal-open .main { overflow: hidden; }
body.drawer-open { overflow: hidden; }

.app { block-size: 100dvh; }

.shell {
	display: grid;
	grid-template-columns: 232px 1fr;
	block-size: 100dvh;
}

.sidebar {
	background: var(--bg-raised);
	border-inline-end: 1px solid var(--border);
	padding: 1rem 0.75rem;
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	block-size: 100dvh;
	overflow-y: auto;
}

.brand {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	padding: 0.25rem 0.5rem 1rem;
	font-weight: 700;
	letter-spacing: 0.2px;
}

.brand-mark {
	inline-size: 28px;
	block-size: 28px;
	border-radius: 8px;
	background: var(--accent);
	display: grid;
	place-items: center;
	color: var(--accent-contrast);
	font-size: 0.85rem;
	font-weight: 800;
}

.nav-link {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	padding: 0.5rem 0.65rem;
	border-radius: var(--radius);
	color: var(--text);
	text-decoration: none;
	font-size: 0.95rem;
}

.nav-link:hover { background: color-mix(in oklab, var(--accent) 14%, transparent); }
.nav-link[aria-current="page"] { background: color-mix(in oklab, var(--accent) 22%, transparent); font-weight: 600; }

.sidebar-footer {
	margin-block-start: auto;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	padding-block-start: 0.75rem;
	border-block-start: 1px solid var(--border);
	font-size: 0.85rem;
	color: var(--muted);
}

.main { min-width: 0; display: flex; flex-direction: column; block-size: 100dvh; overflow-y: auto; }

.topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.85rem 1.25rem;
	border-block-end: 1px solid var(--border);
	background: color-mix(in oklab, var(--bg-raised) 92%, transparent);
	position: sticky;
	inset-block-start: 0;
	z-index: 5;
	backdrop-filter: blur(6px);
	flex-wrap: wrap;
}

.menu-toggle { display: none; }
.drawer-backdrop { display: none; }

.topbar-title { font-weight: 650; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.page { padding: 1.1rem 1.25rem 2.5rem; display: flex; flex-direction: column; gap: 1rem; }

/* --- building blocks ----------------------------------------------------- */

.card {
	background: var(--bg-raised);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 1rem;
	box-shadow: var(--shadow);
	min-width: 0;
}

.card-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	flex-wrap: wrap;
	margin-block-end: 0.75rem;
}

.grid { display: grid; gap: 1rem; }
.grid-cards { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat { display: flex; flex-direction: column; gap: 0.2rem; }
.stat-label { color: var(--muted); font-size: 0.85rem; }
.stat-value { font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 0.78rem; }

.row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.mono { font-family: var(--mono); font-size: 0.86em; }
.nowrap { white-space: nowrap; }
.break { overflow-wrap: anywhere; }

.empty {
	padding: 1.5rem;
	text-align: center;
	color: var(--muted);
	border: 1px dashed var(--border);
	border-radius: var(--radius);
}

.error-box {
	padding: 0.8rem 1rem;
	border-radius: var(--radius);
	border: 1px solid color-mix(in oklab, var(--bad) 45%, var(--border));
	background: color-mix(in oklab, var(--bad) 12%, transparent);
	color: var(--text);
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
}

/* --- controls ------------------------------------------------------------ */

button, .button {
	font: inherit;
	border-radius: var(--radius);
	border: 1px solid var(--border);
	background: var(--bg-input);
	color: var(--text);
	padding: 0.45rem 0.85rem;
	cursor: pointer;
	text-decoration: none;
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
}

button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); font-weight: 600; }
button.danger { border-color: color-mix(in oklab, var(--bad) 60%, var(--border)); color: var(--bad); }
button.ghost { background: transparent; }
button.small { padding: 0.25rem 0.55rem; font-size: 0.83rem; }

input, select, textarea {
	font: inherit;
	color: var(--text);
	background: var(--bg-input);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 0.45rem 0.6rem;
	width: 100%;
}

input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible,
.nav-link:focus-visible {
	outline: 2px solid color-mix(in oklab, var(--accent) 70%, transparent);
	outline-offset: 2px;
	border-radius: 6px;
}

label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.88rem; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 0.5rem; color: var(--text); }
label.inline input { width: auto; }

.field-grid { display: grid; gap: 0.85rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-block-start: 0.75rem; }

/* --- tables -------------------------------------------------------------- */

.filter-row input[type="search"] { max-width: 280px; }
.filter-row select { max-width: 170px; }

.table-wrap { overflow-x: auto; max-width: 100%; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: start; padding: 0.5rem 0.6rem; border-block-end: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
tbody tr:hover { background: color-mix(in oklab, var(--accent) 7%, transparent); }
td.wrap { white-space: normal; }

/* --- badges -------------------------------------------------------------- */

.badge {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	padding: 0.1rem 0.5rem;
	border-radius: 999px;
	font-size: 0.76rem;
	border: 1px solid var(--border);
	color: var(--muted);
	white-space: nowrap;
}

.badge.ok { color: var(--ok); border-color: color-mix(in oklab, var(--ok) 45%, var(--border)); }
.badge.bad { color: var(--bad); border-color: color-mix(in oklab, var(--bad) 45%, var(--border)); }
.badge.warn { color: var(--warn); border-color: color-mix(in oklab, var(--warn) 45%, var(--border)); }
.badge.live { color: var(--ok); }

.dot { inline-size: 8px; block-size: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

/* --- charts -------------------------------------------------------------- */

.spark { display: block; width: 100%; height: 46px; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.spark-area { fill: color-mix(in oklab, var(--accent) 18%, transparent); stroke: none; }
.spark-grid { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark-axis { fill: var(--muted); font-size: 9px; }
.spark-point { fill: transparent; }
.spark-point:hover { fill: color-mix(in oklab, var(--accent) 45%, transparent); }
.chart-hint { color: var(--muted); font-size: 0.8rem; padding: 0.35rem 0; }
.chart-hint.empty { padding: 1.2rem 0.5rem; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

/* --- modal / toast ------------------------------------------------------- */

.overlay {
	position: fixed;
	inset: 0;
	background: rgb(3 7 18 / 65%);
	display: grid;
	place-items: center;
	padding: 1rem;
	z-index: 50;
}

.modal {
	background: var(--bg-raised);
	border: 1px solid var(--border);
	border-radius: 14px;
	box-shadow: var(--shadow);
	padding: 1.1rem;
	width: min(560px, 100%);
	max-height: 85vh;
	overflow-y: auto;
}

.modal h2 { margin-block-end: 0.6rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-block-start: 1rem; }

.toasts {
	position: fixed;
	inset-block-end: 1rem;
	inset-inline-end: 1rem;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	z-index: 60;
	max-width: min(420px, calc(100vw - 2rem));
}

.toast {
	background: var(--bg-raised);
	border: 1px solid var(--border);
	border-inline-start: 3px solid var(--accent);
	border-radius: var(--radius);
	padding: 0.6rem 0.8rem;
	box-shadow: var(--shadow);
	font-size: 0.88rem;
}

.toast.error { border-inline-start-color: var(--bad); }
.toast.ok { border-inline-start-color: var(--ok); }

/* --- login --------------------------------------------------------------- */

.login-wrap {
	min-height: 100vh;
	display: grid;
	place-items: center;
	padding: 1rem;
}

.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 0.9rem; }
.login-card h1 { margin-block-end: 0.25rem; }

/* --- responsive ---------------------------------------------------------- */

@media (max-width: 860px) {
	.shell { grid-template-columns: 1fr; }
	.menu-toggle { display: inline-flex; }
	.sidebar {
		position: fixed;
		inset-block: 0;
		inset-inline-start: 0;
		inline-size: min(280px, 82vw);
		block-size: 100dvh;
		z-index: 40;
		padding: 1rem 0.75rem;
		flex-direction: column;
		overflow-y: auto;
		border-inline-end: 1px solid var(--border);
		border-block-end: 0;
		transform: translateX(-100%);
		transition: transform 0.18s ease;
	}
	[dir="rtl"] .sidebar { transform: translateX(100%); }
	.sidebar.is-open { transform: translateX(0); }
	.drawer-backdrop {
		display: block;
		position: fixed;
		inset: 0;
		background: rgb(3 7 18 / 60%);
		z-index: 39;
	}
	.drawer-backdrop[hidden] { display: none; }
	.brand { padding: 0.25rem 0.5rem 1rem; }
	.nav-link { white-space: nowrap; }
	.sidebar-footer { margin-block-start: auto; padding-block-start: 0.75rem; border-block-start: 1px solid var(--border); flex-direction: column; }
	.page { padding: 0.9rem 0.9rem 2rem; }
	.stat-value { font-size: 1.3rem; }
	th, td { padding: 0.45rem 0.4rem; }
	.topbar { padding: 0.6rem 0.75rem; }
}
