:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --text: #e8eaf0;
  --muted: #8b91a1;
  --accent: #5b8cff;
  --accent-text: #fff;
  --mine: #2d5bd8;
  --ok: #3ccf7e;
  --warn: #f0b429;
  --danger: #e5484d;
  --border: #2a2f3a;
  --radius: 14px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8; --panel: #fff; --panel-2: #eef0f4; --text: #14161b; --muted: #626a7a;
    --mine: #2d5bd8; --border: #dde1e8; color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
code { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .92em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

button, .button {
  font: inherit; border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: .65em 1.1em; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-block;
}
button:disabled { opacity: .5; cursor: not-allowed; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.small { padding: .4em .8em; font-size: .9rem; }
.big { padding: .95em 1.6em; font-size: 1.1rem; width: 100%; }

/* ---------- Početna ---------- */
.home { max-width: 460px; margin: 0 auto; padding: 12vh 16px 32px; text-align: center; }
.logo { font-size: 3rem; }
.home h1 { margin: .2em 0 .3em; font-size: 2.2rem; letter-spacing: -.02em; }
.lead { color: var(--muted); margin: 0 0 2rem; }
.ttl { display: flex; align-items: center; justify-content: center; gap: .5em; margin-bottom: 1rem; color: var(--muted); }
select { font: inherit; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: .35em .5em; }
.facts { list-style: none; padding: 0; margin: 2.5rem 0 0; text-align: left; display: grid; gap: .8rem; }
.facts li { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: .8em 1em; color: var(--muted); font-size: .95rem; }
.facts strong { color: var(--text); }

/* ---------- Soba ---------- */
.room { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }
.bar {
  display: flex; align-items: center; gap: .6rem; padding: .7rem 16px;
  border-bottom: 1px solid var(--border); background: var(--panel);
  padding-top: max(.7rem, env(safe-area-inset-top));
}
.brand { color: var(--text); text-decoration: none; font-weight: 700; white-space: nowrap; }
.status { display: flex; gap: .4rem; flex: 1; justify-content: center; flex-wrap: wrap; min-width: 0; }
.pill { font-size: .8rem; padding: .25em .7em; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }
.pill:empty { display: none; }

.invite { margin: 12px 16px 0; padding: .9rem 1rem; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.invite p { margin: 0 0 .7rem; color: var(--muted); font-size: .92rem; }
.linkrow { display: flex; gap: .5rem; }
.linkrow input {
  flex: 1; min-width: 0; font: .85rem ui-monospace, Consolas, monospace; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: .45em .6em;
}

.safety { margin: .6rem 16px 0; font-size: .8rem; color: var(--muted); text-align: center; }
.safety code { color: var(--text); letter-spacing: .05em; }

.messages { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 16px; display: flex; flex-direction: column; gap: .4rem; }
.msg { max-width: 80%; padding: .5em .8em .35em; border-radius: 16px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg .body { white-space: pre-wrap; }
.msg time { display: block; font-size: .7rem; opacity: .65; text-align: right; margin-top: .1em; }
.mine { align-self: flex-end; background: var(--mine); color: #fff; border-bottom-right-radius: 5px; }
.theirs { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 5px; }
.system { align-self: center; font-size: .8rem; color: var(--muted); text-align: center; }

.typing { margin: 0 16px .3rem; font-size: .8rem; color: var(--muted); }

.composer {
  display: flex; gap: .5rem; padding: .7rem 16px; border-top: 1px solid var(--border); background: var(--panel);
  padding-bottom: max(.7rem, env(safe-area-inset-bottom));
}
.composer textarea {
  flex: 1; resize: none; font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 12px; padding: .6em .8em; max-height: 160px;
}
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.overlay { position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); display: grid; place-items: center; padding: 16px; }
.card { max-width: 380px; text-align: center; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem 1.5rem; }
.card h2 { margin: .3em 0; }
.card p { color: var(--muted); margin: 0 0 1.4rem; }

@media (max-width: 480px) {
  .brand { font-size: .95rem; }
  .msg { max-width: 88%; }
}

/* ---------- Slike, zvuk, pregled ---------- */
.icon { background: transparent; border-color: transparent; padding: .35em .5em; line-height: 1; }
.icon:hover { background: var(--panel-2); }

.attach {
  display: grid; place-items: center; flex: none; width: 2.6rem; font-size: 1.25rem;
  border-radius: 12px; cursor: pointer; user-select: none;
}
.attach:hover { background: var(--panel-2); }
.attach[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.attach.busy { pointer-events: none; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.msg.image { padding: 4px; max-width: min(78%, 320px); }
.msg.image img {
  display: block; width: 100%; height: auto; max-height: 360px; object-fit: cover;
  border-radius: 12px; cursor: zoom-in; background: var(--panel-2);
}
.msg.image time { padding: .15em .45em .1em; }
.msg.image .body { padding: .4em .5em; }

.lightbox {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  background: rgba(0, 0, 0, .92); padding: 16px; cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.lightbox .icon {
  position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px;
  color: #fff; font-size: 1.4rem; background: rgba(255, 255, 255, .12); border-radius: 999px;
}

@media (max-width: 480px) {
  .msg.image { max-width: 82%; }
  .msg.image img { max-height: 300px; }
  .bar { gap: .3rem; }
}

/* ---------- Glasovne poruke ---------- */
.composer.recording { align-items: center; }
.recbar { flex: 1; display: flex; align-items: center; gap: .6rem; min-height: 2.6rem; }
.rec-time { font-variant-numeric: tabular-nums; animation: pulse 1.4s ease-in-out infinite; }
.rec-max { font-size: .85rem; margin-right: auto; }
.mic { flex: none; font-size: 1.2rem; border-radius: 12px; }
.mic:disabled { opacity: .5; }

.msg.audio { padding: .45em .6em .3em; width: min(78%, 280px); }
.voice { display: flex; align-items: center; gap: .6rem; }
.voice .play {
  flex: none; width: 2.2rem; height: 2.2rem; padding: 0; border-radius: 999px; border: 0;
  display: grid; place-items: center; font-size: .85rem; line-height: 1;
  background: var(--accent); color: var(--accent-text);
}
.mine .voice .play { background: #fff; color: var(--mine); }
.voice .track {
  flex: 1; height: 6px; border-radius: 999px; cursor: pointer; position: relative;
  background: color-mix(in srgb, currentColor 22%, transparent);
}
.voice .track::before { content: ""; position: absolute; inset: -10px 0; } /* veća zona za dodir na telefonu */
.voice .fill { width: 0; height: 100%; border-radius: inherit; background: currentColor; transition: width .2s linear; }
.theirs .voice .fill { background: var(--accent); }
.voice .dur { flex: none; font-size: .8rem; font-variant-numeric: tabular-nums; opacity: .85; min-width: 2.4em; text-align: right; }

@media (max-width: 480px) {
  .msg.audio { width: 82%; }
}

/* ---------- Privatnost ---------- */
.home.legal { text-align: left; padding-top: 32px; }
.legal h2 { font-size: 1.1rem; margin: 1.6em 0 .4em; }
.legal ul { padding-left: 1.2em; margin: 0; }
.legal li, .legal p { color: var(--muted); margin: .4em 0; }
.footnote { margin-top: 1.5rem; font-size: .9rem; }
.footnote a { color: var(--muted); }

/* ---------- Poruka koja nije poslata ---------- */
.msg.failed { outline: 1px solid var(--danger); }
.notsent { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .6rem; margin-top: .3em; font-size: .78rem; }
.notsent button { font-size: .78rem; padding: .25em .6em; }
.msg.image .notsent, .msg.audio .notsent { padding: 0 .45em .2em; }

/* ---------- Instalacija i nalog ---------- */
.install { margin-top: 1.2rem; padding: .7em 1em; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); font-size: .9rem; }
.install p { margin: 0; color: var(--muted); }
.install button { margin-top: .6rem; }

.home.account { text-align: left; padding-top: 32px; }
.account h2 { font-size: 1.1rem; margin: 1.8em 0 .3em; }
.account p { margin: .4em 0 .8em; }
.stack { display: grid; gap: .8rem; }
.stack label { display: grid; gap: .3rem; color: var(--muted); font-size: .9rem; }
.stack input { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: .6em .8em; }
.message { padding: .6em .8em; border-radius: 10px; background: var(--panel-2); font-size: .9rem; }

/* ---------- Uređaji ---------- */
.devices { list-style: none; margin: .6rem 0 1.2rem; padding: 0; display: grid; gap: .4rem; }
.devices li { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .7rem; padding: .6em .8em; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; font-size: .9rem; }
.devices code { color: var(--muted); }
.devices button { margin-left: auto; }
