:root {
	--brand: #238e99;
	--brand-dark: #176d76;
	--brand-soft: #dff3f4;
	--accent: #f36f61;
	--ink: #13252d;
	--muted: #65767e;
	--surface: #ffffff;
	--canvas: #f4f7f8;
	--border: #dce5e8;
	--shadow-sm: 0 2px 8px rgba(19, 37, 45, .08);
	--shadow-lg: 0 18px 48px rgba(9, 25, 31, .24);
	--topbar-height: 58px;
	--bottom-nav-height: 66px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body {
	margin: 0;
	padding-top: calc(var(--topbar-height) + env(safe-area-inset-top));
	background: var(--canvas);
	color: var(--ink);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
	font-size: 16px;
	-webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
a { color: inherit; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.app-main { min-height: calc(100dvh - var(--topbar-height) - env(safe-area-inset-top)); padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom)); }

.topbar {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 60;
	height: calc(var(--topbar-height) + env(safe-area-inset-top));
	padding-top: env(safe-area-inset-top);
	background: var(--brand);
	box-shadow: 0 1px 0 rgba(255,255,255,.15);
}
.topbar-inner { height: var(--topbar-height); display: flex; align-items: center; justify-content: space-between; padding: 0 16px; margin: 0 auto; max-width: 1280px; }
.brand { display: inline-flex; align-items: center; }
.brand img { display: block; height: 34px; width: auto; }
.desktop-nav { display: none; gap: 6px; }
.desktop-nav-link { color: #dff3f4; text-decoration: none; font-weight: 650; padding: 10px 15px; border-radius: 999px; }
.desktop-nav-link:hover, .desktop-nav-link.active { color: white; background: rgba(11, 78, 85, .3); }

.bottom-nav {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 70;
	height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
	padding-bottom: env(safe-area-inset-bottom);
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	background: var(--surface);
	border-top: 1px solid var(--border);
	box-shadow: 0 -8px 24px rgba(19, 37, 45, .08);
}
.bottom-nav-link { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: #718188; text-decoration: none; font-size: 11px; font-weight: 700; }
.bottom-nav-link svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bottom-nav-link.active { color: var(--brand); }

.page-shell { width: min(100%, 1180px); margin: 0 auto; padding: 22px 14px 36px; }
.page-heading { margin: 0; font-size: clamp(25px, 5vw, 34px); letter-spacing: -.035em; }
.page-subheading { margin: 6px 0 0; color: var(--muted); line-height: 1.45; }
.section-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-sm); }
.btn { border: 0; border-radius: 12px; min-height: 44px; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 750; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--brand); color: white; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--brand-soft); color: var(--brand-dark); }
.btn-danger { background: #fff0ee; color: #b73b31; }
.btn:disabled { opacity: .55; cursor: wait; }

/* Tracking map */
.tracking-page { overflow: hidden; }
.tracking-page .app-main { height: calc(100dvh - var(--topbar-height) - env(safe-area-inset-top) - var(--bottom-nav-height) - env(safe-area-inset-bottom)); min-height: 0; padding-bottom: 0; }
.map-shell, #map { width: 100%; height: 100%; }
.map-shell { position: relative; overflow: hidden; background: #0a1216; }
.mapboxgl-ctrl-top-right { top: 8px; right: 6px; }
.mapboxgl-ctrl-group { border-radius: 12px !important; overflow: hidden; box-shadow: var(--shadow-sm) !important; }

.flight-sheet {
	position: fixed;
	left: 0;
	right: 0;
	bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
	z-index: 65;
	max-height: min(72dvh, 620px);
	background: var(--surface);
	border-radius: 22px 22px 0 0;
	box-shadow: var(--shadow-lg);
	transform: translateY(calc(100% + 20px));
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: transform .24s ease, opacity .16s ease, visibility 0s linear .24s;
	overflow: auto;
}
.flight-sheet.open { transform: translateY(0); opacity: 1; visibility: visible; pointer-events: auto; transition-delay: 0s; }
.sheet-close { position: absolute; top: 12px; right: 12px; z-index: 2; width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(255,255,255,.92); color: var(--ink); display: grid; place-items: center; cursor: pointer; }
.sheet-close svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; }
.flight-sheet-content { padding: 20px 16px 18px; }
.sheet-loading { min-height: 210px; display: grid; place-content: center; justify-items: center; gap: 13px; padding: 54px 24px 34px; color: var(--muted); font-weight: 700; text-align: center; }
.loading-spinner { width: 34px; height: 34px; border: 3px solid var(--brand-soft); border-top-color: var(--brand); border-radius: 50%; animation: sheet-spin .8s linear infinite; }
@keyframes sheet-spin { to { transform: rotate(360deg); } }
.flight-sheet-hero { display: grid; grid-template-columns: 104px 1fr; gap: 14px; align-items: center; }
.flight-sheet-photo { width: 104px; aspect-ratio: 4/3; border-radius: 13px; object-fit: cover; background: #e8eff1; }
.flight-number-with-logo { display: flex; align-items: center; gap: 7px; min-width: 0; }
.airline-logo { flex: 0 0 auto; display: block; object-fit: contain; }
.airline-logo[hidden] { display: none; }
.airline-logo-sheet { width: 25px; height: 25px; }
.flight-number { margin: 0 0 4px; color: var(--muted); font-size: 14px; font-weight: 750; letter-spacing: .03em; }
.flight-number-with-logo .flight-number { margin-bottom: 0; }
.flight-route-large { margin: 0; font-size: 25px; line-height: 1.1; letter-spacing: -.04em; }
.flight-route-large span { color: var(--brand-dark); }
.flight-route-cities { margin: 5px 0 0; color: var(--muted); font-size: 13px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flight-identity { margin: 7px 0 0; color: var(--muted); font-size: 14px; }
.flight-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0; }
.metric { background: var(--canvas); border-radius: 12px; padding: 10px; min-width: 0; }
.metric-label { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.metric-value { display: block; margin-top: 3px; font-size: 15px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.history-pill { background: var(--brand-soft); color: var(--brand-dark); border-radius: 999px; padding: 6px 10px; font-size: 13px; font-weight: 700; text-decoration: none; }
.history-pill:hover { background: #ccebed; }
.sheet-actions { display: grid; gap: 8px; }
.sheet-error { padding: 28px 18px; text-align: center; color: var(--muted); }

/* Unified log */
.log-toolbar { position: sticky; top: calc(var(--topbar-height) + env(safe-area-inset-top)); z-index: 40; margin: -22px -14px 15px; padding: 17px 14px 12px; background: rgba(244,247,248,.96); backdrop-filter: blur(12px); }
.log-title-row { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.result-count { color: var(--muted); font-size: 13px; white-space: nowrap; }
.search-box { position: relative; }
.search-box svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 19px; height: 19px; fill: none; stroke: var(--muted); stroke-width: 2; }
.search-input { width: 100%; height: 46px; border: 1px solid var(--border); border-radius: 14px; padding: 0 79px 0 42px; color: var(--ink); background: white; outline: none; box-shadow: var(--shadow-sm); }
.search-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(35,142,153,.13); }
.search-submit { position: absolute; right: 5px; top: 5px; height: 36px; border: 0; border-radius: 10px; padding: 0 13px; background: var(--brand); color: white; font-size: 12px; font-weight: 800; cursor: pointer; }
.filter-row { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip { flex: 0 0 auto; height: 36px; border: 1px solid var(--border); border-radius: 999px; padding: 0 13px; display: inline-flex; align-items: center; background: white; color: var(--muted); font-size: 13px; font-weight: 750; cursor: pointer; text-decoration: none; }
.filter-chip.active { background: var(--brand); color: white; border-color: var(--brand); }
.spot-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.spot-card { position: relative; min-width: 0; overflow: hidden; background: white; border: 1px solid var(--border); border-radius: 15px; box-shadow: var(--shadow-sm); transition: transform .15s ease, box-shadow .15s ease; }
.spot-card:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(19,37,45,.13); }
.spot-card-link { display: block; color: inherit; text-decoration: none; }
.spot-image-wrap { position: relative; aspect-ratio: 16/10; overflow: hidden; background: #dfe7ea; }
.spot-image { width: 100%; height: 100%; display: block; object-fit: cover; }
.card-overlay { position: absolute; display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 50%; background: rgba(12,29,35,.72); color: white; backdrop-filter: blur(6px); }
.card-overlay svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.favorite-button { top: 8px; right: 8px; cursor: pointer; }
.favorite-button.active { color: #ff6b69; }
.favorite-button.active svg { fill: currentColor; }
.note-indicator { left: 8px; bottom: 8px; pointer-events: none; }
.flight-type-indicator { right: 8px; bottom: 8px; color: white; }
.spot-card-body { padding: 10px 10px 11px; min-width: 0; }
.spot-card-primary { min-width: 0; }
.spot-card-flight { font-size: 15px; font-weight: 800; overflow: hidden; white-space: nowrap; }
.spot-card-flight > span { overflow: hidden; text-overflow: ellipsis; }
.airline-logo-card { width: 21px; height: 21px; }
.spot-card-reg { margin-top: 4px; color: var(--muted); font-size: 12px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spot-card-route { margin-top: 5px; color: var(--brand-dark); font-size: 13px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spot-card-date { margin-top: 5px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-status { padding: 44px 18px; color: var(--muted); text-align: center; }
.load-more-wrap { display: flex; justify-content: center; padding: 24px 0 8px; }

/* Spot details */
.back-button { display: inline-flex; align-items: center; gap: 5px; margin-bottom: 12px; border: 0; background: transparent; padding: 5px 0; color: var(--brand-dark); font-weight: 750; cursor: pointer; }
.back-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; }
.detail-layout { display: grid; gap: 16px; }
.detail-hero { overflow: hidden; }
.detail-photo { width: 100%; max-height: 430px; aspect-ratio: 16/9; object-fit: cover; display: block; background: #e4ebed; }
.detail-summary { padding: 18px; }
.detail-kicker { color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: 12px; font-weight: 800; }
.detail-flight-number { margin: 8px 0 2px; font-size: clamp(32px, 9vw, 49px); line-height: 1.05; letter-spacing: -.045em; }
.airline-logo-detail { width: clamp(37px, 10vw, 52px); height: clamp(37px, 10vw, 52px); }
.detail-route { margin: 4px 0 3px; color: var(--brand-dark); font-size: clamp(24px, 7vw, 38px); line-height: 1.1; letter-spacing: -.045em; }
.detail-route-cities { margin: 5px 0 7px; color: var(--muted); font-size: clamp(14px, 4vw, 17px); font-weight: 650; }
.detail-meta { color: var(--muted); }
.facts-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1px; overflow: hidden; }
.fact { padding: 14px; background: white; border-bottom: 1px solid var(--border); }
.fact-label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 750; }
.fact-value { display: block; margin-top: 4px; font-weight: 750; overflow-wrap: anywhere; }
.detail-section { padding: 17px; }
.detail-section h2 { margin: 0 0 12px; font-size: 19px; }
.note-list { display: grid; gap: 9px; }
.note-card { background: var(--canvas); padding: 12px; border-radius: 12px; white-space: pre-wrap; }
.note-form { display: grid; gap: 9px; margin-top: 12px; }
.note-form textarea { width: 100%; min-height: 92px; resize: vertical; border: 1px solid var(--border); border-radius: 12px; padding: 11px; }
.detail-map { width: 100%; height: 330px; border-radius: 13px; overflow: hidden; }
.danger-zone { margin-top: 16px; }

/* Settings */
.settings-grid { display: grid; gap: 13px; margin-top: 20px; }
.settings-card { padding: 18px; }
.settings-card h2 { margin: 0 0 5px; font-size: 18px; }
.settings-card p { margin: 0; color: var(--muted); line-height: 1.45; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 15px; }

/* Authentication */
.auth-body { min-height: 100dvh; display: grid; place-items: center; padding: max(24px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom)); background: radial-gradient(circle at top, #43aeb8 0, #238e99 42%, #176d76 100%); }
.auth-shell { width: min(100%, 420px); }
.auth-logo { display: block; width: min(270px, 72vw); height: auto; margin: 0 auto 25px; }
.auth-card { padding: 25px; border-radius: 22px; background: rgba(255,255,255,.98); box-shadow: var(--shadow-lg); }
.auth-card h1 { margin: 0; font-size: 28px; letter-spacing: -.035em; }
.auth-card > p { margin: 7px 0 21px; color: var(--muted); line-height: 1.45; }
.auth-form { display: grid; gap: 9px; }
.auth-form label { margin-top: 4px; font-size: 13px; font-weight: 750; }
.auth-form input { width: 100%; height: 46px; border: 1px solid var(--border); border-radius: 12px; padding: 0 12px; outline: none; }
.auth-form input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(35,142,153,.13); }
.auth-form .btn { margin-top: 9px; width: 100%; }

@media (min-width: 600px) {
	.spot-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
}

@media (min-width: 768px) {
	:root { --topbar-height: 66px; }
	.desktop-nav { display: flex; }
	.bottom-nav { display: none; }
	.app-main { padding-bottom: 0; }
	.page-shell { padding: 30px 24px 48px; }
	.tracking-page .app-main { height: calc(100dvh - var(--topbar-height)); }
	.log-toolbar { top: var(--topbar-height); margin: -30px -24px 20px; padding: 22px 24px 15px; }
	.log-controls { display: grid; grid-template-columns: minmax(280px, 460px) 1fr; align-items: center; gap: 14px; }
	.filter-row { margin-top: 0; justify-content: flex-end; }
	.spot-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 17px; }
	.flight-sheet { position: absolute; left: auto; right: 16px; bottom: auto; top: 16px; width: 390px; max-height: calc(100% - 32px); border-radius: 20px; transform: translateX(calc(100% + 40px)); }
	.flight-sheet.open { transform: translateX(0); }
	.flight-sheet-content { padding: 20px; }
	.detail-layout { grid-template-columns: minmax(0, 1.3fr) minmax(330px, .7fr); align-items: start; }
	.detail-side { display: grid; gap: 16px; }
	.settings-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (min-width: 1180px) {
	.spot-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
