:root {
  --navy: #13294b;
  --navy-2: #1d3b68;
  --navy-3: #2a4d80;
  --mint: #2ec4a6;
  --mint-d: #1fa98d;
  --mint-soft: #e3f8f2;
  --bg: #eef2f7;
  --card: #ffffff;
  --line: #dde4ee;
  --text: #1b2433;
  --muted: #66748a;
  --danger: #c0392b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(19, 41, 75, .08), 0 4px 16px rgba(19, 41, 75, .05);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior: none;
}
button { font: inherit; cursor: pointer; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
svg { display: block; }
.hidden { display: none !important; }

/* ---------- logowanie ---------- */
.login-wrap { min-height: 100%; display: flex; flex-direction: column; }
.login-top { background: var(--navy); color: #fff; padding: 20px 24px; font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 10px; }
.login-top .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--mint); }
.login-box { width: 100%; max-width: 380px; margin: 8vh auto 0; padding: 0 16px; }
.login-card { background: var(--card); border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; color: var(--navy); }
.login-card p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--mint); border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 9px; border: 1px solid var(--line); background: #fff; font-weight: 600;
}
.btn:hover { background: #f6f8fb; }
.btn-primary { background: var(--mint); border-color: var(--mint); color: var(--navy); }
.btn-primary:hover { background: var(--mint-d); border-color: var(--mint-d); }
.btn-danger { color: var(--danger); }
.btn-block { width: 100%; padding: 12px; }
.err-msg { background: #fdecec; color: #9b1c1c; padding: 10px 12px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; }

/* ---------- układ ---------- */
.app { display: grid; grid-template-columns: 340px 1fr; height: 100vh; height: 100dvh; }
.side { display: flex; flex-direction: column; background: var(--card); border-right: 1px solid var(--line); min-height: 0; }
.side-top {
  background: var(--navy); color: #fff; padding: 14px 14px 14px 18px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex; align-items: center; gap: 10px;
}
.brand { font-weight: 700; font-size: 17px; flex: 1; display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--mint); flex: none; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 0; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.side-top .icon-btn { color: #fff; }
.side-top .icon-btn:hover { background: var(--navy-2); }
.icon-btn:hover { background: #eef2f7; }

.side-tools { padding: 12px; display: flex; gap: 8px; border-bottom: 1px solid var(--line); }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 10px; background: var(--bg);
  border-radius: 9px; color: var(--muted);
}
.search input { border: 0; background: transparent; padding: 9px 0; width: 100%; outline: none; }
.side-tools .btn { padding: 8px 10px; }

.conv-list { flex: 1; overflow-y: auto; padding: 6px 0; }
.conv {
  display: flex; gap: 12px; align-items: center; padding: 10px 14px; cursor: pointer; position: relative;
  border-left: 3px solid transparent;
}
.conv:hover { background: #f5f7fb; }
.conv.active { background: var(--mint-soft); border-left-color: var(--mint); }
.conv-body { flex: 1; min-width: 0; }
.conv-row { display: flex; align-items: baseline; gap: 8px; }
.conv-name { font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--muted); flex: none; }
.conv-prev { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.conv.unread .conv-name, .conv.unread .conv-prev { color: var(--text); font-weight: 700; }
.badge {
  background: var(--mint); color: var(--navy); font-size: 12px; font-weight: 700; min-width: 20px; height: 20px;
  border-radius: 10px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.section-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 12px 18px 4px; }
.empty-hint { padding: 24px; color: var(--muted); text-align: center; font-size: 14px; }

.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff; position: relative; user-select: none;
}
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar.group { border-radius: 12px; background: var(--navy-2); }
.avatar .online { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: var(--mint); border: 2px solid #fff; }

/* ---------- czat ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.chat-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); gap: 10px; text-align: center; padding: 20px; }
.chat-empty .big { width: 72px; height: 72px; border-radius: 20px; background: var(--card); display: flex; align-items: center; justify-content: center; color: var(--mint); box-shadow: var(--shadow); }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--card); border-bottom: 1px solid var(--line);
  padding-top: calc(10px + env(safe-area-inset-top)); min-height: 62px;
}
.chat-title { flex: 1; min-width: 0; }
.chat-title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 16px; }
.chat-title small { color: var(--muted); font-size: 13px; }
.back-btn { display: none; }

.msgs { flex: 1; overflow-y: auto; padding: 16px 18px 8px; display: flex; flex-direction: column; }
.load-more { align-self: center; margin-bottom: 12px; font-size: 13px; }
.day-sep { align-self: center; font-size: 12px; font-weight: 600; color: var(--muted); background: #e2e8f1; padding: 4px 12px; border-radius: 20px; margin: 14px 0 10px; }

.msg { display: flex; gap: 10px; margin-top: 2px; max-width: 100%; }
.msg.first { margin-top: 12px; }
.msg .av-slot { width: 32px; flex: none; }
.msg-col { min-width: 0; max-width: min(640px, 78%); display: flex; flex-direction: column; align-items: flex-start; }
.msg-meta { font-size: 12px; color: var(--muted); margin: 0 0 3px 2px; }
.msg-meta b { color: var(--navy); font-weight: 600; margin-right: 6px; }
.bubble {
  background: var(--card); border-radius: 4px 14px 14px 14px; padding: 8px 12px; box-shadow: 0 1px 1px rgba(19,41,75,.06);
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.45; position: relative;
}
.msg:not(.first) .bubble { border-radius: 14px; }
.bubble a { color: var(--navy-3); }
.bubble .time { font-size: 11px; color: var(--muted); margin-left: 8px; float: right; margin-top: 5px; }
.msg.mine { flex-direction: row-reverse; }
.msg.mine .msg-col { align-items: flex-end; }
.msg.mine .bubble { background: var(--navy); color: #fff; border-radius: 14px 4px 14px 14px; }
.msg.mine:not(.first) .bubble { border-radius: 14px; }
.msg.mine .bubble a { color: #9ff0de; }
.msg.mine .bubble .time { color: #a9b8d0; }
.msg.deleted .bubble { background: transparent; box-shadow: none; border: 1px dashed var(--line); color: var(--muted); font-style: italic; }
.msg.pending { opacity: .7; }
.msg.failed .bubble { outline: 2px solid var(--danger); }
.msg-actions { opacity: 0; align-self: center; transition: opacity .15s; display: flex; gap: 2px; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions .icon-btn { width: 30px; height: 30px; color: var(--muted); }

.files { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; max-width: 100%; }
.msg.mine .files { align-items: flex-end; }
.imgs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; max-width: 360px; }
.imgs.one { grid-template-columns: 1fr; }
.imgs a { display: block; border-radius: 12px; overflow: hidden; background: #dfe6ef; aspect-ratio: 1; }
.imgs.one a { aspect-ratio: auto; max-height: 360px; }
.imgs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.imgs.one img { max-height: 360px; object-fit: contain; background: #dfe6ef; }
.file-card {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--card);
  border: 1px solid var(--line); text-decoration: none; color: var(--text); max-width: 340px; min-width: 220px;
}
.file-card:hover { border-color: var(--mint); }
.file-ico {
  width: 40px; height: 46px; border-radius: 6px; background: var(--navy-2); color: #fff; font-size: 10px; font-weight: 700;
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 7px; flex: none; letter-spacing: .03em;
}
.file-ico.pdf { background: #d64541; }
.file-ico.xls { background: #1e8a4c; }
.file-ico.doc { background: #2b6cc4; }
.file-ico.zip { background: #8a6d3b; }
.file-info { min-width: 0; flex: 1; }
.file-info b { display: block; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-info small { color: var(--muted); font-size: 12px; }
.file-card .dl { color: var(--muted); flex: none; }

/* odpowiedzi i oznaczenia */
.quote {
  display: block; border-left: 3px solid var(--mint); background: rgba(19, 41, 75, .05); border-radius: 6px;
  padding: 5px 9px; margin: 0 0 6px; font-size: 13px; cursor: pointer; max-width: 100%; white-space: normal;
}
.quote b { display: block; color: var(--mint-d); font-size: 12px; }
.quote span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); }
.msg.mine .quote { background: rgba(255, 255, 255, .1); }
.msg.mine .quote b { color: #9ff0de; }
.msg.mine .quote span { color: #c6d2e6; }
.mention { font-weight: 600; color: var(--navy-3); background: #e1e8f4; border-radius: 4px; padding: 0 3px; }
.mention.me { background: var(--mint-soft); color: #0d5c4a; }
.msg.mine .mention { background: rgba(255, 255, 255, .15); color: #fff; }
.msg.mention-me .bubble { box-shadow: inset 3px 0 0 var(--mint), 0 1px 1px rgba(19,41,75,.06); }
.badge.at { background: var(--navy); color: #fff; margin-right: 4px; }
.msg { transition: background .3s; border-radius: 10px; }
.msg.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { background: rgba(46, 196, 166, .22); } 100% { background: transparent; } }
.msg.swipe-ready .msg-col { filter: brightness(.97); }
.msg.swipe-ready::before { content: ''; }

/* ---------- pole wpisywania ---------- */
.composer { position: relative; background: var(--card); border-top: 1px solid var(--line); padding: 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
.reply-bar { display: flex; align-items: center; gap: 8px; border-left: 3px solid var(--mint); background: var(--bg); border-radius: 8px; padding: 6px 4px 6px 10px; margin-bottom: 8px; }
.reply-bar .rb-text { flex: 1; min-width: 0; font-size: 13px; }
.reply-bar b { display: block; color: var(--mint-d); font-size: 12px; }
.reply-bar span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.reply-bar .icon-btn { width: 30px; height: 30px; color: var(--muted); }
.mention-box { position: absolute; left: 12px; right: 12px; bottom: 100%; margin-bottom: 6px; background: #fff; border-radius: 12px; box-shadow: 0 8px 30px rgba(19,41,75,.18); padding: 6px; max-width: 360px; z-index: 30; }
.mi { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; cursor: pointer; }
.mi small { color: var(--muted); font-size: 12px; }
.mi.on, .mi:hover { background: var(--mint-soft); }
.pending-files { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.pf { position: relative; display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: 10px; padding: 6px 30px 6px 6px; max-width: 220px; font-size: 13px; }
.pf img { width: 40px; height: 40px; object-fit: cover; border-radius: 7px; }
.pf .file-ico { width: 32px; height: 38px; font-size: 9px; padding-bottom: 5px; }
.pf span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pf button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 22px; height: 22px; border-radius: 50%; border: 0; background: #cfd8e4; display: flex; align-items: center; justify-content: center; padding: 0; }
.comp-row { display: flex; align-items: flex-end; gap: 6px; }
.comp-row .icon-btn { color: var(--muted); }
.comp-row textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 20px; padding: 9px 14px; max-height: 160px;
  line-height: 1.4; background: var(--bg); min-height: 40px;
}
.comp-row textarea:focus { outline: none; border-color: var(--mint); background: #fff; }
.send-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--mint); color: var(--navy); display: flex; align-items: center; justify-content: center; flex: none; }
.send-btn:disabled { background: #cfd8e4; color: #fff; cursor: default; }
.cam-btn { display: none !important; }

.drop-overlay {
  position: absolute; inset: 0; background: rgba(19, 41, 75, .82); color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; z-index: 20; border: 3px dashed var(--mint); border-radius: 8px; margin: 8px; pointer-events: none;
}
.progress { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 4px; width: 100%; min-width: 120px; }
.progress i { display: block; height: 100%; background: var(--mint); width: 0; transition: width .2s; }

/* ---------- menu, modale, lightbox ---------- */
.menu { position: absolute; background: #fff; border-radius: 12px; box-shadow: 0 8px 30px rgba(19,41,75,.2); padding: 6px; z-index: 50; min-width: 220px; }
.menu button { display: flex; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 8px; gap: 10px; align-items: center; }
.menu button:hover { background: var(--bg); }
.menu .who { padding: 10px 12px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu .who small { display: block; color: var(--muted); }

.modal-bg { position: fixed; inset: 0; background: rgba(19, 41, 75, .45); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 480px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; padding: 16px 16px 12px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; flex: 1; color: var(--navy); }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-foot { padding: 12px 20px 16px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); }

.pick-list { border: 1px solid var(--line); border-radius: 10px; max-height: 320px; overflow-y: auto; }
.pick { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.pick:last-child { border-bottom: 0; }
.pick:hover { background: #f6f8fb; }
.pick input { width: 18px; height: 18px; accent-color: var(--mint); }
.pick small { color: var(--muted); }

table.adm { width: 100%; border-collapse: collapse; font-size: 14px; }
table.adm th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); }
table.adm td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.adm tr.off td { color: var(--muted); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; background: var(--mint-soft); color: #0d5c4a; }
.tag.navy { background: #e1e8f4; color: var(--navy); }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tabs button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.tabs button.on { background: #fff; color: var(--navy); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.lightbox { position: fixed; inset: 0; background: rgba(8, 16, 30, .94); z-index: 80; display: flex; flex-direction: column; }
.lb-top { display: flex; justify-content: flex-end; gap: 6px; padding: 10px; padding-top: calc(10px + env(safe-area-inset-top)); }
.lb-top a, .lb-top button { color: #fff; }
.lb-top .icon-btn:hover { background: rgba(255,255,255,.12); }
.lb-img { flex: 1; display: flex; align-items: center; justify-content: center; padding: 0 12px 20px; min-height: 0; }
.lb-img img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 11px 18px; border-radius: 10px; z-index: 90; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.err { background: var(--danger); }
.notif-bar { background: var(--mint-soft); color: #0d5c4a; font-size: 13px; padding: 10px 14px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); }
.notif-bar button { border: 0; background: var(--mint); color: var(--navy); font-weight: 700; border-radius: 7px; padding: 6px 10px; font-size: 12px; }
.notif-bar .x { background: none; color: var(--muted); padding: 4px; }

/* ---------- telefon ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app .chat { display: none; }
  .app.chat-open .side { display: none; }
  .app.chat-open .chat { display: flex; }
  .back-btn { display: inline-flex; margin-left: -6px; }
  .msgs { padding: 12px 10px 6px; }
  .msg-col { max-width: 84%; }
  .msg .av-slot { width: 28px; }
  .msg .avatar.sm { width: 28px; height: 28px; font-size: 11px; }
  .msg-actions { opacity: .6; }
  .msg-actions .icon-btn { width: 26px; height: 26px; }
  .cam-btn { display: inline-flex !important; }
  .file-card { min-width: 0; }
  .modal-bg { align-items: flex-end; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92dvh; padding-bottom: env(safe-area-inset-bottom); }
  table.adm .hide-m { display: none; }
  .comp-row textarea { font-size: 16px; } /* iOS nie powiększa wtedy ekranu */
}
