:root {
	--blue: #1d4ed8;
	--blue-600: #2563eb;
	--blue-50: #eff6ff;
	--ink: #0f172a;
	--muted: #64748b;
	--line: #e2e8f0;
	--bg: #f1f5f9;
	--card: #ffffff;
	--green: #16a34a;
	--orange: #ea580c;
	--red: #dc2626;
	--radius: 14px;
	--safe-top: env(safe-area-inset-top, 0px);
	--safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
	margin: 0;
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
	color: var(--ink);
	background: var(--bg);
}

body {
	padding-bottom: calc(72px + var(--safe-bottom));
}

/* App bar */
.app-bar {
	position: sticky;
	top: 0;
	z-index: 10;
	background: linear-gradient(135deg, var(--blue-600), var(--blue));
	color: #fff;
	padding-top: var(--safe-top);
	box-shadow: 0 2px 8px rgba(2, 32, 96, 0.25);
}
.app-bar-inner {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 16px;
}
.app-bar h1 { font-size: 1.1rem; margin: 0; font-weight: 700; }
.install-hint {
	font-size: 0.8rem;
	background: rgba(255,255,255,0.2);
	padding: 6px 12px;
	border-radius: 20px;
}

.content { padding: 16px; max-width: 760px; margin: 0 auto; }
.view { display: block; }
.view[hidden] { display: none; }

h2 { font-size: 1.25rem; margin: 4px 0 14px; }
h3 { font-size: 1rem; margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 0.85rem; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }

/* Cards */
.card {
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: 16px;
	margin-bottom: 14px;
	box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

/* Vehicle card */
.card-vehicle { background: linear-gradient(135deg, #1e3a8a, #2563eb); color: #fff; border: none; }
.vehicle-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.vehicle-plate {
	font-size: 1.5rem; font-weight: 800; letter-spacing: 1px;
	background: #fff; color: var(--ink); display: inline-block;
	padding: 4px 12px; border-radius: 6px; border: 2px solid #1e3a8a;
}
.vehicle-make { margin-top: 8px; opacity: 0.9; }
.vehicle-odo { text-align: right; }
.vehicle-odo .muted { color: rgba(255,255,255,0.8); display: block; }
.vehicle-odo strong { font-size: 1.2rem; }

/* Documents */
.docs-grid, .stats-grid { display: grid; gap: 12px; }
.docs-grid { grid-template-columns: 1fr 1fr; }
.stats-grid { grid-template-columns: 1fr 1fr 1fr; }
.doc-card { margin-bottom: 14px; }
.doc-label { font-size: 0.8rem; color: var(--muted); }
.doc-date { font-size: 1.05rem; font-weight: 700; margin: 4px 0; }
.doc-days { font-size: 0.85rem; font-weight: 600; }
.doc-card.ok { border-left: 4px solid var(--green); }
.doc-card.warn { border-left: 4px solid var(--orange); }
.doc-card.danger { border-left: 4px solid var(--red); }
.doc-card.ok .doc-days { color: var(--green); }
.doc-card.warn .doc-days { color: var(--orange); }
.doc-card.danger .doc-days { color: var(--red); }

.stat { text-align: center; padding: 14px 8px; margin-bottom: 14px; }
.stat .muted { display: block; margin-bottom: 4px; }
.stat strong { font-size: 1.1rem; }

/* Buttons */
.btn {
	appearance: none; border: 1px solid var(--line); background: #fff; color: var(--ink);
	padding: 12px 16px; border-radius: 10px; font-size: 0.95rem; font-weight: 600;
	cursor: pointer; transition: background 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-danger { background: #fff; color: var(--red); border-color: #fecaca; }
.btn-block { width: 100%; display: block; margin-top: 4px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.toolbar h2 { margin: 0; }
.filter-row { margin-bottom: 12px; }

/* Forms */
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 12px; }
.input {
	display: block; width: 100%; margin-top: 5px;
	padding: 12px; border: 1px solid var(--line); border-radius: 10px;
	font-size: 16px; color: var(--ink); background: #fff;
}
.input:focus { outline: none; border-color: var(--blue-600); box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.form-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Trips list */
.trips-list { display: flex; flex-direction: column; gap: 10px; }
.trip {
	background: var(--card); border: 1px solid var(--line); border-radius: 12px;
	padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px;
	cursor: pointer;
}
.trip-main { min-width: 0; }
.trip-route { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trip-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.trip-km { font-weight: 800; color: var(--blue); white-space: nowrap; }
.month-divider { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin: 8px 2px 2px; font-weight: 700; }

/* Tabbar */
.tabbar {
	position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
	display: flex; background: #fff; border-top: 1px solid var(--line);
	padding-bottom: var(--safe-bottom);
}
.tab {
	flex: 1; border: none; background: none; color: var(--muted);
	padding: 8px 4px; font-size: 0.72rem; font-weight: 600;
	display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--blue); }

/* Modal */
.modal {
	position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,0.5);
	display: flex; align-items: flex-end; justify-content: center;
}
.modal[hidden] { display: none; }
.modal-box {
	background: #fff; width: 100%; max-width: 560px;
	border-radius: 18px 18px 0 0; max-height: 92vh; overflow-y: auto;
	padding-bottom: calc(16px + var(--safe-bottom));
	animation: slideup 0.2s ease;
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
.modal-head h3 { margin: 0; }
.modal-body { padding: 16px; }
.icon-btn { border: none; background: none; font-size: 1.8rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 6px; }
.computed-km { background: var(--blue-50); color: var(--blue); padding: 10px; border-radius: 10px; text-align: center; margin-bottom: 14px; font-size: 0.95rem; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

/* Login */
.login-screen {
	position: fixed; inset: 0; z-index: 200;
	background: linear-gradient(135deg, var(--blue-600), var(--blue));
	display: flex; align-items: center; justify-content: center;
	padding: 24px; padding-top: calc(24px + var(--safe-top)); padding-bottom: calc(24px + var(--safe-bottom));
	overflow-y: auto;
}
.login-screen[hidden] { display: none; }
.login-box {
	background: #fff; width: 100%; max-width: 380px;
	border-radius: var(--radius); padding: 24px;
	box-shadow: 0 10px 30px rgba(2, 32, 96, 0.35);
}
.login-box h2 { margin: 0 0 6px; }
.login-box .muted { margin: 0 0 18px; }
.login-box .btn-block { margin-top: 6px; }
.login-error { color: var(--red); font-size: 0.9rem; font-weight: 600; margin: 10px 0 0; }
.login-note { margin: 14px 0 0; font-size: 0.78rem; text-align: center; }

.account-card #btn-logout { margin-top: 6px; }

/* Toast */
.toast {
	position: fixed; bottom: calc(82px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
	background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 24px; z-index: 100;
	font-size: 0.9rem; box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}

/* Print area hidden on screen */
.print-area { display: none; }

/* ============ PRINT ============ */
@media print {
	html, body { margin: 0 !important; padding: 0 !important; background: #fff !important; width: auto !important; }
	.app-bar, .tabbar, .content, .modal, .toast, .login-screen { display: none !important; }
	.print-area { display: block !important; margin: 0 !important; padding: 0 !important; width: 100% !important; }
	.print-doc {
		-webkit-print-color-adjust: exact; print-color-adjust: exact;
		width: 100% !important; margin: 0 !important; padding: 0 !important; box-sizing: border-box;
	}
	.print-doc table { page-break-inside: auto; width: 100% !important; }
	.print-doc tr { page-break-inside: avoid; }
	.print-doc thead { display: table-header-group; }
	@page { size: A4 landscape; margin: 10mm; }
}

/* ============ Dokument wydruku (też podgląd na ekranie) ============ */
.print-doc {
	font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
	font-size: 12px; color: #0f172a; line-height: 1.3;
}

/* Nagłówek dokumentu */
.print-doc .doc-header {
	display: flex; justify-content: space-between; align-items: center; gap: 18px;
	border-bottom: 2px solid #1d4ed8; padding-bottom: 9px; margin-bottom: 12px;
}
.print-doc .doc-title h1 {
	font-size: 19px; margin: 0; color: #1d4ed8; letter-spacing: 0.3px; font-weight: 800;
}
.print-doc .doc-sub { font-size: 13px; color: #475569; margin-top: 3px; font-weight: 600; text-transform: capitalize; }
.print-doc .doc-plate {
	text-align: center; border: 2px solid #1e3a8a; border-radius: 7px;
	padding: 4px 14px; min-width: 125px; background: #fff;
}
.print-doc .plate-label { display: block; font-size: 8px; letter-spacing: 1px; text-transform: uppercase; color: #64748b; }
.print-doc .plate-no { display: block; font-size: 20px; font-weight: 800; letter-spacing: 1px; color: #0f172a; }

/* Panele informacyjne */
.print-doc .info-panels { display: flex; gap: 14px; margin-bottom: 12px; }
.print-doc .panel {
	flex: 1; border: 1px solid #cbd5e1; border-radius: 7px; overflow: hidden; background: #fff;
}
.print-doc .panel-title {
	background: #1d4ed8; color: #fff; font-size: 10.5px; font-weight: 700;
	text-transform: uppercase; letter-spacing: 0.5px; padding: 4px 10px;
}
.print-doc .ir { display: flex; padding: 3px 10px; font-size: 11.5px; border-top: 1px solid #eef2f7; }
.print-doc .panel .ir:first-of-type { border-top: none; }
.print-doc .ir .k { width: 92px; color: #64748b; flex-shrink: 0; }
.print-doc .ir .v { font-weight: 600; }

/* Tabela */
.print-doc table { width: 100%; border-collapse: collapse; margin-top: 3px; }
.print-doc th, .print-doc td { border: 1px solid #cbd5e1; padding: 4px 7px; font-size: 12px; }
.print-doc thead th {
	background: #1e3a8a; color: #fff; text-align: center; font-weight: 700;
	font-size: 11px; text-transform: uppercase; letter-spacing: 0.2px; padding: 5px 7px;
}
.print-doc tbody tr:nth-child(even) td { background: #f1f5f9; }
.print-doc td.num, .print-doc th.num { text-align: right; white-space: nowrap; }
.print-doc td.c, .print-doc th.c { text-align: center; }
.print-doc tfoot td {
	font-weight: 800; background: #dbeafe; color: #1e3a8a; font-size: 12.5px; border-color: #93c5fd;
}

/* Podpisy i stopka */
.print-doc .sign { margin-top: 46px; display: flex; justify-content: space-around; gap: 40px; }
.print-doc .sign .line {
	border-top: 1px solid #64748b; width: 240px; text-align: center;
	padding-top: 5px; font-size: 11px; color: #475569;
}
.print-doc .doc-foot {
	margin-top: 18px; padding-top: 7px; border-top: 1px solid #e2e8f0;
	text-align: center; font-size: 9px; color: #94a3b8;
}
.print-doc .year-summary td.c { text-align: center; }
