:root,
html[data-theme="dark"],
html[data-theme="light"],
html[data-theme="royal"],
html[data-theme="forest"] {
  --bg: #080b12;
  --panel: #10141f;
  --panel-2: #151b29;
  --line: rgba(255,255,255,.08);
  --text: #f4f7fb;
  --muted: #8f9aae;
  --accent: #5b6cff;
  --danger: #ff5d6c;
  --shadow: 0 28px 90px rgba(0,0,0,.42);
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
body.modal-open { overflow: hidden; }

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

/* sakrij sve stare/progress linije */
.upload-progress,
.upload-progress-bar,
.file-progress,
.file-progress-bar,
#uploadProgress,
#uploadProgressBar,
.progress,
.progress-bar {
  display: none !important;
  visibility: hidden !important;
  height: 0 !important;
  overflow: hidden !important;
}

/* AUTH + GENERAL */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: var(--bg); }
.auth-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 28px;
}
.auth-card { width: min(440px, 100%); padding: 32px; }
.brand-mark,
.brand-dot {
  display: inline-grid;
  place-items: center;
  background: var(--accent);
  color: white;
  font-weight: 900;
  letter-spacing: -.05em;
}
.brand-mark { width: 64px; height: 64px; border-radius: 22px; font-size: 24px; }
.brand-dot { width: 48px; height: 48px; border-radius: 18px; flex: 0 0 auto; }
.auth-card h1 { margin: 18px 0 6px; font-size: 30px; letter-spacing: -.04em; }
.auth-card p, .admin-header p { margin: 0; color: var(--muted); }
label { display: block; margin: 14px 0 7px; color: var(--muted); font-size: 14px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #0c1019;
  color: var(--text);
  padding: 13px 15px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: rgba(91,108,255,.7); box-shadow: 0 0 0 4px rgba(91,108,255,.12); }
button,
.auth-card button,
.inline-form button,
.stacked button {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 800;
  background: var(--accent);
  color: white;
  transition: transform .15s ease, opacity .15s ease, background .15s ease;
}
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }
button.danger { background: var(--danger); }
.auth-card button { width: 100%; margin-top: 18px; }
.auth-links { margin-top: 16px; text-align: center; color: var(--muted); font-size: 14px; }
.alert { padding: 12px 14px; border-radius: 16px; margin: 14px 0; border: 1px solid var(--line); }
.alert.error { background: rgba(255,93,108,.14); }
.alert.success, .alert.info { background: rgba(91,108,255,.13); }

/* POTPUNO NOVI CHAT LAYOUT */
.chat-page { overflow: hidden; }
.messenger-app {
  height: 100vh;
  width: 100vw;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  background: var(--bg);
}
.side-panel {
  min-width: 0;
  padding: 24px;
  background: #0b0f18;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand-stack { display: flex; align-items: center; gap: 14px; }
.brand-stack h1 { margin: 0; font-size: 20px; line-height: 1.05; letter-spacing: -.04em; }
.brand-stack p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.side-status {
  margin-top: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 20px;
  padding: 14px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.status-dot { width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: #38d27a; box-shadow: 0 0 0 4px rgba(56,210,122,.12); flex: 0 0 auto; }
.side-status p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.side-nav { margin-top: auto; display: grid; gap: 8px; }
.side-nav a,
.top-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 14px;
  color: var(--text);
  font-weight: 750;
  font-size: 14px;
}
.side-nav a { padding: 13px 14px; justify-content: flex-start; }
.side-nav a:hover, .top-actions a:hover { background: var(--panel-2); }

.conversation-panel {
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 70% 0%, rgba(91,108,255,.10), transparent 35%),
    var(--bg);
}
.conversation-top {
  min-height: 78px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: rgba(8,11,18,.86);
  backdrop-filter: blur(14px);
}
.eyebrow { display: block; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.conversation-top h2 { margin: 2px 0 0; font-size: 22px; letter-spacing: -.04em; }
.top-actions { display: flex; gap: 8px; }
.top-actions a { padding: 10px 13px; }

.messages {
  flex: 1;
  overflow: auto;
  padding: 34px min(6vw, 72px) 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
.empty-chat {
  margin: auto;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 6px;
  text-align: center;
}
.empty-chat strong { color: var(--text); font-size: 20px; }

.message { display: flex; position: relative; }
.message.mine { justify-content: flex-end; }
.message.other { justify-content: flex-start; }
.message.grouped { margin-top: -5px; }
.bubble {
  max-width: min(62%, 700px);
  min-width: 0;
  padding: 11px 13px;
  border-radius: 18px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  position: relative;
}
.mine .bubble { background: var(--accent); border-color: transparent; color: white; }
.message.grouped .bubble { border-top-left-radius: 10px; border-top-right-radius: 10px; }
.message.image-only .bubble {
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  overflow: visible;
}
.message.image-only.mine .bubble { background: transparent; }
.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 22px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}
.mine .meta { color: rgba(255,255,255,.72); }
.meta strong { color: var(--text); font-weight: 850; }
.mine .meta strong { color: #fff; }
.badge {
  font-size: 10px;
  text-transform: uppercase;
  color: white;
  background: rgba(255,255,255,.17);
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 900;
}
.body { white-space: normal; overflow-wrap: anywhere; line-height: 1.45; }
.reads { font-size: 11px; color: rgba(255,255,255,.62); margin-top: 7px; }
.other .reads { color: var(--muted); }
.typing { min-height: 24px; padding: 0 min(6vw, 72px); color: var(--muted); font-size: 13px; }

.message-more {
  margin-left: auto;
  width: 26px;
  height: 24px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: inherit;
  opacity: .55;
}
.message-more:hover { opacity: 1; background: rgba(255,255,255,.10); transform: none; }
.message-more.floating {
  position: absolute;
  top: 4px;
  right: 4px;
  opacity: 0;
  background: rgba(0,0,0,.22);
  color: white;
}
.message.grouped:hover .message-more.floating { opacity: 1; }

.reply-quote {
  width: 100%;
  display: grid;
  gap: 2px;
  margin: 0 0 8px;
  padding: 8px 10px;
  border: 0;
  border-left: 3px solid rgba(255,255,255,.45);
  border-radius: 10px;
  background: rgba(255,255,255,.10);
  color: inherit;
  text-align: left;
  transform: none !important;
}
.other .reply-quote { border-left-color: var(--accent); background: rgba(255,255,255,.06); }
.reply-quote strong { font-size: 12px; }
.reply-quote span { color: rgba(255,255,255,.72); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.other .reply-quote span { color: var(--muted); }
.flash .bubble { outline: 3px solid rgba(91,108,255,.45); outline-offset: 4px; }

.image-attachment {
  display: block;
  position: relative;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  line-height: 0;
  cursor: pointer;
  border-radius: 18px;
  overflow: hidden;
  max-width: min(380px, 78vw);
  transform: none !important;
}
.bubble:not(:empty) .image-attachment { margin-top: 8px; }
.image-attachment img {
  display: block;
  width: 100%;
  max-width: min(380px, 78vw);
  max-height: 420px;
  object-fit: cover;
  border-radius: 18px;
  transition: filter .18s ease, transform .18s ease;
}
.image-attachment:hover img { filter: brightness(.78); transform: scale(1.015); }
.image-open-indicator {
  position: absolute;
  right: 10px;
  top: 10px;
  line-height: 1;
  color: white;
  background: rgba(8,11,18,.66);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 850;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .18s ease, transform .18s ease;
  backdrop-filter: blur(10px);
}
.image-attachment:hover .image-open-indicator { opacity: 1; transform: translateY(0); }
.image-error .image-open-indicator { display: none; }
.image-error-text { display: none; line-height: 1.3; padding: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.image-error .image-error-text { display: block; }
.file-attachment {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.08);
  color: inherit;
}
.file-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: rgba(255,255,255,.10); }
.file-attachment small { display: block; color: var(--muted); margin-top: 2px; }
.mine .file-attachment small { color: rgba(255,255,255,.72); }
.file-attachment em { margin-left: auto; font-style: normal; color: inherit; opacity: .75; font-size: 13px; }

.composer {
  padding: 14px min(6vw, 72px) 22px;
  border-top: 1px solid var(--line);
  background: rgba(8,11,18,.88);
  backdrop-filter: blur(14px);
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 8px;
}
.composer textarea {
  min-height: 42px;
  max-height: 140px;
  resize: none;
  border: 0;
  background: transparent;
  box-shadow: none !important;
  padding: 11px 6px;
  line-height: 1.45;
}
.attach-btn {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #0b0f18;
  color: var(--text);
  font-size: 24px;
  font-weight: 500;
}
.send-btn,
.composer button[type="submit"] { min-width: 108px; height: 44px; padding: 0 16px; border-radius: 16px; background: var(--accent); color: white; }
.file-preview,
.reply-composer {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}
.file-preview button,
.reply-composer button {
  padding: 7px 10px;
  border-radius: 10px;
  background: #0b0f18;
  color: var(--text);
}
.reply-composer div { min-width: 0; display: grid; gap: 2px; }
.reply-composer strong { color: var(--text); font-size: 13px; }
.reply-composer span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.message-context-menu {
  position: fixed;
  display: none;
  z-index: 999999;
  min-width: 190px;
  padding: 8px;
  border-radius: 18px;
  background: #111724;
  border: 1px solid var(--line);
  box-shadow: 0 22px 60px rgba(0,0,0,.45);
}
.message-context-menu button {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 11px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  transform: none !important;
}
.message-context-menu button:hover { background: rgba(255,255,255,.08); }
.message-context-menu .danger-menu { color: var(--danger); }

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 1000000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 26px;
  background: rgba(0,0,0,.78);
  backdrop-filter: blur(14px);
}
.image-modal[hidden] { display: none; }
.image-modal img {
  max-width: 94vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 20px;
  box-shadow: 0 26px 90px rgba(0,0,0,.55);
}
.image-modal-close {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  color: white;
  border: 1px solid rgba(255,255,255,.16);
  font-size: 30px;
  line-height: 1;
}

/* ADMIN */
.admin-shell { width: min(1200px, 100%); margin: 0 auto; padding: 26px; }
.admin-header { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 20px; }
.admin-header h1 { margin: 0; letter-spacing: -.04em; }
.admin-header nav { display: flex; gap: 10px; flex-wrap: wrap; }
.admin-header nav a { padding: 10px 13px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); }
.panel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.panel { padding: 20px; }
.panel h2 { margin-top: 0; letter-spacing: -.02em; }
.stacked button { margin-top: 14px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 900px; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 14px; vertical-align: top; }
th { color: var(--muted); font-size: 13px; }
td span, td em { color: var(--muted); font-size: 13px; }
.inline-form { display: flex; gap: 8px; align-items: center; margin: 0 0 8px; }
.inline-form input, .inline-form select { width: auto; min-width: 130px; }
.inline-form button { padding: 10px 12px; }
.actions { min-width: 390px; }
.status-pill { display: inline-flex; padding: 5px 9px; border-radius: 999px; border: 1px solid var(--line); }
.status-pill.ok { color: #38d27a; }
.status-pill.off { color: var(--danger); }

@media (max-width: 900px) {
  .messenger-app { grid-template-columns: 1fr; }
  .side-panel { display: none; }
  .conversation-top { min-height: 64px; padding: 12px 14px; }
  .conversation-top h2 { font-size: 18px; }
  .eyebrow { display: none; }
  .top-actions a { padding: 8px 10px; font-size: 13px; }
  .messages { padding: 18px 12px 14px; gap: 9px; }
  .bubble { max-width: 84%; }
  .image-attachment, .image-attachment img { max-width: 78vw; }
  .composer { padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
  .composer-row { border-radius: 22px; }
  .send-btn, .composer button[type="submit"] { min-width: 82px; }
  .typing { padding: 0 12px; }
  .panel-grid { grid-template-columns: 1fr; }
  .admin-shell { padding: 14px; }
}

@media (max-width: 520px) {
  .top-actions a { font-size: 0; width: 38px; height: 38px; padding: 0; }
  .top-actions a::first-letter { font-size: 14px; }
  .top-actions a[href*="admin"]::after { content: "A"; font-size: 14px; }
  .top-actions a[href*="change_password"]::after { content: "Š"; font-size: 14px; }
  .top-actions a[href*="logout"]::after { content: "⎋"; font-size: 16px; }
  .bubble { max-width: 88%; }
  .composer textarea { padding-left: 2px; }
  .send-btn, .composer button[type="submit"] { min-width: 72px; font-size: 13px; }
}
