/* Custom styles placeholder */

/* Base tweaks for readability */
html, body {
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

/* Font - Inter for modern UI */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
body {
	font-family: "Inter", ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

/* Motion tokens */
:root {
	--easing: cubic-bezier(.22, .61, .36, 1);
	--dur-fast: .18s;
	--dur-base: .32s;
	--dur-slow: .6s;
}

/* Design tokens */
:root {
	--sidebar-bg: #0f172a; /* slate-900 */
	--sidebar-bg-2: #111827; /* gray-900 */
	--sidebar-accent: #1f2937; /* gray-800 */
	--sidebar-text: #cbd5e1; /* slate-300 */
	--brand: #6366f1; /* indigo-500 */
	--brand-600: #4f46e5;
	--brand-700: #4338ca;
	--surface: #C7CDEC; /* light app background (preferred) */
	--card-bg: #ffffff;
	--card-border: #e5e7eb;
	--muted: #6b7280;
	--text: #0f172a;
	--ring: rgba(99,102,241,.4);
	--link: #4338ca;
}
html.dark:root {
	--card-bg: #111827;
	--card-border: #374151;
	--muted: #9ca3af;
	--surface: #0b1220;
	--text: #e5e7eb;
	--ring: rgba(99,102,241,.35);
	--link: #93c5fd;
}

/* App surface */
body { background: var(--surface); color: var(--text); }
/* Override Tailwind's bg-gray-100 for light theme across app pages */
html:not(.dark) body.bg-gray-100 { background-color: #C7CDEC !important; }

/* Global link color */
a { color: var(--link); }
a:hover { text-decoration: underline; }

/* Force darker text in light theme for common utility classes */
html:not(.dark) .text-gray-600 { color: #1f2937 !important; } /* gray-800 */
html:not(.dark) .text-gray-500 { color: #374151 !important; } /* gray-700 */
html:not(.dark) .text-gray-400 { color: #4b5563 !important; } /* gray-600 */
html:not(.dark) table thead th, html:not(.dark) table thead { color: #111827 !important; } /* gray-900 */
html:not(.dark) h1, html:not(.dark) h2, html:not(.dark) h3, html:not(.dark) h4, html:not(.dark) h5, html:not(.dark) h6 { color: #0f172a; }

/* Sidebar and content contrast in dark mode */
html.dark .bg-white { background-color: #1f2937 !important; }
html.dark .text-gray-900 { color: #e5e7eb !important; }
html.dark .border-gray-200 { border-color: #374151 !important; }

/* Link focus */
a:focus {
	outline: 2px solid #6366f1;
	outline-offset: 2px;
}

/* Global smooth transitions */
body, .app-topbar, .app-sidebar, .card, .form-input, .form-select, .form-textarea,
.menu-link, .status-pill, .theme-toggle, .btn-primary, .btn-ghost, table, th, td {
	transition:
		background-color var(--dur-base) var(--easing),
		color var(--dur-base) var(--easing),
		border-color var(--dur-base) var(--easing),
		box-shadow var(--dur-base) var(--easing),
		transform var(--dur-fast) var(--easing),
		opacity var(--dur-base) var(--easing);
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after {
		animation-duration: 0.001ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.001ms !important;
		scroll-behavior: auto !important;
	}
}

/* App sidebar (template-inspired) */
.app-sidebar {
	background: radial-gradient(1200px 400px at -150px -100px, var(--sidebar-bg-2), var(--sidebar-bg));
	color: var(--sidebar-text);
	border-right: 1px solid rgba(255,255,255,0.06);
	border-top-right-radius: 1.25rem;
	border-bottom-right-radius: 0;
	box-shadow: 0 10px 30px rgba(2, 6, 23, 0.7);
	transition: width var(--dur-base) var(--easing), background-color var(--dur-base) var(--easing), color var(--dur-base) var(--easing), border-color var(--dur-base) var(--easing);
	height: 100vh;
	overflow: hidden; /* prevent sidebar itself from scrolling; internal area will scroll */
	z-index: 50;
}

/* Ensure the scrollable area can actually shrink inside flex layout */
.app-sidebar .sidebar-content {
	flex: 1 1 auto;
	min-height: 0; /* critical for nested flex + overflow to allow scrolling */
}

/* Mobile specific override for sidebar overlaying */
.app-sidebar.translate-x-0 {
	z-index: 60 !important; /* Ensure it sits above everything on mobile */
	width: min(22rem, 100vw) !important; /* Ensure full width on mobile open */
	max-width: 100vw;
	box-shadow: 0 20px 40px rgba(0,0,0,.35);
}
/* Ensure labels are forced visible when sidebar is open on mobile */
.app-sidebar.translate-x-0 .brand .brand-name,
.app-sidebar.translate-x-0 .menu-link .label,
.app-sidebar.translate-x-0 .promo {
	display: block !important;
}

.app-sidebar .brand {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 1rem 1.25rem;
	font-weight: 700;
	color: #e5e7eb;
}
.app-sidebar .menu {
	padding: 0.25rem 0.5rem 1rem 0.5rem;
	flex: 1 1 auto;                 /* let menu take available vertical space */
	overflow-y: auto;               /* scroll only the menu area if content is tall */
	-ms-overflow-style: none;       /* IE/Edge hide scrollbar */
	scrollbar-width: none;          /* Firefox hide scrollbar */
	-webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
	touch-action: pan-y;            /* allow vertical touch scroll gestures */
	overscroll-behavior: contain;   /* keep scroll gestures local to the menu */
}
.app-sidebar .menu::-webkit-scrollbar { width: 0; height: 0; } /* WebKit hide scrollbar */
/* ensure content isn't hidden behind the bottom logout area */
.app-sidebar .menu { padding-bottom: 4.5rem; }
.app-sidebar .menu-link {
	display: flex;
	align-items: center;
	gap: .625rem;
	padding: .625rem .75rem;
	border-radius: .5rem;
	color: var(--sidebar-text);
	transition:
		background-color var(--dur-fast) var(--easing),
		color var(--dur-fast) var(--easing),
		box-shadow var(--dur-fast) var(--easing),
		transform var(--dur-fast) var(--easing);
}
.app-sidebar .menu-link:hover {
	background: rgba(255,255,255,0.06);
	color: #fff;
	transform: translateX(2px);
}
.app-sidebar .menu-link.active {
	background: linear-gradient(135deg, var(--brand), var(--brand-600));
	color: #fff;
	box-shadow: 0 6px 16px rgba(99,102,241,.35);
}
.app-sidebar .promo {
	background: linear-gradient(135deg, #0ea5e9, #8b5cf6);
	color: #fff;
	border-radius: .75rem;
	padding: .875rem;
	display: flex;
	align-items: center;
	gap: .75rem;
	margin: 1rem;
	box-shadow: 0 10px 25px rgba(0,0,0,.25);
}
.app-sidebar .promo img {
	width: 44px;
	height: 44px;
	border-radius: .5rem;
	object-fit: cover;
}

/* Header / topbar */
.app-topbar {
	background: #ffffff;
	border-bottom: 1px solid var(--card-border);
	backdrop-filter: saturate(180%) blur(8px);
	position: sticky;
	top: 0;
	z-index: 30;
	transition: background-color var(--dur-base) var(--easing), border-color var(--dur-base) var(--easing);
}
html.dark .app-topbar {
	background: #0b1324;
	border-color: #1f2937;
}
/* Sun/Moon theme toggle */
.theme-toggle {
	border: 1px solid var(--card-border);
	border-radius: .5rem;
	padding: .25rem .5rem;
	font-size: 1rem;
	line-height: 1;
	background: #fff;
	color: #111827;
	box-shadow: 0 1px 1px rgba(0,0,0,.02);
	transform-origin: center;
}
html.dark .theme-toggle {
	background: #111827;
	color: #e5e7eb;
	border-color: #374151;
}
.theme-toggle .sun { display: inline; }
.theme-toggle .moon { display: none; }
html.dark .theme-toggle .sun { display: none; }
html.dark .theme-toggle .moon { display: inline; }
.theme-toggle:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(0,0,0,.08); }
.theme-toggle:active { transform: translateY(0); }

.avatar {
	width: 28px;
	height: 28px;
	border-radius: 999px;
	background: linear-gradient(135deg, var(--brand), var(--brand-700));
	display: inline-flex;
	align-items: center;
	justify-content: center;
	color: #fff;
	font-weight: 700;
	font-size: .75rem;
}

/* Cards */
.card {
	background: var(--card-bg);
	border: 1px solid var(--card-border);
	border-radius: .75rem;
	box-shadow:
		0 1px 1px rgba(0,0,0,0.02),
		0 4px 12px rgba(0,0,0,0.06);
	transition: box-shadow .2s ease, transform .2s ease;
}
.card:hover { box-shadow: 0 6px 24px rgba(0,0,0,.08); transform: translateY(-1px); }

/* Page entrance animation */
html.pre-animate main .card,
html.pre-animate main .kpi,
html.pre-animate main table,
html.pre-animate .promo,
html.pre-animate canvas {
	opacity: 0;
	transform: translateY(6px) scale(0.995);
}
html.animate main .card,
html.animate main .kpi,
html.animate main table,
html.animate .promo,
html.animate canvas {
	opacity: 1;
	transform: none;
	transition:
		opacity var(--dur-slow) var(--easing),
		transform var(--dur-slow) var(--easing);
}
/* Stagger common grids */
html.animate .grid > *:nth-child(1) { transition-delay: 40ms; }
html.animate .grid > *:nth-child(2) { transition-delay: 80ms; }
html.animate .grid > *:nth-child(3) { transition-delay: 120ms; }
html.animate .grid > *:nth-child(4) { transition-delay: 160ms; }
html.animate .grid > *:nth-child(5) { transition-delay: 200ms; }
html.animate .grid > *:nth-child(6) { transition-delay: 240ms; }

.card .card-header {
	padding: 1rem;
	border-bottom: 1px solid var(--card-border);
	font-weight: 600;
}
.card .card-body { padding: 1rem; }
.card .muted { color: var(--muted); }
.segmented {
	display: inline-flex;
	background: #f3f4f6;
	border: 1px solid var(--card-border);
	border-radius: .625rem;
	overflow: hidden;
}
.segmented button {
	padding: .375rem .75rem;
	font-size: .8125rem;
	color: #374151;
}
.segmented button.active {
	background: #fff;
	color: #111827;
	box-shadow: inset 0 0 0 1px var(--card-border);
}
.card .card-title {
	font-weight: 600;
	color: #111827;
}
html.dark .card .card-title { color: #e5e7eb; }
.kpi .value { font-size: 1.5rem; font-weight: 700; }
.kpi .label { color: var(--muted); font-size: .8125rem; }

/* Tables */
table thead tr { background: rgba(0,0,0,0.03); }
html.dark table thead tr { background: rgba(255,255,255,0.06); }
table tbody tr { transition: background-color .15s ease; }
table tbody tr:hover { background: rgba(99,102,241,0.06); }
html.dark table tbody tr:hover { background: rgba(99,102,241,0.1); }
table tbody tr:nth-child(odd) { background: rgba(0,0,0,0.015); }
html.dark table tbody tr:nth-child(odd) { background: rgba(255,255,255,0.025); }
th, td { vertical-align: middle; }

/* Status pills (Paid, Declined, In progress, etc.) - generic */
.status-pill {
	display: inline-flex;
	align-items: center;
	gap: .375rem;
	padding: .125rem .5rem;
	border-radius: 999px;
	font-size: .75rem;
	font-weight: 600;
	box-shadow: inset 0 0 0 1px rgba(0,0,0,.04);
}
.status-green { background: rgba(16,185,129,.12); color: #059669; }
.status-red { background: rgba(239,68,68,.12); color: #dc2626; }
.status-blue { background: rgba(59,130,246,.12); color: #2563eb; }

/* Forms */
.form-grid { display: grid; gap: .75rem; }
.form-row { display: grid; grid-template-columns: 1fr 2fr; gap: .75rem; }
.form-label { font-size: .8125rem; color: var(--muted); }
.form-input, .form-select, .form-textarea {
	background: #fff;
	color: #111827;
	border: 1px solid var(--card-border);
	border-radius: .5rem;
	padding: .5rem .625rem;
	transition: box-shadow .15s ease, border-color .15s ease;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
	outline: none;
	border-color: var(--brand);
	box-shadow: 0 0 0 4px var(--ring);
}
html.dark .form-input, html.dark .form-select, html.dark .form-textarea {
	background: #0f172a;
	color: #e5e7eb;
	border-color: #1f2937;
}

/* Button variants */
.btn-primary {
	background: linear-gradient(135deg, var(--brand), var(--brand-600));
	color: #fff;
	border: 0;
	border-radius: .5rem;
	padding: .5rem .875rem;
	font-weight: 600;
	box-shadow: 0 6px 16px rgba(99,102,241,.25);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(99,102,241,.28); }
.btn-primary:active { transform: translateY(0); box-shadow: 0 3px 10px rgba(99,102,241,.2); }
.btn-ghost {
	background: transparent;
	color: var(--brand-600);
	border: 1px solid var(--card-border);
	border-radius: .5rem;
	padding: .5rem .875rem;
}
.btn-ghost:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(0,0,0,.06); }
.btn-ghost:active { transform: translateY(0); }

/* Floating dropdown panels (navbar menus) */
.dropdown-panel {
	position: fixed;
	top: 3.5rem; /* ~ top-14 */
	right: 0.5rem;
	width: 20rem;
	max-width: 90vw;
	background: var(--card-bg);
	border: 1px solid var(--card-border);
	border-radius: .75rem;
	box-shadow: 0 10px 30px rgba(0,0,0,.15);
	z-index: 50;
	overflow: hidden;
}
.dropdown-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: .5rem .75rem;
	border-bottom: 1px solid var(--card-border);
	font-weight: 600;
}
.dropdown-body { max-height: 16rem; overflow: auto; }
.dropdown-footer {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: .5rem;
	padding: .5rem .75rem;
	border-top: 1px solid var(--card-border);
}

/* Quiet search input */
.search-wrap { position: relative; }
.search-wrap .search-icon {
	position: absolute;
	left: .5rem;
	top: 50%;
	transform: translateY(-50%);
	pointer-events: none;
	color: #9ca3af;
}
.search-input {
	padding-left: 2rem;
	border-radius: .5rem;
	background: #f5f6f8;
	border: 1px solid transparent;
	color: #111827;
	line-height: 1.25;
	height: 34px;
}
html.dark .search-input {
	background: #111827;
	border-color: #1f2937;
	color: #e5e7eb;
}
.search-input::placeholder { color: #9ca3af; }
.search-input:hover { border-color: var(--card-border); background: #f9fafb; }
.search-input:focus {
	background: #ffffff;
	border-color: var(--brand);
	box-shadow: 0 0 0 2px var(--ring);
	outline: none;
}
html.dark .search-input:focus { background: #0f172a; }

/* Subtle topbar icon buttons */
.topbar-btn {
	border-radius: .5rem;
	padding: .25rem .5rem;
}
.topbar-btn:hover { background: rgba(17,24,39,.05); }
html.dark .topbar-btn:hover { background: rgba(255,255,255,.06); }

/* Collapsed sidebar styles */
.app-sidebar.collapsed { width: 72px !important; }
.app-sidebar .brand { position: sticky; top: 0; z-index: 10; }
 .app-sidebar .brand .brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: .5rem; background: transparent; color: inherit; }
 .app-sidebar .brand .brand-mark img { display: block; width: 100%; height: 100%; object-fit: contain; background: transparent; }
.app-sidebar .brand .brand-name { margin-left: .5rem; }
.app-sidebar.collapsed .brand .brand-name { display: none; }
.app-sidebar .menu-link { display: flex; align-items: center; }
.app-sidebar .menu-link .icon { width: 20px; height: 20px; color: #cbd5e1; }
.app-sidebar .menu-link .label { margin-left: .5rem; color: inherit; }
.app-sidebar.collapsed .menu-link { justify-content: center; }
.app-sidebar.collapsed .menu-link .label { display: none; }
.app-sidebar.collapsed .promo { display: none; }

/* Submenu styles adapted to pro-sidebar-template naming */
.app-sidebar .menu-item.sub-menu > .menu-toggle {
	display: flex;
	align-items: center;
	justify-content: flex-start;
	width: 100%;
	padding: .625rem .75rem;
	border-radius: .5rem;
	color: var(--sidebar-text);
	background: transparent;
}
.app-sidebar .menu-item.sub-menu > .menu-toggle:hover {
	background: rgba(255,255,255,0.06);
	color: #fff;
}
/* Previously .submenu; now we use .sub-menu-list wrapper */
.app-sidebar .sub-menu-list {
	display: none;
	padding-left: .5rem;
	margin-top: .25rem;
	margin-bottom: .25rem;
}
.app-sidebar .menu-item.sub-menu.open > .sub-menu-list {
	display: block;
}
/* Align padding and caret like the template */
.app-sidebar .menu-item.sub-menu > .menu-toggle.menu-link {
	padding-left: .75rem;
}
.app-sidebar .menu-item.sub-menu > .menu-toggle .caret {
	margin-left: auto;
}

/* Mobile: make sidebar an overlay that does NOT push content */
@media (max-width: 768px) {
	/* Form & controls stack nicely */
	.form-row { grid-template-columns: 1fr; }
	.form-input, .form-select, .form-textarea { width: 100%; }
	.btn-primary, .btn-ghost { width: 100%; min-height: 40px; }
	.search-input { max-width: 100%; width: 100%; }

	/* On small screens, treat sidebar as a pure overlay:
	   - It should not reserve horizontal space in the flex layout
	   - When opened, it floats above the page content */
	.app-sidebar {
		/* Remove reserved width so main content can use full width when sidebar is hidden */
		flex: 0 0 auto !important;
		width: 0 !important;
	}
	.app-sidebar.translate-x-0 {
		width: min(22rem, 100vw) !important; /* visible width when open as drawer */
	}
}

/* Premium global page loader (splash) */
.page-loader {
	position: fixed;
	inset: 0;
	z-index: 9999;
	display: flex;
	align-items: center;
	justify-content: center;
	background:
		radial-gradient(circle at 10% 0%, rgba(219,234,254,0.9), rgba(199,205,236,0.96)),
		radial-gradient(circle at 100% 100%, rgba(221,214,254,0.9), rgba(199,205,236,0.96));
	backdrop-filter: blur(18px) saturate(160%);
	-webkit-backdrop-filter: blur(18px) saturate(160%);
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition:
		opacity 0.35s var(--easing),
		visibility 0.35s var(--easing),
		background-color 0.35s var(--easing);
}
html.dark .page-loader {
	background:
		radial-gradient(circle at 10% 0%, rgba(15,23,42,0.96), rgba(15,23,42,0.98)),
		radial-gradient(circle at 100% 100%, rgba(15,23,42,0.96), rgba(15,23,42,0.98));
}
.page-loader--active {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
}
.page-loader__backdrop {
	position: absolute;
	inset: 0;
	background: radial-gradient(circle at top, rgba(255,255,255,0.18), transparent 55%);
	display: flex;
	align-items: center;
	justify-content: center;
}
html.dark .page-loader__backdrop {
	background: radial-gradient(circle at top, rgba(15,23,42,0.8), transparent 55%);
}
.page-loader__card {
	position: relative;
	z-index: 1;
	padding: 2.5rem 2.75rem 2.25rem;
	border-radius: 1.75rem;
	background: rgba(255,255,255,0.96);
	box-shadow:
		0 22px 60px rgba(15,23,42,0.35),
		0 0 0 1px rgba(148,163,184,0.22);
	display: flex;
	flex-direction: column;
	align-items: center;
	min-width: 260px;
	max-width: 320px;
	gap: 0.75rem;
	animation: loaderPop 0.6s var(--easing) forwards;
}
html.dark .page-loader__card {
	background: rgba(15,23,42,0.96);
	box-shadow:
		0 22px 60px rgba(15,23,42,0.85),
		0 0 0 1px rgba(30,64,175,0.4);
}
.page-loader__logo-wrap {
	position: relative;
	width: 88px;
	height: 88px;
	display: flex;
	align-items: center;
	justify-content: center;
}
.page-loader__ring {
	position: absolute;
	inset: 0;
	border-radius: 999px;
	border: 2px solid rgba(148,163,184,0.35);
	border-top-color: var(--brand);
	border-right-color: var(--brand-600);
	box-shadow:
		0 0 0 1px rgba(148,163,184,0.25),
		0 0 24px rgba(129,140,248,0.45);
	animation: loaderSpin 1.3s linear infinite;
}
.page-loader__ring::after {
	content: "";
	position: absolute;
	inset: -8px;
	border-radius: inherit;
	border: 1px solid rgba(129,140,248,0.4);
	filter: blur(3px);
	opacity: 0.65;
}
.page-loader__logo {
	position: relative;
	width: 64px;
	height: 64px;
	border-radius: 1.25rem;
	object-fit: contain;
	background: radial-gradient(circle at 30% 0%, rgba(255,255,255,0.9), rgba(226,232,240,0.9));
	box-shadow:
		0 10px 25px rgba(15,23,42,0.35),
		0 0 0 1px rgba(148,163,184,0.35);
	animation:
		loaderZoomIn 0.6s var(--easing) both,
		loaderPulse 1.7s ease-in-out infinite;
}
html.dark .page-loader__logo {
	background: radial-gradient(circle at 30% 0%, rgba(31,41,55,0.98), rgba(15,23,42,0.98));
	box-shadow:
		0 10px 28px rgba(15,23,42,0.9),
		0 0 0 1px rgba(30,64,175,0.5);
}
.page-loader__name {
	margin-top: 1.25rem;
	font-size: 0.9rem;
	font-weight: 700;
	letter-spacing: 0.25em;
	text-transform: uppercase;
	color: #111827;
	text-align: center;
	opacity: 0.9;
	animation: loaderLabelSlide 0.7s var(--easing) both;
}
html.dark .page-loader__name {
	color: #e5e7eb;
	opacity: 0.96;
}
.page-loader__hint {
	font-size: 0.78rem;
	color: #6b7280;
	text-align: center;
	margin-top: 0.1rem;
	opacity: 0.85;
}
html.dark .page-loader__hint {
	color: #9ca3af;
}

@keyframes loaderPop {
	0% {
		opacity: 0;
		transform: translateY(10px) scale(0.96);
	}
	60% {
		opacity: 1;
		transform: translateY(0) scale(1.02);
	}
	100% {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}
@keyframes loaderZoomIn {
	0% {
		transform: scale(0.9);
	}
	100% {
		transform: scale(1);
	}
}
@keyframes loaderPulse {
	0%, 100% {
		box-shadow:
			0 10px 22px rgba(15,23,42,0.40),
			0 0 0 0 rgba(129,140,248,0.45);
	}
	50% {
		box-shadow:
			0 18px 40px rgba(15,23,42,0.6),
			0 0 0 8px rgba(129,140,248,0);
	}
}
@keyframes loaderSpin {
	from {
		transform: rotate(0deg);
	}
	to {
		transform: rotate(360deg);
	}
}
@keyframes loaderLabelSlide {
	0% {
		opacity: 0;
		transform: translateY(6px);
	}
	100% {
		opacity: 1;
		transform: translateY(0);
	}
}
