:root {
	color-scheme: dark;
	--topbar-h: 52px;
	--report-w: 460px;

	--bg:             #121211;
	--surface-1:      #1a1a19;
	--surface-2:      #232321;
	--surface-3:      #2c2c2a;
	--border:         #383835;
	--text-primary:   #f0efec;
	--text-secondary: #c3c2b7;
	--text-muted:     #8f8e86;
	--accent:         #3987e5;

	/* Sinif renkleri: kategorik palet (koyu mod adimlari), 3D gorunum ile rapor ayni renkleri kullanir */
	--cls-ground:  #d95926;
	--cls-object:  #3987e5;
	--cls-noise:   #199e70;
	--cls-other:   #8f8e86;
	/* Yol ile acilan dosyalardaki diger ASPRS siniflari (kategorik paletin 4-7. slotlari) */
	--cls-3:       #c98500;
	--cls-4:       #d55181;
	--cls-5:       #008300;
	--cls-6:       #9085e9;

	--status-warning: #fab219;
}

html, body {
	margin: 0;
	height: 100%;
	overflow: hidden;
	background: var(--bg);
	color: var(--text-primary);
	font: 13px/1.4 "Segoe UI", system-ui, sans-serif;
}

button, input, select { font: inherit; color: inherit; }

.num, td.num, .stat .v { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }

/* ---------- Ust arac cubugu ---------- */
#topbar {
	position: absolute; top: 0; left: 0; right: 0;
	height: var(--topbar-h);
	display: flex; align-items: center; gap: 12px;
	padding: 0 12px;
	background: var(--surface-1);
	border-bottom: 1px solid var(--border);
	overflow-x: auto; overflow-y: hidden;
	scrollbar-width: none;
	white-space: nowrap;
	z-index: 20;
}
#topbar::-webkit-scrollbar { display: none; }
#topbar .brand {
	flex: none; display: flex; align-items: center;
	background: none !important; border: 0 !important; padding: 0 !important;
}
#topbar .brand img { display: block; height: 34px; width: auto; border-radius: 5px; }
#topbar .brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Masaustu: kontroller ust cubukta satir ici; Gorunum dugmesi ve kisa etiketler gizli */
#controls { display: contents; }
#btn_menu, #topbar .short { display: none; }
#topbar .group { display: flex; align-items: center; gap: 6px; }
#topbar .label { color: var(--text-muted); font-size: 12px; }
#topbar .spacer { flex: 1; min-width: 0; }
#topbar input[type=range] { width: 80px; accent-color: var(--accent); }
#topbar output { min-width: 40px; color: var(--text-secondary); }
#topbar .tools { gap: 4px; }
@media (max-width: 1720px) {
	#topbar .group > .label:not([for=budget]):not([for=psize]) { display: none; }
}
.check { display: flex; align-items: center; gap: 5px; color: var(--text-secondary); cursor: pointer; }
.check input { accent-color: var(--accent); }

#topbar button, .seg button {
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 6px;
	padding: 5px 9px;
	cursor: pointer;
	color: var(--text-secondary);
}
#topbar button:hover { background: var(--surface-3); color: var(--text-primary); }
#topbar button.active, #topbar button.primary[aria-expanded=true] {
	background: var(--accent); border-color: var(--accent); color: #fff;
}
.seg { display: flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child, .seg button:has(+ button[hidden]) { border-radius: 0 6px 6px 0; }
.seg button[hidden] { display: none; }

.chips { display: flex; gap: 6px; }
.chip {
	display: inline-flex; align-items: center; gap: 6px;
}
.chip .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
#topbar .chip[aria-pressed=false] { opacity: .45; text-decoration: line-through; }

/* ---------- Acilis ekrani: projeler + yeni goruntule ---------- */
#home {
	position: absolute; top: var(--topbar-h); left: 0; right: 0; bottom: 0; z-index: 40;
	overflow-y: auto; background: var(--bg);
}
.home-inner { max-width: 1040px; margin: 0 auto; padding: 28px 16px 48px; }
.hero { display: block; width: 100%; max-width: 800px; height: auto; border-radius: 12px; margin: 0 0 22px; }
.home-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.home-head h1 { margin: 0; font-size: 20px; font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
	display: flex; flex-direction: column; gap: 10px; text-align: left;
	padding: 16px 18px; border-radius: 12px; cursor: pointer;
	background: var(--surface-1); border: 1px solid var(--border); color: var(--text-primary);
}
.card:hover { border-color: var(--accent); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card .d { color: var(--text-secondary); font-size: 12.5px; line-height: 1.5; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.card .meta b { color: var(--text-primary); font-weight: 600; }
.card .stackbar { height: 8px; }
.card .badge { align-self: flex-start; font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--surface-3); color: var(--text-secondary); }
.card.new { align-items: center; justify-content: center; min-height: 150px; border-style: dashed; color: var(--text-secondary); }
.card.new .plus { font-size: 28px; line-height: 1; color: var(--accent); }

#new_view {
	margin-top: 22px; padding: 18px 20px; border-radius: 12px;
	background: var(--surface-1); border: 1px solid var(--border);
}
#new_view h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button {
	background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
	padding: 7px 12px; cursor: pointer; color: var(--text-secondary);
}
.tabs button[aria-selected=true] { color: var(--text-primary); border-bottom-color: var(--accent); }
#new_view label { display: block; color: var(--text-secondary); margin-bottom: 6px; }
#new_view .row { display: flex; gap: 6px; }
#new_view input[type=text] {
	flex: 1; min-width: 0;
	background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
	padding: 7px 9px; font-family: Consolas, monospace; font-size: 12.5px;
}
#new_view input[type=text]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#new_view input[type=file] { color: var(--text-secondary); }
#new_view button.primary, #new_view .row button {
	background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
	padding: 6px 12px; cursor: pointer; color: var(--text-secondary);
}
#new_view button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
#new_view button:disabled { opacity: .5; cursor: default; }
#local_file_box { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
#local_path_box + #local_file_box[hidden] { display: none; }
#open_status { margin-top: 10px; }
.progress { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
#open_bar { height: 100%; width: 0; background: var(--accent); transition: width .4s; }
#open_msg, #hf_status, #copc_msg { margin-top: 6px; color: var(--text-secondary); font-size: 12px; word-break: break-all; }
.err { color: #e66767 !important; }
#open_recent { margin-top: 10px; }
#open_recent .t, .hf-group .t { color: var(--text-muted); font-size: 11.5px; margin: 10px 0 4px; }
#open_recent button.recent {
	display: block; width: 100%; text-align: left;
	background: none; border: 0; border-radius: 5px; padding: 4px 6px;
	font-family: Consolas, monospace; font-size: 12px; color: var(--text-secondary);
	overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer;
}
#open_recent button.recent:hover { background: var(--surface-2); color: var(--text-primary); }
.hf-item {
	display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%;
	padding: 7px 10px; margin-bottom: 6px; border-radius: 6px; border: 0; text-align: left; cursor: pointer;
	background: var(--surface-2); color: var(--text-primary); text-decoration: none; font-size: 12.5px;
}
.hf-item:hover { background: var(--surface-3); }
.hf-item .n { font-family: Consolas, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hf-item .s { flex: none; color: var(--text-muted); font-size: 11.5px; }
.hf-item .k { flex: none; font-size: 11px; padding: 1px 7px; border-radius: 8px; background: var(--accent); color: #fff; }

/* ---------- Indirme paneli ---------- */
#download_panel {
	position: absolute; top: calc(var(--topbar-h) + 8px); right: 12px; z-index: 30;
	width: 440px; max-width: calc(100vw - 24px); max-height: calc(100vh - var(--topbar-h) - 24px);
	overflow-y: auto; box-sizing: border-box;
	padding: 14px 16px;
	background: var(--surface-1);
	border: 1px solid var(--border);
	border-radius: 10px;
	box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
#download_panel h2 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
#download_panel h3 { margin: 14px 0 6px; font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.dl-row {
	display: flex; align-items: center; justify-content: space-between; gap: 10px;
	padding: 7px 10px; border-radius: 6px; background: var(--surface-2); margin-bottom: 6px;
	color: var(--text-primary); text-decoration: none;
}
.dl-row:hover { background: var(--surface-3); }
.dl-row .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-row .s { flex: none; color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 12px; }
#download_panel select {
	width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; margin-bottom: 6px;
}
#download_panel a.link { color: var(--accent); }
td.dl a { color: var(--accent); text-decoration: none; }
td.dl a:hover { text-decoration: underline; }
#hud_src:empty { display: none; }
#hud_src { color: var(--text-primary); max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
#topbar button:disabled { opacity: .4; cursor: default; }

/* ---------- Goruntuleyici ---------- */
#viewer_wrap.potree_container {
	position: absolute;
	top: var(--topbar-h); bottom: 0; left: 0;
	right: 0;
	transition: right .25s;
}
body.report-open #viewer_wrap.potree_container { right: var(--report-w); }
#potree_render_area { background: radial-gradient(ellipse at center, #2a2c2e 0%, #121211 100%); }
#potree_quick_buttons { display: none !important; }

#hud {
	position: absolute; left: 10px; bottom: 10px; z-index: 10;
	display: flex; gap: 14px;
	padding: 5px 10px;
	background: rgba(18, 18, 17, .75);
	border: 1px solid var(--border);
	border-radius: 6px;
	color: var(--text-secondary);
	font-size: 12px;
	pointer-events: none;
}
#hud b { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }
#hud_loading { color: var(--accent); }

#viewer_msg {
	position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%);
	z-index: 10;
	max-width: 480px;
	padding: 18px 22px;
	background: var(--surface-1);
	border: 1px solid var(--border);
	border-radius: 10px;
	color: var(--text-secondary);
	line-height: 1.6;
}
#viewer_msg code { color: var(--text-primary); }

/* ---------- Rapor paneli ---------- */
#report {
	position: absolute; top: var(--topbar-h); right: 0; bottom: 0;
	width: var(--report-w);
	box-sizing: border-box;
	background: var(--surface-1);
	border-left: 1px solid var(--border);
	overflow-y: auto;
	transform: translateX(100%);
	transition: transform .25s;
	z-index: 15;
}
body.report-open #report { transform: none; }
.report-head {
	position: sticky; top: 0; z-index: 2;
	display: flex; justify-content: space-between; align-items: flex-start;
	padding: 14px 18px 10px;
	background: var(--surface-1);
	border-bottom: 1px solid var(--border);
}
.report-head h1 { margin: 0; font-size: 16px; font-weight: 600; }
button.icon {
	background: none; border: 0; color: var(--text-muted);
	font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px;
}
button.icon:hover { color: var(--text-primary); }
#report_body { padding: 4px 18px 30px; }

#report section { margin-top: 20px; }
#report h2 {
	margin: 0 0 10px; font-size: 13px; font-weight: 600;
	color: var(--text-secondary);
	text-transform: uppercase; letter-spacing: .04em;
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.stat .k { color: var(--text-muted); font-size: 11.5px; }
.stat .v { font-size: 18px; font-weight: 600; margin-top: 2px; }
.stat .s { color: var(--text-secondary); font-size: 11.5px; }
.stat .k .sw { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 5px; }

/* Siniflarin yigilmis cubugu */
.stackbar { display: flex; gap: 2px; height: 18px; }
.stackbar > div { height: 100%; min-width: 2px; cursor: default; }
.stackbar > div:first-child { border-radius: 4px 0 0 4px; }
.stackbar > div:last-child { border-radius: 0 4px 4px 0; }
.stackbar > div:only-child { border-radius: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; color: var(--text-secondary); font-size: 12px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; vertical-align: -1px; }
.legend b { color: var(--text-primary); font-weight: 600; }

/* Karo haritasi */
.map-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.map-head select {
	background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px;
}
#tile_map { display: block; width: 100%; height: auto; }
#tile_map rect.cell { stroke: var(--surface-1); stroke-width: 2; cursor: pointer; }
#tile_map rect.cell:hover { stroke: var(--text-primary); }
#tile_map rect.cell.sel { stroke: #fff; stroke-width: 3; }
.ramp-legend { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 11.5px; color: var(--text-muted); }
.ramp-legend .ramp { flex: 1; height: 8px; border-radius: 4px; }
.hint { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; }

/* Uyarilar */
.flags { list-style: none; margin: 0; padding: 0; }
.flags li {
	display: flex; gap: 8px; align-items: flex-start;
	padding: 7px 8px; border-radius: 6px; cursor: pointer;
}
.flags li:hover { background: var(--surface-2); }
.flag-icon {
	flex: none; width: 16px; height: 16px; border-radius: 50%;
	background: var(--status-warning); color: #1a1a19;
	font-weight: 700; font-size: 11px; line-height: 16px; text-align: center;
}
.flags .t { color: var(--text-primary); }
.flags .d { color: var(--text-secondary); font-size: 12px; }
.ok { color: var(--text-secondary); }

/* Tablo */
.tbl-wrap { max-height: 380px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 5px 7px; text-align: left; white-space: nowrap; }
td.num, th.num { text-align: right; }
thead th {
	position: sticky; top: 0;
	background: var(--surface-2); color: var(--text-muted); font-weight: 600;
	cursor: pointer; user-select: none;
}
thead th[aria-sort=ascending]::after { content: " ▲"; }
thead th[aria-sort=descending]::after { content: " ▼"; }
tbody tr { cursor: pointer; border-top: 1px solid var(--border); }
tbody tr:hover { background: var(--surface-2); }
tbody tr.sel { background: var(--surface-3); }
tbody td.flagged::before { content: "!"; display: inline-block; width: 14px; height: 14px; margin-right: 5px; border-radius: 50%; background: var(--status-warning); color: #1a1a19; font-weight: 700; font-size: 10px; line-height: 14px; text-align: center; }

dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; }
dl.kv dt { color: var(--text-muted); }
dl.kv dd { margin: 0; color: var(--text-primary); font-variant-numeric: tabular-nums; }

details { margin-top: 10px; background: var(--surface-2); border-radius: 8px; }
details summary { cursor: pointer; padding: 8px 12px; color: var(--text-secondary); }
details pre {
	margin: 0; padding: 0 12px 12px;
	max-height: 360px; overflow: auto;
	font: 11px/1.45 Consolas, monospace; color: var(--text-secondary);
	white-space: pre;
}

#tooltip {
	position: fixed; z-index: 1000; pointer-events: none;
	background: var(--surface-3); border: 1px solid var(--border); border-radius: 6px;
	padding: 7px 10px; font-size: 12px; color: var(--text-primary);
	box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
	max-width: 260px;
}
#tooltip .tt-h { font-weight: 600; margin-bottom: 3px; }
#tooltip .tt-r { display: flex; justify-content: space-between; gap: 14px; color: var(--text-secondary); }
#tooltip .tt-r b { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Mobil / tablet ---------- */
@media (max-width: 900px) {
	:root { --report-w: 100vw; }
	#topbar { gap: 8px; padding: 0 10px; overflow: visible; }
	#topbar .brand img { height: 30px; }
	#btn_menu, #topbar .short { display: inline; }
	#topbar .long { display: none; }
	#btn_menu[aria-expanded=true] { background: var(--accent); border-color: var(--accent); color: #fff; }

	/* Gorunum paneli: ust cubugun altinda acilan dikey liste */
	#controls {
		display: none;
		position: fixed; top: var(--topbar-h); left: 0; right: 0; z-index: 35;
		max-height: calc(100dvh - var(--topbar-h) - 40px); overflow-y: auto;
		flex-direction: column; align-items: stretch; gap: 14px;
		padding: 14px 16px 18px;
		background: var(--surface-1); border-bottom: 1px solid var(--border);
		box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
		white-space: normal;
	}
	body.menu-open #controls { display: flex; }
	#controls .group { flex-wrap: wrap; gap: 8px; }
	#controls .group > .label { display: block !important; width: 100%; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
	#controls .chips { flex-wrap: wrap; }
	#controls input[type=range] { flex: 1; width: auto; min-width: 140px; }
	#controls button, #controls .seg button { padding: 9px 12px; }
	#controls .tools { display: grid; grid-template-columns: repeat(3, 1fr); }

	/* Rapor tam ekran katman; goruntuleyici kuculmez */
	body.report-open #viewer_wrap.potree_container { right: 0; }
	#report { width: 100vw; }

	#viewer_msg { max-width: calc(100vw - 40px); box-sizing: border-box; }
	#hud { gap: 10px; font-size: 11px; max-width: calc(100vw - 20px); flex-wrap: wrap; }
	#download_panel { left: 12px; right: 12px; width: auto; }
	.home-inner { padding: 16px 12px 40px; }
	.hero { border-radius: 8px; margin-bottom: 16px; }
	.home-head h1 { font-size: 18px; }
	#new_view { padding: 14px; }
	#new_view .row { flex-wrap: wrap; }
	#new_view .row input[type=text] { flex-basis: 100%; }
	.grid { grid-template-columns: 1fr; }
	.stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 370px) {
	#topbar .brand img { height: 26px; }
	#btn_menu .t { display: none; }
	#topbar button { padding: 5px 8px; }
}
#topbar .group[hidden] { display: none !important; }
