/* app/admin/assets/admin.css
   Core admin stylesheet. Override per-site by copying this file to
   config/admin/assets/admin.css — that copy wins and survives deploys.
   Plain CSS with design tokens; no frameworks, no CDNs. */

:root {
	--bg: #f1f5f9;
	--surface: #ffffff;
	--surface-2: #f8fafc;
	--border: #e2e8f0;
	--text: #0f172a;
	--text-muted: #64748b;
	--primary: #2563eb;
	--primary-hover: #1d4ed8;
	--primary-soft: #eff6ff;
	--danger: #dc2626;
	--danger-hover: #b91c1c;
	--success: #16a34a;
	--warning: #d97706;
	--radius: 8px;
	--sidebar-width: 230px;
	--topbar-height: 52px;
	--shadow: 0 1px 3px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }

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

body.admin-body {
	background: var(--bg);
	color: var(--text);
	font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- topbar ----------------------------------------------------------- */

.admin-topbar {
	position: fixed;
	inset: 0 0 auto 0;
	height: var(--topbar-height);
	background: #0f172a;
	color: #fff;
	display: flex;
	align-items: center;
	gap: .75rem;
	padding: 0 1rem;
	box-shadow: 0px 1px 5px rgb(0 0 0 / 20%);
	z-index: 40;
}

.admin-brand {
	color: #fff;
	font-weight: 700;
	font-size: 1.05rem;
	display: inline-flex;
	align-items: center;
	gap: .5rem;
}

.admin-brand:hover { text-decoration: none; color: #fff; }

.admin-brand-tag {
	background: var(--primary);
	color: #fff;
	font-size: .68rem;
	text-transform: uppercase;
	letter-spacing: .04em;
	padding: .15rem .5rem;
	border-radius: 999px;
}

.admin-top-actions {
	margin-left: auto;
	display: flex;
	align-items: center;
	gap: .75rem;
}

.admin-user {
	color: #cbd5e1;
	font-size: .875rem;
	white-space: nowrap;
}

.sidebar-toggle {
	display: none;
	background: transparent;
	border: 1px solid #334155;
	color: #fff;
	font-size: 1.1rem;
	line-height: 1;
	width: 34px;
	height: 34px;
	border-radius: 6px;
	cursor: pointer;
}

/* ---- sidebar ---------------------------------------------------------- */

.admin-wrap {
	display: flex;
	min-height: 100vh;
	padding-top: var(--topbar-height);
}

.admin-sidebar {
	width: var(--sidebar-width);
	flex: 0 0 var(--sidebar-width);
	background: var(--surface);
	border-right: 1px solid var(--border);
	padding: 1rem .75rem;
}

.admin-menu {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.admin-menu-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: .5rem;
	padding: .55rem .75rem;
	border-radius: 6px;
	color: var(--text);
	font-weight: 500;
}

.admin-menu-item:hover { background: var(--surface-2); text-decoration: none; }

.admin-menu-item.active {
	background: var(--primary-soft);
	color: var(--primary);
}

.menu-count {
	background: var(--border);
	color: var(--text-muted);
	font-size: .72rem;
	font-weight: 600;
	padding: .1rem .45rem;
	border-radius: 999px;
}

.admin-menu-item.active .menu-count {
	background: var(--primary);
	color: #fff;
}

/* Plugin index links in the sidebar — indented + subdued so they read as
   sub-items under "Plugin manager", not as sibling top-level entries. */
.admin-menu-item.plugin-link {
	padding-left: 1.6rem;
	font-size: .88rem;
	font-weight: 500;
	color: var(--text-muted);
}
.admin-menu-item.plugin-link::after {
	content: "➜"; /* ▸ */
	margin-right: .45rem;
	color: var(--border);
	font-size: .78rem;
}
.admin-menu-item.plugin-link:hover { color: var(--text); }
.admin-menu-item.plugin-link.active { color: var(--primary); }
.admin-menu-item.plugin-link.active::before { color: var(--primary); }

.admin-menu-heading {
	font-size: .72rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: .05em;
	color: var(--text-muted);
	padding: .9rem .75rem .35rem;
}

/* ---- main ------------------------------------------------------------- */

.admin-main {
	flex: 1 1 auto;
	min-width: 0;
	padding: 1.5rem 1.75rem 3rem;
}

.admin-page-title {
	margin: 0 0 1.25rem;
	font-size: 1.6rem;
	line-height: 1.25;
	display: flex;
	align-items: center;
	gap: .75rem;
	flex-wrap: wrap;
}

.muted { color: var(--text-muted); }
.inline { display: inline; }

/* ---- flash ------------------------------------------------------------ */

.flash {
	padding: .7rem 1rem;
	border-radius: var(--radius);
	margin-bottom: 1rem;
	font-size: .9rem;
}

.flash-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.flash-error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.flash-warning { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.flash-warning-inline { color: #92400e; font-size: .8125rem; }

.flash ul { margin: .35rem 0 0; padding-left: 1.25rem; }

/* ---- panels, cards ---------------------------------------------------- */

.panel {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 1.25rem;
	margin-bottom: 1.25rem;
}

.stat-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
	gap: 1rem;
	margin-bottom: 1.5rem;
}

.stat-card {
	display: block;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 1rem 1.25rem;
	color: var(--text);
}

.stat-card:hover { border-color: var(--primary); text-decoration: none; }

.stat-value { display: block; font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.stat-label { display: block; color: var(--text-muted); font-size: .85rem; }

/* Dashboard info cards (site overview + system details). */
.dash-cards {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
	gap: 1rem;
	margin-bottom: 1.5rem;
}
.dash-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 1rem 1.25rem;
}
.dash-card h3 { margin: 0 0 .75rem; font-size: .95rem; }
.dash-info { display: grid; grid-template-columns: 1fr 1.6fr; gap: .35rem .75rem; margin: 0; font-size: .85rem; }
.dash-info dt { color: var(--text-muted); font-weight: 600; }
.dash-info dd { margin: 0; overflow-wrap: anywhere; }

/* Theme picker. */
.theme-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
	gap: 1rem;
}
.theme-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 1rem 1.25rem;
}
.theme-card.active { border-color: var(--primary); }
.theme-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: .75rem;
}
.theme-byline { margin-top: .25rem; font-size: .8rem; }
.theme-desc { margin: .5rem 0 0; font-size: .85rem; color: var(--text-muted); }
.theme-badge {
	background: var(--primary-soft);
	color: var(--primary);
	font-size: .72rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: .04em;
	padding: .25rem .6rem;
	border-radius: 999px;
}

/* Plugin manager — wide full-width cards, deliberately distinct from the
   theme picker's compact grid of cards. */
.plugin-list { display: flex; flex-direction: column; gap: 1rem; }
.plugin-card {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1.25rem;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 1.1rem 1.25rem;
}
.plugin-card.active { border-color: var(--primary); }
.plugin-head { display: flex; align-items: center; gap: .6rem; }
.plugin-title { font-size: 1.05rem; font-weight: 700; }
.plugin-byline { margin-top: .25rem; font-size: .8rem; }
.plugin-desc { margin: .5rem 0 0; font-size: .85rem; color: var(--text-muted); max-width: 64ch; }
.plugin-actions { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }
.plugin-badge {
	font-size: .72rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: .04em;
	padding: .25rem .6rem;
	border-radius: 999px;
}
.plugin-badge.active { background: var(--primary-soft); color: var(--primary); }
.plugin-badge.inactive { background: var(--border); color: var(--text-muted); }

/* ---- lists ------------------------------------------------------------ */

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .5rem 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .muted { display: block; font-size: .82rem; }

/* ---- tables ----------------------------------------------------------- */

.table { width: 100%; border-collapse: collapse; font-size: .92rem; }

.table th, .table td {
	text-align: left;
	padding: .6rem .75rem;
	border-bottom: 1px solid var(--border);
	vertical-align: top;
}

.table th { font-weight: 600; color: var(--text-muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }

.table tbody tr:hover { background: var(--surface-2); }

.actions-col { white-space: nowrap; text-align: right; }

.order-col { width: 6rem; }

.order-input {
	width: 4.5rem;
	padding: .35rem .5rem;
	font: inherit;
	font-size: .875rem;
	border: 1px solid var(--border);
	border-radius: 6px;
	background: var(--surface);
	color: var(--text);
}

.badge {
	display: inline-block;
	padding: .1rem .5rem;
	border: 1px solid var(--border);
	border-radius: 999px;
	font-size: .72rem;
	font-weight: 500;
	text-transform: uppercase;
	letter-spacing: .04em;
	color: var(--text-muted);
	white-space: nowrap;
}

/* ---- toolbar ---------------------------------------------------------- */

.toolbar {
	display: flex;
	align-items: center;
	gap: 1rem;
	margin-bottom: 1.25rem;
}

/* ---- tabs (Users & Roles page) ---------------------------------------- */

.admin-tabs {
	display: flex;
	gap: .35rem;
	margin: 0 0 1rem;
	border-bottom: 1px solid var(--border);
	flex-wrap: wrap;
}

.admin-tab {
	padding: .5rem .95rem;
	border: 1px solid transparent;
	border-bottom: none;
	border-radius: 8px 8px 0 0;
	text-decoration: none;
	color: var(--text-muted);
	font-weight: 600;
	line-height: 1.3;
}

.admin-tab:hover { color: var(--text); }

.admin-tab.active {
	border-color: var(--border);
	background: var(--surface);
	color: var(--primary);
}

/* ---- buttons ---------------------------------------------------------- */

.btn {
	display: inline-block;
	background: var(--surface);
	border: 1px solid var(--border);
	color: var(--text);
	font: inherit;
	font-size: .9rem;
	font-weight: 500;
	padding: .45rem .9rem;
	border-radius: 6px;
	cursor: pointer;
	line-height: 1.4;
}

.btn:hover { background: var(--surface-2); text-decoration: none; }

.btn-sm { padding: .25rem .6rem; font-size: .82rem; }

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

.btn-primary:hover { background: var(--primary-hover); }

.btn-danger {
	background: var(--danger);
	border-color: var(--danger);
	color: #fff;
}

.btn-danger:hover { background: var(--danger-hover); }

/* ---- forms ------------------------------------------------------------ */


/* Fieldset grouping: labelled groups of fields on the edit forms. */
.form-group {
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: .7rem .9rem 1rem;
	margin: 0 0 1rem;
}
.form-group legend {
	font-size: .78rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: .04em;
	color: var(--text-muted);
	padding: 0 .35rem;
}
.form-group .form-row:last-child { margin-bottom: 0; }

.form-row { margin-bottom: .75rem; }

.form-row label {
	display: block;
	font-weight: 600;
	font-size: .85rem;
	margin-bottom: .25rem;
}

.form-row input[type="text"],
.form-row input[type="password"],
.form-row input[type="number"],
.form-row textarea,
.form-row select {
	width: 100%;
	padding: .45rem .65rem;
	border: 1px solid var(--border);
	border-radius: 6px;
	font: inherit;
	background: var(--surface);
	color: var(--text);
}

.form-row input:focus,
.form-row textarea:focus,
.form-row select:focus {
	outline: none;
	border-color: var(--primary);
	box-shadow: 0 0 0 3px var(--primary-soft);
}

.form-row textarea { resize: vertical; }

.form-row input[type="checkbox"] {
	width: 1.1rem;
	height: 1.1rem;
	accent-color: var(--primary);
}

.form-row .help { display: block; color: var(--text-muted); font-size: .75rem; margin-top: .2rem; }

/* Half-width fields flow side by side into a two-column grid; full-width
   fields and group markers break the row. */
.form-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
	column-gap: 1.25rem;
	align-items: start;
}

/* Slug fields don't need full width — cap them so they sit compactly
   beside the title in a two-column row. */
.form-grid .form-row input[name="slug"] { max-width: 280px; }

/* Settings-page textareas (description, tagline) — keep them modest so
   the card doesn't balloon vertically. */
.settings-card-body textarea { min-height: 3.5rem; max-height: 6rem; }

/* Editor field header: label + an Expand control for the content field. */
.form-label-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: .75rem;
	margin-bottom: .35rem;
}
.form-label-row label { margin-bottom: 0; }

/* Fallback for the Expand control when the editor isn't loaded: grow the
   raw textarea instead of toggling HugeRTE fullscreen. */
.form-row textarea.expanded { min-height: 75vh; font-size: 1rem; }

.form-actions {
	display: flex;
	align-items: center;
	gap: .75rem;
	padding-top: .25rem;
}

/* ---- login ------------------------------------------------------------ */

/* ---- control-panel settings ------------------------------------------- */

/* Settings page renders as a responsive grid of grouped cards, one card per
   section (Site identity, Appearance, Analytics, Maintenance). */
.settings-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
	gap: 1.25rem;
	align-items: start;
}

.settings-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	overflow: hidden;
}

.settings-card-head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: .75rem;
	padding: 1rem 1.25rem;
	border-bottom: 1px solid var(--border);
	background: var(--surface-2);
}

.settings-card-icon {
	font-size: 1.4rem;
	line-height: 1;
	flex-shrink: 0;
}

.settings-card-head h2 {
	margin: 0;
	font-size: .95rem;
	font-weight: 700;
}

.settings-card-head p {
	margin: 0;
	font-size: .82rem;
	color: var(--text-muted);
}

.settings-card-body { padding: 1.25rem; }
.settings-card-body .form-row:last-child { margin-bottom: 0; }

/* Checkbox (Maintenance mode) renders as a labelled switch-style row. */
.settings-card-body .form-row:has(input[type="checkbox"]) {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: .5rem;
}
.settings-card-body .form-row:has(input[type="checkbox"]) label { margin: 0; }
.settings-card-body .form-row:has(input[type="checkbox"]) .help {
	flex-basis: 100%;
	text-align: left;
}
.settings-card-body .form-row:has(input[type="checkbox"]) input[type="checkbox"] {
	width: 1.3rem;
	height: 1.3rem;
	margin-left: auto;
}

.settings-form .form-actions { margin-top: 1.5rem; }

/* ---- login ------------------------------------------------------------ */

.login-wrap {
	display: flex;
	justify-content: center;
	padding-top: 8vh;
}

.login-box { width: 100%; max-width: 380px; }

.login-box .form-actions { justify-content: flex-end; }

/* ---- logs ------------------------------------------------------------- */

.log-list {
	font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
	font-size: .82rem;
	padding: 0;
	overflow-x: auto;
}

.log-line {
	display: flex;
	gap: .6rem;
	padding: .45rem .75rem;
	border-bottom: 1px solid var(--border);
}

.log-line:last-child { border-bottom: 0; }

.log-time { color: var(--text-muted); white-space: nowrap; }
.log-level { font-weight: 700; white-space: nowrap; }

.log-error .log-level { color: var(--danger); }
.log-warning .log-level { color: var(--warning); }
.log-info .log-level { color: var(--text-muted); }

.log-message { word-break: break-word; }

/* ---- modal preview ---------------------------------------------------- */

.preview-modal {
	position: fixed;
	inset: 0;
	z-index: 60;
	display: none;
	align-items: center;
	justify-content: center;
	padding: 1.5rem;
}

.preview-modal.is-open {
	display: flex;
}

.preview-modal-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(15, 23, 42, .55);
}

.preview-modal-dialog {
	position: relative;
	width: min(1100px, 100%);
	height: min(88vh, 100%);
	background: var(--surface);
	border-radius: var(--radius);
	box-shadow: 0 20px 60px rgba(15, 23, 42, .35);
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.preview-modal-bar {
	display: flex;
	align-items: center;
	gap: .75rem;
	padding: .6rem .9rem;
	border-bottom: 1px solid var(--border);
	background: var(--surface-2);
	flex-wrap: wrap;
}

.preview-modal-bar .btn:last-child { margin-left: auto; }

.preview-modal-hint { font-size: .8rem; }

#preview-frame {
	flex: 1 1 auto;
	width: 100%;
	border: 0;
	background: #fff;
}

/* Buttons/links using the hidden attribute must stay hidden despite
   .btn { display: inline-block } — e.g. the "Open in new tab" link. */
.btn[hidden] { display: none; }

body.preview-open { overflow: hidden; }

/* ---- media library ---------------------------------------------------- */

.media-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
	gap: 1rem;
}

.media-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	overflow: hidden;
	box-shadow: var(--shadow);
	display: flex;
	flex-direction: column;
}

.media-thumb {
	display: block;
	height: 140px;
	background: var(--surface-2);
	overflow: hidden;
}

.media-thumb img {
	display: block;
	width: 100%;
	height: 140px;
	object-fit: cover;
}

.media-thumb-file {
	display: flex;
	align-items: center;
	justify-content: center;
	font-weight: 700;
	font-size: 1.5rem;
	color: var(--text-muted);
	letter-spacing: .06em;
}

.media-card-body {
	padding: .65rem .75rem .75rem;
	display: flex;
	flex-direction: column;
	gap: .35rem;
}

.media-name {
	font-size: .85rem;
	font-weight: 600;
	word-break: break-all;
}

.media-meta {
	font-size: .78rem;
}

.media-actions {
	margin-top: .25rem;
}

/* ---- responsive ------------------------------------------------------- */

@media (max-width: 860px) {
	.sidebar-toggle { display: inline-block; }

	.admin-sidebar {
		position: fixed;
		top: var(--topbar-height);
		bottom: 0;
		left: 0;
		z-index: 30;
		transform: translateX(-100%);
		transition: transform .18s ease;
		box-shadow: var(--shadow);
	}

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

	.admin-main { padding: 1rem 1rem 2.5rem; }

	.admin-top-actions .admin-user { display: none; }
}
