:root {
  --bg: #111418;
  --panel: #1b2027;
  --line: #2c333d;
  --text: #e6e9ee;
  --muted: #9aa4b1;
  --accent: #3d8bfd;
  --error: #ff6b6b;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, "Segoe UI", sans-serif;
}

[hidden] { display: none !important; }

#login {
  max-width: 360px;
  margin: 12vh auto 0;
  padding: 0 16px;
}

h1 { display: flex; align-items: center; gap: 10px; font-size: 24px; margin: 0 0 8px; font-weight: 600; }

.logo { flex: none; width: 30px; height: 30px; }
.logo rect { fill: var(--accent); }
.logo path { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; }

.hint { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

#form { display: grid; gap: 6px; }

label { font-size: 14px; color: var(--muted); margin-top: 8px; }

input {
  font: inherit;
  font-size: 20px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  letter-spacing: 0.04em;
}

input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  color: #fff;
  background: var(--accent);
}

#name { font-size: 17px; letter-spacing: 0; }

.field-hint { margin: 0; font-size: 13px; color: var(--muted); }

#submit, #cancel { margin-top: 18px; padding: 12px; font-size: 17px; font-weight: 600; }
#cancel { background: #2b3440; }

#status { min-height: 1.5em; margin-top: 16px; color: var(--muted); }
#status.error { color: var(--error); }
#login:has(#cancel:not([hidden])) #status::before {
  content: '';
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  margin-right: 8px;
  vertical-align: -0.05em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  #login:has(#cancel:not([hidden])) #status::before { animation: none; }
}

#viewer {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
}

#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  touch-action: none;
  outline: none;
  cursor: default;
}

/* Poslední snímek přes video, když spojení vypadlo: ztlumený ukazuje, že obraz neběží, a drží
   ho, dokud nezačne chodit obraz nového spojení. */
#freeze {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  filter: grayscale(0.6) brightness(0.55);
}

/* Lišta je schovaná nahoře, vykoukne jen proužek; po najetí myší se vysune. Vystředí ji okraje
   left a right s automatickými okraji, ne left: 50%, jinak by se zalamovala už v polovině okna. */
#bar {
  position: absolute;
  top: 0;
  left: 16px;
  right: 16px;
  width: fit-content;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 32px);
  padding: 6px 8px 8px 14px;
  background: rgba(27, 32, 39, 0.94);
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 10px 10px;
  font-size: 13px;
  transform: translateY(calc(-100% + 6px));
  transition: transform 0.15s ease-out;
  z-index: 2;
}

#bar:hover, #bar.show { transform: none; }

#host-name {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 4px;
}

#host-name b { color: var(--text); font-weight: 600; }

#mode {
  position: absolute;
  top: 10px;
  left: 12px;
  padding: 3px 10px;
  border-radius: 6px;
  background: rgba(74, 61, 22, 0.92);
  border: 1px solid #806a2a;
  color: #ffe08a;
  font-size: 13px;
  pointer-events: none;
  z-index: 1;
}

#mode:not([hidden]) ~ #stats { top: 44px; }

#bar button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 13px;
  background: #2b3440;
  white-space: nowrap;
}
#bar button:hover { background: #36414f; }
#bar select {
  font: inherit;
  font-size: 13px;
  padding: 3px 4px;
  color: var(--text);
  background: #2b3440;
  border: 1px solid #3a4757;
  border-radius: 8px;
  cursor: pointer;
}
#bar select:hover { background: #36414f; }
#bar select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Při rozbaleném výběru lišta nezajede, i když myš přejde na nabídku. */
#bar:has(select:focus) { transform: none; }
#bar #btn-close { background: #a33a3a; }
#bar #btn-close:hover { background: #bd4545; }

#stats {
  position: absolute;
  top: 40px;
  left: 12px;
  margin: 0;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.75);
  border-radius: 8px;
  font: 12px/1.45 ui-monospace, Consolas, monospace;
  color: #d8f5d0;
  pointer-events: none;
  z-index: 1;
}

#notice {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(640px, calc(100% - 32px));
  padding: 10px 16px;
  background: rgba(27, 32, 39, 0.95);
  border: 1px solid #806a2a;
  border-radius: 8px;
  color: #ffe08a;
  font-size: 14px;
  white-space: pre-line;
  pointer-events: none;
  z-index: 1;
}

#bar button[aria-pressed="true"] { background: #3a4757; box-shadow: inset 0 0 0 1px var(--accent); }
#bar #btn-chat.unread { background: var(--accent); }
.badge {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #fff;
  color: #1f4f99;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
#bar #btn-audio[aria-pressed="false"] { color: var(--muted); }
.ico {
  flex: none;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* Zvuk: reproduktor s vlnami hraje, přeškrtnutý je vypnutý; šířka tlačítka zůstává stejná. */
.ico .speaker { fill: currentColor; }
#btn-audio[aria-pressed="true"] .cross,
#btn-audio[aria-pressed="false"] .waves { display: none; }

/* Jen ikony (fitBar v app.js): popisek zůstane jménem tlačítka pro čtečku obrazovky. Na velmi úzkém
   okně se lišta navíc zalomí. */
#bar.wrap { flex-wrap: wrap; justify-content: center; }
#bar.compact .label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
#bar.compact button { padding: 5px 8px; }

/* Panely Zprávy a Soubory: vpravo vedle obrazu, na úzkém okně přes něj. */
.panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  font-size: 14px;
  z-index: 3;
}

@media (min-width: 720px) {
  #viewer.with-panel #video, #viewer.with-panel #freeze { width: calc(100% - 340px); }
  #viewer.with-panel #bar { right: 356px; max-width: calc(100% - 372px); }
  #viewer.with-panel #notice { left: calc((100% - 340px) / 2); max-width: min(640px, calc(100% - 372px)); }
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 { flex: 1; margin: 0; font-size: 15px; font-weight: 600; }

button.icon {
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

button.icon:hover { background: #2b3440; color: var(--text); }
.panel button:disabled { opacity: 0.45; cursor: default; }
.panel input, .panel textarea { font-size: 14px; letter-spacing: 0; }

#chat-log {
  flex: 1;
  margin: 0;
  padding: 12px 14px;
  list-style: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#chat-log:empty::before {
  content: 'Zprávy se ukážou člověku u vzdáleného počítače v okně Vzdálené plochy.';
  color: var(--muted);
}

.msg { max-width: 88%; align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.msg .who { display: block; font-size: 12px; color: var(--muted); }
.msg.mine .who { text-align: right; }

.msg p {
  margin: 2px 0 0;
  padding: 7px 10px;
  border-radius: 10px;
  background: #252c35;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.mine p { background: #1f3b63; }

#chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }

#chat-text {
  flex: 1;
  min-width: 0;
  height: 64px;
  resize: none;
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}

#chat-text:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#chat-form button { padding: 0 14px; font-size: 14px; }

#files-nav { display: flex; gap: 6px; padding: 10px 10px 8px; }
#files-path { flex: 1; min-width: 0; padding: 6px 8px; }
#files-nav button { padding: 0 10px; font-size: 13px; background: #2b3440; }
#files-nav button:hover:not(:disabled) { background: #36414f; }
#files-up { font-size: 16px; }

#files-msg { margin: 0 14px 8px; font-size: 13px; color: var(--muted); }
#files-msg:empty { display: none; }
#files-msg.error { color: var(--error); }

#files-list {
  flex: 1;
  min-height: 80px;
  margin: 0;
  padding: 0 6px;
  list-style: none;
  overflow-y: auto;
}

#files-list.off { opacity: 0.5; }

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 14px;
}

.item:hover:not(:disabled) { background: #252c35; }
.item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* Ikony: složka je žlutá s ouškem, soubor obrys listu. */
.item::before { content: ''; flex: none; }
.item.dir::before {
  width: 16px;
  height: 12px;
  border-radius: 2px;
  background: #d9a93b;
  box-shadow: -1px -3px 0 -1px #d9a93b;
}
.item.file::before {
  width: 12px;
  height: 15px;
  margin: 0 2px;
  background: var(--muted);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 15'%3E%3Cpath fill='none' stroke='%23000' stroke-width='1.4' stroke-linejoin='round' d='M.7.7H7.3L11.3 4.7V14.3H.7Z M7.3.7V4.7H11.3'/%3E%3C/svg%3E") center / contain no-repeat;
}

.files-actions { padding: 10px; border-top: 1px solid var(--line); }
#files-pick { width: 100%; padding: 8px; font-size: 14px; }
.files-hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); text-align: center; }

#transfers {
  max-height: 40%;
  margin: 0;
  padding: 0 10px 6px;
  list-style: none;
  overflow-y: auto;
}

#transfers:empty { display: none; }

.transfer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 6px;
  align-items: center;
  padding: 6px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.transfer-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transfer.down .transfer-name::before { content: '↓ '; color: var(--muted); }
.transfer.up .transfer-name::before { content: '↑ '; color: var(--muted); }
.transfer .icon { width: 24px; height: 24px; font-size: 16px; }
.transfer progress { grid-column: 1 / -1; width: 100%; height: 6px; accent-color: var(--accent); }
.transfer-info { grid-column: 1 / -1; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.transfer.failed .transfer-info { color: var(--error); }
.transfer.ok .transfer-info { color: #8fd18f; }

#drop {
  position: absolute;
  inset: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  background: rgba(17, 20, 24, 0.85);
  color: var(--text);
  font-size: 18px;
  text-align: center;
  pointer-events: none;
  z-index: 4;
}

#drop p { margin: 0; max-width: 640px; }
#drop-dir { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
#drop.off { border-color: #806a2a; }

/* Telefon: pole pro klávesnici telefonu je neviditelné; stojí dole, aby prohlížeč kvůli němu
   neposouval stránku. Písmo 16 px, jinak by iPhone stránku při psaní přiblížil. */
#kbd {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  font-size: 16px;
  resize: none;
  pointer-events: none;
}

/* Zvláštní klávesy nad klávesnicí telefonu, dokud je otevřená. */
#keys {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 4px;
  padding: 6px max(8px, env(safe-area-inset-right, 0px)) 6px max(8px, env(safe-area-inset-left, 0px));
  overflow-x: auto;
  background: rgba(27, 32, 39, 0.96);
  border-top: 1px solid var(--line);
  z-index: 2;
}
#keys[hidden] { display: none; }
#keys button {
  flex: 1 0 auto;
  min-width: 38px;
  min-height: 40px;
  padding: 6px 4px;
  font-size: 15px;
  background: #2b3440;
}
#viewer:has(#keys:not([hidden])) #notice { bottom: 70px; }

/* Na dotykovém displeji vykoukne z lišty větší kus, aby se do ní dalo ťuknout. */
@media (pointer: coarse) {
  #bar { transform: translateY(calc(-100% + 16px)); }
  #bar button, #bar select { min-height: 36px; }
}
