/*
 * Paragraph Sorter Tool — Stylesheet
 * Plugin:  Paragraph Sorter Tool v1.0.0
 * License: GPL v2 or later
 */

/* ═══════════════════════════════════════════
   0. CSS Custom Properties (Design Tokens)
═══════════════════════════════════════════ */
.pst-wrap {
	--pst-bg:           #f4f3f0;
	--pst-surface:      #ffffff;
	--pst-surface-alt:  #f9f8f6;
	--pst-border:       #e3e0da;
	--pst-border-focus: #5b7cf6;
	--pst-text:         #1a1916;
	--pst-text-muted:   #6b6860;
	--pst-text-subtle:  #9e9b96;
	--pst-accent-1:     #5b7cf6;
	--pst-accent-2:     #f05a28;
	--pst-accent-3:     #22c997;
	--pst-pill-bg:      #eeede9;
	--pst-pill-active-bg: #5b7cf6;
	--pst-pill-active-text: #ffffff;
	--pst-card-bg:      #f0eeea;
	--pst-card-border:  #e3e0da;
	--pst-shadow-sm:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
	--pst-shadow-md:    0 4px 16px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.05);
	--pst-shadow-lg:    0 12px 40px rgba(0,0,0,.12), 0 4px 16px rgba(0,0,0,.07);
	--pst-radius-sm:    6px;
	--pst-radius-md:    12px;
	--pst-radius-lg:    18px;
	--pst-radius-xl:    24px;
	--pst-radius-pill:  999px;
	--pst-font-ui:      system-ui, -apple-system, 'Segoe UI', sans-serif;
	--pst-font-mono:    'Courier New', 'Courier', monospace;
	--pst-transition:   0.2s ease;
	--pst-textarea-h:   280px;
}

@media (prefers-color-scheme: dark) {
	.pst-wrap[data-theme="auto"] {
		--pst-bg:          #141412;
		--pst-surface:     #1e1d1a;
		--pst-surface-alt: #252420;
		--pst-border:      #2e2c28;
		--pst-text:        #f0ede8;
		--pst-text-muted:  #9e9b94;
		--pst-text-subtle: #6b6860;
		--pst-pill-bg:     #2a2824;
		--pst-card-bg:     #252420;
		--pst-card-border: #2e2c28;
		--pst-shadow-sm:   0 1px 3px rgba(0,0,0,.3);
		--pst-shadow-md:   0 4px 16px rgba(0,0,0,.35);
		--pst-shadow-lg:   0 12px 40px rgba(0,0,0,.45);
	}
}

.pst-wrap[data-theme="dark"] {
	--pst-bg:          #141412;
	--pst-surface:     #1e1d1a;
	--pst-surface-alt: #252420;
	--pst-border:      #2e2c28;
	--pst-text:        #f0ede8;
	--pst-text-muted:  #9e9b94;
	--pst-text-subtle: #6b6860;
	--pst-pill-bg:     #2a2824;
	--pst-card-bg:     #252420;
	--pst-card-border: #2e2c28;
	--pst-shadow-sm:   0 1px 3px rgba(0,0,0,.3);
	--pst-shadow-md:   0 4px 16px rgba(0,0,0,.35);
	--pst-shadow-lg:   0 12px 40px rgba(0,0,0,.45);
}

/* ═══════════════════════════════════════════
   1. Base
═══════════════════════════════════════════ */
.pst-wrap {
	background: var(--pst-bg);
	color: var(--pst-text);
	font-family: var(--pst-font-ui);
	font-size: 15px;
	line-height: 1.6;
	border-radius: var(--pst-radius-xl);
	overflow: hidden;
	box-shadow: var(--pst-shadow-lg);
	transition: background var(--pst-transition), color var(--pst-transition);
	position: relative;
	max-width: 1200px;
	margin: 0 auto;
}

.pst-wrap *, .pst-wrap *::before, .pst-wrap *::after { box-sizing: border-box; }
.pst-wrap h1, .pst-wrap h2, .pst-wrap h3,
.pst-wrap p, .pst-wrap fieldset, .pst-wrap legend { margin: 0; padding: 0; border: none; }

/* ═══════════════════════════════════════════
   2. Header
═══════════════════════════════════════════ */
.pst-header {
	background: var(--pst-surface);
	border-bottom: 1px solid var(--pst-border);
	padding: 28px 36px 24px;
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 16px;
	position: relative;
}

.pst-header::before {
	content: '';
	position: absolute;
	top: 0; left: 0; right: 0;
	height: 3px;
	background: linear-gradient(90deg, var(--pst-accent-1), var(--pst-accent-2), var(--pst-accent-3));
}

.pst-header-inner { flex: 1; }

.pst-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }

.pst-logo-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px; height: 40px;
	background: linear-gradient(135deg, var(--pst-accent-1), var(--pst-accent-2));
	border-radius: var(--pst-radius-md);
	font-size: 20px;
	color: #fff;
	flex-shrink: 0;
	box-shadow: 0 4px 12px rgba(91,124,246,.35);
}

.pst-title {
	font-size: 24px;
	font-weight: 700;
	color: var(--pst-text);
	letter-spacing: -0.5px;
	line-height: 1;
}

.pst-subtitle { font-size: 14px; color: var(--pst-text-muted); }

.pst-theme-toggle {
	background: var(--pst-pill-bg);
	border: 1px solid var(--pst-border);
	border-radius: var(--pst-radius-pill);
	padding: 8px 14px;
	cursor: pointer;
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 16px;
	color: var(--pst-text-muted);
	transition: background var(--pst-transition), color var(--pst-transition), transform var(--pst-transition);
	flex-shrink: 0;
}
.pst-theme-toggle:hover { background: var(--pst-border); color: var(--pst-text); transform: scale(1.05); }

/* Sun/Moon visibility logic */
.pst-wrap:not([data-theme="dark"]) .pst-icon-sun { display: none; }
.pst-wrap[data-theme="dark"] .pst-icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
	.pst-wrap[data-theme="auto"] .pst-icon-sun { display: none; }
}
@media (prefers-color-scheme: light) {
	.pst-wrap[data-theme="auto"] .pst-icon-moon { display: none; }
}

/* ═══════════════════════════════════════════
   3. Grid
═══════════════════════════════════════════ */
.pst-grid { display: grid; grid-template-columns: 1fr 1fr; }

@media (max-width: 860px) { .pst-grid { grid-template-columns: 1fr; } }

/* ═══════════════════════════════════════════
   4. Panels
═══════════════════════════════════════════ */
.pst-panel {
	background: var(--pst-surface);
	padding: 28px 32px;
	display: flex;
	flex-direction: column;
	gap: 16px;
	transition: background var(--pst-transition);
}

.pst-panel--input { border-right: 1px solid var(--pst-border); }

@media (max-width: 860px) {
	.pst-panel--input { border-right: none; border-bottom: 1px solid var(--pst-border); }
}

.pst-panel-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.pst-panel-title {
	font-size: 14px;
	font-weight: 600;
	color: var(--pst-text-muted);
	text-transform: uppercase;
	letter-spacing: 0.08em;
	display: flex;
	align-items: center;
	gap: 6px;
}

.pst-panel-icon { font-size: 16px; opacity: 0.6; }

.pst-live-stats { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--pst-text-subtle); }
.pst-stat strong { color: var(--pst-accent-1); font-weight: 700; }
.pst-stat-sep { opacity: 0.4; }

/* ═══════════════════════════════════════════
   5. Textareas
═══════════════════════════════════════════ */
.pst-textarea {
	width: 100%;
	min-height: var(--pst-textarea-h);
	padding: 16px 18px;
	background: var(--pst-surface-alt);
	border: 1.5px solid var(--pst-border);
	border-radius: var(--pst-radius-md);
	color: var(--pst-text);
	font-family: var(--pst-font-mono);
	font-size: 14px;
	line-height: 1.7;
	resize: vertical;
	transition: border-color var(--pst-transition), box-shadow var(--pst-transition), background var(--pst-transition);
}
.pst-textarea:focus { outline: none; border-color: var(--pst-border-focus); box-shadow: 0 0 0 3px rgba(91,124,246,.15); }
.pst-textarea::placeholder { color: var(--pst-text-subtle); font-family: var(--pst-font-ui); font-size: 13px; }
.pst-textarea--output { cursor: default; }

.pst-output-wrapper { position: relative; }

.pst-empty-state {
	position: absolute; inset: 0;
	display: flex; flex-direction: column;
	align-items: center; justify-content: center;
	gap: 8px;
	pointer-events: none;
	transition: opacity var(--pst-transition);
}
.pst-empty-state.pst-hidden { opacity: 0; }
.pst-empty-icon { font-size: 40px; opacity: 0.12; }
.pst-empty-state p { font-size: 13px; color: var(--pst-text-subtle); }

/* ═══════════════════════════════════════════
   6. Options Row
═══════════════════════════════════════════ */
.pst-options-row { display: flex; flex-wrap: wrap; gap: 12px; }

.pst-checkbox-label {
	display: flex; align-items: center; gap: 7px;
	cursor: pointer; font-size: 13px;
	color: var(--pst-text-muted);
	user-select: none;
	transition: color var(--pst-transition);
}
.pst-checkbox-label:hover { color: var(--pst-text); }
.pst-checkbox-label input[type="checkbox"] { position: absolute; opacity: 0; width: 0; height: 0; }

.pst-checkmark {
	display: inline-block;
	width: 16px; height: 16px;
	border: 1.5px solid var(--pst-border);
	border-radius: 4px;
	background: var(--pst-surface-alt);
	transition: background var(--pst-transition), border-color var(--pst-transition);
	flex-shrink: 0; position: relative;
}
.pst-checkbox-label input:checked + .pst-checkmark { background: var(--pst-accent-1); border-color: var(--pst-accent-1); }
.pst-checkbox-label input:checked + .pst-checkmark::after {
	content: '';
	position: absolute; top: 2px; left: 4px;
	width: 5px; height: 8px;
	border: 2px solid #fff;
	border-top: none; border-left: none;
	transform: rotate(45deg);
}

/* ═══════════════════════════════════════════
   7. Sort Pill Grid
═══════════════════════════════════════════ */
.pst-sort-fieldset { border: 1.5px solid var(--pst-border); border-radius: var(--pst-radius-md); padding: 14px 16px; }
.pst-sort-legend { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--pst-text-subtle); padding: 0 6px; }

.pst-sort-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
	gap: 6px;
	margin-top: 10px;
}

.pst-sort-pill {
	display: flex; align-items: center; gap: 6px;
	padding: 8px 12px;
	background: var(--pst-pill-bg);
	border: 1.5px solid transparent;
	border-radius: var(--pst-radius-sm);
	cursor: pointer;
	font-size: 12px;
	color: var(--pst-text-muted);
	transition: background var(--pst-transition), color var(--pst-transition), transform var(--pst-transition), box-shadow var(--pst-transition);
	user-select: none;
	line-height: 1.2;
}
.pst-sort-pill:hover { background: var(--pst-border); color: var(--pst-text); transform: translateY(-1px); box-shadow: var(--pst-shadow-sm); }
.pst-sort-pill--active { background: var(--pst-accent-1); color: #fff; box-shadow: 0 3px 10px rgba(91,124,246,.4); }
.pst-sort-pill input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; }
.pst-pill-icon { font-size: 13px; font-weight: 700; opacity: 0.8; flex-shrink: 0; }
.pst-pill-label { font-weight: 500; white-space: nowrap; }

/* ═══════════════════════════════════════════
   8. Buttons
═══════════════════════════════════════════ */
.pst-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.pst-btn {
	display: inline-flex; align-items: center; gap: 7px;
	padding: 11px 20px;
	border-radius: var(--pst-radius-pill);
	border: none; cursor: pointer;
	font-size: 13px; font-weight: 600;
	font-family: var(--pst-font-ui);
	transition: transform var(--pst-transition), box-shadow var(--pst-transition), opacity var(--pst-transition), background var(--pst-transition);
	white-space: nowrap;
}
.pst-btn:focus-visible { outline: 2px solid var(--pst-border-focus); outline-offset: 2px; }
.pst-btn:active { transform: scale(0.97) !important; }
.pst-btn-icon { font-size: 15px; line-height: 1; }

.pst-btn--primary { background: linear-gradient(135deg, var(--pst-accent-1) 0%, #7b5cf0 100%); color: #fff; box-shadow: 0 4px 14px rgba(91,124,246,.4); flex: 1; }
.pst-btn--primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(91,124,246,.55); }

.pst-btn--accent { background: linear-gradient(135deg, var(--pst-accent-3) 0%, #16a07c 100%); color: #fff; box-shadow: 0 4px 14px rgba(34,201,151,.35); flex: 1; }
.pst-btn--accent:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(34,201,151,.5); }

.pst-btn--ghost { background: var(--pst-pill-bg); color: var(--pst-text-muted); border: 1.5px solid var(--pst-border); }
.pst-btn--ghost:hover { background: var(--pst-border); color: var(--pst-text); transform: translateY(-1px); }

.pst-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

/* ═══════════════════════════════════════════
   9. Summary Cards
═══════════════════════════════════════════ */
.pst-summary-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

@media (max-width: 480px) { .pst-summary-cards { grid-template-columns: repeat(2, 1fr); } }

.pst-card {
	background: var(--pst-card-bg);
	border: 1px solid var(--pst-card-border);
	border-radius: var(--pst-radius-md);
	padding: 14px 12px; text-align: center;
	display: flex; flex-direction: column; gap: 3px;
	transition: background var(--pst-transition), transform var(--pst-transition);
}
.pst-card:hover { transform: translateY(-1px); }
.pst-card-value { font-size: 22px; font-weight: 700; color: var(--pst-accent-1); line-height: 1; }
.pst-card-label { font-size: 11px; color: var(--pst-text-subtle); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 500; }

/* ═══════════════════════════════════════════
   10. Toast
═══════════════════════════════════════════ */
.pst-toast {
	position: absolute; bottom: 24px; left: 50%;
	transform: translateX(-50%) translateY(12px);
	background: var(--pst-text); color: var(--pst-bg);
	font-size: 13px; font-weight: 600;
	padding: 10px 20px; border-radius: var(--pst-radius-pill);
	opacity: 0; pointer-events: none;
	transition: opacity 0.25s ease, transform 0.25s ease;
	white-space: nowrap; z-index: 100;
}
.pst-toast.pst-toast--visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ═══════════════════════════════════════════
   11. Info Footer
═══════════════════════════════════════════ */
.pst-info { background: var(--pst-surface-alt); border-top: 1px solid var(--pst-border); padding: 36px 36px 32px; }
.pst-info-title { font-size: 16px; font-weight: 700; color: var(--pst-text); margin-bottom: 20px; letter-spacing: -0.3px; }
.pst-info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.pst-info-card { background: var(--pst-surface); border: 1px solid var(--pst-border); border-radius: var(--pst-radius-md); padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.pst-info-icon { font-size: 20px; }
.pst-info-card h3 { font-size: 14px; font-weight: 600; color: var(--pst-text); }
.pst-info-card p { font-size: 13px; color: var(--pst-text-muted); line-height: 1.5; }

/* ═══════════════════════════════════════════
   12. Animations
═══════════════════════════════════════════ */
@keyframes pst-pulse {
	0%, 100% { box-shadow: 0 0 0 0 rgba(91,124,246,.35); }
	50% { box-shadow: 0 0 0 6px rgba(91,124,246,0); }
}
.pst-btn--primary.pst-processing { animation: pst-pulse 1.2s infinite; }

@keyframes pst-fadeIn {
	from { opacity: 0; transform: translateY(6px); }
	to { opacity: 1; transform: translateY(0); }
}
.pst-panel { animation: pst-fadeIn 0.35s ease both; }
.pst-panel--output { animation-delay: 0.1s; }

/* ═══════════════════════════════════════════
   13. Responsive
═══════════════════════════════════════════ */
@media (max-width: 640px) {
	.pst-header { padding: 20px 20px 18px; }
	.pst-panel { padding: 20px; }
	.pst-info { padding: 24px 20px; }
	.pst-sort-grid { grid-template-columns: repeat(2, 1fr); }
	.pst-summary-cards { grid-template-columns: repeat(2, 1fr); }
	.pst-actions { flex-direction: column; }
	.pst-btn { justify-content: center; }
}

.pst-hidden { display: none !important; }
