/* Shared styles for tool UIs: toolbars, dropdowns, sidebars, modals, and buttons */

/* Toolbar container */
.tool-toolbar {
	position: fixed;
	top: 4px;
	right: 0.5rem;
	z-index: 40;
	display: flex;
	align-items: center;
	gap: 0.5rem;
	background-color: oklch(from var(--card) l c h / 0.8);
	backdrop-filter: blur(6px);
	border-radius: 0.5rem;
	padding: 0.25rem;
}

/* Icon button inside toolbar */
.tool-icon-btn {
	background: var(--card);
	color: var(--foreground);
	border: 1px solid var(--border);
	padding: 0.5rem;
	border-radius: 0.5rem;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	transition: background-color 150ms, box-shadow 150ms;
	cursor: pointer;
}
.tool-icon-btn:hover {
	background: var(--muted);
	box-shadow: 0 2px 8px #0000001a;
}

/* Dropdown menus from toolbar */
.tool-menu {
	position: absolute;
	right: 0;
	margin-top: 0.25rem;
	width: max-content;
	min-width: 7rem;
	max-width: 12rem;
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 0.375rem;
	box-shadow: 0 8px 24px #0000002e;
	z-index: 50;
}
.tool-menu.hidden { display: none; }
.tool-menu button,
.tool-menu a {
    display: flex;
    width: 100%;
	text-align: left;
	font-size: 0.875rem;
	padding: 0.375rem 0.5rem;
	color: var(--foreground);
	background: transparent;
	border: 0;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	white-space: nowrap;
}
.tool-menu button:hover,
.tool-menu a:hover { background: var(--muted); }

/* Prevent chevrons/icons from shrinking and wrapping to a new line */
.tool-menu svg { flex-shrink: 0; }

/* Submenus (flyouts) appear to the left (toolbar sits on the right edge) */

/* Ensure hover path between parent and submenu remains continuous */
.tool-menu .group > div {
	left: auto !important;
	right: calc(100% - 1px) !important; /* overlap by 1px to avoid hover gap */
	margin-left: 0 !important;
	margin-right: 0 !important;
	width: max-content;
	min-width: 7rem;
	max-width: 12rem;
	white-space: nowrap;
}

/* Touch-friendly submenu support */
.tool-menu .group > div.touch-visible {
	display: block !important;
}

/* Ensure submenus work on both hover and touch */
@media (hover: hover) {
	.tool-menu .group:hover > div {
		display: block;
	}
}

/* For touch devices, rely on JavaScript to show/hide submenus */
@media (hover: none) {
	.tool-menu .group > div {
		display: none;
	}
	.tool-menu .group > div.touch-visible {
		display: block !important;
	}
}

/* Context menu (right-click) */
.tool-context-menu {
	position: absolute;
	z-index: 50;
	background: var(--card);
	color: var(--foreground);
	border: 1px solid var(--border);
	border-radius: 0.375rem;
	box-shadow: 0 10px 24px #0000002e;
	min-width: 10rem;
}
.tool-context-menu.hidden { display: none; }
.tool-context-item {
	display: block;
	width: 100%;
	text-align: left;
	padding: 0.5rem 0.75rem;
	font-size: 0.875rem;
	background: transparent;
	border: 0;
	cursor: pointer;
}
.tool-context-item:hover { background: var(--muted); }
.tool-context-submenu {
	position: absolute;
	left: 100%;
	top: 0;
	z-index: 50;
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 0.375rem;
	box-shadow: 0 10px 24px #0000002e;
	min-width: 8rem;
}

/* Floating style panel (e.g., text style) */
.tool-style-panel {
	position: absolute;
	z-index: 50;
	background: var(--card);
	color: var(--foreground);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: 0 10px 24px #0000002e;
	padding: 0.75rem;
	width: 20rem;
	font-size: 0.875rem;
}
.tool-style-panel .tool-style-label { font-size: 0.75rem; color: var(--muted-foreground); }
.tool-style-panel .tool-style-actions { display: flex; justify-content: flex-end; gap: 0.5rem; padding-top: 0.25rem; }

/* Slide-in sidebars */
.tool-sidebar {
	position: fixed;
	top: 0;
	right: 0;
	height: 100%;
	width: 20rem;
	margin-top: 0;
	background: oklch(from var(--card) l c h / 0.8);
	backdrop-filter: blur(12px);
	border-left: 1px solid var(--border);
	box-shadow: 0 10px 30px #00000040;
	transition: transform 300ms ease-in-out;
	/* Neutralize Tailwind translate utilities to avoid conflicts with transform */
	translate: 0;
	z-index: 50;
}
.tool-sidebar.translate-x-full { transform: translateX(100%); translate: 0 !important; }
.tool-sidebar:not(.translate-x-full) { transform: translateX(0); translate: 0 !important; }
.tool-sidebar-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 1rem;
	border-bottom: 1px solid var(--border);
	background: oklch(from var(--card) l c h / 0.85);
}
.tool-sidebar-body {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 1rem;
	background: oklch(from var(--card) l c h / 0.8);
}

/* Standard buttons for tool UIs */
.tool-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	white-space: nowrap;
	border-radius: var(--radius);
	font-size: 0.875rem;
	font-weight: 600;
	transition: transform 150ms, box-shadow 150ms, background-color 150ms;
	height: 2.75rem;
	padding: 0 1rem;
	border: 1px solid var(--border);
	cursor: pointer;
}
.tool-btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.tool-btn:active { transform: scale(0.98); }
.tool-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.tool-btn-secondary {
	background: var(--secondary);
	color: var(--secondary-foreground);
	border: 1px solid var(--muted-foreground);
	cursor: pointer;
}
.tool-btn-secondary:hover { background: color-mix(in oklch, var(--secondary), black 8%); }

.tool-btn-primary {
	background: var(--primary);
	color: var(--primary-foreground);
	cursor: pointer;
}
.tool-btn-primary:hover { background: color-mix(in oklch, var(--primary), black 6%); }

.tool-btn-success {
	background: #555;
	color: white;
	cursor: pointer;
}
.tool-btn-success:hover { background: #666; }

.tool-btn-danger {
	background: #dc2626;
	color: white;
	cursor: pointer;
}
.tool-btn-danger:hover { background: #b91c1c; }

/* Utility helpers */
.tool-hidden { display: none !important; }
.tool-shadow { box-shadow: 0 4px 16px #00000026; }

/* Modals overlay basic */
.tool-modal-overlay {
	position: fixed;
	inset: 0;
	background: #00000080;
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 50;
}
.tool-modal-overlay.hidden {
	display: none;
}
.tool-modal {
	background: var(--card);
	color: var(--foreground);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 1.5rem;
	max-width: 28rem;
	width: 100%;
}

/* FullCalendar button overrides */
.fc .fc-toolbar-title {
	font-size: 1.125rem; /* 18px on wide screens (default) */
	line-height: 1.5rem;
}
.fc .fc-button-primary {
	background: var(--secondary);
	color: var(--secondary-foreground);
	border-color: var(--border);
}
.fc .fc-button-primary:hover {
	background: color-mix(in oklch, var(--secondary), black 8%);
}
/* Hover border color for all FullCalendar buttons */
.fc .fc-button:hover {
	border-color: color-mix(in oklch, var(--border), black 12%);
}

/* Add Event button styling to use primary color scheme */
#calAddEventBtn {
	background: var(--primary);
	color: var(--primary-foreground);
}
#calAddEventBtn:hover {
	background: color-mix(in oklch, var(--primary), black 6%);
}

/* Save Event button in calendar modal uses primary color scheme */
#calSaveEvent {
	background: var(--primary);
	color: var(--primary-foreground);
}
#calSaveEvent:hover {
	background: color-mix(in oklch, var(--primary), black 6%);
}
/* Active/pressed state (week/day buttons, etc.) */
.fc .fc-button-active,
.fc .fc-button-primary.fc-button-active,
.fc .fc-button-primary:not(:disabled).fc-button-active {
	background: color-mix(in oklch, var(--secondary), black 14%);
	color: var(--secondary-foreground);
	border-color: color-mix(in oklch, var(--border), black 10%);
}

/* Responsive adjustments for FullCalendar and tool toolbar */
@media (max-width: 640px) {
	/* Top-right floating toolbar: smaller and tighter on mobile */
	.tool-toolbar {
		right: 0.25rem;
		top: 0.25rem;
		gap: 0.25rem;
		padding: 0.125rem;
		border-radius: 0.375rem;
	}
	.tool-icon-btn {
		padding: 0.375rem;
		border-radius: 0.375rem;
	}

	/* FullCalendar header toolbar layout */
	.fc .fc-header-toolbar {
		display: grid;
		grid-template-columns: 1fr;
		row-gap: 0.25rem;
		align-items: center;
	}
	/* Ensure segments can wrap neatly */
	.fc .fc-header-toolbar > .fc-toolbar-chunk {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		gap: 0.25rem;
	}
	/* Center title on its own row */
	.fc .fc-toolbar-title {
		font-size: 1rem;
		line-height: 1.25rem;
		text-align: center;
	}
	/* Shrink button sizes and spacing */
	.fc .fc-button {
		padding: 0.25rem 0.5rem;
		font-size: 0.75rem;
		line-height: 1rem;
		height: 2rem;
		border-radius: 0.375rem;
	}
	/* Make the view switch group and prev/next group wrap gracefully */
	.fc .fc-button-group {
		flex-wrap: wrap;
		gap: 0.25rem;
	}
	/* Icons inside prev/next smaller */
	.fc .fc-icon, .fc .fc-button .fc-icon {
		font-size: 0.875rem;
	}
	/* Tighten calendar outer padding container from our template */
	#calendar {
		min-height: 18rem;
	}
	/* Event details action buttons smaller */
	#eventDetails button {
		padding: 0.25rem 0.5rem;
		font-size: 0.75rem;
		line-height: 1rem;
	}
	/* Add Event CTA smaller */
	#calAddEventBtn {
		padding: 0.5rem 0.75rem;
		font-size: 0.875rem;
	}
}
