/* ============================================================================
   application.css — dark control-panel theme.

   Hand-written, zero build step (the project bans an npm/CSS toolchain).
   Replaces Bootstrap 3 entirely — see GH #31 / F14. Fonts come from the
   Google Fonts <link> in views/layout.php.

   Layout:
     1. tokens          2. reset / base       3. atmosphere
     4. header/toolbar  5. table + rows       6. inline-edit rows
     7. buttons         8. inputs + fields    9. alert
     10. panel (fallback create + edit page)  11. responsive cards
     12. animation
   ============================================================================ */

/* --- 1. tokens ----------------------------------------------------------- */
:root {
	--bg:            #131519;
	--surface:       #1a1d23;
	--surface-2:     #21252e;
	--surface-3:     #272c37;
	--border:        #2b303b;
	--border-strong: #3a414f;

	--text:        #e7e9ec;
	--text-muted:  #8b919e;
	--text-faint:  #5b616d;

	--accent:        #22d3ee;
	--accent-hover:  #5ce0f3;
	--accent-ink:    #06262b;
	--accent-glow:   rgba(34, 211, 238, .16);
	--accent-line:   rgba(34, 211, 238, .55);

	--danger:      #fb7185;
	--danger-bg:   rgba(251, 113, 133, .12);
	--success:     #4ade80;
	--success-bg:  rgba(74, 222, 128, .12);

	--font-display: 'Bricolage Grotesque', 'Hanken Grotesk', system-ui, sans-serif;
	--font-ui:      'Hanken Grotesk', system-ui, -apple-system, sans-serif;
	--font-mono:    'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

	--radius:    10px;
	--radius-sm: 7px;
	--shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px -8px rgba(0,0,0,.55);
	--ring:      0 0 0 3px var(--accent-glow);
}

/* --- 2. reset / base ----------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

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

body {
	background: var(--bg);
	color: var(--text);
	font-family: var(--font-ui);
	font-size: 15px;
	line-height: 1.55;
	-webkit-font-smoothing: antialiased;
	letter-spacing: .002em;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; margin: 0; }

a { color: var(--accent); text-decoration: none; }

button { font-family: inherit; }

::selection { background: var(--accent-glow); color: var(--text); }

.container {
	max-width: 1000px;
	margin: 0 auto;
	padding: 56px 28px 96px;
	position: relative;
	z-index: 1;
}

[hidden] { display: none !important; }

/* --- 3. atmosphere ------------------------------------------------------- */
/* A faint top glow + fractal-noise grain so the dark surface has depth
   instead of reading as flat #131519. Both are fixed and non-interactive. */
body::before {
	content: "";
	position: fixed;
	inset: 0;
	z-index: 0;
	pointer-events: none;
	background:
		radial-gradient(900px 420px at 78% -8%, rgba(34,211,238,.10), transparent 70%),
		radial-gradient(700px 380px at 8% 0%,  rgba(34,211,238,.05), transparent 70%);
}
body::after {
	content: "";
	position: fixed;
	inset: 0;
	z-index: 0;
	pointer-events: none;
	opacity: .035;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* --- 4. header + toolbar ------------------------------------------------- */
.app-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	margin-bottom: 28px;
}

.app-id { display: flex; align-items: baseline; gap: 12px; }

.app-dot {
	width: 9px; height: 9px;
	border-radius: 50%;
	background: var(--accent);
	box-shadow: 0 0 0 4px var(--accent-glow);
	align-self: center;
	animation: pulse 2.6s ease-in-out infinite;
}

.app-title {
	font-size: 26px;
	letter-spacing: -.02em;
}

.app-count {
	font-family: var(--font-mono);
	font-size: 12px;
	color: var(--text-muted);
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 999px;
	padding: 2px 10px;
	align-self: center;
}

.toolbar { margin-bottom: 18px; }

.search-field { position: relative; max-width: 340px; }

.search-field .search-icon {
	position: absolute;
	left: 12px; top: 50%;
	transform: translateY(-50%);
	color: var(--text-faint);
	pointer-events: none;
}

.search-input {
	width: 100%;
	padding: 9px 14px 9px 36px;
	font-family: var(--font-mono);
	font-size: 13px;
	color: var(--text);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	outline: none;
	transition: border-color .15s, box-shadow .15s;
}
.search-input::placeholder { color: var(--text-faint); }
.search-input:focus {
	border-color: var(--accent-line);
	box-shadow: var(--ring);
}

/* --- 5. table + rows ----------------------------------------------------- */
.table-wrap {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	overflow: hidden;
}

.data-table {
	width: 100%;
	border-collapse: collapse;
}

.data-table thead th {
	text-align: left;
	font-family: var(--font-ui);
	font-size: 11px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: .09em;
	color: var(--text-faint);
	padding: 13px 18px;
	background: var(--surface-2);
	border-bottom: 1px solid var(--border);
}
.data-table thead th.col-actions { text-align: right; }

/* sortable column headers (F4) — the <th> keeps its faint-uppercase look;
   the <a> just makes the whole label clickable and aligns the caret. */
.data-table thead th .th-sort {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	color: inherit;          /* override the global accent <a> colour */
	transition: color .14s;
}
.data-table thead th .th-sort:hover { color: var(--text-muted); }
.data-table thead th .th-sort:focus-visible {
	outline: none;
	box-shadow: var(--ring);
	border-radius: 3px;
}
/* the active sort column reads brighter than the rest */
.data-table thead th[aria-sort="ascending"] .th-sort,
.data-table thead th[aria-sort="descending"] .th-sort { color: var(--text); }

.sort-caret { font-size: 9px; line-height: 1; color: var(--accent); }
.sort-caret--idle { color: var(--text-faint); opacity: .55; }

.data-table tbody td {
	padding: 13px 18px;
	border-bottom: 1px solid var(--border);
	vertical-align: middle;
	white-space: nowrap;
}
.data-table tbody tr:last-child td { border-bottom: none; }

/* Name reads in the UI face; the rest is monospace data. */
.data-table tbody td:first-child {
	font-weight: 600;
	color: var(--text);
	/* the accent edge lives here — see the tr rules below */
	box-shadow: inset 2px 0 0 transparent;
	transition: box-shadow .14s;
}
.data-table tbody td:nth-child(2),
.data-table tbody td:nth-child(3),
.data-table tbody td:nth-child(4) {
	font-family: var(--font-mono);
	font-size: 13px;
	color: var(--text-muted);
}
/* E-mail is the one column that can run long — let it ellipsize, not wrap. */
.data-table tbody td:nth-child(2) {
	max-width: 240px;
	overflow: hidden;
	text-overflow: ellipsis;
}

.empty-cell { color: var(--text-faint); }

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

/* Glowing accent edge on hover / focus / while editing. Painted as an inset
   box-shadow on the first cell — NOT an absolutely-positioned ::before, which
   would need `position: relative` on the <tr>, and that breaks Chrome's
   thead/tbody column-width sync (header columns size independently). */
.data-table tbody tr:hover td:first-child,
.data-table tbody tr:focus-within td:first-child {
	box-shadow: inset 2px 0 0 var(--accent-line);
}
.data-table tbody tr.row-editing td:first-child {
	box-shadow: inset 2px 0 0 var(--accent);
}

.data-table tbody tr.row-editing { background: var(--surface-2); }
.data-table tbody tr.row-editing td {
	border-top: 1px solid var(--accent-line);
	border-bottom: 1px solid var(--accent-line);
}

/* Brief confirmation flash after a successful save. */
.data-table tbody tr.row-flash { animation: flash 1.1s ease-out; }

/* empty-state row (no filter matches) */
.empty-row td {
	text-align: center;
	color: var(--text-faint);
	font-family: var(--font-mono);
	font-size: 13px;
	padding: 28px 18px !important;
}

/* --- pagination strip (F4) ---------------------------------------------- */
/* Sits inside .table-wrap, below the table — the card's overflow:hidden
   clips it to the rounded bottom corners. */
.pagination {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 12px 18px;
	background: var(--surface-2);
	border-top: 1px solid var(--border);
}

.page-info {
	font-family: var(--font-mono);
	font-size: 12px;
	color: var(--text-muted);
}
.page-info-sep { color: var(--text-faint); margin: 0 4px; }

.page-step {
	font-size: 13px;
	font-weight: 600;
	color: var(--text);
	padding: 6px 12px;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	background: var(--surface-3);
	transition: background .14s, border-color .14s, color .14s;
}
.page-step:hover { background: var(--surface); border-color: var(--text-faint); }
.page-step:focus-visible { outline: none; box-shadow: var(--ring); }
/* boundary links (Prev on page 1, Next on the last page) — dimmed and inert */
.page-step[aria-disabled="true"] {
	color: var(--text-faint);
	background: transparent;
	border-color: var(--border);
	pointer-events: none;
}

/* --- row actions --------------------------------------------------------- */
.col-actions { text-align: right; white-space: nowrap; width: 1%; }

.row-actions {
	display: inline-flex;
	gap: 6px;
	justify-content: flex-end;
}

.delete-form { display: inline; margin: 0; }

/* visually-hidden but kept for screen readers (e.g. the empty Actions header) */
.visually-hidden {
	position: absolute;
	width: 1px; height: 1px;
	margin: -1px; padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* --- 6. inline-edit rows ------------------------------------------------- */
.cell-edit { padding: 9px 12px !important; }
.cell-edit:first-child { padding-left: 16px !important; }

.input-cell {
	width: 100%;
	min-width: 0;
	padding: 7px 10px;
	font-family: var(--font-mono);
	font-size: 13px;
	color: var(--text);
	background: var(--surface-3);
	border: 1px solid var(--border-strong);
	border-radius: 6px;
	outline: none;
	transition: border-color .15s, box-shadow .15s;
}
.input-cell:focus {
	border-color: var(--accent-line);
	box-shadow: var(--ring);
}
.cell-edit.has-error .input-cell {
	border-color: var(--danger);
	box-shadow: 0 0 0 3px var(--danger-bg);
}

.cell-edit .field-error {
	display: block;
	margin-top: 4px;
	font-family: var(--font-ui);
	font-size: 11.5px;
	color: var(--danger);
	min-height: 0;
}

/* --- 7. buttons ---------------------------------------------------------- */
.btn {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	font-family: var(--font-ui);
	font-size: 13.5px;
	font-weight: 600;
	line-height: 1;
	padding: 10px 16px;
	border-radius: var(--radius-sm);
	border: 1px solid transparent;
	cursor: pointer;
	transition: background .14s, border-color .14s, box-shadow .14s, transform .06s;
	white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { box-shadow: var(--ring); outline: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
	background: var(--accent);
	color: var(--accent-ink);
}
.btn-primary:hover:not(:disabled) {
	background: var(--accent-hover);
	box-shadow: 0 0 24px -6px var(--accent-glow);
}

.btn-ghost {
	background: var(--surface-2);
	color: var(--text);
	border-color: var(--border-strong);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); border-color: var(--text-faint); }

.btn-glyph {
	font-family: var(--font-mono);
	font-size: 15px;
	font-weight: 400;
	line-height: 0;
}

/* compact row-action buttons — icon by default, label expands on row hover */
.btn-icon {
	display: inline-flex;
	align-items: center;
	font-family: var(--font-ui);
	font-size: 12px;
	font-weight: 600;
	padding: 7px 9px;
	border-radius: 6px;
	border: 1px solid var(--border-strong);
	background: var(--surface-3);
	color: var(--text-muted);
	cursor: pointer;
	transition: background .14s, color .14s, border-color .14s;
}
.btn-ico { display: block; flex: none; }

/* The label sits collapsed beside the icon and expands when that specific
   button is hovered or focused — not on row hover. Save / Discard carry raw
   text (no .btn-label) so they always read clearly. */
.btn-label {
	display: inline-block;
	max-width: 0;
	overflow: hidden;
	white-space: nowrap;
	opacity: 0;
	transition: max-width .18s ease, opacity .14s ease, margin-left .18s ease;
}
.btn-icon:hover .btn-label,
.btn-icon:focus-visible .btn-label {
	max-width: 72px;
	opacity: 1;
	margin-left: 5px;
}
.row-actions [data-action="save"],
.row-actions [data-action="cancel"] { padding: 7px 12px; }
.btn-icon:hover {
	background: var(--surface-2);
	color: var(--text);
	border-color: var(--text-faint);
}
.btn-icon-danger:hover {
	color: var(--danger);
	border-color: var(--danger);
	background: var(--danger-bg);
}
.btn-icon-accent {
	color: var(--accent-ink);
	background: var(--accent);
	border-color: var(--accent);
}
.btn-icon-accent:hover {
	background: var(--accent-hover);
	color: var(--accent-ink);
	border-color: var(--accent-hover);
}
.btn-icon:disabled { opacity: .55; cursor: not-allowed; }

/* --- 8. inputs + fields (stacked forms) ---------------------------------- */
.stack-form { display: flex; flex-direction: column; gap: 18px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
	font-size: 12px;
	font-weight: 600;
	letter-spacing: .04em;
	text-transform: uppercase;
	color: var(--text-muted);
}

.input {
	width: 100%;
	padding: 10px 13px;
	font-family: var(--font-mono);
	font-size: 13.5px;
	color: var(--text);
	background: var(--surface-2);
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	outline: none;
	transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--text-faint); }
.input:focus { border-color: var(--accent-line); box-shadow: var(--ring); }

.field.has-error .input {
	border-color: var(--danger);
	box-shadow: 0 0 0 3px var(--danger-bg);
}
.field-error {
	font-family: var(--font-ui);
	font-size: 12px;
	color: var(--danger);
}

.form-row { display: flex; gap: 10px; align-items: center; margin-top: 4px; }

/* --- 9. alert ------------------------------------------------------------ */
.alert {
	display: flex;
	align-items: center;
	gap: 9px;
	padding: 11px 15px;
	margin-bottom: 16px;
	border-radius: var(--radius-sm);
	font-size: 13.5px;
	font-weight: 500;
	border: 1px solid transparent;
}
.alert::before {
	content: "";
	width: 7px; height: 7px;
	border-radius: 50%;
	flex: none;
}
.alert-success {
	background: var(--success-bg);
	border-color: rgba(74,222,128,.3);
	color: #b6f3c9;
}
.alert-success::before { background: var(--success); }
.alert-danger {
	background: var(--danger-bg);
	border-color: rgba(251,113,133,.3);
	color: #fbc4cc;
}
.alert-danger::before { background: var(--danger); }

/* --- 10. panel (no-JS create fallback + edit page) ----------------------- */
.panel {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	overflow: hidden;
}
.create-fallback { margin-top: 28px; }

.panel-head {
	padding: 15px 22px;
	background: var(--surface-2);
	border-bottom: 1px solid var(--border);
}
.panel-head h2 {
	font-size: 15px;
	letter-spacing: -.01em;
}
.panel-body { padding: 22px; }

.page-head { margin-bottom: 24px; }
.page-head .crumb {
	font-family: var(--font-mono);
	font-size: 12px;
	color: var(--text-faint);
	margin-bottom: 6px;
}
.page-head h1 { font-size: 24px; }

/* --- 11. responsive cards ----------------------------------------------- */
@media (max-width: 720px) {
	.container { padding: 36px 16px 72px; }

	.app-header { flex-direction: column; align-items: flex-start; gap: 14px; }
	.app-header .btn { width: 100%; justify-content: center; }
	.search-field { max-width: none; }

	.table-wrap {
		background: transparent;
		border: none;
		box-shadow: none;
		overflow: visible;
	}
	.data-table thead { display: none; }
	.data-table, .data-table tbody, .data-table tr, .data-table td { display: block; }

	.data-table tbody tr {
		background: var(--surface);
		border: 1px solid var(--border);
		border-radius: var(--radius);
		margin-bottom: 12px;
		padding: 6px 4px;
		box-shadow: var(--shadow);
	}
	.data-table tbody tr.row-editing { border-color: var(--accent-line); }

	.data-table tbody td {
		display: flex;
		justify-content: space-between;
		align-items: center;
		gap: 16px;
		border-bottom: 1px solid var(--border);
		padding: 11px 16px;
		white-space: normal;
		max-width: none;
		overflow: visible;
	}
	.data-table tbody td:last-child { border-bottom: none; }
	/* the e-mail column carries a desktop ellipsis cap (max-width + overflow) at
	   a higher specificity than the rule above — undo it for the card layout,
	   or the e-mail cell stays narrower than the card and looks misaligned. */
	.data-table tbody td:nth-child(2) {
		max-width: none;
		overflow: visible;
	}
	/* the value is a real flex item so every row aligns identically — raw text
	   nodes size unpredictably as anonymous flex items (the e-mail drifted). */
	.data-table tbody td .cell-value {
		flex: 1;
		min-width: 0;
		text-align: right;
		word-break: break-word;
	}
	.data-table tbody td::before {
		content: attr(data-label);
		font-size: 11px;
		font-weight: 600;
		text-transform: uppercase;
		letter-spacing: .08em;
		color: var(--text-faint);
		flex: none;
	}

	/* inline-edit cells stack the label above a full-width input */
	.cell-edit { flex-direction: column; align-items: stretch !important; gap: 5px; }
	.cell-edit::before { align-self: flex-start; }

	.col-actions { width: auto; }
	.row-actions { width: 100%; }
	.row-actions .btn-icon,
	.row-actions .delete-form { flex: 1; }
	.row-actions .delete-form button { width: 100%; }
	.btn-icon { justify-content: center; }
	/* touch screens have no hover — show the action labels permanently */
	.btn-label { max-width: none; opacity: 1; margin-left: 6px; }

	.empty-row td { justify-content: center; }
	.empty-row td::before { content: none; }

	/* the table-wrap loses its card chrome on mobile — give the pagination
	   strip its own so it doesn't float bare. */
	.pagination {
		flex-direction: column;
		gap: 10px;
		margin-top: 12px;
		border: 1px solid var(--border);
		border-radius: var(--radius);
	}
	.page-step { width: 100%; text-align: center; }
}

/* --- 12. animation ------------------------------------------------------- */
@keyframes pulse {
	0%, 100% { box-shadow: 0 0 0 4px var(--accent-glow); }
	50%      { box-shadow: 0 0 0 7px rgba(34,211,238,.05); }
}

@keyframes flash {
	0%   { background: var(--accent-glow); box-shadow: inset 2px 0 0 var(--accent); }
	100% { background: transparent; }
}

@keyframes row-in {
	from { opacity: 0; transform: translateY(-6px); }
	to   { opacity: 1; transform: translateY(0); }
}
.row-enter { animation: row-in .28s ease-out; }

/* staggered first paint of the seeded rows */
@keyframes lift-in {
	from { opacity: 0; transform: translateY(8px); }
	to   { opacity: 1; transform: translateY(0); }
}
.app-header, .toolbar, .table-wrap, .create-fallback, .page-head, .panel {
	animation: lift-in .4s ease-out both;
}
.toolbar       { animation-delay: .05s; }
.table-wrap    { animation-delay: .1s; }
.create-fallback { animation-delay: .15s; }

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after {
		animation-duration: .001s !important;
		animation-iteration-count: 1 !important;
		transition-duration: .001s !important;
	}
}
