:root {
  --bg: #f4f5f7; --fg: #1b1f24; --muted: #6a7380; --card: #fff; --line: #dde1e6;
  --acc: #2563eb; --acc-fg: #fff; --mine: #2563eb; --mine-fg: #fff; --other: #fff; --bad: #c62828;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111418; --fg: #e8eaed; --muted: #9aa3ad; --card: #1b1f25; --line: #2c323a;
          --acc: #3b82f6; --mine: #2f6fde; --other: #222830; --bad: #ef5350; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--fg); }
h1 { font-size: 1.4rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
a { color: var(--acc); }
code { background: var(--bg); padding: .1rem .35rem; border-radius: 4px; word-break: break-all; }
button, .btn {
  font: inherit; border: 0; border-radius: 10px; padding: .7rem 1rem; background: var(--acc); color: var(--acc-fg);
  cursor: pointer; text-decoration: none; display: inline-block; text-align: center;
}
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--fg); border: 1px solid var(--line); }
button.danger { background: var(--bad); }
.small { padding: .35rem .65rem; font-size: .85rem; border-radius: 8px; }
input, textarea {
  font: inherit; width: 100%; padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--fg);
}
input:focus, textarea:focus { outline: 2px solid var(--acc); outline-offset: -1px; }
label { font-size: .9rem; color: var(--muted); }

.card { max-width: 380px; margin: 6vh auto; width: calc(100% - 24px); background: var(--card); padding: 1.6rem; border-radius: 16px;
        box-shadow: 0 2px 18px rgba(0,0,0,.08); }
.logo { font-weight: 800; letter-spacing: .04em; color: var(--acc); margin-bottom: .4rem; }
.form { display: grid; gap: .45rem; }
.form button { margin-top: .6rem; }
.err { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); padding: .55rem .7rem; border-radius: 8px; font-size: .92rem; }
.hint { color: var(--muted); font-size: .9rem; }
.note { margin-top: 1rem; font-size: .9rem; padding: .7rem; border-radius: 10px; background: var(--bg); }
.bad { color: var(--bad); }

/* razgovori: lista + otvoreni razgovor (na telefonu jedno po jedno) */
.app { display: flex; height: 100dvh; max-width: 1100px; margin: 0 auto; background: var(--bg); }
.side { width: 320px; flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--card); min-height: 0; }
.side header, .chat header { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .6rem .8rem;
               border-bottom: 1px solid var(--line); background: var(--card); min-height: 3.4rem; }
.who { display: flex; align-items: center; gap: .6rem; }
.newbar { display: flex; gap: .5rem; padding: .6rem .8rem; }
.newbar button { flex: 1; }
.panel { padding: 0 .8rem .8rem; border-bottom: 1px solid var(--line); }
.convs { overflow-y: auto; flex: 1; min-height: 0; }
.conv { display: flex; align-items: center; gap: .6rem; width: 100%; text-align: left; background: transparent; color: var(--fg);
        border-radius: 0; padding: .7rem .8rem; border-bottom: 1px solid var(--line); }
.conv.sel { background: color-mix(in srgb, var(--acc) 12%, transparent); }
.conv .ico { width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center; background: var(--bg); flex: none; }
.conv .ct { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.conv .cn { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.new .cn { color: var(--acc); }
.conv .cm { font-size: .78rem; color: var(--muted); }
.badge { background: var(--acc); color: #fff; border-radius: 999px; font-size: .78rem; padding: .1rem .5rem; font-weight: 700; }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ctitles { flex: 1; min-width: 0; }
.ctitle { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.csub { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat .back { display: none; }
.info { padding: .6rem .8rem; border-bottom: 1px solid var(--line); background: var(--card); display: grid; gap: .5rem; }
.info ul { margin: 0; padding-left: 1.1rem; }
.info li { margin: .2rem 0; }
.info li button { margin-left: .5rem; }
.row { display: flex; gap: .5rem; }
.status { color: var(--muted); font-size: .85rem; }
.msgs { flex: 1; overflow-y: auto; padding: .8rem; display: flex; flex-direction: column; gap: .5rem; min-height: 0; }
.empty { color: var(--muted); text-align: center; margin: 20% 1rem 0; }
.msg { max-width: 82%; background: var(--other); border: 1px solid var(--line); padding: .45rem .7rem .35rem; border-radius: 14px 14px 14px 4px; align-self: flex-start; }
.msg.mine { align-self: flex-end; background: var(--mine); color: var(--mine-fg); border-color: transparent; border-radius: 14px 14px 4px 14px; }
.msg.stub { background: transparent; color: var(--muted); border: 1px dashed var(--line); font-size: .85rem; }
.msg .from { font-size: .8rem; font-weight: 600; color: var(--acc); }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .time { font-size: .7rem; opacity: .65; text-align: right; }
.msg .rc { font-size: .75rem; opacity: .9; margin-top: .15rem; }
.msg .rc.ok { color: inherit; }
.msg .readbtn { margin-top: .35rem; width: 100%; background: #16a34a; }
.composer { display: flex; gap: .5rem; padding: .6rem; border-top: 1px solid var(--line); background: var(--card);
            padding-bottom: max(.6rem, env(safe-area-inset-bottom)); }
.composer textarea { resize: none; min-height: 2.8rem; }
@media (max-width: 720px) {
  .side { width: 100%; border-right: 0; }
  .chat { display: none; }
  .app.open .side { display: none; }
  .app.open .chat { display: flex; }
  .chat .back { display: inline-block; }
}

/* admin */
.admin { max-width: 900px; margin: 0 auto; padding: 1rem; }
.admin header { display: flex; justify-content: space-between; align-items: center; }
.admin section { background: var(--card); border-radius: 14px; padding: 1rem; margin: 1rem 0; }
.admin .row { display: flex; gap: .5rem; }
.admin table { width: 100%; border-collapse: collapse; margin-top: .8rem; font-size: .92rem; }
.admin th, .admin td { text-align: left; padding: .45rem .4rem; border-bottom: 1px solid var(--line); }
.admin .acts { display: flex; gap: .35rem; flex-wrap: wrap; justify-content: flex-end; }
.admin section { overflow-x: auto; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; }
.stats div { background: var(--card); border-radius: 14px; padding: .8rem; display: flex; flex-direction: column; }
.stats b { font-size: 1.6rem; }
.stats span { color: var(--muted); font-size: .85rem; }
.mon.on { border: 2px solid #f59e0b; }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; background: var(--line); margin-right: .45rem; }
.dot.on { background: #16a34a; }
.viewer:not(:empty) { margin-top: 1rem; border-top: 2px solid var(--acc); padding-top: .6rem; }
.vhead { display: flex; justify-content: space-between; align-items: center; }
.mtext { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 28rem; }
.events td:first-child { white-space: nowrap; color: var(--muted); width: 9rem; }
.events tr.warn td:last-child { color: var(--bad); }
@media (max-width: 720px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* A4 list sa 12 QR kodova */
body.print { background: #888; color: #000; }
.bar { display: flex; gap: 1rem; align-items: center; justify-content: space-between; padding: .6rem 1rem; background: #fff; }
.sheet { width: 210mm; height: 297mm; margin: 1rem auto; background: #fff; padding: 8mm;
         display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(4, 1fr); }
.cell { border: 1px dashed #999; margin: -.5px; display: flex; flex-direction: column; align-items: center;
        justify-content: center; text-align: center; position: relative; padding: 2mm; }
.cell .num { position: absolute; top: 2mm; left: 3mm; font-weight: 700; font-size: 11pt; }
.cell .qr svg { width: 44mm; height: 44mm; display: block; }
.cell .t1 { font-weight: 700; font-size: 10pt; margin-top: 1mm; }
.cell .t2 { font-size: 7.5pt; color: #333; }
.cell .t3 { font-size: 7pt; color: #555; margin-top: .5mm; word-break: break-all; }
.cell .st { position: absolute; top: 40%; transform: rotate(-20deg); font-size: 16pt; font-weight: 800; color: #c62828;
            border: 3px solid #c62828; padding: 1mm 3mm; background: rgba(255,255,255,.85); }
@page { size: A4 portrait; margin: 0; }
@media print {
  body.print { background: #fff; }
  .noprint { display: none !important; }
  .sheet { margin: 0; box-shadow: none; }
}
