/* Halkatla — mobile-first redesign */

*, *::before, *::after { box-sizing: border-box; }

:root {
	--bg: #f5f6f8;
	--surface: #ffffff;
	--surface-alt: #f0f1f3;
	--text: #1c1e21;
	--text-muted: #6b7280;
	--border: #e3e5e9;
	--accent: #4f46e5;
	--accent-soft: #eef2ff;
	--accent-contrast: #ffffff;
	--running: #16a34a;
	--running-soft: #f0fdf4;
	--cancelled: #dc2626;
	--unknown: #d97706;
	--unknown-soft: #fffbeb;
	--danger: #dc2626;
	--radius: 10px;
	--radius-sm: 6px;
	--shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 1px 8px rgba(0, 0, 0, .04);
	--header-h: 56px;
	--maxw: 1280px;
	--sp-1: 4px;
	--sp-2: 8px;
	--sp-3: 12px;
	--sp-4: 16px;
	--sp-5: 24px;
	--sp-6: 32px;
	color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg: #15171b;
		--surface: #1c1f24;
		--surface-alt: #23262c;
		--text: #e8e9eb;
		--text-muted: #9aa0a8;
		--border: #2b2f36;
		--shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 1px 8px rgba(0, 0, 0, .35);
		--accent: #818cf8;
		--accent-soft: #262a45;
		--running-soft: #16281f;
		--unknown-soft: #2b2314;
	}
}

.hidden { display: none !important; }

html { min-height: 100%; }

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	-webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5em; margin: 0 0 var(--sp-4); }
h2 { font-size: 1.1em; margin: var(--sp-5) 0 var(--sp-2); color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
p { margin: 0 0 var(--sp-3); }

button, input, select { font: inherit; color: inherit; }

svg { width: 1em; height: 1em; }

img.showImage {
	max-width: 100%;
	height: auto;
	max-height: 220px;
	border-radius: var(--radius);
	display: block;
}

/* ===== App shell ===== */

.topbar {
	position: sticky;
	top: 0;
	z-index: 30;
	display: flex;
	align-items: center;
	gap: var(--sp-3);
	height: var(--header-h);
	padding: 0 var(--sp-4);
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	border-top: 3px solid var(--accent);
}

.nav-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	margin: 0 calc(var(--sp-2) * -1) 0 calc(var(--sp-3) * -1);
	border: none;
	background: transparent;
	color: var(--text);
	border-radius: var(--radius-sm);
	cursor: pointer;
}
.nav-toggle:hover { background: var(--surface-alt); }
.nav-toggle svg { width: 22px; height: 22px; }

.brand {
	font-size: 1.15em;
	font-weight: 700;
	color: var(--accent);
}
.brand:hover { text-decoration: none; filter: brightness(1.15); }

.topbar-spacer { flex: 1; }

.layout {
	display: flex;
	align-items: flex-start;
	max-width: var(--maxw);
	margin: 0 auto;
}

.content {
	flex: 1;
	min-width: 0;
	padding: var(--sp-4);
}
@media (min-width: 640px) {
	.content { padding: var(--sp-5); }
}

/* Off-canvas nav on mobile, static sidebar from 900px up */
.sidenav {
	position: fixed;
	top: var(--header-h);
	left: 0;
	bottom: 0;
	width: 260px;
	max-width: 82vw;
	overflow-y: auto;
	background: var(--surface);
	border-right: 1px solid var(--border);
	transform: translateX(-100%);
	transition: transform .2s ease;
	z-index: 25;
	padding-bottom: var(--sp-5);
}
body.nav-open .sidenav { transform: translateX(0); }

.nav-scrim {
	display: none;
	position: fixed;
	inset: var(--header-h) 0 0 0;
	background: rgba(0, 0, 0, .35);
	z-index: 20;
}
body.nav-open .nav-scrim { display: block; }

@media (min-width: 900px) {
	.nav-toggle { display: none; }
	.layout { align-items: flex-start; }
	.sidenav {
		position: sticky;
		top: var(--header-h);
		transform: none;
		width: 240px;
		flex: none;
		max-height: calc(100vh - var(--header-h));
		border-right: 1px solid var(--border);
	}
	.nav-scrim { display: none !important; }
}

.nav-legend {
	display: flex;
	flex-wrap: wrap;
	gap: var(--sp-1) var(--sp-3);
	padding: var(--sp-4) var(--sp-4) var(--sp-3);
	font-size: .82em;
	color: var(--text-muted);
}
.nav-legend span { display: inline-flex; align-items: center; gap: var(--sp-1); }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); flex: none; }
.legend-dot.running { background: var(--running); }
.legend-dot.cancelled { background: var(--cancelled); }
.legend-dot.unknown { background: var(--unknown); }

.nav-filter { margin: 0 var(--sp-4) var(--sp-3); width: calc(100% - var(--sp-4) * 2); }

.sidenav ul { list-style: none; margin: 0; padding: var(--sp-2) 0; }
.sidenav li { border-bottom: 1px solid var(--border); }
.sidenav li:last-child { border-bottom: none; }
.sidenav a {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	padding: var(--sp-3) var(--sp-4);
	color: var(--text);
	min-height: 44px;
}
.sidenav a:hover { background: var(--surface-alt); text-decoration: none; }
.sidenav a::before {
	content: "";
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--text-muted);
	flex: none;
}
.sidenav li.running a::before { background: var(--running); }
.sidenav li.cancelled a::before { background: var(--cancelled); }
.sidenav li.unknown a::before { background: var(--unknown); }
.sidenav li.nav-plain a::before { display: none; }
.sidenav-auto-icon { width: 13px; height: 13px; margin-left: 5px; vertical-align: -2px; color: var(--accent); flex: none; }

/* ===== Buttons & form controls ===== */

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--sp-2);
	min-height: 40px;
	padding: 0 var(--sp-4);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--surface);
	color: var(--text);
	cursor: pointer;
}
.btn:hover { background: var(--surface-alt); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); }

input[type="text"], input[type="password"], select {
	min-height: 40px;
	padding: 0 var(--sp-3);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--surface);
	color: var(--text);
	width: 100%;
}
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
input[type="text"]:disabled { color: var(--text-muted); background: var(--surface-alt); }

.form-grid { display: flex; flex-direction: column; gap: var(--sp-4); max-width: 480px; margin-bottom: var(--sp-4); }
.form-row { display: flex; flex-direction: column; gap: var(--sp-1); }
.form-row label { font-size: .9em; color: var(--text-muted); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; margin-bottom: var(--sp-5); }
.form-status { font-size: .85em; color: var(--text-muted); }

.error-box {
	background: color-mix(in srgb, var(--danger) 12%, var(--surface));
	border: 1px solid var(--danger);
	color: var(--danger);
	padding: var(--sp-3) var(--sp-4);
	border-radius: var(--radius-sm);
	margin-bottom: var(--sp-4);
}

/* ===== Show cards (episode lists / search results) ===== */

.show-section { margin-bottom: var(--sp-6); }
.section-head {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
}
.section-head h2 { margin: var(--sp-5) 0 var(--sp-2); flex: 1; }
.icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	border: none;
	background: transparent;
	color: var(--text-muted);
	cursor: pointer;
	border-radius: var(--radius-sm);
	flex: none;
}
.icon-btn:hover { background: var(--surface-alt); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.spinning { color: var(--accent); }
.icon-btn.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.empty-note { color: var(--text-muted); padding: var(--sp-3) 0; }

.tab-bar {
	display: flex;
	gap: var(--sp-2);
	overflow-x: auto;
	border-bottom: 1px solid var(--border);
	margin-bottom: var(--sp-4);
}
.tab-btn {
	display: inline-flex;
	align-items: center;
	gap: var(--sp-2);
	white-space: nowrap;
	padding: var(--sp-3) var(--sp-2);
	border: none;
	border-bottom: 2px solid transparent;
	background: transparent;
	color: var(--text-muted);
	cursor: pointer;
	font-weight: 500;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 20px;
	height: 20px;
	padding: 0 6px;
	border-radius: 999px;
	background: var(--surface-alt);
	color: var(--text-muted);
	font-size: .78em;
	font-weight: 600;
}
.tab-badge-accent { background: var(--unknown); color: #fff; }

.ep-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-left: 3px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	overflow: hidden;
}
.ep-card-pending { border-left-color: var(--unknown); }
.ep-card-done { border-left-color: var(--running); }
.ep-card-main {
	display: flex;
	align-items: center;
	gap: var(--sp-3);
	padding: var(--sp-3) var(--sp-4);
}
.ep-card-info { flex: 1; min-width: 0; }
.ep-card-title { display: flex; flex-wrap: wrap; gap: 0 var(--sp-2); align-items: baseline; }
.ep-card-title a { font-weight: 600; color: var(--text); }
.ep-card-title a:hover { color: var(--accent); }
.ep-card-ep { color: var(--text-muted); font-size: .9em; }
.ep-card-sub {
	font-size: .88em;
	color: var(--text-muted);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.ep-card-date { font-size: .82em; color: var(--text-muted); white-space: nowrap; }
.ep-card-actions { display: flex; align-items: center; gap: var(--sp-2); flex: none; }
.ep-card-actions label { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: .82em; color: var(--text-muted); }

.status-pill {
	display: inline-flex;
	align-items: center;
	gap: var(--sp-2);
	font-size: .82em;
	padding: 3px 10px;
	border-radius: 999px;
	border: 1px solid var(--border);
	background: var(--surface-alt);
	color: var(--text-muted);
	cursor: pointer;
}
.status-pill:disabled { cursor: default; opacity: .7; }
.status-pill-Done { border-color: var(--running); color: var(--running); background: var(--running-soft); }
.status-pill-Error { border-color: var(--danger); color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.status-pill-InProgress { border-color: var(--unknown); color: var(--unknown); background: var(--unknown-soft); }

.attempt-history {
	margin-bottom: var(--sp-3);
	padding-bottom: var(--sp-3);
	border-bottom: 1px solid var(--border);
}
.attempt-history-title {
	font-size: .78em;
	color: var(--text-muted);
	text-transform: uppercase;
	letter-spacing: .04em;
	margin-bottom: var(--sp-2);
}
.attempt-row {
	display: flex;
	align-items: center;
	gap: var(--sp-3);
	padding: 4px 0;
	font-size: .85em;
}
.attempt-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attempt-date { color: var(--text-muted); font-size: .92em; }
.attempt-row .status-pill { cursor: default; flex: none; }

.ep-card-detail {
	border-top: 1px solid var(--border);
	padding: var(--sp-3) var(--sp-4);
	background: var(--surface-alt);
}

/* ===== NZB result cards ===== */

.nzb-search-form {
	display: flex;
	flex-wrap: wrap;
	gap: var(--sp-3);
	align-items: flex-end;
	margin-bottom: var(--sp-4);
}
.nzb-search-form .form-row { flex: 1 1 220px; margin: 0; }
.nzb-search-form .btn { flex: none; }

.nzb-result {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: var(--sp-3);
	display: flex;
	gap: var(--sp-3);
	align-items: flex-start;
}
.nzb-result + .nzb-result { margin-top: var(--sp-2); }
.nzb-result-tried-Error { background: color-mix(in srgb, var(--danger) 8%, var(--surface)); border-color: var(--danger); }
.nzb-result-tried-Done { background: var(--running-soft); border-color: var(--running); }
.nzb-result-tried-InProgress { background: var(--unknown-soft); border-color: var(--unknown); }
.nzb-result-tried-badge { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 20px; height: 20px; }
.nzb-result-tried-badge svg { width: 18px; height: 18px; }
.nzb-result-tried-Error .nzb-result-tried-badge { color: var(--danger); }
.nzb-result-tried-Done .nzb-result-tried-badge { color: var(--running); }
.nzb-result-tried-InProgress .nzb-result-tried-badge { color: var(--unknown); }
.nzb-result-actions { display: flex; flex-direction: column; gap: var(--sp-2); flex: none; }
.nzb-result-actions .icon-btn { border: 1px solid var(--border); width: 36px; height: 36px; }
.nzb-result-actions .icon-btn-idle { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.nzb-result-actions .icon-btn-done { color: var(--running); border-color: var(--running); background: var(--running-soft); }
.nzb-result-actions .icon-btn-error { color: var(--danger); border-color: var(--danger); }
.nzb-result-body { flex: 1; min-width: 0; }
.nzb-result-title { display: flex; justify-content: space-between; gap: var(--sp-2); font-weight: 600; }
.nzb-result-title a { color: var(--text); overflow-wrap: anywhere; }
.nzb-result-title a:hover { color: var(--accent); }
.nzb-result-size { color: var(--text-muted); font-weight: 400; white-space: nowrap; }
.nzb-result-meta {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	gap: var(--sp-1) var(--sp-3);
	font-size: .85em;
	color: var(--text-muted);
	margin-top: var(--sp-1);
}
.nzb-result-meta .comments-toggle { cursor: pointer; color: var(--accent); }
.nzb-comments {
	margin-top: var(--sp-2);
	padding-top: var(--sp-2);
	border-top: 1px solid var(--border);
	font-size: .85em;
}
.nzb-comments ul { margin: 0; padding-left: 1.2em; }
.nzb-comments li { list-style: disc; }

/* ===== Tables that remain tables (AllShows) rendered as cards via markup, styled here ===== */

.halkatlaGrid { width: 100%; }

.nowrap { white-space: nowrap; }

.table-scroll { overflow-x: auto; margin-bottom: var(--sp-4); }
.simple-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.simple-table th, .simple-table td { text-align: left; padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); }
.simple-table th { color: var(--text-muted); font-size: .85em; text-transform: uppercase; letter-spacing: .03em; }
.simple-table tr:last-child td { border-bottom: none; }

.autocomplete-wrap { position: relative; }
.autocomplete-list {
	position: absolute;
	z-index: 10;
	top: calc(100% + 4px);
	left: 0;
	right: 0;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	box-shadow: var(--shadow);
	max-height: 260px;
	overflow-y: auto;
}
.autocomplete-item { padding: var(--sp-2) var(--sp-3); cursor: pointer; }
.autocomplete-item:hover, .autocomplete-item.active { background: var(--surface-alt); }

.view-show-head { display: flex; flex-wrap: wrap-reverse; gap: var(--sp-5); align-items: flex-start; margin-bottom: var(--sp-4); }
.view-show-head .form-grid { flex: 1 1 260px; margin-bottom: 0; }
.view-show-head img.showImage { flex: 0 1 220px; }

@media (max-width: 480px) {
	.ep-card-main { flex-wrap: wrap; }
	.ep-card-date { order: 3; width: 100%; }
}
