/**
 * Scientific Calculator — Dedicated stylesheet
 *
 * Always dark-ish theme: in light mode uses dark grays instead of white.
 * 8-column unified grid with color-coded function zones.
 */

/* ============================================================
   CALCULATOR CONTAINER
   ============================================================ */

/* Ensure the Bootstrap container doesn't constrain the calculator */
body:has(.sci-calc-container) main .container {
	min-width: 1296px;
}

.sci-calc-container {
	display: flex;
	border: 1px solid #21262d;
	border-radius: 12px;
	overflow: visible;
	background: #0d1117;
	max-width: 1296px;
	min-width: 935px;
	margin: 0 auto;
	position: relative;
}

.sci-calc-main {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-width: 0;
	/* Main panel determines the container height; history panel fills the rest */
	max-width: 880px;
	position: relative;
	z-index: 2;
	border-radius: 12px 0 0 12px;
}

/* ============================================================
   DISPLAY
   ============================================================ */

.sci-calc-display {
	padding: 18px 22px;
	text-align: right;
	border-bottom: 1px solid #21262d;
	min-height: 123.187px;
	box-sizing: border-box;
}

.sci-calc-expr {
	width: 100%;
	background: transparent;
	border: none;
	outline: none;
	color: #c9d1d9;
	font-size: 1.15em;
	font-family: 'Consolas', 'Fira Mono', monospace;
	text-align: right;
	caret-color: #a3e635;
}

.sci-calc-expr::placeholder {
	color: #9ca3af;
}

.sci-calc-result {
	color: #a3e635;
	font-size: 2.4em;
	font-weight: 600;
	min-height: 1.2em;
	word-break: break-all;
}

/* Force result div to maintain height even when empty */
.sci-calc-result:empty::before {
	content: '\00a0';
}

/* ============================================================
   SYNTAX HINT & REFERENCE
   ============================================================ */

.sci-calc-hint {
	color: #484f58;
	font-size: 0.75em;
	text-align: left;
	padding: 4px 22px;
	border-bottom: 1px solid #21262d;
	font-style: italic;
}

.sci-calc-hint .syntax-toggle {
	color: #79c0ff;
	cursor: pointer;
	font-style: normal;
}

.sci-calc-syntax-ref {
	display: none;
	padding: 12px 22px;
	border-bottom: 1px solid #21262d;
	font-size: 0.82em;
	color: #8b949e;
	max-height: 300px;
	overflow-y: auto;
}

.sci-calc-syntax-ref.open {
	display: block;
}

.sci-calc-syntax-ref h6 {
	color: #c9d1d9;
	margin: 8px 0 4px;
	font-size: 0.95em;
}

.sci-calc-syntax-ref h6:first-child {
	margin-top: 0;
}

.sci-calc-syntax-ref code {
	color: #a3e635;
}

/* ============================================================
   MODE BAR
   ============================================================ */

.sci-calc-mode-bar {
	display: flex;
	padding: 6px 8px;
	gap: 4px;
	border-bottom: 1px solid #21262d;
	font-size: 0.8em;
	flex-wrap: wrap;
	align-items: center;
}

.sci-calc-mode-bar .mode-btn {
	padding: 4px 8px;
	border-radius: 5px;
	cursor: pointer;
	border: none;
	font-family: inherit;
	font-size: inherit;
	transition: background 0.15s;
}

.sci-calc-mode-bar .mode-btn.active {
	background: #238636;
	color: #fff;
}

.sci-calc-mode-bar .mode-btn.inactive {
	background: #21262d;
	color: #666;
}

.sci-calc-mode-bar .mode-btn.toggle-2nd {
	color: #79c0ff;
}

.sci-calc-mode-bar .mode-btn.toggle-inv {
	color: #d2a8ff;
}

.sci-calc-mode-bar .mode-btn.toggle-hyp {
	color: #ffa657;
}

.sci-calc-mode-sep {
	width: 1px;
	height: 20px;
	background: #21262d;
	margin: 0 4px;
	flex-shrink: 0;
}

/* ============================================================
   BUTTON GRID
   ============================================================ */

.sci-calc-buttons {
	flex: 1;
	display: grid;
	grid-template-columns: repeat(8, 1fr);
	gap: 3px;
	padding: 6px;
	overflow: visible;
	border-radius: 0 0 0 12px;
}

.sci-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 6px;
	cursor: pointer;
	font-size: 0.95em;
	padding: 6px 0;
	border: none;
	font-family: inherit;
	transition: filter 0.1s;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	line-height: 1;
	height: 32px;
}

.sci-btn:hover {
	filter: brightness(1.3);
}

.sci-btn:active {
	filter: brightness(0.8);
}

/* Instant custom tooltips via data-tip attribute */
.sci-btn[data-tip] {
	position: relative;
	overflow: visible;
}

.sci-btn[data-tip]::after {
	content: attr(data-tip);
	position: absolute;
	bottom: 100%;
	left: 50%;
	transform: translateX(-50%);
	background: #161b22;
	color: #e6edf3;
	font-size: 13px;
	font-weight: normal;
	line-height: 1.4;
	padding: 5px 8px;
	border-radius: 5px;
	border: 1px solid #30363d;
	white-space: nowrap;
	pointer-events: none;
	opacity: 0;
	z-index: 9999;
	transition: opacity 0.1s;
	margin-bottom: 4px;
}

.sci-btn[data-tip]:hover::after {
	opacity: 1;
}

/* Color-coded zones */
.sci-btn-calc { background: #1a1a2e; color: #c4b5fd; }
.sci-btn-fin { background: #1a2e1a; color: #86efac; }
.sci-btn-trig { background: #1e293b; color: #79c0ff; }
.sci-btn-const { background: #1e293b; color: #ffa657; }
.sci-btn-power { background: #1e293b; color: #d2a8ff; }
.sci-btn-stat { background: #1a2e2e; color: #5eead4; }
.sci-btn-matrix { background: #1a2a2e; color: #67e8f9; }
.sci-btn-bit { background: #2a1a1a; color: #fca5a5; }
.sci-btn-num { background: #1c2128; color: #e6edf3; font-size: 1.3em; height: 48px; }
.sci-btn-op { background: #21262d; color: #ffa657; height: 48px; }
.sci-btn-op-arith { background: #21262d; color: #ffa657; font-size: 1.6em; height: 48px; }
.sci-btn-mem { background: #21262d; color: #79c0ff; height: 48px; }
.sci-btn-del { background: #3d1117; color: #f85149; height: 48px; }
.sci-btn-clear { background: #3d1117; color: #f85149; height: 48px; }
.sci-btn-eq { background: #238636; color: #fff; font-weight: bold; font-size: 1.3em; height: 48px; }
.sci-btn-numpad { height: 48px; }
.sci-btn-span2 { grid-column: span 2; }

/* ============================================================
   HISTORY PANEL
   ============================================================ */

.sci-calc-history {
	border-left: 1px solid #21262d;
	padding: 14px;
	font-size: 0.88em;
	background: #0d1117;
	display: flex;
	flex-direction: column;
	/* Absolutely positioned so it doesn't influence container height.
	   left: 880px matches main panel max-width; fills to right edge. */
	position: absolute;
	left: 880px;
	right: 0;
	top: 0;
	bottom: 0;
	z-index: 1;
	border-radius: 0 12px 12px 0;
}

.sci-calc-history .sci-history-header,
.sci-calc-history .sci-history-actions {
	flex-shrink: 0;
}

#sci-history-items {
	flex: 1;
	overflow-y: auto;
	min-height: 0;
}

.sci-history-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 12px;
}

.sci-history-title {
	font-weight: 600;
	color: #d1d5db;
	font-size: 1.31em;
}

.sci-history-item {
	border-bottom: 1px solid #21262d;
	padding: 8px 0;
	cursor: pointer;
}

.sci-history-item:hover {
	background: rgba(255, 255, 255, 0.03);
}

.sci-history-item:last-of-type {
	border-bottom: none;
}

.sci-history-item-expr {
	color: #9ca3af;
	font-size: 1.1em;
	font-family: 'Consolas', 'Fira Mono', monospace;
	word-break: break-all;
}

.sci-history-item-result {
	color: #a3e635;
	font-weight: 600;
	font-size: 1.25em;
}

.sci-history-actions {
	margin-top: 16px;
	display: flex;
	gap: 6px;
}

.sci-history-actions button {
	flex: 1;
	background: #21262d;
	padding: 6px;
	text-align: center;
	border-radius: 5px;
	cursor: pointer;
	font-size: 0.88em;
	border: none;
	font-family: inherit;
}

.sci-history-actions button:hover {
	filter: brightness(1.3);
}

.sci-history-actions .export-btn { color: #79c0ff; }
.sci-history-actions .clear-btn { color: #f85149; }

/* ============================================================
   LIGHT MODE OVERRIDES — stay dark-ish
   ============================================================ */

[data-bs-theme="light"] .sci-calc-container {
	background: #1a1a1a;
	border-color: #333;
}

[data-bs-theme="light"] .sci-calc-display {
	border-color: #333;
}

[data-bs-theme="light"] .sci-calc-expr {
	color: #e0e0e0;
}

[data-bs-theme="light"] .sci-calc-hint {
	color: #666;
	border-color: #333;
}

[data-bs-theme="light"] .sci-calc-mode-bar {
	border-color: #333;
}

[data-bs-theme="light"] .sci-calc-mode-bar .mode-btn.inactive {
	background: #2a2a2a;
}

[data-bs-theme="light"] .sci-calc-buttons {
	background: #1a1a1a;
}

[data-bs-theme="light"] .sci-calc-history {
	background: #1a1a1a;
	border-color: #333;
}

[data-bs-theme="light"] .sci-history-item {
	border-color: #333;
}

[data-bs-theme="light"] .sci-calc-syntax-ref {
	border-color: #333;
}

[data-bs-theme="light"] .sci-history-actions button {
	background: #2a2a2a;
}

/* ============================================================
   RESPONSIVE: TABLET (768-991px)
   ============================================================ */

@media (max-width: 991px) {
	.sci-calc-main {
		max-width: none;
	}

	.sci-calc-history {
		position: static;
		left: auto;
		width: 100%;
		border-left: none;
		border-top: 1px solid #21262d;
		border-radius: 0 0 12px 12px;
		max-height: 200px;
	}
}

/* ============================================================
   RESPONSIVE: MOBILE (<768px)
   ============================================================ */

@media (max-width: 767px) {
	.sci-calc-buttons {
		grid-template-columns: repeat(4, 1fr);
	}

	.sci-btn {
		min-height: 44px;
		font-size: 0.85em;
	}

	.sci-btn-num {
		font-size: 1.1em;
	}

	.sci-btn-op-arith {
		font-size: 1.3em;
	}

	.sci-calc-result {
		font-size: 1.8em;
	}

	.sci-calc-history {
		position: static;
		max-height: 160px;
	}

	.sci-btn-span2 {
		grid-column: span 1;
	}
}
