/*
  Flat / Modern Design System
  - Mobile-first
  - Professional, trustworthy, energetic
*/

/* -------- Reset (simple) -------- */
*,
*::before,
*::after {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	padding: 0;
}

img,
svg {
	max-width: 100%;
	height: auto;
}

input,
button,
select,
textarea {
	font: inherit;
}

/* -------- Tokens (CSS Variables) -------- */
:root {
	/* Brand */
	--primary: #2563eb;
	--secondary: #10b981;
	--accent: #f59e0b;

	/* Surfaces */
	--bg: #f8fafc;
	--card: #ffffff;
	--border: #e5e7eb;

	/* Typography */
	--text: #1f2933;
	--muted: #6b7280;
	--link: var(--primary);

	/* Radius / Shadow */
	--radius-sm: 10px;
	--radius-md: 14px;
	--shadow-sm: 0 1px 2px rgba(31, 41, 51, 0.06), 0 2px 6px rgba(31, 41, 51, 0.08);
	--shadow-focus: 0 0 0 3px rgba(37, 99, 235, 0.22);

	/* Motion */
	--transition: 160ms ease;

	/* Layout */
	--topbar-h: 64px;

	color-scheme: light;
}

/* Dark Mode (CSS Variables override) */
html[data-theme="dark"] {
	color-scheme: dark;

	/* Surfaces */
	--bg: #0b1220;
	--card: #0f172a;
	--border: rgba(148, 163, 184, 0.18);

	/* Typography */
	--text: #e5e7eb;
	--muted: #94a3b8;

	/* Shadow / Focus */
	--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25), 0 10px 30px rgba(0, 0, 0, 0.25);
	--shadow-focus: 0 0 0 3px rgba(37, 99, 235, 0.35);
}

/* -------- Global styles -------- */
body {
	font-family: Vazirmatn, IRANSans, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
	background: var(--bg);
	color: var(--text);
	line-height: 1.6;
	padding-top: var(--topbar-h);
}

body.app--noTopbar {
	padding-top: 0;
}

a {
	color: var(--link);
	text-decoration: none;
	transition: color var(--transition);
}

a:hover {
	text-decoration: underline;
}

button {
	background: transparent;
}

/* Inputs */
input,
select,
textarea {
	width: 100%;
	padding: 10px 12px;
	border-radius: var(--radius-sm);
	border: 1px solid var(--border);
	background: var(--card);
	color: var(--text);
	transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
select:focus,
textarea:focus {
	outline: none;
	border-color: var(--primary);
	box-shadow: var(--shadow-focus);
}

/* Tables */
table {
	border-collapse: collapse;
	width: 100%;
}

/* -------- Components -------- */
button,
.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 10px 12px;
	border-radius: var(--radius-sm);
	border: 1px solid var(--border);
	background: var(--card);
	color: var(--text);
	text-decoration: none;
	font-weight: 600;
	font-size: 14px;
	line-height: 1;
	cursor: pointer;
	transition: background-color var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition), color var(--transition);
}

button:focus,
.btn:focus {
	outline: none;
	box-shadow: var(--shadow-focus);
}

button:hover,
.btn:hover {
	transform: translateY(-1px);
}

.btn--primary {
	background: var(--primary);
	border-color: var(--primary);
	color: #ffffff;
}

.btn--secondary {
	background: var(--secondary);
	border-color: var(--secondary);
	color: #ffffff;
}

.btn--accent {
	background: var(--accent);
	border-color: var(--accent);
	color: #111827;
}

/* Optional utility class for inputs (kept for readability in templates) */
.input { }

.card {
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	padding: 14px;
	box-shadow: var(--shadow-sm);
	transition: box-shadow var(--transition), transform var(--transition);
}

.card:hover {
	transform: translateY(-1px);
}

.badge {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 4px 10px;
	border-radius: 999px;
	border: 1px solid var(--border);
	background: var(--card);
	color: var(--text);
	font-size: 12px;
	font-weight: 700;
}

.badge--secondary {
	border-color: var(--secondary);
	color: var(--secondary);
}

.badge--accent {
	border-color: var(--accent);
	color: #92400e;
}

.alert {
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	padding: 12px;
	background: var(--card);
	color: var(--text);
	box-shadow: var(--shadow-sm);
}

.alert--success {
	border-color: rgba(16, 185, 129, 0.35);
	background: rgba(16, 185, 129, 0.08);
}

.alert--warning {
	border-color: rgba(245, 158, 11, 0.40);
	background: rgba(245, 158, 11, 0.12);
}

.alert--info {
	border-color: rgba(37, 99, 235, 0.35);
	background: rgba(37, 99, 235, 0.08);
}

.container {
	max-width: 1100px;
	margin: 0 auto;
	padding: 16px;
}

.topbar {
	background: var(--card);
	border-bottom: 1px solid var(--border);
	padding: 0 16px; /* Add padding directly to topbar instead of relying on container */
}

.topbar--fixed {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 40; /* Higher than sidebar (30/10) */
	height: var(--topbar-h);
	display: flex;
	align-items: center;
	box-shadow: var(--shadow-sm);
}

.topbar__row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	width: 100%;
	/* Removed max-width container restriction */
}

.topbar__left {
	display: flex;
	align-items: center;
	gap: 16px; /* More spacing */
	min-width: 0;
}

.hamburger {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	border-radius: var(--radius-sm);
	border: 1px solid var(--border);
	background: var(--card);
	color: var(--text);
	flex-shrink: 0; /* Prevent shrinking if space is tight */
}

.hamburger:hover {
	transform: translateY(-1px);
}

.drawerOverlay {
	display: none;
}

.topbar__right {
	display: inline-flex;
	align-items: center;
	gap: 10px;
}

.themeToggle {
	padding: 10px;
	min-width: 40px;
}

.themeToggle__icon {
	width: 18px;
	height: 18px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.themeToggle__icon--sun {
	display: none;
}

html[data-theme="dark"] .themeToggle__icon--sun {
	display: inline-flex;
}

html[data-theme="dark"] .themeToggle__icon--moon {
	display: none;
}

.topbar__title {
	color: var(--muted);
	font-size: 13px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.topbar__user {
	font-size: 13px;
	font-weight: 700;
	color: var(--text);
	padding: 6px 10px;
	border: 1px solid var(--border);
	border-radius: 999px;
	background: var(--card);
}

.brand {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	color: var(--text);
	text-decoration: none;
	font-weight: 800;
}

.brand__icon {
	width: 34px;
	height: 34px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: var(--radius-sm);
	border: 1px solid var(--border);
	background: var(--bg);
}

.brand__name {
	white-space: nowrap;
}

.topbar__nav {
	display: flex;
	gap: 10px;
	flex-wrap: wrap;
}

.layout {
	display: flex;
	gap: 16px;
	align-items: flex-start;
	flex-direction: column;
}

/* -------- Admin Panel Shell (Refactored) -------- */
.appShell {
	display: flex;
	flex-direction: column;
	min-height: calc(100vh - var(--topbar-h));
	position: relative;
}

body.app--noTopbar .appShell {
	min-height: 100vh;
}

.appShell--full {
	display: block;
}

.appShell__sidebar {
	/* Mobile default: Fixed off-canvas */
	position: fixed;
	top: var(--topbar-h);
	right: 0;
	bottom: 0;
	width: 280px;
	background: var(--bg); /* Match body bg or card bg */
	z-index: 50;
	transform: translateX(100%); /* Hide off-screen (RTL: positive moves right? No, standard coord system: right is +x. If dir=rtl, right:0 is start. Transform translateX(100%) moves it further right (outside). Correct.) */
	transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	border-left: 1px solid var(--border);
	overflow-y: auto;
}

body.drawer-open .appShell__sidebar {
	transform: translateX(0);
}

.appShell__content {
	width: 100%;
	flex: 1;
	min-width: 0; /* Prevent flex overflow */
	padding: 16px;
}

.appShell__contentInner {
	max-width: 1200px;
	margin: 0 auto;
}

.appShell__contentInner--full {
	max-width: none;
}

/* Sidebar Component styling override for shell */
.sidebar {
	width: 100%;
	height: 100%; /* Fill container */
	border: none;
	border-radius: 0;
	box-shadow: none;
	background: transparent;
	padding: 16px;
}

.sidebar__nav {
	display: flex;
	flex-direction: column;
	gap: 4px; /* Tighter gap for desktop */
}

/* Sidebar Links */
.sideLink {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 10px 12px;
	border-radius: var(--radius-sm);
	color: var(--text);
	text-decoration: none;
	font-size: 14px;
	font-weight: 500;
	transition: background-color var(--transition), color var(--transition);
	border: 1px solid transparent; /* Prevent layout shift on hover if border added */
}

.sideLink__icon {
	width: 20px;
	height: 20px;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--muted);
	transition: color var(--transition);
}

.sideLink__label {
	flex: 1;
}

.sideLink:hover {
	background: rgba(37, 99, 235, 0.08); /* Light primary bg */
	color: var(--primary);
	text-decoration: none;
}

.sideLink:hover .sideLink__icon {
	color: var(--primary);
}

.sideLink--active {
	background: rgba(37, 99, 235, 0.12);
	color: var(--primary);
	font-weight: 700;
}

.sideLink--active .sideLink__icon {
	color: var(--primary);
}

/* Mobile Sidebar Links (Button style) */
@media (max-width: 1023px) {
	.sidebar__nav {
		gap: 8px; /* Bigger gap on mobile */
		padding-top: 10px;
	}
	
	.sideLink {
		background: var(--card); /* Card background */
		border: 1px solid var(--border);
		padding: 14px 16px; /* Larger touch target */
		font-size: 15px;
		box-shadow: 0 1px 2px rgba(0,0,0,0.05);
	}

	.sideLink__icon {
		width: 24px;
		height: 24px; /* Larger icon container */
	}

	/* Active state enhancement for mobile */
	.sideLink--active {
		border-color: var(--primary);
		background: var(--primary);
		color: #ffffff;
		box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2);
	}
	
	.sideLink--active .sideLink__icon {
		color: #ffffff;
	}
}

/* Drawer Overlay */
.drawerOverlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.5);
	z-index: 40;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.3s;
	backdrop-filter: blur(2px);
}

body.drawer-open .drawerOverlay {
	opacity: 1;
	pointer-events: auto;
}

/* -------- Desktop (Laptop/PC) -------- */
@media (min-width: 1024px) {
	.hamburger {
		display: none;
	}

	.appShell {
		display: grid;
		grid-template-columns: 260px 1fr;
		align-items: start;
	}

	.appShell--full {
		display: block;
	}

	.appShell__sidebar {
		position: sticky;
		top: var(--topbar-h);
		right: auto;
		bottom: auto;
		width: auto; /* Grid handles width */
		height: calc(100vh - var(--topbar-h));
		transform: none;
		border-left: 1px solid var(--border);
		z-index: 10;
		background: var(--card); /* Sidebar usually card color on desktop */
	}

	.appShell__content {
		padding: 24px;
	}
	
	.drawerOverlay {
		display: none; /* Never show overlay on desktop */
	}
}

/* -------- Utilities -------- */
.table-responsive {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	width: 100%;
	padding-bottom: 12px;
}


.link {
	color: var(--link);
	text-decoration: none;
	padding: 6px 10px;
	border: 1px solid var(--border);
	border-radius: 8px;
	background: var(--card);
	transition: background-color var(--transition), border-color var(--transition), transform var(--transition);
}

.link--active {
	font-weight: 700;
}

.link:hover {
	text-decoration: underline;
	transform: translateY(-1px);
}

.h1 {
	margin: 0;
	font-size: 20px;
}

.h2 {
	margin: 0;
	font-size: 16px;
}

.h3 {
	margin: 0;
	font-size: 14px;
	font-weight: 800;
}

.muted {
	margin: 4px 0 0;
	color: var(--muted);
	font-size: 13px;
}

.cards {
	display: grid;
	grid-template-columns: 1fr;
	gap: 12px;
	margin: 16px 0;
}

@media (min-width: 640px) {
	.cards {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (min-width: 1024px) {
	.cards {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}
}

.card {
	/* handled by Design System */
}

.card__title {
	color: var(--muted);
	font-size: 13px;
}

.card__value {
	font-size: 28px;
	font-weight: 700;
	margin-top: 6px;
}

/* Dashboard Stat Cards */
.statCard {
	padding: 14px;
}

.statCard__row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
}

.statCard__meta {
	min-width: 0;
	flex: 1;
}

.statCard__icon {
	width: 44px;
	height: 44px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: var(--radius-sm);
	border: 1px solid var(--border);
	background: var(--bg);
	color: var(--muted);
	flex: 0 0 44px;
}

.statCard--primary {
	border-top: 3px solid rgba(37, 99, 235, 0.55);
}

.statCard--primary .statCard__icon {
	border-color: rgba(37, 99, 235, 0.35);
	background: rgba(37, 99, 235, 0.06);
	color: var(--primary);
}

.statCard--secondary {
	border-top: 3px solid rgba(16, 185, 129, 0.55);
}

.statCard--secondary .statCard__icon {
	border-color: rgba(16, 185, 129, 0.35);
	background: rgba(16, 185, 129, 0.08);
	color: var(--secondary);
}

.statCard--accent {
	border-top: 3px solid rgba(245, 158, 11, 0.60);
}

.statCard--accent .statCard__icon {
	border-color: rgba(245, 158, 11, 0.40);
	background: rgba(245, 158, 11, 0.12);
	color: var(--accent);
}

.section {
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	padding: 14px;
	margin: 16px 0;
	box-shadow: var(--shadow-sm);
}

@media (max-width: 639px) {
	.container {
		padding: 12px;
	}
	.section {
		padding: 12px;
	}
}

.section__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	margin-bottom: 10px;
}

@media (max-width: 639px) {
	.section__header {
		flex-direction: column;
		align-items: stretch;
	}
	.section__header .btn {
		width: 100%;
		justify-content: center;
	}
}

/* -------- Forms (UX-focused) -------- */
.form {
	display: grid;
	gap: 12px;
}

.form--grid2 {
	grid-template-columns: 1fr;
}

@media (min-width: 1024px) {
	.form--grid2 {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

.field {
	display: grid;
	gap: 6px;
}

.field--span2 {
	grid-column: 1 / -1;
}

.field__label {
	font-size: 13px;
	font-weight: 700;
	color: var(--text);
}

.field__hint {
	font-size: 12px;
	color: var(--muted);
}

.field__error {
	font-size: 12px;
	font-weight: 700;
	color: var(--accent);
}

.inputWrap {
	position: relative;
}

.inputWrap__icon {
	position: absolute;
	right: 12px;
	top: 50%;
	transform: translateY(-50%);
	width: 18px;
	height: 18px;
	color: var(--muted);
	pointer-events: none;
}

.inputWrap input,
.inputWrap select,
.inputWrap textarea {
	padding-right: 40px;
}

.input--error,
.select--error,
.textarea--error {
	border-color: rgba(245, 158, 11, 0.55);
}

.formActions {
	display: flex;
	gap: 10px;
	flex-wrap: wrap;
	justify-content: flex-end;
	grid-column: 1 / -1;
	margin-top: 4px;
}

@media (max-width: 639px) {
	.formActions {
		flex-direction: column;
		align-items: stretch;
	}
	.formActions .btn,
	.formActions button {
		width: 100%;
	}
}

/* -------- Auth pages -------- */
.auth {
	min-height: calc(100vh - 32px);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
	position: relative;
	overflow: hidden;
}

.auth::before {
	content: "";
	position: absolute;
	inset: 0;
	background:
		radial-gradient(1200px 600px at 50% -10%, rgba(37, 99, 235, 0.55), transparent 60%),
		radial-gradient(900px 450px at 18% 0%, rgba(16, 185, 129, 0.18), transparent 55%),
		linear-gradient(180deg, rgba(37, 99, 235, 0.22), var(--bg) 70%);
	pointer-events: none;
}

.auth::after {
	content: "";
	position: absolute;
	left: -10vw;
	right: -10vw;
	bottom: -14vh;
	height: min(46vh, 340px);
	background:
		radial-gradient(55% 120% at 20% 100%, rgba(37, 99, 235, 0.22), transparent 60%),
		radial-gradient(65% 140% at 70% 100%, rgba(16, 185, 129, 0.14), transparent 60%),
		linear-gradient(180deg, transparent 0, var(--bg) 65%);
	transform: rotate(-2deg);
	pointer-events: none;
}

.authCard {
	width: 100%;
	max-width: 420px;
	border-radius: var(--radius-md);
	overflow: hidden;
	border: 1px solid var(--border);
	background: var(--card);
	box-shadow: var(--shadow-sm);
	position: relative;
	z-index: 1;
}

.authHero {
	background: linear-gradient(180deg, rgba(37, 99, 235, 0.85), rgba(37, 99, 235, 0.55), rgba(16, 185, 129, 0.35));
	color: #ffffff;
	padding: 30px 18px;
}

.authHero__inner {
	display: grid;
	gap: 6px;
	text-align: center;
}

.authHero__title {
	font-weight: 900;
	font-size: 20px;
	letter-spacing: 0.2px;
}

.authHero__subtitle {
	font-size: 12px;
	opacity: 0.9;
	max-width: 320px;
	margin: 0 auto;
}

.authBody {
	padding: 16px;
	display: grid;
	gap: 12px;
}

.authBody__kicker {
	text-align: center;
	font-weight: 900;
	letter-spacing: 2px;
	font-size: 12px;
	color: var(--muted);
}

.authBody__title {
	margin: 0;
	text-align: center;
}

.authForm {
	gap: 14px;
}

.authInput {
	border-radius: 999px;
	background: rgba(148, 163, 184, 0.10);
}

html[data-theme="dark"] .authInput {
	background: rgba(148, 163, 184, 0.08);
}

.authBtn {
	min-width: 190px;
	border-color: transparent;
	background: linear-gradient(90deg, var(--primary), var(--secondary));
}

.authMeta {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	font-size: 12px;
	color: var(--muted);
}

.authCheck {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	cursor: pointer;
}

.authCheck input {
	width: 16px;
	height: 16px;
	accent-color: var(--primary);
}

.authMeta__hint {
	white-space: nowrap;
}

.authFooter {
	padding: 0 16px 16px;
	text-align: center;
	font-size: 12px;
	color: var(--muted);
}

.authFooter a {
	font-weight: 800;
}

/* -------- Toasts -------- */
.toastHost {
	position: fixed;
	top: calc(var(--topbar-h) + 12px);
	left: 12px;
	right: 12px;
	z-index: 40;
	display: grid;
	gap: 10px;
	pointer-events: none;
}

@media (min-width: 640px) {
	.toastHost {
		left: auto;
		right: 12px;
		width: 360px;
	}
}

.toast {
	pointer-events: auto;
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	padding: 12px;
	background: var(--card);
	box-shadow: var(--shadow-sm);
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 10px;
	animation: toast-in 160ms ease;
}

.toast__text {
	font-size: 13px;
	font-weight: 700;
	color: var(--text);
}

.toast__close {
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	width: 34px;
	height: 34px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: var(--card);
}

.toast--success {
	border-color: rgba(16, 185, 129, 0.35);
	background: rgba(16, 185, 129, 0.08);
}

.toast--error {
	border-color: rgba(245, 158, 11, 0.40);
	background: rgba(245, 158, 11, 0.12);
}

.toast--info {
	border-color: rgba(37, 99, 235, 0.35);
	background: rgba(37, 99, 235, 0.08);
}

@keyframes toast-in {
	from { transform: translateY(-6px); opacity: 0; }
	to { transform: translateY(0); opacity: 1; }
}

/* -------- Submit loader -------- */
.submitOverlay {
	position: fixed;
	inset: 0;
	background: rgba(15, 23, 42, 0.22);
	display: none;
	align-items: center;
	justify-content: center;
	z-index: 45;
}

html[data-theme="dark"] .submitOverlay {
	background: rgba(0, 0, 0, 0.42);
}

body.submitting .submitOverlay {
	display: flex;
}

.spinner {
	width: 44px;
	height: 44px;
	border-radius: 999px;
	border: 3px solid rgba(229, 231, 235, 0.9);
	border-top-color: rgba(37, 99, 235, 0.8);
	background: transparent;
	animation: spin 700ms linear infinite;
}

@keyframes spin {
	from { transform: rotate(0deg); }
	to { transform: rotate(360deg); }
}

.empty {
	color: var(--muted);
	padding: 10px 0;
}

.tableWrap {
	overflow: auto;
	-webkit-overflow-scrolling: touch;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	box-shadow: var(--shadow-sm);
}

@media (max-width: 639px) {
	.tableWrap {
		border-radius: 12px;
	}
}

.table {
	width: 100%;
	border-collapse: collapse;
	min-width: 720px;
	background: var(--card);
}

@media (max-width: 639px) {
	.table {
		min-width: 640px;
	}
	.table th,
	.table td {
		padding: 8px;
		font-size: 12px;
	}
	.truncate {
		max-width: 200px;
	}
}

.table th,
.table td {
	padding: 10px;
	border-bottom: 1px solid var(--border);
	text-align: right;
	vertical-align: top;
	font-size: 13px;
}

.table th {
	color: var(--muted);
	font-weight: 600;
	background: var(--bg);
	position: sticky;
	top: 0;
	z-index: 1;
}

.table tbody tr {
	transition: background-color var(--transition);
}

.table tbody tr:hover {
	background: rgba(37, 99, 235, 0.04);
}

html[data-theme="dark"] .table tbody tr:hover {
	background: rgba(37, 99, 235, 0.12);
}

.table tbody tr:last-child td {
	border-bottom: 0;
}

.truncate {
	max-width: 320px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
