/* Freelance Client Tracker — light, minimal, system-font design. */

:root {
	color-scheme: light;
	--bg: #f6f7f9;
	--surface: #ffffff;
	--surface-2: #f1f3f6;
	--text: #171a20;
	--muted: #6b7280;
	--border: #e4e6eb;
	--accent: #2563eb;
	--accent-hover: #1d4ed8;
	--accent-soft: #eff6ff;
	--accent-ring: rgba(37, 99, 235, 0.16);
	--danger: #dc2626;
	--danger-soft: #fef2f2;
	--radius: 12px;
	--radius-sm: 8px;
	--shadow: 0 1px 2px rgba(23, 26, 32, 0.05), 0 8px 24px rgba(23, 26, 32, 0.06);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
	margin: 0;
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 15px;
	line-height: 1.55;
	background: var(--bg);
	color: var(--text);
	-webkit-font-smoothing: antialiased;
}

:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

button { font: inherit; }

/* ── Brand ─────────────────────────────────────────────────────── */

.brand {
	display: flex;
	align-items: center;
	gap: 10px;
	font-weight: 700;
	font-size: 15px;
	letter-spacing: -0.01em;
}

.brand svg { color: var(--accent); flex-shrink: 0; }

/* ── Inputs ────────────────────────────────────────────────────── */

.field { margin-bottom: 14px; }

.field label {
	display: block;
	font-size: 13px;
	font-weight: 600;
	margin-bottom: 6px;
}

.input {
	width: 100%;
	padding: 9px 11px;
	font: inherit;
	font-size: 14.5px;
	color: var(--text);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	transition: border-color 0.15s ease-out, box-shadow 0.15s ease-out;
}

textarea.input { resize: vertical; min-height: 72px; }

.input:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-ring);
}

.input.invalid { border-color: var(--danger); }

.field-error {
	color: var(--danger);
	font-size: 12.5px;
	margin-top: 5px;
	min-height: 0;
}
.field-error:empty { display: none; }

.form-error {
	display: none;
	background: var(--danger-soft);
	color: #b91c1c;
	border: 1px solid #fecaca;
	padding: 10px 12px;
	border-radius: var(--radius-sm);
	font-size: 13.5px;
	margin-bottom: 14px;
}
.form-error.show { display: block; }

/* ── Buttons ───────────────────────────────────────────────────── */

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	font-weight: 600;
	font-size: 14px;
	padding: 9px 14px;
	border-radius: var(--radius-sm);
	border: 1px solid transparent;
	cursor: pointer;
	white-space: nowrap;
	transition: background-color 0.15s ease-out, border-color 0.15s ease-out, color 0.15s ease-out, transform 0.1s ease-out;
}

.btn:active { transform: scale(0.97); }

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

.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); }

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

.btn-block { width: 100%; }

.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.link-btn {
	background: none;
	border: none;
	color: var(--accent);
	font-size: 13.5px;
	font-weight: 500;
	cursor: pointer;
	padding: 4px 8px;
	border-radius: 6px;
	transition: background-color 0.15s ease-out, color 0.15s ease-out;
}
.link-btn:hover { background: var(--accent-soft); }
.link-btn.delete { color: var(--danger); }
.link-btn.delete:hover { background: var(--danger-soft); }
.link-btn.armed { background: var(--danger); color: #fff; font-weight: 600; }

/* ── Auth pages ────────────────────────────────────────────────── */

.auth-wrap {
	min-height: 100dvh;
	display: grid;
	place-items: center;
	padding: 24px 16px;
}

.auth-brand {
	justify-content: center;
	margin-bottom: 20px;
	font-size: 17px;
}

.auth-card {
	width: 100%;
	max-width: 400px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 14px;
	padding: 28px;
	box-shadow: var(--shadow);
}

.auth-card h1 {
	margin: 0 0 4px;
	font-size: 20px;
	letter-spacing: -0.02em;
}

.auth-sub {
	color: var(--muted);
	font-size: 14px;
	margin: 0 0 20px;
}

.auth-switch {
	margin: 16px 0 0;
	text-align: center;
	font-size: 13.5px;
	color: var(--muted);
}

.auth-switch a {
	color: var(--accent);
	font-weight: 600;
	text-decoration: none;
	padding: 6px 4px;
	margin: -6px -4px;
	display: inline-block;
}
.auth-switch a:hover { text-decoration: underline; }

/* ── App shell ─────────────────────────────────────────────────── */

.app-shell { display: flex; min-height: 100dvh; }

.sidebar {
	width: 236px;
	flex-shrink: 0;
	background: var(--surface);
	border-right: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	gap: 4px;
	padding: 20px 14px 16px;
	position: sticky;
	top: 0;
	height: 100dvh;
}

.sidebar .brand { padding: 0 10px 16px; }

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
	display: flex;
	align-items: center;
	gap: 10px;
	width: 100%;
	padding: 9px 12px;
	border: none;
	background: none;
	border-radius: var(--radius-sm);
	font-size: 14.5px;
	font-weight: 500;
	color: var(--muted);
	text-align: left;
	cursor: pointer;
	transition: background-color 0.15s ease-out, color 0.15s ease-out;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.sidebar-user {
	margin-top: auto;
	border-top: 1px solid var(--border);
	padding-top: 14px;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.sidebar-user .name { font-weight: 600; font-size: 14px; }
.sidebar-user .email {
	color: var(--muted);
	font-size: 12.5px;
	word-break: break-all;
	margin-bottom: 2px;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 12px 24px;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	position: sticky;
	top: 0;
	z-index: 10;
}

.search {
	position: relative;
	flex: 1;
	max-width: 420px;
}

.search svg {
	position: absolute;
	left: 11px;
	top: 50%;
	transform: translateY(-50%);
	color: var(--muted);
	pointer-events: none;
}

.search .input { padding-left: 36px; }

.content {
	padding: 24px;
	max-width: 1080px;
	width: 100%;
	margin: 0 auto;
}

.page-title {
	margin: 0;
	font-size: 22px;
	font-weight: 700;
	letter-spacing: -0.02em;
}

.page-sub {
	color: var(--muted);
	margin: 2px 0 20px;
	font-size: 14px;
}

/* ── Stat cards ────────────────────────────────────────────────── */

.stats-grid {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 14px;
}

.stat-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 18px;
}

.stat-card .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat-card .value {
	font-size: 28px;
	font-weight: 700;
	letter-spacing: -0.02em;
	margin-top: 6px;
	line-height: 1.2;
}

/* ── Clients table ─────────────────────────────────────────────── */

.table-toolbar {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-bottom: 14px;
	flex-wrap: wrap;
}

.table-toolbar .input { width: auto; min-width: 160px; }

.table-count { color: var(--muted); font-size: 13.5px; margin-left: auto; }

.table-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	overflow-x: auto;
}

.clients-table { width: 100%; border-collapse: collapse; font-size: 14px; }

.clients-table th {
	text-align: left;
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--muted);
	font-weight: 600;
	padding: 11px 14px;
	border-bottom: 1px solid var(--border);
	white-space: nowrap;
}

.clients-table th.sortable { cursor: pointer; user-select: none; }
.clients-table th.sortable:hover { color: var(--text); }
.sort-ind { font-size: 9px; margin-left: 3px; }

.clients-table td {
	padding: 11px 14px;
	border-bottom: 1px solid var(--border);
	vertical-align: middle;
}

.clients-table tbody tr:last-child td { border-bottom: 0; }

@media (hover: hover) and (pointer: fine) {
	.clients-table tbody tr:hover { background: #fafbfc; }
}

.cell-strong { font-weight: 600; }
.dim { color: var(--muted); }

.pill {
	display: inline-block;
	padding: 3px 10px;
	border-radius: 999px;
	font-size: 12px;
	font-weight: 600;
	white-space: nowrap;
}
.pill.lead { background: #eff6ff; color: #1d4ed8; }
.pill.active { background: #ecfdf5; color: #047857; }
.pill.paused { background: #fffbeb; color: #b45309; }
.pill.archived { background: #f4f4f5; color: #52525b; }

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

/* ── Empty states ──────────────────────────────────────────────── */

.empty-state { text-align: center; padding: 56px 20px; }
.empty-emoji { font-size: 44px; margin-bottom: 12px; }
.empty-state h3 { margin: 0 0 6px; font-size: 17px; letter-spacing: -0.01em; }
.empty-state p { color: var(--muted); margin: 0 auto 18px; max-width: 380px; font-size: 14px; }
.empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ── Modal ─────────────────────────────────────────────────────── */

.modal-overlay {
	position: fixed;
	inset: 0;
	background: rgba(15, 18, 25, 0.45);
	display: grid;
	place-items: center;
	padding: 16px;
	z-index: 100;
	animation: fadeIn 0.18s ease-out;
}

.modal {
	background: var(--surface);
	border-radius: 14px;
	width: 100%;
	max-width: 540px;
	max-height: 90dvh;
	overflow-y: auto;
	padding: 22px 24px;
	animation: popIn 0.2s cubic-bezier(0.23, 1, 0.32, 1);
}

.modal h2 { margin: 0 0 2px; font-size: 18px; letter-spacing: -0.01em; }
.modal .sub { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.96); } }

/* ── Toast ─────────────────────────────────────────────────────── */

.toast {
	position: fixed;
	bottom: 20px;
	left: 50%;
	transform: translateX(-50%);
	background: #1f2430;
	color: #fff;
	padding: 10px 16px;
	border-radius: var(--radius-sm);
	font-size: 13.5px;
	font-weight: 500;
	box-shadow: var(--shadow);
	z-index: 200;
	animation: toastIn 0.2s ease-out;
}

@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ── Responsive ────────────────────────────────────────────────── */

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

@media (max-width: 840px) {
	.app-shell { flex-direction: column; }

	.sidebar {
		position: static;
		width: auto;
		height: auto;
		flex-direction: row;
		align-items: center;
		gap: 8px;
		padding: 10px 16px;
		border-right: 0;
		border-bottom: 1px solid var(--border);
	}

	.sidebar .brand { padding: 0 8px 0 0; }
	.sidebar .brand span { display: none; }

	.nav { flex-direction: row; }
	.nav-item { width: auto; padding: 8px 12px; }

	.sidebar-user {
		margin: 0 0 0 auto;
		border-top: 0;
		padding-top: 0;
		flex-direction: row;
		align-items: center;
		gap: 10px;
	}
	.sidebar-user .name { font-size: 13.5px; }
	.sidebar-user .email { display: none; }

	.content { padding: 16px; }
	.topbar { padding: 10px 16px; }
}

@media (max-width: 560px) {
	.stat-card .value { font-size: 24px; }
	.content, .topbar { padding-left: 12px; padding-right: 12px; }
}

/* Stack the table into cards on small screens (down to 380px). */
@media (max-width: 640px) {
	.clients-table thead { display: none; }

	.clients-table,
	.clients-table tbody,
	.clients-table tr,
	.clients-table td {
		display: block;
		width: 100%;
	}

	.clients-table tr { border-bottom: 1px solid var(--border); padding: 10px 14px; }
	.clients-table tbody tr:last-child { border-bottom: 0; }

	.clients-table td {
		border-bottom: 0;
		padding: 4px 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		gap: 12px;
		text-align: right;
	}

	.clients-table td::before {
		content: attr(data-label);
		color: var(--muted);
		font-size: 12px;
		font-weight: 600;
		text-align: left;
	}

	.clients-table td.no-label::before { content: none; }
	.clients-table td.actions-cell { justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
	.modal-overlay, .modal, .toast { animation: none; }
	.btn, .link-btn, .input { transition: none; }
}
