:root {
	--bg: #0f1216;
	--panel: #151a21;
	--muted: #8aa0b6;
	--text: #e7eef7;
	--accent: #40a0ff;
	--accent-muted: #2b77bf;
	--border: #263140;
	--pos: #35c26b;
	--neg: #ff6b6b;
	--warn: #ffc46b;
	--mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
	--radius: 10px;
}

* { box-sizing: border-box; }
html, body {
	height: 100%;
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font-family: 'Montserrat', 'Google Sans', 'Noto Sans', 'Castoro', sans-serif;
	overflow: auto; /* was: hidden — allow full-page scrolling */
	display: flex;
	flex-direction: column;
}

/* Top bar */
.topbar {
	position: sticky;
	top: 0;
	z-index: 10;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 10px 14px;
	background: linear-gradient(180deg, rgba(21,26,33,0.95), rgba(21,26,33,0.9));
	border-bottom: 1px solid var(--border);
	backdrop-filter: blur(6px);
}
.brand { font-weight: 700; letter-spacing: .2px; font-size: 22px; line-height: 1.1; }
.controls {
	display: flex; flex-wrap: wrap; align-items: end; gap: 12px; position: relative;
}
.control { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.control input:not([type="checkbox"]):not([type="radio"]), .control select {
	color: var(--text); background: var(--panel); border: 1px solid var(--border);
	padding: 8px 10px; border-radius: 8px; min-width: 180px;
}
.control select[multiple] { min-width: 220px; min-height: 40px; }

/* Drop zone styles */
.drop-zone {
	border: 2px dashed var(--border);
	border-radius: 8px;
	padding: 8px 12px;
	text-align: center;
	cursor: pointer;
	transition: all 0.2s ease;
	background: var(--panel);
	min-width: 220px;
	position: relative;
	min-height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.drop-zone:hover {
	border-color: var(--accent);
	background: rgba(64, 160, 255, 0.05);
}

.drop-zone.drag-over {
	border-color: var(--accent);
	background: rgba(64, 160, 255, 0.1);
	border-style: solid;
}

.drop-zone-content {
	display: flex;
	align-items: center;
	gap: 8px;
	pointer-events: none;
}

.drop-zone-icon {
	font-size: 16px;
	opacity: 0.7;
}

.drop-zone-text {
	font-size: 14px;
	color: var(--text);
	line-height: 1.2;
}

.drop-zone-subtext {
	font-size: 11px;
	color: var(--muted);
	margin-top: 1px;
}

.drop-zone.has-file {
	border-color: var(--pos);
	background: rgba(53, 194, 107, 0.1);
}

.drop-zone.has-file .drop-zone-icon {
	color: var(--pos);
}

.divider { width: 1px; height: 36px; background: var(--border); align-self: center; }

.btn {
	background: var(--panel); color: var(--text); border: 1px solid var(--border);
	padding: 8px 12px; border-radius: 8px; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent-muted); color: #fff; }
.btn:hover { filter: brightness(1.05); }
/* model dropdown */
.model-filter { position: relative; }
.btn.mini { padding: 4px 8px; font-size: 13px; }
.model-panel {
	position: absolute; top: calc(100% + 6px); left: 0; z-index: 20;
	background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
	box-shadow: 0 8px 24px rgba(0,0,0,0.35);
	width: 360px; max-width: min(360px, 90vw); max-height: 320px; overflow: hidden;
}
/* flip to the right edge of the trigger when needed */
.model-panel.align-right { left: auto; right: 0; }
.model-panel-head {
	display: flex; align-items: center; gap: 8px; padding: 6px; border-bottom: 1px solid var(--border);
}
.model-panel-head input[type="text"] {
	flex: 1; min-width: 0; background: #10151b; color: var(--text);
	border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px;
}
.model-panel .spacer { flex: 1; }
.model-list {
	max-height: 260px; overflow: auto; padding: 6px;
	display: block; /* simple list for tighter packing */
}
.model-item {
	display: flex; align-items: center; gap: 8px; font-size: 13px;
	padding: 2px 4px; border-radius: 6px;
}
.model-item:hover { background: rgba(255,255,255,0.04); }
.model-item input {
	width: 14px; height: 14px; min-width: 14px; padding: 0; margin: 0; border: 0;
	accent-color: var(--accent);
}
.model-item .mono {
	overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}

/* Layout */
.layout {
	flex: 1;
	min-height: 0;
	display: flex;
	flex-direction: column;
	gap: 12px;
	padding: 12px;
	max-height: none; /* contain within viewport */
	box-sizing: border-box;
}

/* NEW: two-column layout that replaces top/bottom sections */
.columns {
	display: grid;
	grid-template-columns: 1fr 320px; /* left grows, right fixed-ish */
	gap: 12px;
	flex: 1 1 auto;
	min-height: 0;
	max-height: 100%; /* contain within layout */
}

/* Left column: table on top, charts below */
.left-col {
	display: grid;
	/* Give the table more space than the charts */
	grid-template-rows: 1fr auto;
	gap: 12px;
	min-height: 0;
	max-height: 100%;
}
.left-bottom {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 12px;
	min-height: 0;
	height: 280px; /* fixed height for charts */
}

/* Right column: KPIs grow, Notes stays compact at bottom */
.right-col {
	display: grid;
	/* was: grid-template-rows: 1fr auto; */
	grid-template-rows: minmax(0, 1fr) auto; /* allow first row to shrink and scroll */
	gap: 12px;
	min-height: 0;
}

/* Panels */
.left-panel, .right-panel {
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	min-height: 0;
}
.left-panel { 
	display: flex; 
	flex-direction: column;
	min-height: 0;
	overflow: hidden; /* confine scrolling to .table-wrap */
	height: 100%; /* fill available space in grid row */
}
.left-panel h2, .right-panel h3 { margin: 6px 12px 4px 12px; font-size: 18px; }
/* Header row above the table: title left, column filter right */
.table-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin: 6px 12px 4px 12px;
}

/* Reuse dropdown styles; ensure relative anchor for the panel */
.col-filter { position: relative; }

/* Utility: hide table columns */
.col-hidden { display: none !important; }

.table-wrap {
	flex: 1;
	overflow: auto;
	overflow-x: auto;
	overflow-y: auto;
	scrollbar-gutter: stable both-edges;
	border-top: 1px solid var(--border);
	border-radius: 0 0 var(--radius) var(--radius);
	/* make the table area the scroll container */
	min-height: 0; /* was: 300px */
	max-height: 100%;
	overflow: auto;
}

/* Right panel now fills available space in its column */
.right-panel {
	display: flex;
	flex-direction: column;
	padding: 12px;
	height: 100%; /* fill the 1fr row */
	min-height: 0;
	overflow: auto; /* enable internal scroll instead of overlapping Notes */
}

/* Bottom section with charts and notes */
.below-panels {
	display: grid;
	grid-template-columns: 1fr 1fr 300px;
	gap: 12px;
}

/* Table */
table {
	border-collapse: separate;
	border-spacing: 0;
	width: max-content;
	min-width: 100%;
}
thead th {
	position: sticky; 
	top: 0; 
	background: #10151b;
	border-bottom: 1px solid var(--border); 
	z-index: 1;
}
/* Table footer for totals */
tfoot td {
	position: sticky;
	bottom: 0;
	background: #10151b;
	border-top: 2px solid var(--border);
	font-weight: 600;
	z-index: 1;
}
th, td {
	padding: 10px; 
	font-size: 16px; /* increased from 14px */
	border-bottom: 1px solid var(--border);
	white-space: normal;
	text-align: center;
	overflow-wrap: anywhere;
	word-break: break-word;
}
/* Keep model column left-aligned for readability */
.model-col {
	left: 0; 
	background: #10151b;
	max-width: 240px; 
	overflow-wrap: anywhere;
	z-index: 2;
	text-align: left;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* Responsive: further restrict model-col width on small screens */
@media (max-width: 700px) {
	.model-col {
		max-width: 120px;
	}
}

/* Table cells: allow safe wrapping for other columns */
th, td {
	overflow-wrap: anywhere;
	word-break: break-word;
}

tbody tr:hover { background: rgba(255,255,255,0.03); }

/* Cards contain their children; canvases fit inside */
.card {
	background: #10151b; 
	border: 1px solid var(--border); 
	border-radius: 10px;
	padding: 8px 12px 12px;
	min-height: 0;
	display: flex; 
	flex-direction: column; 
	overflow: hidden;
	height: 100%; /* fill available space */
}
.card h3 { margin: 6px 0 6px 0; font-size: 16px; }
.card canvas { 
	width: 100% !important; 
	height: 100% !important; 
	max-width: 100% !important;
	max-height: 100% !important;
	display: block; 
	flex: 1 1 auto;
}

/* Compact notes card so KPIs can grow */
.notes-card {
	min-height: 120px; /* smaller than default 300px */
}

/* KPIs should be able to grow and fill available space */
.kpis { 
	display: grid; 
	grid-template-columns: 1fr;
	gap: 10px; 
	margin-bottom: 4px;
	flex: 1 1 auto; /* allow growth within right-panel */
	align-content: start;
	align-items: start;
}

.kpi {
	background: #10151b; 
	border: 1px solid var(--border); 
	border-radius: 10px;
	padding: 10px 12px;
	display: grid; 
	row-gap: 4px; 
	align-content: center;
	min-height: 60px;
}

.kpi-value {
	font-size: 18px; /* larger KPI values */
	font-weight: 600;
	line-height: 1.2;
}

/* Reduce opacity for zero values */
.zero-value {
	opacity: 0.4;
}

/* Notes wrap safely and remain contained */
.notes { margin: 8px 0 0 18px; padding: 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

/* Utility: keep numbers on one line to preserve readability */
.mono { font-family: var(--mono); white-space: nowrap; }

/* About Me card styles */
.about-me-card {
	min-height: 100px;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 12px;
}

.about-me-content {
	text-align: center;
	color: var(--muted);
	font-size: 15px;
}

.about-link {
	color: var(--accent);
	text-decoration: none;
	font-size: 14px;
}
.about-link:hover {
	text-decoration: underline;
}

/* Privacy card styles */
.privacy-card {
	background: #10151b;
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 10px 12px;
	margin-bottom: 0;
	font-size: 13px;
}

.privacy-content {
	text-align: center;
	color: var(--muted);
	font-size: 12px;
}

/* Table header tooltip */
.table-tooltip {
	position: fixed;
	z-index: 9999;
	background: #222c38;
	color: #e7eef7;
	border: 1px solid var(--border);
	border-radius: 6px;
	padding: 7px 12px;
	font-size: 13px;
	box-shadow: 0 2px 12px rgba(0,0,0,0.18);
	pointer-events: none;
	white-space: pre-line;
	max-width: 260px;
	opacity: 0.97;
	transition: opacity 0.08s;
}

/* Responsive */
@media (max-width: 1100px) {
	/* Switch to scrollable layout for smaller screens */
	.layout {
		max-height: none; /* remove height constraint */
		min-height: 100vh; /* ensure full page coverage */
	}
	
	.columns {
		display: block;
		flex: 0 0 auto;
		min-height: auto;
		height: auto;
		max-height: none;
	}
	
	.left-col {
		display: block; /* remove grid completely */
		grid-template-rows: none;
		max-height: none;
	}
	
	.left-bottom {
		grid-template-columns: 1fr; /* stack charts vertically */
		height: auto; /* remove fixed height */
		margin-top: 12px;
	}
	
	.card {
		height: 280px; /* fixed height for charts on mobile */
		min-height: 280px;
	}
	
	.card canvas {
		height: 220px !important;
		max-height: 220px !important;
	}
	
	.kpis { 
		grid-template-columns: repeat(2, 1fr);
	}
	
	body { overflow: auto; }
	.model-panel { width: min(90vw, 360px); }

	/* Make right column flow under the left column content */
	.right-col {
		display: block;
		grid-template-rows: none;
		min-height: auto;
		margin-top: 12px;
		max-height: none;
	}
	
	.right-panel {
		height: auto;
		overflow: visible;
	}
}

/* Short viewport adjustments */
@media (max-height: 800px) {
	.layout {
		max-height: none; /* allow scrolling on short screens */
		min-height: 100vh;
	}
	.columns {
		max-height: none;
	}
	.left-col {
		max-height: none;
	}
	.left-bottom {
		height: 240px; /* slightly smaller charts on short screens */
	}
	.kpis { 
		flex: 0 0 auto;
	}
	.kpi {
		min-height: 48px;
	}
	body { 
		overflow-y: auto; 
		min-height: 100vh; 
	}
}

/* Column filter panel: always align left edge of panel to right edge of button */
.col-filter .model-panel {
	right: 0;
	left: auto;
	width: max-content;
	min-width: unset;
	max-width: unset;
	z-index: 40;
	box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
