* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0b0e14; color: #d7dce6; font-family: -apple-system, system-ui, sans-serif; }
body { overscroll-behavior: none; }

.screen { height: 100dvh; display: flex; flex-direction: column; box-sizing: border-box; }
.screen[hidden] { display: none; }

#login { align-items: center; justify-content: center; gap: 12px; padding: 24px; }
#login h1 { margin: 0 0 8px; }
#login input, #login button { padding: 14px; border-radius: 10px; border: 1px solid #2a2f3a; background: #151924; color: inherit; font-size: 16px; width: 100%; max-width: 320px; }
#login button { background: #2b6cff; border-color: #2b6cff; font-weight: 600; }
.err { color: #ff5c5c; min-height: 1.2em; }

#topbar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #10141c; border-bottom: 1px solid #1e2330; padding-top: max(8px, env(safe-area-inset-top)); }
#topbar button { background: transparent; border: 0; color: #d7dce6; font-size: 20px; padding: 6px 10px; }
#status { flex: 1; font-size: 13px; opacity: 0.75; }

#termContainer { flex: 1; min-height: 0; position: relative; }
#termContainer .term-pane { position: absolute; inset: 0; padding: 4px; }
#termContainer .term-pane .xterm { height: 100%; }
#termContainer .term-pane.selmode { outline: 2px solid #2b6cff; outline-offset: -2px; }
#termContainer .term-pane .sel-overlay {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 6px 8px;
  background: #0b0e14;
  color: #d7dce6;
  font-family: Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.25;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
  z-index: 10;
}
#topbar button.active { background: #2b6cff; color: #fff; border-radius: 6px; }

/* Mosaic view */
#mosaicView { flex: 1; min-height: 0; padding: 12px; overflow-y: auto; background: #0b0e14; }
#mosaicView .mosaic-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mosaic-tile { position: relative; background: #10141c; border: 2px solid #1e2330; border-radius: 10px; overflow: hidden; aspect-ratio: 16/10; cursor: pointer; transition: border-color .2s; }
.mosaic-tile:active { border-color: #2b6cff; }
.mosaic-tile .tile-preview { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.mosaic-tile .tile-preview canvas { transform-origin: top left; }
.mosaic-tile .tile-label { position: absolute; bottom: 0; left: 0; right: 0; padding: 6px 8px; background: linear-gradient(transparent, rgba(0,0,0,0.8)); font-size: 11px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.mosaic-tile .tile-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.tile-dot.idle { background: #4ade80; }
.tile-dot.busy { background: #f59e0b; animation: dotPulse 1s ease infinite; }
.tile-dot.waiting { background: #ef4444; animation: dotPulse .6s ease infinite; }
@keyframes dotPulse { 50% { opacity: .4; } }
.mosaic-tile .tile-close { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0,0,0,0.6); border: 1px solid #2a2f3a; color: #d7dce6; font-size: 12px; display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 2; }
.mosaic-add { display: flex; align-items: center; justify-content: center; background: #10141c; border: 2px dashed #263044; border-radius: 10px; aspect-ratio: 16/10; cursor: pointer; color: #8a93a6; font-size: 28px; transition: border-color .2s, color .2s; }
.mosaic-add:active { border-color: #2b6cff; color: #2b6cff; }

#imgBtn { position: fixed; right: 10px; bottom: calc(var(--vkb-h, 56px) + 52px); width: 36px; height: 36px; border-radius: 50%; background: rgba(26,32,48,0.75); border: 1px solid #263044; color: #8a93a6; padding: 0; display: flex; align-items: center; justify-content: center; z-index: 60; backdrop-filter: blur(6px); touch-action: none; }
#imgBtn:active, #imgBtn.busy { background: #2b6cff; color: #fff; border-color: #2b6cff; }

#voiceBtn { position: fixed; right: 10px; bottom: calc(var(--vkb-h, 56px) + 8px); width: 36px; height: 36px; border-radius: 50%; background: rgba(26,32,48,0.75); border: 1px solid #263044; color: #8a93a6; padding: 0; display: flex; align-items: center; justify-content: center; z-index: 60; backdrop-filter: blur(6px); touch-action: none; }
#voiceBtn:active, #voiceBtn.rec { background: #2b6cff; color: #fff; border-color: #2b6cff; }

#vkb { flex: 0 0 auto; display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 4px; padding: 6px; padding-bottom: max(6px, env(safe-area-inset-bottom)); background: #0e1220; border-top: 1px solid #1e2330; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
#vkb button { flex: 0 0 auto; min-width: 44px; background: #1a2030; border: 1px solid #263044; color: #d7dce6; padding: 10px 12px; border-radius: 8px; font-size: 14px; touch-action: manipulation; white-space: nowrap; }
#vkb button:active { background: #2b6cff; }
#scrollCtl { position: absolute; right: 8px; top: 60px; display: flex; flex-direction: column; gap: 6px; z-index: 50; }
#scrollCtl button { width: 44px; height: 44px; border-radius: 22px; background: rgba(26,32,48,0.85); border: 1px solid #263044; color: #d7dce6; font-size: 18px; backdrop-filter: blur(6px); padding: 0; display: flex; align-items: center; justify-content: center; touch-action: manipulation; }
#scrollCtl button:active { background: #2b6cff; }

dialog { background: #151924; color: inherit; border: 1px solid #2a2f3a; border-radius: 12px; max-width: 90vw; width: 420px; }
dialog form { display: flex; flex-direction: column; gap: 8px; }
dialog input, dialog textarea { padding: 10px; border-radius: 8px; border: 1px solid #2a2f3a; background: #0e1220; color: inherit; font: inherit; }
dialog textarea { min-height: 80px; }
dialog button { padding: 10px 14px; border-radius: 8px; border: 0; background: #2b6cff; color: white; font-weight: 600; }
#hostsList { list-style: none; padding: 0; margin: 0 0 10px; }
#hostsList li { display: flex; justify-content: space-between; padding: 8px; border-radius: 8px; background: #0e1220; margin-bottom: 6px; }
#hostsList button { background: transparent; color: #8aa0ff; padding: 4px 8px; }

/* ─── Reauth button (topbar) — palette du site ─────────────────── */
#reauthBtn { padding: 4px 8px; border-radius: 6px; display: flex; align-items: center; justify-content: center; opacity: 0.7; transition: background .2s, color .2s, opacity .2s; }
#reauthBtn:hover, #reauthBtn:active { opacity: 1; background: #1a2030; }
/* Avertissement : token expire dans <3 jours */
#reauthBtn.warn { color: #f59e0b; opacity: 1; }
#reauthBtn.warn::after { content: ''; position: absolute; width: 6px; height: 6px; border-radius: 50%; background: #f59e0b; box-shadow: 0 0 0 2px #10141c; margin: -10px 0 0 -4px; }
/* Critique : token expiré / WS refusé */
#reauthBtn.danger { color: #ef4444; opacity: 1; animation: reauthPulse 1.5s ease-in-out infinite; }
@keyframes reauthPulse { 50% { opacity: 0.5; } }

/* ─── Overlay session expirée ─────────────────────────────────── */
#sessionExpired { position: fixed; inset: 0; z-index: 200; background: rgba(11, 14, 20, 0.92); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; padding: 24px; }
#sessionExpired[hidden] { display: none; }
#sessionExpired .se-card { background: #151924; border: 1px solid #2a2f3a; border-left: 3px solid #ef4444; border-radius: 12px; padding: 28px 24px; max-width: 360px; width: 100%; text-align: center; box-shadow: 0 24px 60px rgba(0,0,0,0.6); }
#sessionExpired h2 { margin: 0 0 12px; font-size: 1.25rem; color: #ef4444; }
#sessionExpired p { margin: 0 0 18px; color: #d7dce6; font-size: 0.95rem; line-height: 1.55; }
#sessionExpired .se-hint { font-size: 0.78rem; opacity: 0.55; margin: 14px 0 0; }
#sessionExpired button { padding: 12px 22px; border-radius: 8px; border: 0; background: #2b6cff; color: #fff; font-weight: 600; font-size: 0.95rem; cursor: pointer; transition: background .2s; }
#sessionExpired button:hover, #sessionExpired button:active { background: #1d56d9; }

/* ─── App version (topbar) + diag panel ─────────────────────── */
#appVersion { font-size: 10px; opacity: 0.45; padding: 2px 6px; border-radius: 4px; background: #1a2030; color: #8aa0ff; letter-spacing: 0.05em; user-select: none; -webkit-user-select: none; cursor: pointer; }
#appVersion:active { opacity: 0.9; background: #2b6cff; color: #fff; }
#diagPanel { position: fixed; inset: 0; z-index: 200; background: rgba(11,14,20,0.92); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; padding: 24px; }
#diagPanel[hidden] { display: none; }
#diagPanel .se-card { max-width: 420px; }
#diagPanel pre { background: #0e1220; padding: 12px; border-radius: 8px; font-family: Menlo, Consolas, monospace; font-size: 12px; line-height: 1.5; color: #d7dce6; text-align: left; max-height: 60vh; overflow: auto; white-space: pre-wrap; word-break: break-word; }
