/**
 * RatNotes Frontend Styles
 *
 * @package RatNotes
 */

.ratnotes-frontend {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
	max-width: 1400px;
	margin: 0 auto;
	padding: 20px;
	background-color: #1e1e2e;
	color: #cdd6f4;
	border-radius: 12px;
	position: relative;
}

.ratnotes-frontend-sidebar-overlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.45);
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity 0.2s ease;
	z-index: 9998;
}

.ratnotes-frontend-sidebar {
	position: fixed;
	top: 0;
	left: 0;
	width: 280px;
	height: 100vh;
	background: #232538;
	border-right: 1px solid #45475a;
	box-shadow: 8px 0 24px rgba(0, 0, 0, 0.35);
	transform: translateX(-100%);
	transition: transform 0.25s ease;
	z-index: 9999;
	overflow-y: auto;
}

.ratnotes-frontend.sidebar-open .ratnotes-frontend-sidebar {
	transform: translateX(0);
}

.ratnotes-frontend.sidebar-open .ratnotes-frontend-sidebar-overlay {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
}

.ratnotes-frontend-sidebar-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 16px;
	border-bottom: 1px solid #45475a;
}

.ratnotes-frontend-sidebar-header h3 {
	margin: 0;
	font-size: 16px;
	color: #cdd6f4;
}

.ratnotes-frontend-sidebar-close {
	border: none;
	background: transparent;
	color: #a6adc8;
	cursor: pointer;
	padding: 4px;
	border-radius: 6px;
}

.ratnotes-frontend-sidebar-close:hover {
	background: #313244;
	color: #cdd6f4;
}

.ratnotes-frontend-category-list {
	display: flex;
	flex-direction: column;
	gap: 4px;
	padding: 12px;
}

.ratnotes-frontend-category-create-wrap {
	padding: 12px 12px 4px;
	border-bottom: 1px solid #45475a;
}

.ratnotes-frontend-category-create-form {
	display: flex;
	gap: 6px;
	align-items: center;
}

.ratnotes-frontend-category-create-input {
	flex: 1;
	padding: 8px 10px;
	background: #313244;
	border: 1px solid #45475a;
	border-radius: 6px;
	color: #cdd6f4;
	font-size: 13px;
	min-width: 0;
}

.ratnotes-frontend-category-create-input:focus {
	outline: none;
	border-color: #89b4fa;
	background: #45475a;
}

.ratnotes-frontend-category-create-input::placeholder {
	color: #6c7086;
}

.ratnotes-frontend-category-create-submit {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	width: 32px;
	height: 32px;
	flex-shrink: 0;
	background: #89b4fa;
	border: none;
	border-radius: 6px;
	color: #1e1e2e;
	cursor: pointer;
}

.ratnotes-frontend-category-create-submit:hover {
	background: #b4befe;
}

.ratnotes-frontend-category-create-submit:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.ratnotes-frontend-category-create-error {
	margin-top: 6px;
	font-size: 12px;
	color: #f38ba8;
}

.ratnotes-frontend-offline-banner {
	margin-bottom: 12px;
	padding: 10px 12px;
	border: 1px solid rgba(137, 180, 250, 0.35);
	border-radius: 8px;
	background: rgba(137, 180, 250, 0.12);
	color: #cdd6f4;
	font-size: 13px;
	font-weight: 500;
}

.ratnotes-frontend-offline-banner.notice-info {
	border-color: rgba(137, 180, 250, 0.35);
	background: rgba(137, 180, 250, 0.12);
	color: #cdd6f4;
}

.ratnotes-frontend-offline-banner.notice-success {
	border-color: rgba(166, 227, 161, 0.45);
	background: rgba(166, 227, 161, 0.14);
	color: #a6e3a1;
}

.ratnotes-frontend-offline-banner.notice-error {
	border-color: rgba(243, 139, 168, 0.45);
	background: rgba(243, 139, 168, 0.14);
	color: #f38ba8;
}

.ratnotes-frontend-install-hint {
	margin-bottom: 12px;
	padding: 10px 12px;
	border: 1px solid rgba(249, 226, 175, 0.45);
	border-radius: 8px;
	background: rgba(249, 226, 175, 0.12);
	color: #f9e2af;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	font-size: 13px;
	font-weight: 500;
}

.ratnotes-frontend-install-hint-text {
	line-height: 1.4;
}

.ratnotes-frontend-install-hint-close {
	border: none;
	background: transparent;
	color: #f9e2af;
	cursor: pointer;
	font-size: 18px;
	line-height: 1;
	padding: 0;
	width: 22px;
	height: 22px;
	border-radius: 999px;
	flex: 0 0 auto;
}

.ratnotes-frontend-install-hint-close:hover {
	background: rgba(249, 226, 175, 0.2);
}

.ratnotes-frontend-category-item {
	text-align: left;
	border: none;
	background: transparent;
	color: #a6adc8;
	cursor: pointer;
	padding: 10px 12px;
	border-radius: 8px;
	font-size: 14px;
	transition: background-color 0.2s, color 0.2s;
}

.ratnotes-frontend-category-item:hover {
	background: #313244;
	color: #cdd6f4;
}

.ratnotes-frontend-category-item.active {
	background: #45475a;
	color: #89b4fa;
}

/* Navigation */
.ratnotes-frontend-nav {
	display: flex;
	gap: 10px;
	margin-bottom: 20px;
	border-bottom: 1px solid #45475a;
	padding-bottom: 10px;
}

.ratnotes-frontend-nav-item {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 8px 16px;
	border: none;
	background: transparent;
	cursor: pointer;
	border-radius: 20px;
	font-size: 14px;
	color: #a6adc8;
	transition: background-color 0.2s, color 0.2s;
}

.ratnotes-frontend-nav-item:hover {
	background-color: #313244;
	color: #cdd6f4;
}

.ratnotes-frontend-nav-item.active {
	background-color: #45475a;
	color: #89b4fa;
}

.ratnotes-frontend-nav-item .dashicons {
	font-size: 18px;
	width: 18px;
	height: 18px;
}

/* Header */
.ratnotes-frontend-header {
	display: flex;
	gap: 15px;
	margin-bottom: 20px;
	align-items: center;
	flex-wrap: wrap;
}

.ratnotes-frontend-menu-toggle {
	min-width: 40px;
	height: 40px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: #313244;
	border: 1px solid #45475a;
	color: #cdd6f4;
	cursor: pointer;
}

.ratnotes-frontend-menu-toggle:hover {
	background: #45475a;
}

.ratnotes-frontend-search {
	flex: 1;
	min-width: 200px;
}

.ratnotes-frontend-search-input {
	width: 100%;
	padding: 12px 16px;
	border: 1px solid #45475a;
	border-radius: 8px;
	font-size: 14px;
	background-color: #313244;
	color: #cdd6f4;
	transition: background-color 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.ratnotes-frontend-search-input:focus {
	outline: none;
	background-color: #45475a;
	border-color: #89b4fa;
	box-shadow: 0 0 0 3px rgba(137, 180, 250, 0.2);
}

.ratnotes-frontend-search-input::placeholder {
	color: #6c7086;
}

.ratnotes-frontend-search-input::-webkit-search-cancel-button {
	-webkit-appearance: none;
	appearance: none;
	height: 18px;
	width: 18px;
	cursor: pointer;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23a6adc8'%3E%3Cpath d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/%3E%3C/svg%3E");
	background-size: contain;
	background-repeat: no-repeat;
	background-position: center;
}

.ratnotes-frontend-search-input::-webkit-search-cancel-button:hover {
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23cdd6f4'%3E%3Cpath d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/%3E%3C/svg%3E");
}

.ratnotes-frontend-create-btn {
	display: flex;
	align-items: center;
	gap: 6px;
	background-color: #89b4fa;
	color: #1e1e2e;
	border: none;
}

.ratnotes-frontend-create-btn:hover {
	background-color: #b4befe;
}

.ratnotes-frontend-selected-category {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin: 0 0 16px;
	padding: 10px 12px;
	border-left: 3px solid #89b4fa;
	background: rgba(137, 180, 250, 0.08);
	border-radius: 8px;
	color: #cdd6f4;
	font-size: 14px;
	font-weight: 500;
}

.ratnotes-frontend-selected-category-text {
	line-height: 1.2;
}

.ratnotes-frontend-clear-category {
	order: -1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	margin-left: 0;
	margin-right: 2px;
	padding: 0;
	border: 1px solid rgba(137, 180, 250, 0.75);
	border-radius: 999px;
	background: rgba(137, 180, 250, 0.22);
	color: #cdd6f4;
	font-size: 16px;
	font-weight: 700;
	line-height: 1;
	cursor: pointer;
}

.ratnotes-frontend-clear-category:hover {
	background: rgba(137, 180, 250, 0.4);
	color: #ffffff;
}

.ratnotes-frontend-clear-category:focus {
	outline: none;
	box-shadow: 0 0 0 2px rgba(137, 180, 250, 0.25);
}

.ratnotes-frontend-selected-category-wrap {
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin-bottom: 16px;
}

.ratnotes-frontend-category-create-btn {
	display: none;
	margin: 0;
	align-self: flex-start;
	background-color: #89b4fa;
	color: #1e1e2e;
}

.ratnotes-frontend-category-create-btn:hover {
	background-color: #b4befe;
}

/* Grid */
.ratnotes-frontend-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 16px;
}

.ratnotes-frontend-grid[data-columns="2"] {
	grid-template-columns: repeat(2, 1fr);
}

.ratnotes-frontend-grid[data-columns="4"] {
	grid-template-columns: repeat(4, 1fr);
}

.ratnotes-frontend-grid[data-columns="5"] {
	grid-template-columns: repeat(5, 1fr);
}

/* Loading */
.ratnotes-frontend-loading {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 60px 20px;
	color: #a6adc8;
}

.ratnotes-frontend-loading .spinner {
	float: none;
	margin-bottom: 15px;
}

/* Note Card */
.ratnotes-frontend-note {
	display: flex;
	flex-direction: column;
	background-color: #313244;
	border: 1px solid #45475a;
	border-radius: 8px;
	padding: 16px;
	cursor: pointer;
	transition: box-shadow 0.2s, transform 0.1s, background-color 0.2s;
	position: relative;
	min-height: 200px;
	/* Allow the card to shrink to its grid track instead of stretching to
	   fit an unbreakable token (e.g. a long pasted URL) and blowing out the column. */
	min-width: 0;
	color: #cdd6f4;
}

.ratnotes-frontend-note:hover {
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
	background-color: #45475a;
}

.ratnotes-frontend-note:active {
	transform: scale(0.99);
}

.ratnotes-frontend-note.pinned {
	border: 2px solid #89b4fa;
}

.ratnotes-frontend-note.pinned::before {
	content: "";
	position: absolute;
	top: -2px;
	right: -2px;
	width: 20px;
	height: 20px;
	background-color: #89b4fa;
	border-radius: 0 8px 0 8px;
}

.ratnotes-frontend-note.pinned::after {
	content: "";
	position: absolute;
	top: 2px;
	right: 2px;
	width: 12px;
	height: 12px;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%231e1e2e'%3E%3Cpath d='M16 12V4H8v8l-2 2v2h5v6l1 2 1-2v-6h5v-2l-2-2z'/%3E%3C/svg%3E");
	background-size: contain;
}

.ratnotes-frontend-note-title {
	font-size: 16px;
	font-weight: 600;
	margin-bottom: 8px;
	color: #cdd6f4;
	line-height: 1.4;
	overflow-wrap: anywhere;
}

.ratnotes-frontend-note:empty + .ratnotes-frontend-note-content {
	margin-top: 0;
}

.ratnotes-frontend-note-content {
	font-size: 14px;
	color: #bac2de;
	line-height: 1.6;
	white-space: pre-wrap;
	word-wrap: break-word;
	/* anywhere (unlike break-word) lets long unbreakable tokens like URLs
	   break for wrapping AND shrink the min-content used for grid sizing. */
	overflow-wrap: anywhere;
	flex: 1;
}

/*
 * Card preview only: show the first several lines then hard-clip with no
 * ellipsis. max-height is a whole multiple of the line height (1.6 x 14px)
 * so text is never cut mid-line. Scoped to cards inside .ratnotes-frontend-note
 * so it never touches the modal editor textarea (full note stays intact).
 */
.ratnotes-frontend-note .ratnotes-frontend-note-content {
	min-height: 0;
	max-height: 9.6em;
	overflow: hidden;
}

.ratnotes-frontend-note-labels {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 12px;
}

.ratnotes-frontend-label {
	display: inline-block;
	padding: 4px 10px;
	background-color: rgba(255, 255, 255, 0.1);
	border-radius: 12px;
	font-size: 12px;
	color: #a6adc8;
}

.ratnotes-frontend-note-category {
	margin-top: auto;
	display: inline-flex;
	align-self: flex-start;
	padding: 4px 10px;
	border-radius: 999px;
	background: rgba(137, 180, 250, 0.14);
	color: #89b4fa;
	font-size: 12px;
	font-weight: 600;
	line-height: 1.2;
}

.ratnotes-frontend-note-restore {
	margin-top: 10px;
	align-self: flex-start;
	border: none;
	background: transparent;
	color: #89b4fa;
	font-size: 12px;
	font-weight: 600;
	cursor: pointer;
	padding: 0;
	text-decoration: underline;
}

.ratnotes-frontend-note-restore:hover {
	color: #b4befe;
}

/* Empty State */
.ratnotes-frontend-empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 60px 20px;
	color: #a6adc8;
	grid-column: 1 / -1;
}

.ratnotes-frontend-empty .dashicons {
	font-size: 48px;
	width: 48px;
	height: 48px;
	margin-bottom: 16px;
	opacity: 0.5;
}

.ratnotes-frontend-empty h3 {
	margin: 0 0 8px;
	font-size: 18px;
	font-weight: 500;
	color: #cdd6f4;
}

.ratnotes-frontend-empty p {
	margin: 0;
	font-size: 14px;
}

/* Modal */
.ratnotes-frontend-modal {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
}

.ratnotes-frontend-modal-overlay {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: rgba(0, 0, 0, 0.7);
}

.ratnotes-frontend-modal-content {
	position: relative;
	background-color: #1e1e2e;
	border-radius: 8px;
	width: 90%;
	max-width: 600px;
	max-height: 90vh;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
	border: 1px solid #45475a;
}

.ratnotes-frontend-modal-header {
	display: flex;
	align-items: center;
	padding: 16px;
	border-bottom: 1px solid #45475a;
}

input.ratnotes-frontend-note-title {
	flex: 1;
	border: none;
	font-size: 18px;
	font-weight: 600;
	padding: 8px;
	margin-right: 10px;
	background-color: transparent;
	color: #cdd6f4;
}

input.ratnotes-frontend-note-title:focus {
	outline: none;
}

.ratnotes-frontend-modal-close {
	background: transparent;
	border: none;
	cursor: pointer;
	padding: 8px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background-color 0.2s;
	color: #a6adc8;
}

.ratnotes-frontend-modal-close:hover {
	background-color: #313244;
	color: #cdd6f4;
}

.ratnotes-frontend-modal-body {
	flex: 1;
	padding: 16px;
	overflow-y: auto;
}

textarea.ratnotes-frontend-note-content {
	width: 100%;
	min-height: 200px;
	border: none;
	resize: vertical;
	font-size: 14px;
	line-height: 1.6;
	padding: 8px;
	font-family: inherit;
	background-color: transparent;
	color: #bac2de;
}

textarea.ratnotes-frontend-note-content:focus {
	outline: none;
}

textarea.ratnotes-frontend-note-content::placeholder {
	color: #6c7086;
}

.ratnotes-frontend-modal-footer {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 12px 16px;
	border-top: 1px solid #45475a;
	background-color: #313244;
}

.ratnotes-frontend-actions {
	display: flex;
	gap: 8px;
	align-items: center;
}

.ratnotes-frontend-actions .button {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 8px 12px;
	min-width: 32px;
	min-height: 32px;
	background-color: #45475a;
	color: #cdd6f4;
	border: none;
	cursor: pointer;
}

.ratnotes-frontend-actions .button:hover {
	background-color: #585b70;
}

.ratnotes-frontend-actions .button-primary {
	background-color: #89b4fa;
	color: #1e1e2e;
}

.ratnotes-frontend-actions .button-primary:hover {
	background-color: #b4befe;
}

.ratnotes-frontend-actions .dashicons {
	font-size: 18px;
	width: 18px;
	height: 18px;
	line-height: 18px;
	display: inline-block;
	text-align: center;
}

.ratnotes-frontend-category-picker {
	position: relative;
	margin-left: auto;
}

.ratnotes-frontend-category-trigger {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	max-width: 220px;
}

.ratnotes-frontend-category-trigger-text {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.ratnotes-frontend-category-menu {
	position: absolute;
	right: 0;
	bottom: calc(100% + 8px);
	min-width: 220px;
	max-height: 220px;
	overflow-y: auto;
	padding: 8px;
	border: 1px solid #585b70;
	border-radius: 8px;
	background: #1e1e2e;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
	display: none;
	z-index: 100001;
}

.ratnotes-frontend-category-picker.open .ratnotes-frontend-category-menu {
	display: block;
}

.ratnotes-frontend-category-option {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 6px 4px;
	font-size: 13px;
	color: #cdd6f4;
	cursor: pointer;
}

.ratnotes-frontend-category-option input[type="checkbox"] {
	margin: 0;
}

.ratnotes-frontend-category-empty {
	padding: 8px 6px;
	font-size: 13px;
	color: #a6adc8;
}

/* Responsive */
@media (max-width: 1024px) {
	.ratnotes-frontend-grid[data-columns="5"],
	.ratnotes-frontend-grid[data-columns="4"] {
		grid-template-columns: repeat(3, 1fr);
	}
}

@media (max-width: 768px) {
	.ratnotes-frontend-grid {
		grid-template-columns: repeat(2, 1fr);
	}

	.ratnotes-frontend-header {
		flex-direction: column;
		align-items: stretch;
	}

	.ratnotes-frontend-nav {
		flex-wrap: wrap;
	}

	/*
	 * On phones the modal becomes a near-full-height sheet instead of a
	 * content-sized box. dvh tracks the real viewport on iOS (with a vh
	 * fallback), and the body/textarea flex to fill the extra height.
	 */
	.ratnotes-frontend-modal-content {
		width: 95%;
		height: 92vh;
		height: 92dvh;
		max-height: 92vh;
		max-height: 92dvh;
	}

	.ratnotes-frontend-modal-body {
		display: flex;
		flex-direction: column;
	}

	textarea.ratnotes-frontend-note-content {
		flex: 1;
		height: 100%;
	}
}

/*
 * iOS auto-zooms the page whenever a focused text field has a font-size
 * below 16px, and never zooms back out. Force focusable fields to 16px on
 * touch devices so tapping into a note (or search) never triggers the zoom.
 * Scoped to coarse pointers so desktop sizing is untouched.
 */
@media (pointer: coarse) {
	textarea.ratnotes-frontend-note-content,
	input.ratnotes-frontend-note-title,
	.ratnotes-frontend-search-input,
	.ratnotes-frontend-category-create-input {
		font-size: 16px;
	}
}

@media (max-width: 480px) {
	.ratnotes-frontend-grid {
		grid-template-columns: 1fr;
	}

	.ratnotes-frontend-actions {
		flex-wrap: wrap;
		justify-content: flex-start;
		gap: 6px;
	}

	.ratnotes-frontend-category-picker {
		width: auto;
		max-width: 150px;
		margin-left: 0;
		flex: 0 1 auto;
	}

	.ratnotes-frontend-category-trigger {
		width: auto;
		max-width: 150px;
		padding: 8px 10px;
		justify-content: flex-start;
	}

	.ratnotes-frontend-category-menu {
		left: 0;
		right: auto;
		width: 100%;
		min-width: 0;
	}
}
