/* ================================================================
   SSRT Demo — standalone simplified app
   Same visual family as frontend/style.css (Tailwind gray palette),
   dark by default with a light theme via body.light-theme.
   ================================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
	--bg:            #111827;
	--panel:         #1F2937;
	--panel-2:       #374151;
	--border:        #374151;
	--border-2:      #4B5563;
	--text:          #F3F4F6;
	--text-muted:    #9CA3AF;
	--accent:        #3B82F6;
	--accent-soft:   rgba(59, 130, 246, 0.15);
	--green:         #10B981;
	--red:           #EF4444;
	--amber:         #F59E0B;
	--shadow:        0 2px 8px rgba(0, 0, 0, 0.5);
}

body.light-theme {
	--bg:            #F3F4F6;
	--panel:         #FFFFFF;
	--panel-2:       #E5E7EB;
	--border:        #D1D5DB;
	--border-2:      #9CA3AF;
	--text:          #111827;
	--text-muted:    #6B7280;
	--accent-soft:   rgba(59, 130, 246, 0.10);
	--shadow:        0 2px 8px rgba(0, 0, 0, 0.10);
}

html { height: 100%; }

body {
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
	background: var(--bg);
	color: var(--text);
	line-height: 1.5;
	transition: background 0.2s, color 0.2s;
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--panel-2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-2); }

/* ================================================================
   HEADER / FOOTER
   ================================================================ */
header {
	background: var(--panel);
	border-bottom: 1px solid var(--border);
	flex-shrink: 0;
	box-shadow: var(--shadow);
}

.header-container {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	width: 100%;
	max-width: 64rem;
	margin: 0 auto;
	padding: 0.9rem 1.5rem;
}

#logo { height: 2.2rem; width: auto; }

header h1 { font-size: 1.15rem; font-weight: 600; letter-spacing: 0.01em; }

.demo-badge {
	font-size: 0.62rem;
	font-weight: 700;
	letter-spacing: 0.08em;
	color: var(--accent);
	border: 1px solid var(--accent);
	border-radius: 0.3rem;
	padding: 0.1rem 0.4rem;
	vertical-align: 0.25em;
	margin-left: 0.35rem;
}

#theme-toggle {
	margin-left: auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.5rem;
	height: 2.5rem;
	background: var(--panel-2);
	border: 1px solid var(--border-2);
	border-radius: 0.5rem;
	font-size: 1.15rem;
	cursor: pointer;
	transition: transform 0.1s;
}
#theme-toggle:active { transform: scale(0.94); }
body:not(.light-theme) .theme-icon-sun  { display: none; }
body.light-theme       .theme-icon-moon { display: none; }

footer {
	flex-shrink: 0;
	text-align: center;
	padding: 1rem;
	color: var(--text-muted);
	font-size: 0.85rem;
	border-top: 1px solid var(--border);
	background: var(--panel);
}

/* ================================================================
   LAYOUT
   ================================================================ */
main {
	flex: 1;
	width: 100%;
	max-width: 64rem;
	margin: 0 auto;
	padding: 1.25rem 1.5rem 2rem;
	display: flex;
	flex-direction: column;
	gap: 1.1rem;
}

.card {
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 0.75rem;
	box-shadow: var(--shadow);
	padding: 1.1rem 1.25rem;
}

/* ================================================================
   SETUP CARD — connection + languages
   ================================================================ */
.setup-row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.9rem;
}

.conn-group { display: flex; align-items: center; gap: 0.55rem; }

.conn-dot {
	width: 0.65rem;
	height: 0.65rem;
	border-radius: 50%;
	background: var(--text-muted);
	flex-shrink: 0;
	transition: background 0.2s;
}
.conn-dot[data-state="on"]         { background: var(--green); box-shadow: 0 0 6px var(--green); }
.conn-dot[data-state="connecting"] { background: var(--amber); animation: blink 1s infinite; }
.conn-dot[data-state="off"]        { background: var(--red); }
@keyframes blink { 50% { opacity: 0.35; } }

#conn-label { font-size: 0.88rem; color: var(--text-muted); }

#reconnect-btn {
	background: var(--panel-2);
	border: 1px solid var(--border-2);
	border-radius: 0.45rem;
	color: var(--text);
	font-size: 0.82rem;
	padding: 0.42rem 0.8rem;
	cursor: pointer;
}
#reconnect-btn:hover { border-color: var(--accent); }

.lang-group { display: flex; align-items: center; gap: 0.5rem; }

.select-wrap select {
	appearance: none;
	background: var(--bg);
	border: 1px solid var(--border-2);
	border-radius: 0.45rem;
	color: var(--text);
	font-size: 0.9rem;
	padding: 0.45rem 2rem 0.45rem 0.7rem;
	cursor: pointer;
	min-width: 10.5rem;
}
.select-wrap { position: relative; }
.select-wrap::after {
	content: '▾';
	position: absolute;
	right: 0.65rem;
	top: 50%;
	transform: translateY(-50%);
	pointer-events: none;
	color: var(--text-muted);
	font-size: 0.8rem;
}
.select-wrap select:focus { outline: none; border-color: var(--accent); }
.select-wrap select:disabled { opacity: 0.55; cursor: not-allowed; }

#lang-swap-btn {
	background: var(--panel-2);
	border: 1px solid var(--border-2);
	border-radius: 0.45rem;
	color: var(--text);
	width: 2.1rem;
	height: 2.1rem;
	font-size: 1rem;
	cursor: pointer;
	flex-shrink: 0;
}
#lang-swap-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
#lang-swap-btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ================================================================
   INPUT CARD — mic + file
   ================================================================ */
.input-grid {
	display: grid;
	grid-template-columns: 1fr auto 1fr;
	gap: 1.1rem;
	align-items: stretch;
}

.input-pane {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.8rem;
	padding: 0.4rem 0.2rem;
}

.input-pane h2 { font-size: 0.95rem; font-weight: 600; }

.pane-divider {
	display: flex;
	align-items: center;
	color: var(--text-muted);
	font-size: 0.8rem;
}
.pane-divider span {
	writing-mode: vertical-rl;
	text-orientation: mixed;
	border-left: 1px solid var(--border);
	padding-left: 0.55rem;
	letter-spacing: 0.2em;
}

.hint { font-size: 0.8rem; color: var(--text-muted); text-align: center; max-width: 18rem; }

/* --- record button --- */
#rec-btn {
	display: inline-flex;
	align-items: center;
	gap: 0.6rem;
	background: var(--accent);
	color: #fff;
	border: none;
	border-radius: 999px;
	font-size: 0.95rem;
	font-weight: 600;
	padding: 0.7rem 1.5rem;
	cursor: pointer;
	transition: background 0.15s, transform 0.1s;
}
#rec-btn:hover:not(:disabled) { filter: brightness(1.1); }
#rec-btn:active { transform: scale(0.97); }
#rec-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.rec-icon {
	width: 0.8rem;
	height: 0.8rem;
	border-radius: 50%;
	background: #fff;
	flex-shrink: 0;
	transition: border-radius 0.2s;
}
#rec-btn.recording { background: var(--red); }
#rec-btn.recording .rec-icon { border-radius: 2px; animation: blink 1.2s infinite; }

/* --- dropzone --- */
#dropzone {
	width: 100%;
	max-width: 22rem;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.35rem;
	border: 2px dashed var(--border-2);
	border-radius: 0.75rem;
	padding: 1.1rem 1rem;
	text-align: center;
	cursor: pointer;
	transition: border-color 0.15s, background 0.15s;
}
#dropzone:hover, #dropzone:focus, #dropzone.dragover {
	border-color: var(--accent);
	background: var(--accent-soft);
	outline: none;
}
#dropzone.disabled { opacity: 0.5; pointer-events: none; }
.dz-icon { font-size: 1.4rem; }
.dz-text { font-size: 0.85rem; }
.dz-formats { font-size: 0.72rem; color: var(--text-muted); letter-spacing: 0.03em; }

/* --- file progress --- */
#file-progress { width: 100%; max-width: 22rem; display: flex; flex-direction: column; gap: 0.45rem; }
#file-progress[hidden] { display: none; }

.file-name-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.6rem;
}
#file-name {
	font-size: 0.82rem;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
#file-cancel-btn {
	background: transparent;
	border: 1px solid var(--border-2);
	border-radius: 0.4rem;
	color: var(--text-muted);
	font-size: 0.75rem;
	padding: 0.2rem 0.6rem;
	cursor: pointer;
	flex-shrink: 0;
}
#file-cancel-btn:hover { border-color: var(--red); color: var(--red); }

.progress-track {
	width: 100%;
	height: 0.5rem;
	background: var(--panel-2);
	border-radius: 999px;
	overflow: hidden;
}
.progress-fill {
	height: 100%;
	width: 0%;
	background: var(--accent);
	border-radius: 999px;
	transition: width 0.15s linear;
}
.progress-fill.indeterminate {
	width: 30% !important;
	animation: slide 1.2s ease-in-out infinite;
}
@keyframes slide {
	0%   { margin-left: 0; }
	50%  { margin-left: 70%; }
	100% { margin-left: 0; }
}
#file-phase { font-size: 0.78rem; color: var(--text-muted); }

#status-line {
	margin-top: 0.9rem;
	padding-top: 0.7rem;
	border-top: 1px solid var(--border);
	font-size: 0.85rem;
	color: var(--text-muted);
}
#status-text.active { color: var(--green); font-weight: 600; }

/* ================================================================
   RESULTS
   ================================================================ */
.result-card { padding: 0; overflow: hidden; }

.result-header {
	display: flex;
	align-items: center;
	gap: 0.55rem;
	padding: 0.7rem 1.1rem;
	border-bottom: 1px solid var(--border);
	background: color-mix(in srgb, var(--panel) 70%, var(--bg));
}
.result-header h2 { font-size: 0.92rem; font-weight: 600; }
.result-lang { font-size: 0.8rem; color: var(--text-muted); }

#rec-dot {
	width: 0.6rem;
	height: 0.6rem;
	border-radius: 50%;
	background: var(--text-muted);
	opacity: 0.4;
}
#rec-dot[data-active="true"] { background: var(--red); opacity: 1; animation: blink 1.2s infinite; }

.copy-btn {
	margin-left: auto;
	background: transparent;
	border: 1px solid var(--border-2);
	border-radius: 0.4rem;
	color: var(--text-muted);
	font-size: 0.72rem;
	padding: 0.18rem 0.55rem;
	cursor: pointer;
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }

.result-output {
	min-height: 7.5rem;
	max-height: 16rem;
	overflow-y: auto;
	padding: 0.9rem 1.1rem;
	font-size: 1.02rem;
	white-space: pre-wrap;
	word-break: break-word;
}
#translation-output { font-size: 1.1rem; }

.placeholder { color: var(--text-muted); font-style: italic; font-size: 0.9rem; }

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 720px) {
	.input-grid { grid-template-columns: 1fr; }
	.pane-divider span {
		writing-mode: horizontal-tb;
		border-left: none;
		border-top: 1px solid var(--border);
		padding: 0.4rem 0 0;
		width: 100%;
		text-align: center;
	}
	.setup-row { flex-direction: column; align-items: stretch; }
	.conn-group { flex-wrap: wrap; }
	header h1 { font-size: 1rem; }
	.header-container { padding: 0.7rem 1rem; }
	main { padding: 0.9rem 0.9rem 1.4rem; gap: 0.8rem; }
	.card { padding: 0.9rem 1rem; }

	/* language selection stays on one line: selects shrink instead of wrapping */
	.lang-group { flex-wrap: nowrap; }
	.select-wrap { flex: 1 1 0; min-width: 0; }
	.select-wrap select { width: 100%; min-width: 0; }

	/* compact input card — results get the screen space */
	#input-card { padding: 0.7rem 0.9rem; }
	.input-grid { gap: 0.55rem; }
	.input-pane { gap: 0.45rem; padding: 0; }
	.input-pane h2 { font-size: 0.85rem; }
	.input-pane .hint { display: none; }
	.pane-divider { display: none; }
	#rec-btn { padding: 0.55rem 1.2rem; font-size: 0.9rem; }
	#dropzone {
		flex-direction: row;
		justify-content: center;
		gap: 0.5rem;
		padding: 0.55rem 0.8rem;
		max-width: none;
	}
	#dropzone .dz-icon { font-size: 1.05rem; }
	#dropzone .dz-text { font-size: 0.8rem; }
	#dropzone .dz-text br { display: none; }
	#dropzone .dz-formats { display: none; }
	#status-line { margin-top: 0.6rem; padding-top: 0.5rem; font-size: 0.78rem; }
}

/* Wide screens: transcript and translation side by side */
@media (min-width: 900px) {
	main {
		display: grid;
		grid-template-columns: 1fr 1fr;
		align-items: stretch;
	}
	#setup-card, #input-card { grid-column: 1 / -1; }
}

/* ================================================================
   LIVE SESSION — while recording or transcribing, the setup/input
   chrome collapses to a compact bar and the two result panes share
   all remaining screen height, so recognition AND translation are
   visible at the same time (crucial on phones).
   ================================================================ */
body.session-active {
	height: 100vh;
	height: 100dvh;   /* mobile browsers with dynamic toolbars */
	overflow: hidden;
}
body.session-active footer      { display: none; }
body.session-active #setup-card { display: none; }

body.session-active main {
	flex: 1;
	min-height: 0;
	overflow: hidden;
	padding-top: 0.8rem;
	padding-bottom: 0.8rem;
	gap: 0.8rem;
}

/* --- compact input bar --- */
body.session-active #input-card {
	display: flex;
	align-items: center;
	gap: 0.9rem;
	padding: 0.55rem 0.9rem;
}
body.session-active .input-grid   { display: flex; flex: 0 0 auto; gap: 0; }
body.session-active .pane-divider { display: none; }
body.session-active .input-pane   { padding: 0; gap: 0; flex-direction: row; }
body.session-active .input-pane h2,
body.session-active .hint         { display: none; }
body.session-active #rec-btn      { padding: 0.5rem 1.1rem; font-size: 0.88rem; }
body.session-mic  #file-pane      { display: none; }
body.session-file #mic-pane       { display: none; }
body.session-file #dropzone       { display: none; }
body.session-file .input-grid,
body.session-file #file-pane,
body.session-file #file-progress  { flex: 1 1 auto; max-width: none; min-width: 0; }
body.session-active #status-line {
	margin: 0;
	padding: 0;
	border: none;
	flex: 1 1 auto;
	min-width: 0;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	text-align: right;
}

/* --- results fill the remaining height --- */
body.session-active .result-card {
	flex: 1 1 0;
	min-height: 0;
	display: flex;
	flex-direction: column;
}
body.session-active #translation-section { flex-grow: 1.25; }  /* translation gets a bit more */
/* file uploads produce no translation — shrink that pane to its note */
body.session-file #translation-section { flex: 0 0 auto; }
body.session-file #translation-section .result-output { flex: 0 0 auto; max-height: 5.5rem; min-height: 0; }
body.session-active .result-header { padding: 0.5rem 1rem; }
body.session-active .result-output {
	flex: 1 1 auto;
	min-height: 0;
	max-height: none;
}

/* wide screens keep the side-by-side grid during a session */
@media (min-width: 900px) {
	body.session-active main {
		grid-template-rows: auto minmax(0, 1fr);
		min-height: 0;
	}
	body.session-active .result-card { min-height: 0; }
}
