/* ============================================================
 * RESET / BASE
 * ========================================================== */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }
body {
	margin: 0;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,
		"Helvetica Neue", Arial, sans-serif;
	font-size: var(--base-font-size);
	color: var(--text);
	background: var(--bg);
	line-height: 1.45;
	-webkit-font-smoothing: antialiased;
	transition: background var(--t-med), color var(--t-med);
}

h1, h2, h3, h4, p { margin: 0; }
h2 { font-size: 1.4rem; font-weight: 600; margin-bottom: var(--sp-3); }
h3 { font-size: 0.95rem; font-weight: 600; text-transform: uppercase;
	letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: var(--sp-3); }

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

[hidden] { display: none !important; }

code {
	font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
	font-size: 0.9em;
	background: var(--bg-elev-2);
	padding: 1px 5px;
	border-radius: 4px;
}

/* utilities */
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }

/* ============================================================
 * HEADER
 * ========================================================== */
.app-header {
	height: var(--header-h);
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 var(--sp-5);
	position: sticky;
	top: 0;
	z-index: 10;
}

.app-title {
	font-size: 1.15rem;
	font-weight: 600;
	color: var(--accent);
	letter-spacing: -0.01em;
}

.header-actions {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
}

.caller-id {
	font-size: 0.95rem;
	color: var(--text-muted);
	margin-right: var(--sp-3);
	padding: 4px 10px;
	background: var(--accent-soft);
	color: var(--accent);
	border-radius: var(--radius-pill);
	font-variant-numeric: tabular-nums;
}

/* ============================================================
 * BUTTONS
 * ========================================================== */
.icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	background: transparent;
	border: 1px solid transparent;
	border-radius: var(--radius-md);
	color: var(--text-muted);
	transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.icon-btn:hover { background: var(--bg-elev-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

.icon-btn-sm {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	background: transparent;
	border: none;
	border-radius: var(--radius-sm);
	color: var(--text-muted);
}
.icon-btn-sm:hover { background: var(--bg-elev-2); color: var(--text); }
.icon-btn-sm svg { width: 18px; height: 18px; }

#theme-toggle .icon-moon { display: none; }
html[data-theme="dark"] #theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] #theme-toggle .icon-moon { display: block; }

.text-btn {
	background: transparent;
	border: 1px solid var(--border);
	color: var(--text);
	padding: 6px 14px;
	border-radius: var(--radius-md);
	font-size: 0.95rem;
	transition: background var(--t-fast), border-color var(--t-fast);
}
.text-btn:hover { background: var(--bg-elev-2); border-color: var(--border-strong); }
.text-btn.small { padding: 4px 10px; font-size: 0.85rem; }
.text-btn.tiny  { padding: 0; width: 22px; height: 22px; border-radius: 50%; font-size: 0.85rem; }

.primary-btn {
	background: var(--accent);
	color: var(--accent-text);
	border: none;
	padding: 10px 20px;
	border-radius: var(--radius-md);
	font-size: 1rem;
	font-weight: 500;
	transition: background var(--t-fast), transform var(--t-fast);
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn.small { padding: 6px 14px; font-size: 0.9rem; }

.secondary-btn {
	background: transparent;
	color: var(--text);
	border: 1px solid var(--border-strong);
	padding: 8px 16px;
	border-radius: var(--radius-md);
	font-size: 0.95rem;
}
.secondary-btn:hover { background: var(--bg-elev-2); }

/* ============================================================
 * LOGIN VIEW
 * ========================================================== */
.login-view {
	min-height: calc(100vh - var(--header-h));
	display: flex;
	align-items: center;
	justify-content: center;
	padding: var(--sp-5);
}
.login-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	padding: var(--sp-7);
	box-shadow: var(--shadow-md);
	width: 100%;
	max-width: 360px;
	text-align: center;
}
.login-card h2 {
	color: var(--accent);
	margin-bottom: var(--sp-5);
}
#login-code {
	width: 100%;
	padding: 12px 14px;
	font-size: 1rem;
	background: var(--bg-elev-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	margin-bottom: var(--sp-4);
}
#login-code:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-soft);
}
#startup-button { width: 100%; }

.error-banner {
	margin-top: var(--sp-4);
	padding: 10px;
	background: var(--danger-soft);
	color: var(--danger);
	border-radius: var(--radius-md);
	font-size: 0.95rem;
	transition: opacity 1s;
}

/* ============================================================
 * MAIN VIEW LAYOUT
 * ========================================================== */
.main-view {
	max-width: var(--max-w);
	margin: 0 auto;
	padding: var(--sp-5);
	display: grid;
	grid-template-columns: 1fr 1.4fr 1fr;
	gap: var(--sp-5);
	align-items: start;
}

.col-left, .col-center, .col-right {
	display: flex;
	flex-direction: column;
	gap: var(--sp-5);
}

/* ============================================================
 * PANELS (cards)
 * ========================================================== */
.panel {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	padding: var(--sp-5);
}
.panel-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: var(--sp-3);
}
.panel-head h3 { margin-bottom: 0; }

/* ============================================================
 * DEVICE PANEL
 * ========================================================== */
.client-name {
	color: var(--text-muted);
	font-size: 0.9rem;
	word-break: break-all;
	margin-bottom: var(--sp-3);
}
.client-name .identity {
	display: block;
	color: var(--secondary);
	font-size: 1.2rem;
	font-weight: 600;
	letter-spacing: 0.02em;
	margin-top: 2px;
}

.audio-devices label {
	display: block;
	font-size: 0.85rem;
	color: var(--text-muted);
	margin: var(--sp-3) 0 var(--sp-1);
}
.audio-devices select {
	width: 100%;
	padding: 6px;
	background: var(--bg-elev-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	min-height: 60px;
}

/* ============================================================
 * ANSWER MODE GRID
 * ========================================================== */
.mode-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: var(--sp-2);
}
.mode-btn {
	background: var(--bg-elev-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	padding: var(--sp-3);
	text-align: left;
	transition: background var(--t-fast), border-color var(--t-fast),
	            color var(--t-fast), transform var(--t-fast);
	display: flex;
	flex-direction: column;
	gap: 2px;
	color: var(--text);
}
.mode-btn:hover { border-color: var(--border-strong); }
.mode-btn[aria-checked="true"] {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--accent-text);
}
.mode-btn[aria-checked="true"] .mode-desc { color: var(--accent-text); opacity: 0.85; }
.mode-label { font-weight: 600; font-size: 0.95rem; }
.mode-desc { font-size: 0.8rem; color: var(--text-muted); }

/* ============================================================
 * DIALPAD
 * ========================================================== */
.dial-panel { display: flex; flex-direction: column; gap: var(--sp-3); }

.number-input-wrap {
	display: flex;
	align-items: stretch;
	gap: var(--sp-2);
}
#phone-number {
	flex: 1;
	padding: 12px 14px;
	font-size: 1.15rem;
	font-variant-numeric: tabular-nums;
	background: var(--bg-elev-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	letter-spacing: 0.02em;
}
#phone-number:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-soft);
}
#number-backspace {
	width: auto; padding: 0 12px;
	border: 1px solid var(--border);
}

#number-caption {
	font-size: 0.8rem;
	color: var(--text-muted);
	margin: 0;
}

.dialpad {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: var(--sp-2);
	max-width: 320px;
	margin: var(--sp-2) auto 0;
}
.dtmf {
	aspect-ratio: 1.4 / 1;
	min-height: 56px;
	background: var(--bg-elev-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	color: var(--text);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	transition: background var(--t-fast), transform 80ms ease;
}
.dtmf:hover  { background: var(--bg-elev); border-color: var(--border-strong); }
.dtmf:active { transform: scale(0.96); background: var(--accent-soft); }
.d-num { font-size: 1.4rem; font-weight: 500; line-height: 1; }
.d-letters { font-size: 0.65rem; color: var(--text-dim); letter-spacing: 0.1em; margin-top: 2px; }

/* action buttons (call/hangup/mute/conf) */
.action-row {
	display: flex;
	justify-content: center;
	gap: var(--sp-3);
	margin-top: var(--sp-3);
}
.action-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	border-radius: 50%;
	border: none;
	color: white;
	transition: background var(--t-fast), transform var(--t-fast), opacity var(--t-fast);
}
.action-btn svg { width: 24px; height: 24px; }
.action-btn:active { transform: scale(0.94); }
.action-btn.disabled { opacity: 0.4; pointer-events: none; }

.action-btn.call     { background: var(--success); }
.action-btn.call:hover     { background: #266b46; }
html[data-theme="dark"] .action-btn.call:hover { background: #76c4a6; }

.action-btn.hangup   { background: var(--danger); }
.action-btn.hangup:hover   { background: #9b2828; }
html[data-theme="dark"] .action-btn.hangup:hover { background: #f08a8a; }

.action-btn.mute     { background: var(--text-muted); }
.action-btn.mute:hover { background: var(--text); }
.action-btn.mute.active { background: var(--warning); }

.action-btn.conference { background: var(--secondary); }
.action-btn.conference:hover { background: #275082; }
html[data-theme="dark"] .action-btn.conference:hover { background: #92b6e0; }

/* call status row */
.call-status {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: var(--sp-3) var(--sp-4);
	background: var(--accent-soft);
	border-radius: var(--radius-md);
	margin-top: var(--sp-2);
	font-variant-numeric: tabular-nums;
}
.call-target { font-weight: 500; }
.call-timer { font-family: ui-monospace, monospace; font-weight: 600; }

/* volume meters */
.volume-meters {
	margin-top: var(--sp-2);
	padding: var(--sp-3);
	background: var(--bg-elev-2);
	border-radius: var(--radius-md);
}
.volume-meters label { font-size: 0.8rem; color: var(--text-muted); }
.vol-bar {
	width: 100%;
	height: 6px;
	background: var(--border);
	border-radius: var(--radius-pill);
	overflow: hidden;
	margin: 4px 0 var(--sp-2);
}
.vol-fill {
	height: 100%;
	width: 0;
	background: var(--vol-low);
	transition: width 80ms linear, background 80ms linear;
}

/* ============================================================
 * INCOMING CALL PANEL
 * ========================================================== */
.incoming-panel {
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-soft);
}
.incoming-from {
	font-size: 1.2rem;
	color: var(--text-muted);
	margin: var(--sp-3) 0;
}
.incoming-from #incoming-number {
	color: var(--text);
	font-weight: 600;
}

/* ============================================================
 * CONFERENCE PANEL
 * ========================================================== */
.conf-add {
	display: flex;
	gap: var(--sp-2);
	margin-bottom: var(--sp-4);
}
#conf-add-number {
	flex: 1;
	padding: 8px 12px;
	background: var(--bg-elev-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	font-size: 1rem;
}
.participant-list {
	list-style: none;
	margin: 0 0 var(--sp-4);
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: var(--sp-2);
}
.participant-list li {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: var(--sp-3);
	background: var(--bg-elev-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
}
.participant-list li.left {
	opacity: 0.5;
	text-decoration: line-through;
}
.participant-list .p-name { font-weight: 500; }
.participant-list .p-status {
	font-size: 0.75rem;
	color: var(--text-muted);
	margin-left: var(--sp-2);
}
.participant-list .p-kick {
	background: transparent;
	border: 1px solid var(--border);
	color: var(--danger);
	width: 32px; height: 32px;
	border-radius: 50%;
	display: inline-flex; align-items: center; justify-content: center;
}
.participant-list .p-kick:hover { background: var(--danger-soft); border-color: var(--danger); }
.participant-list .p-kick svg { width: 14px; height: 14px; }

/* ============================================================
 * CALL HISTORY
 * ========================================================== */
.history-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: var(--sp-1);
	max-height: 220px;
	overflow-y: auto;
}
.history-list li {
	display: flex;
	align-items: center;
	gap: var(--sp-3);
	padding: var(--sp-2) var(--sp-3);
	border-radius: var(--radius-sm);
	cursor: pointer;
	transition: background var(--t-fast);
	font-size: 0.95rem;
}
.history-list li:hover { background: var(--bg-elev-2); }
.history-list .h-num { flex: 1; font-variant-numeric: tabular-nums; }
.history-list .h-meta { font-size: 0.75rem; color: var(--text-dim); }
.history-list .h-dir {
	width: 18px; height: 18px;
	display: inline-flex; align-items: center; justify-content: center;
	color: var(--text-dim);
}
.history-list .h-dir.in  { color: var(--success); }
.history-list .h-dir.out { color: var(--secondary); }

#history-empty {
	margin-top: var(--sp-2);
	text-align: center;
	padding: var(--sp-4);
}

/* ============================================================
 * COMMAND BAR
 * ========================================================== */
.command-bar {
	display: flex;
	align-items: center;
	background: var(--cli-bg);
	border-radius: var(--radius-md);
	padding: 8px 12px;
	font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.command-bar .prompt {
	color: var(--cli-text);
	font-weight: 600;
	margin-right: 8px;
	user-select: none;
}
#command-input {
	flex: 1;
	background: transparent;
	border: none;
	color: var(--cli-text);
	font: inherit;
	outline: none;
}
#command-input::placeholder { color: rgba(111, 255, 71, 0.35); }

/* ============================================================
 * ACTIVITY LOG
 * ========================================================== */
.log-panel { flex: 1; min-height: 360px; display: flex; flex-direction: column; }
.log {
	flex: 1;
	background: var(--bg-elev-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	padding: var(--sp-3);
	font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
	font-size: 0.85rem;
	overflow-y: auto;
	min-height: 280px;
	max-height: 480px;
}
.log .log-entry {
	padding: 2px 0;
	color: var(--text-muted);
	word-break: break-word;
}
.log .log-entry::before {
	content: "› ";
	color: var(--accent);
}
.log .log-entry.green { color: var(--success); }
.log .log-entry.red   { color: var(--danger); }
.log .log-entry .strike { text-decoration: line-through; opacity: 0.6; }
.log .log-entry .close-x {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 18px; height: 18px;
	margin-left: 6px;
	border-radius: 50%;
	background: var(--danger-soft);
	color: var(--danger);
	cursor: pointer;
	font-size: 0.7rem;
	vertical-align: middle;
}

/* ============================================================
 * SETTINGS DRAWER
 * ========================================================== */
.drawer-backdrop {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.4);
	z-index: 19;
	animation: fadeIn 200ms ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }

.settings-drawer {
	position: fixed;
	top: 0; right: 0; bottom: 0;
	width: 380px;
	max-width: 100vw;
	background: var(--surface);
	border-left: 1px solid var(--border);
	box-shadow: var(--shadow-lg);
	z-index: 20;
	display: flex;
	flex-direction: column;
	animation: slideIn 240ms ease;
}
.drawer-head {
	padding: var(--sp-4) var(--sp-5);
	border-bottom: 1px solid var(--border);
	display: flex;
	align-items: center;
	justify-content: space-between;
}
.drawer-head h2 { margin: 0; font-size: 1.2rem; }
.drawer-body {
	padding: var(--sp-5);
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: var(--sp-6);
}

.setting-group {
	display: flex;
	flex-direction: column;
	gap: var(--sp-2);
}
.setting-label {
	font-weight: 600;
	font-size: 0.95rem;
	margin-bottom: 2px;
}

.seg {
	display: inline-flex;
	background: var(--bg-elev-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	padding: 3px;
	gap: 2px;
}
.seg-btn {
	flex: 1;
	background: transparent;
	border: none;
	color: var(--text-muted);
	padding: 6px 14px;
	border-radius: 7px;
	font-size: 0.9rem;
	transition: background var(--t-fast), color var(--t-fast);
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
	background: var(--surface);
	color: var(--text);
	box-shadow: var(--shadow-sm);
}

.input-row {
	display: flex;
	gap: var(--sp-2);
}
.input-row input {
	flex: 1;
	padding: 8px 12px;
	background: var(--bg-elev-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
}
.input-row input:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ============================================================
 * RESPONSIVE
 * ========================================================== */
@media (max-width: 960px) {
	.main-view {
		grid-template-columns: 1fr;
		gap: var(--sp-4);
		padding: var(--sp-3);
	}
}

@media (max-width: 600px) {
	.app-header { padding: 0 var(--sp-3); }
	.app-title { font-size: 1rem; }
	.caller-id { font-size: 0.85rem; padding: 3px 8px; }
	.icon-btn { width: 34px; height: 34px; }
	.icon-btn svg { width: 18px; height: 18px; }

	.panel { padding: var(--sp-4); }

	.mode-grid { grid-template-columns: 1fr; }

	.dialpad { max-width: 100%; }
	.dtmf { min-height: 64px; }
	.d-num { font-size: 1.5rem; }

	.action-btn { width: 60px; height: 60px; }

	.settings-drawer { width: 100vw; }
}
