/* ═══════════════════════════════════════════════════════════
   INFINLE — Professional Legal AI Interface
   ═══════════════════════════════════════════════════════════ */

/* ─── Variables ─── */
:root {
  --bg: #ffffff;
  --bg-alt: #f7f7f8;
  --sidebar-bg: #f9f9f9;
  --surface: #ffffff;
  --text: #0d0d0d;
  --text-secondary: #4b5563;
  --muted: #6b7280;
  --muted-light: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f0f0f0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: rgba(37, 99, 235, 0.06);
  --accent-muted: #93c5fd;
  --user-msg: #f7f7f8;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --input-bg: #ffffff;
  --input-border: #d1d5db;
  --input-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.04);
  --input-focus-shadow: 0 0 0 3px rgba(37,99,235,0.12), 0 4px 16px rgba(0,0,0,0.06);
  --msg-assistant-bg: transparent;
  --msg-code-bg: #f3f4f6;
  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 0.875rem;
  --radius-xl: 1.25rem;
  --radius-pill: 9999px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.1);
  --font: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --transition: 0.15s ease;
  --text-primary: var(--text);
  --bg-primary: var(--surface);
  --bg-secondary: var(--bg-alt);
  --bg-hover: rgba(0, 0, 0, 0.04);
  --bg-tooltip: #1e293b;
}

body.dark {
  --bg: #0f0f0f;
  --bg-alt: #1a1a1a;
  --sidebar-bg: #0f0f0f;
  --surface: #1a1a1a;
  --text: #e5e5e5;
  --text-secondary: #a1a1aa;
  --muted: #71717a;
  --muted-light: #52525b;
  --border: #27272a;
  --border-light: #1f1f23;
  --accent: #60a5fa;
  --accent-hover: #3b82f6;
  --accent-light: rgba(96, 165, 250, 0.08);
  --accent-muted: #3b82f6;
  --user-msg: #1a1a1a;
  --danger: #f87171;
  --success: #34d399;
  --warning: #fbbf24;
  --input-bg: #1a1a1a;
  --input-border: #3f3f46;
  --input-shadow: 0 1px 3px rgba(0,0,0,0.2), 0 4px 16px rgba(0,0,0,0.15);
  --input-focus-shadow: 0 0 0 3px rgba(96,165,250,0.15), 0 4px 16px rgba(0,0,0,0.2);
  --msg-assistant-bg: transparent;
  --msg-code-bg: #27272a;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.4);
  --text-primary: var(--text);
  --bg-primary: var(--surface);
  --bg-secondary: var(--bg-alt);
  --bg-hover: rgba(255, 255, 255, 0.06);
  --bg-tooltip: #27272a;
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; font-size: 16px; overflow-x: hidden; }
body {
  height: 100vh; height: 100dvh; overflow: hidden;
  font-family: var(--font); font-size: 1rem; font-weight: 400;
  line-height: 1.6; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; } }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Text size variants */
.text-size-large .msg-body, .text-size-large .msg.user { font-size: 1.125rem; line-height: 1.7; }
.text-size-large .welcome-title { font-size: 1.5rem; }
.text-size-xlarge .msg-body, .text-size-xlarge .msg.user { font-size: 1.25rem; line-height: 1.75; }
.text-size-xlarge .welcome-title { font-size: 1.75rem; }
.compact-view .messages { gap: 0; }
.compact-view .msg { padding: 0.375rem 0; }
.compact-view .msg.assistant .msg-body { font-size: 0.875rem; line-height: 1.5; }
.compact-view .msg.assistant .msg-body h2 { font-size: 0.9375rem; margin: 0.75rem 0 0.25rem; }
.compact-view .msg-actions { margin-top: 0.25rem; }
.compact-view .welcome-hero { padding: 1rem 0.5rem; }

/* ═══ LAYOUT ═══ */
.app { display: flex; height: 100vh; height: 100dvh; position: relative; overflow: hidden; }

/* ═══ SIDEBAR ═══ */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 200;
  width: 260px; max-width: 85vw; display: flex; flex-direction: column;
  background: var(--sidebar-bg); border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s ease;
  overflow: hidden;
  padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); padding-left: env(safe-area-inset-left);
}
.sidebar.open { transform: translateX(0); box-shadow: 8px 0 30px rgba(0,0,0,0.12); }
body.dark .sidebar.open { box-shadow: 8px 0 30px rgba(0,0,0,0.4); }

.sidebar-backdrop { display: none; position: fixed; inset: 0; z-index: 190; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); opacity: 0; transition: opacity 0.25s ease; }
.sidebar-backdrop.open { display: block; opacity: 1; }

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 1rem 0.75rem;
  flex-shrink: 0;
}
.sidebar-header .logo-wrap { flex: 1; min-width: 0; }
.sidebar-theme-btn { flex-shrink: 0; width: 32px; height: 32px; min-width: 32px; min-height: 32px; }
.sidebar-collapse-btn {
  display: none;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.sidebar-collapse-btn:hover { background: var(--bg-alt); color: var(--text); border-color: var(--muted-light); }

.sidebar-reopen-btn {
  display: none;
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 180;
  width: 32px;
  height: 48px;
  padding: 0 2px 0 0;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  background: var(--surface);
  color: var(--muted);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.sidebar-reopen-btn:hover { background: var(--bg-alt); color: var(--accent); }

.logo-wrap { display: flex; align-items: center; gap: 0.5rem; }
.logo-icon-img { display: block; height: auto; }
.logo-icon-img { filter: brightness(0) saturate(100%); }
body.dark .logo-icon-img { filter: brightness(0) saturate(100%) invert(1); }
.logo-icon-img.sidebar-icon { width: 46px; }
.logo-icon-img.header-icon { width: 40px; }
.logo-text { display: flex; flex-direction: column; line-height: 1.15; }
.logo-name { font-weight: 700; font-size: 1.1875rem; letter-spacing: 0.04em; color: var(--text); }
.logo-sub { font-size: 0.6875rem; font-weight: 500; letter-spacing: 0.01em; color: var(--muted); }

.btn-new {
  margin: 0.5rem 0.75rem; padding: 0.625rem 1rem; min-height: 40px;
  border-radius: var(--radius-md); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 500; font-size: 0.875rem;
  font-family: var(--font); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  transition: all var(--transition); -webkit-tap-highlight-color: transparent;
}
.btn-new:hover { background: var(--bg-alt); border-color: var(--muted-light); }
.btn-new:active { transform: scale(0.98); }

/* Conversations */
.conversations { flex: 1; min-height: 0; overflow-y: auto; padding: 0.25rem 0.5rem; -webkit-overflow-scrolling: touch; }

.sidebar-search { padding: 8px 12px; }
.sidebar-search input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text); font-size: 13px; font-family: var(--font); outline: none; transition: border-color var(--transition); }
.sidebar-search input:focus { border-color: var(--accent); }
.search-results { padding: 4px 8px; }
.search-result-item { padding: 8px 12px; cursor: pointer; border-radius: var(--radius-md); margin-bottom: 2px; transition: background var(--transition); }
.search-result-item:hover { background: var(--bg-hover); }
.search-snippet { font-size: 12px; line-height: 1.4; color: var(--text); }
.search-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }

.conv-list-label { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 0.5rem 0.5rem 0.375rem; font-weight: 600; }
#convList { list-style: none; }
#convList li.conv-group-header {
  list-style: none;
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted-light);
  padding: 0.625rem 0.5rem 0.25rem;
  margin-top: 0.25rem;
  pointer-events: none;
  user-select: none;
}
#convList li.conv-group-header:first-child { margin-top: 0; padding-top: 0.25rem; }
#convList li.conv-item {
  display: flex; align-items: center; gap: 0.375rem; padding: 0.5rem 0.625rem;
  min-height: 38px; border-radius: var(--radius-md); cursor: pointer;
  font-size: 0.875rem; color: var(--text-secondary);
  transition: background var(--transition); -webkit-tap-highlight-color: transparent; position: relative;
}
#convList li.conv-item:hover { background: var(--bg-alt); }
#convList li.conv-item.active { background: var(--accent-light); color: var(--text); font-weight: 500; }
.conv-item-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 1.75rem; }

.conv-actions-btn { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 6px; border-radius: 4px; opacity: 0; transition: opacity var(--transition); position: absolute; right: 8px; top: 50%; transform: translateY(-50%); }
#convList li.conv-item:hover .conv-actions-btn { opacity: 0.6; }
.conv-actions-btn:hover { opacity: 1 !important; background: var(--bg-hover); }

.conv-context-menu { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); min-width: 140px; z-index: 10001; overflow: hidden; }
.conv-menu-item { padding: 8px 16px; cursor: pointer; font-size: 13px; color: var(--text); transition: background var(--transition); }
.conv-menu-item:hover { background: var(--bg-hover); }
.conv-menu-danger { color: var(--danger); }
.conv-menu-danger:hover { background: rgba(239, 68, 68, 0.06); }
body.dark .conv-menu-danger:hover { background: rgba(239, 68, 68, 0.1); }

/* Bookmarks */
.bookmarks-section { flex-shrink: 0; border-top: 1px solid var(--border); padding-top: 8px; margin-top: 8px; }
.sidebar-section-header { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; font-weight: 600; font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.bookmark-count { background: var(--accent); color: #fff; font-size: 10px; padding: 1px 7px; border-radius: 10px; font-weight: 600; }
.bookmarks-list { max-height: 180px; overflow-y: auto; }
.bookmark-item { padding: 8px 12px; cursor: pointer; border-radius: var(--radius-md); position: relative; transition: background var(--transition); }
.bookmark-item:hover { background: var(--bg-hover); }
.bookmark-preview { font-size: 12px; line-height: 1.4; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bookmark-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.bookmark-delete { position: absolute; top: 6px; right: 6px; background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; opacity: 0; transition: opacity var(--transition); padding: 2px 6px; border-radius: 4px; }
.bookmark-item:hover .bookmark-delete { opacity: 1; }
.bookmark-delete:hover { background: rgba(239,68,68,0.08); color: var(--danger); }
.empty-bookmarks { padding: 12px; text-align: center; color: var(--muted); font-size: 12px; }

.bookmark-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); z-index: 1000; display: flex; align-items: center; justify-content: center; }
.bookmark-modal { background: var(--surface); border-radius: var(--radius-xl); max-width: 700px; width: 90%; max-height: 80vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); }
.bookmark-modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.bookmark-modal-header h3 { margin: 0; font-size: 16px; }
.bookmark-modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--muted); transition: color var(--transition); }
.bookmark-modal-close:hover { color: var(--text); }
.bookmark-modal-body { padding: 20px; overflow-y: auto; flex: 1; line-height: 1.7; }
.bookmark-modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.btn-export-bookmark { padding: 6px 14px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text); cursor: pointer; font-size: 12px; font-family: var(--font); transition: all var(--transition); }
.btn-export-bookmark:hover { background: var(--bg-alt); }

/* Sidebar footer — flex-wrap: sve stane u 300px (inače overflow:hidden na .sidebar reže Odjava/Postavke) */
.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  gap: 0.25rem 0.75rem;
  flex-shrink: 0;
}
.sidebar-footer .link { font-size: 0.75rem; padding: 0.3rem 0.5rem; border-radius: var(--radius-sm); transition: background var(--transition); color: var(--muted); }
.sidebar-footer .link:hover { background: var(--bg-alt); color: var(--text); }
.sidebar-footer-sep { width: 100%; height: 0; border: none; }
.sidebar-footer .link-install { color: var(--accent); font-size: 0.6875rem; font-weight: 600; }
.sidebar-footer .link-install:hover { background: var(--accent-light); }
@media (display-mode: standalone) { .sidebar-footer .link-install { display: none; } }
@media (min-width: 769px) { .sidebar-footer .link-install { display: none !important; } }
.sidebar-footer .link-logout { color: var(--muted-light); font-size: 0.6875rem; }
.sidebar-footer .link-logout:hover { color: var(--danger); background: rgba(239,68,68,0.06); }

/* Mobile header theme toggle */
.header-theme-btn {
  display: none; background: none; border: none; cursor: pointer; padding: 6px;
  border-radius: var(--radius-sm); color: var(--muted); transition: all var(--transition);
}
.header-theme-btn:hover { color: var(--text); background: var(--bg-alt); }
.header-theme-btn .icon-moon, .header-theme-btn .icon-sun { width: 18px; height: 18px; display: block; }
.header-theme-btn .icon-moon { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z'/%3E%3C/svg%3E") no-repeat center/contain; }
.header-theme-btn .icon-sun { display: none; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='5'/%3E%3Cline x1='12' y1='1' x2='12' y2='3'/%3E%3Cline x1='12' y1='21' x2='12' y2='23'/%3E%3Cline x1='4.22' y1='4.22' x2='5.64' y2='5.64'/%3E%3Cline x1='18.36' y1='18.36' x2='19.78' y2='19.78'/%3E%3Cline x1='1' y1='12' x2='3' y2='12'/%3E%3Cline x1='21' y1='12' x2='23' y2='12'/%3E%3Cline x1='4.22' y1='19.78' x2='5.64' y2='18.36'/%3E%3Cline x1='18.36' y1='5.64' x2='19.78' y2='4.22'/%3E%3C/svg%3E") no-repeat center/contain; }
body.dark .header-theme-btn .icon-moon { display: none; }
body.dark .header-theme-btn .icon-sun { display: block; }
.btn-icon { min-width: 36px; min-height: 36px; width: 36px; height: 36px; border-radius: var(--radius-md); border: 1px solid var(--border); background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all var(--transition); }
.btn-icon:hover { background: var(--bg-alt); }

.theme-btn { position: relative; }
.theme-btn .icon-sun { display: none; }
.theme-btn .icon-moon { display: block; width: 1rem; height: 1rem; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z'/%3E%3C/svg%3E") no-repeat center/contain; }
body.dark .theme-btn .icon-moon { display: none; }
body.dark .theme-btn .icon-sun { display: block; width: 1rem; height: 1rem; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='5'/%3E%3Cline x1='12' y1='1' x2='12' y2='3'/%3E%3Cline x1='12' y1='21' x2='12' y2='23'/%3E%3Cline x1='4.22' y1='4.22' x2='5.64' y2='5.64'/%3E%3Cline x1='18.36' y1='18.36' x2='19.78' y2='19.78'/%3E%3Cline x1='1' y1='12' x2='3' y2='12'/%3E%3Cline x1='21' y1='12' x2='23' y2='12'/%3E%3Cline x1='4.22' y1='19.78' x2='5.64' y2='18.36'/%3E%3Cline x1='18.36' y1='5.64' x2='19.78' y2='4.22'/%3E%3C/svg%3E") no-repeat center/contain; }

.link { min-height: 36px; display: inline-flex; align-items: center; color: var(--muted); text-decoration: none; font-size: 0.8125rem; transition: color var(--transition); }
.link:hover { color: var(--text); }

/* ═══ MAIN AREA ═══ */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); width: 100%; height: 100%; overflow: hidden; }

.main-header {
  flex-shrink: 0; display: flex; align-items: center; gap: 0.5rem;
  padding: 0.625rem 1rem; padding-top: max(0.625rem, env(safe-area-inset-top));
  min-height: 48px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.hamburger { flex-shrink: 0; width: 40px; height: 40px; border: none; border-radius: var(--radius-md); background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--text); }
.hamburger:hover { background: var(--bg-alt); }
.header-logo-wrap { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 0; }
.header-logo-wrap .logo-name { font-size: clamp(0.9375rem, 2vw + 0.5rem, 1.1875rem); }
.header-logo-wrap .logo-sub { font-size: 0.625rem; letter-spacing: normal; }

.status-indicator { flex-shrink: 0; width: 8px; height: 8px; border-radius: 50%; margin-left: auto; background: var(--muted-light); transition: background var(--transition); cursor: pointer; }
.status-indicator[data-status="ok"] { background: var(--success); box-shadow: 0 0 6px rgba(16, 185, 129, 0.4); }
.status-indicator[data-status="degraded"] { background: var(--warning); }
.status-indicator[data-status="off"] { background: var(--danger); }

/* ═══ CHAT AREA ═══ */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; width: 100%; max-width: 60rem; margin: 0 auto; padding: 0 1.5rem; overflow: hidden; }
.messages-wrap { position: relative; flex: 1 1 0%; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.messages { flex: 1 1 0%; overflow-y: auto; overflow-x: hidden; padding: 1rem 0 0.5rem; display: flex; flex-direction: column; gap: 0; -webkit-overflow-scrolling: touch; min-height: 0; overscroll-behavior-y: contain; }

.scroll-to-bottom-btn { position: absolute; bottom: 0.5rem; right: 0.5rem; z-index: 10; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--muted); box-shadow: var(--shadow-md); cursor: pointer; display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease; transform: translateY(4px); }
.scroll-to-bottom-btn:hover { background: var(--bg-alt); color: var(--text); }
.scroll-to-bottom-btn.visible { opacity: 1; pointer-events: auto; transform: translateY(0); }

/* ═══ MESSAGES ═══ */
.msg { padding: 1.25rem 0; line-height: 1.7; font-size: 1rem; animation: msgEnter 0.32s cubic-bezier(0.22, 1, 0.36, 1); }
@media (prefers-reduced-motion: reduce) {
  .msg { animation: msgFadeIn 0.2s ease-out; }
}
.msg + .msg { border-top: 1px solid var(--border-light); }
.msg.user { padding: 1.25rem 0; color: var(--text); font-weight: 500; }

.msg.assistant { display: flex; gap: 0.75rem; align-items: flex-start; padding: 1.25rem 0; position: relative; }
.msg.assistant .msg-avatar { flex-shrink: 0; width: 1.875rem; height: 1.875rem; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; margin-top: 2px; padding: 5px; }
.msg-agent-name { font-size: 0.75rem; font-weight: 700; color: var(--accent); margin-bottom: 0.375rem; letter-spacing: 0.02em; }
.msg.assistant .msg-assistant-icon { width: 100%; height: 100%; filter: brightness(0) saturate(100%) invert(1); }
.msg.assistant .msg-body { flex: 1; min-width: 0; max-width: 100%; line-height: 1.7; font-size: 1rem; color: var(--text); word-break: break-word; overflow-wrap: break-word; }

/* Markdown in messages */
.msg.assistant .msg-body p { margin: 0.4em 0; }
.msg.assistant .msg-body p:first-child { margin-top: 0; }
.msg.assistant .msg-body p:last-child { margin-bottom: 0; }
.msg.assistant .msg-body h2 { font-size: 1.1rem; font-weight: 700; margin: 1.25rem 0 0.4rem; color: var(--text); letter-spacing: -0.01em; }
.msg.assistant .msg-body h2:first-child { margin-top: 0; }
.msg.assistant .msg-body h3 { font-size: 1rem; font-weight: 600; margin: 1rem 0 0.3rem; color: var(--text); }
.msg.assistant .msg-body strong { font-weight: 600; }
.msg.assistant .msg-body code { background: var(--msg-code-bg); padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.875rem; font-family: "SF Mono", Monaco, "Cascadia Code", monospace; }
.msg.assistant .msg-body ul, .msg.assistant .msg-body ol { margin: 0.4rem 0; padding-left: 1.5rem; }
.msg.assistant .msg-body li { margin: 0.2rem 0; line-height: 1.6; }
.msg.assistant .msg-body hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.msg.assistant .msg-body blockquote { margin: 0.75rem 0; padding: 0.625rem 1rem; border-left: 3px solid var(--accent); background: var(--accent-light); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-style: italic; color: var(--text-secondary); line-height: 1.6; }
.msg.assistant .msg-body blockquote br:last-child { display: none; }

/* Tables in responses */
.msg.assistant .msg-body .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0.75rem 0; border-radius: var(--radius-md); border: 1px solid var(--border); max-width: 100%; }
.msg.assistant .msg-body table { min-width: 400px; border-collapse: collapse; font-size: 0.875rem; white-space: nowrap; }
.msg.assistant .msg-body th { text-align: left; padding: 0.5rem 0.75rem; background: var(--bg-alt); font-weight: 600; font-size: 0.8125rem; border-bottom: 2px solid var(--border); color: var(--text); white-space: nowrap; }
.msg.assistant .msg-body td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border-light); color: var(--text-secondary); }
.msg.assistant .msg-body tr:last-child td { border-bottom: none; }
.msg.assistant .msg-body tr:hover td { background: var(--accent-light); }

/* Streaming — stable layout */
.msg-streaming .msg-body { min-height: 2em; }
.msg-streaming .stream-content {
  min-height: 1.5em; font-size: 1rem; line-height: 1.7; word-break: break-word;
  contain: content;
}
.msg-streaming .stream-content:empty::after { content: '\00a0'; }
.msg-streaming .stream-content p { margin: 0.4em 0; }
.msg-streaming .stream-content p:first-child { margin-top: 0; }
.msg-streaming .stream-content h2 { font-size: 1.1rem; font-weight: 700; margin: 1rem 0 0.4rem; }
.msg-streaming .stream-content h3 { font-size: 1rem; font-weight: 600; margin: 0.75rem 0 0.3rem; }
.msg-streaming .stream-content ul, .msg-streaming .stream-content ol { margin: 0.4rem 0; padding-left: 1.5rem; }
.msg-streaming .stream-content li { margin: 0.2rem 0; line-height: 1.6; }
.msg-streaming .stream-content strong { font-weight: 600; }
.msg-streaming .stream-content code { background: var(--msg-code-bg); padding: 0.1rem 0.35rem; border-radius: 3px; font-size: 0.875rem; }
.msg-streaming .stream-content hr { border: none; border-top: 1px solid var(--border); margin: 0.75rem 0; }

.msg-streaming .stage-indicator {
  font-size: 0.8125rem; color: var(--muted); padding: 6px 0; display: flex; align-items: center; gap: 8px;
}
.msg-streaming .stage-indicator::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.5s ease-in-out infinite; flex-shrink: 0;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.stream-thinking-wrap { margin: 0.5rem 0 0.75rem; padding: 0.75rem 1rem; border-radius: var(--radius-md); background: var(--accent-light); border-left: 3px solid var(--accent); }
.stream-thinking-label { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); margin-bottom: 0.375rem; }
.stream-thinking { font-size: 0.875rem; line-height: 1.5; color: var(--text-secondary); }
.stream-answer-label { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--success); margin-top: 0.75rem; margin-bottom: 0.25rem; display: none; }

/* Error */
.msg.error { padding: 0.875rem 1rem; border-radius: var(--radius-md); background: rgba(239, 68, 68, 0.04); border: 1px solid rgba(239, 68, 68, 0.12); color: var(--danger); display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; font-size: 0.9375rem; margin: 0.5rem 0; }
.msg.error .error-text { flex: 1; min-width: 0; }
.msg.error .btn-retry { flex-shrink: 0; padding: 0.375rem 0.75rem; font-size: 0.8125rem; border-radius: var(--radius-md); border: 1px solid rgba(239, 68, 68, 0.2); background: transparent; color: var(--danger); cursor: pointer; font-weight: 500; font-family: var(--font); transition: background var(--transition); }
.msg.error .btn-retry:hover { background: rgba(239, 68, 68, 0.08); }

/* User message layout */
.msg.user { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.msg-user-text { flex: 1; min-width: 0; word-break: break-word; }
.msg-time { font-size: 0.6875rem; color: var(--muted-light); flex-shrink: 0; white-space: nowrap; }

/* Message meta (reading time) */
.msg-meta { font-size: 0.6875rem; color: var(--muted-light); margin-top: 0.75rem; padding-top: 0.5rem; border-top: 1px solid var(--border-light); }

/* Inline sources (per message) */
.msg-sources-panel {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-alt);
  font-size: 0.8125rem;
}
.msg-sources-panel[open] { border-color: var(--accent-muted); }
.msg-sources-summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-secondary);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.msg-sources-summary::-webkit-details-marker { display: none; }
.msg-sources-summary::before {
  content: '';
  width: 0;
  height: 0;
  border-left: 5px solid var(--muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: rotate(0deg);
  transition: transform var(--transition);
  flex-shrink: 0;
}
.msg-sources-panel[open] .msg-sources-summary::before { transform: rotate(90deg); }
.msg-sources-list { list-style: none; margin: 0.5rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow-y: auto; }
.msg-source-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.5rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background var(--transition);
}
.msg-source-row:hover { background: var(--bg-hover); }
.msg-source-title { flex: 1; min-width: 0; text-align: left; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.msg-source-score { flex-shrink: 0; font-size: 0.6875rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Message actions — show on hover; ocjena (👍👎) zadnja, odvojena */
.msg-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 4px;
  row-gap: 4px;
  margin-top: 0.5rem;
  opacity: 0;
  transition: opacity var(--transition);
}
.msg.assistant:hover .msg-actions { opacity: 1; }
.msg-action-btn {
  display: inline-flex; align-items: center; gap: 0.25rem; padding: 4px 8px;
  font-size: 0.75rem; border: none; border-radius: var(--radius-sm); background: transparent;
  color: var(--muted); cursor: pointer; font-family: var(--font); transition: all var(--transition);
}
.msg-action-btn:hover { background: var(--bg-alt); color: var(--text); }
.msg-action-btn svg { flex-shrink: 0; }

.msg-feedback {
  display: flex;
  gap: 4px;
  margin-left: auto;
  padding-left: 0.65rem;
  border-left: 1px solid var(--border-light);
  align-items: center;
}
.feedback-btn { background: none; border: none; cursor: pointer; padding: 4px; border-radius: 4px; color: var(--muted); opacity: 0; transition: all var(--transition); }
.msg:hover .feedback-btn { opacity: 0.5; }
.feedback-btn:hover { opacity: 1 !important; background: var(--bg-hover); color: var(--text); }
.feedback-btn.active { color: var(--accent); opacity: 1 !important; }
.feedback-btn.active svg { fill: currentColor; }

/* Shortcuts modal */
.shortcuts-modal { position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center; }
.shortcuts-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.shortcuts-content { position: relative; background: var(--surface); border-radius: var(--radius-xl); padding: 24px; min-width: 320px; box-shadow: var(--shadow-lg); color: var(--text); }
.shortcuts-content h3 { margin: 0 0 16px; font-size: 16px; font-weight: 700; }
.shortcut-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.875rem; }
.shortcut-row:last-child { border-bottom: none; }
kbd { display: inline-block; padding: 3px 8px; font-size: 11px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 4px; font-family: var(--font); font-weight: 500; }

/* ═══ INPUT AREA ═══ */
.input-area { flex-shrink: 0; padding: 6px 0.75rem 0; padding-bottom: max(8px, env(safe-area-inset-bottom)); position: relative; background: var(--bg); border-top: none; }

.jurisdiction-bar {
  display: flex;
  gap: 4px;
  padding: 4px 0 6px;
  justify-content: center;
  flex-wrap: wrap;
}
.jurisdiction-chip {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font);
  transition: all var(--transition);
  letter-spacing: 0.02em;
}
.jurisdiction-chip:hover { border-color: var(--accent); color: var(--accent); }
.jurisdiction-chip.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.format-selector { display: flex; gap: 3px; padding: 2px 0 4px; justify-content: center; flex-wrap: wrap; }
.format-chip {
  font-size: 11px; padding: 3px 10px; border-radius: var(--radius-pill); border: 1px solid var(--border);
  background: transparent; color: var(--muted); cursor: pointer; transition: all var(--transition);
  white-space: nowrap; font-family: var(--font); font-weight: 500;
}
.format-chip:hover { border-color: var(--accent); color: var(--accent); }
.format-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.input-wrap {
  display: flex; align-items: flex-end; gap: 0;
  border: 1px solid var(--input-border); border-radius: var(--radius-xl);
  background: var(--input-bg); padding: 0.375rem 0.5rem 0.375rem 0.875rem;
  min-height: 46px; box-shadow: var(--input-shadow); transition: all var(--transition);
}
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,0.15), 0 4px 20px rgba(0,0,0,0.08); }
body.dark .input-wrap { border-color: #3f3f46; }
body.dark .input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(96,165,250,0.2), 0 4px 20px rgba(0,0,0,0.3); }

#input {
  flex: 1; min-width: 0; border: none; resize: none; font-family: var(--font);
  font-size: 1rem; padding: 0.5rem 0; background: transparent; color: var(--text);
  line-height: 1.5; max-height: 200px; -webkit-appearance: none; appearance: none;
}
@supports (-webkit-touch-callout: none) { #input { font-size: 16px; } }
#input::placeholder { color: var(--muted-light); }
#input:focus { outline: none; }

.btn-send, .btn-stop {
  flex-shrink: 0; width: 36px; height: 36px; border: none; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.btn-send { background: var(--text); color: var(--bg); }
.btn-send:hover { opacity: 0.85; }
.btn-send:active { transform: scale(0.92); }
.btn-send:disabled { opacity: 0.25; cursor: not-allowed; }
.btn-stop { background: var(--danger); color: #fff; display: none; }
.btn-stop:hover { opacity: 0.85; }

.voice-btn { background: none; border: none; cursor: pointer; padding: 8px; border-radius: 50%; color: var(--muted); transition: all 0.2s; display: flex; align-items: center; }
.attach-btn { background: none; border: none; cursor: pointer; padding: 8px; border-radius: 50%; color: var(--muted); transition: all 0.2s; display: flex; align-items: center; }
.attach-btn:hover { background: var(--bg-alt); color: var(--text); }
.attach-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.attach-btn.processing { color: var(--accent); animation: pulse-recording 1.2s infinite; }
.voice-btn:hover { background: var(--bg-alt); color: var(--text); }
.voice-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.voice-btn.recording { color: var(--danger); animation: pulse-recording 1.5s infinite; }
@keyframes pulse-recording { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

.char-counter { position: absolute; right: 4rem; bottom: 1.1rem; font-size: 0.6875rem; color: var(--muted-light); pointer-events: none; }
.char-counter.near-limit { color: var(--warning); }
.char-counter.at-limit { color: var(--danger); font-weight: 600; }

/* ═══ WELCOME SCREEN ═══ */
.welcome-hero { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 2rem 1rem 1rem; margin: auto 0; gap: 0.25rem; transition: opacity 0.2s ease; }
.welcome-logo-big { margin-bottom: 0; }
.logo-icon-img.welcome-icon { width: 48px; opacity: 0.15; }
body.dark .logo-icon-img.welcome-icon { opacity: 0.15; }
.welcome-brand { display: none; }
.welcome-title { font-size: 1.375rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text); margin: 0.5rem 0 0; }
.welcome-subtitle { font-size: 0.875rem; color: var(--muted); margin: 0 0 0.75rem; font-weight: 400; line-height: 1.4; }

.welcome-chips { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.375rem; max-width: 460px; width: 100%; }
.chip {
  display: flex; align-items: center; justify-content: center;
  padding: 0.625rem 0.75rem; border-radius: var(--radius-md); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-secondary); font-size: 0.75rem;
  font-family: var(--font); cursor: pointer; text-align: center; line-height: 1.3;
  transition: all var(--transition); min-height: 44px;
}
.chip:hover { border-color: var(--accent); background: var(--accent-light); color: var(--accent); }
.chip:active { transform: scale(0.97); }
body.dark .chip { background: var(--surface); border-color: var(--border); }
body.dark .chip:hover { background: rgba(96, 165, 250, 0.08); border-color: var(--accent); color: var(--accent); }

.welcome-stats { display: flex; justify-content: center; gap: 1.5rem; margin: 0.5rem 0 0; }
.welcome-stat { text-align: center; }
.welcome-stat strong { display: block; font-size: 1rem; font-weight: 700; color: var(--accent); }
.welcome-stat span { font-size: 0.6875rem; color: var(--muted); font-weight: 500; }

/* ═══ MODALS ═══ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  z-index: 9999; display: none; align-items: flex-end; justify-content: center; padding: 0;
  padding-bottom: env(safe-area-inset-bottom); pointer-events: none; visibility: hidden;
}
.modal-overlay.open { display: flex !important; visibility: visible; pointer-events: auto; }
.modal {
  background: var(--surface); border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%; max-width: 100%; max-height: 92dvh; overflow: hidden;
  display: flex; flex-direction: column; box-shadow: 0 -4px 32px rgba(0,0,0,0.15);
}
.modal.modal-sm { max-height: 60dvh; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; min-height: 52px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-header h2 { margin: 0; font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; }
.modal-close { width: 36px; height: 36px; border: none; background: transparent; font-size: 1.375rem; line-height: 1; color: var(--muted); cursor: pointer; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; transition: all var(--transition); }
.modal-close:hover { background: var(--bg-alt); color: var(--text); }
.modal-body { padding: 1.25rem; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; min-height: 0; }

/* Settings */
.settings-section { margin-bottom: 1.5rem; }
.settings-section h3 { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 0.75rem; font-weight: 600; }
.settings-section label { display: block; margin-bottom: 0.75rem; font-size: 0.9375rem; }
.settings-section label.checkbox { display: flex; align-items: center; gap: 0.5rem; min-height: 40px; cursor: pointer; }
.settings-section div.settings-row { display: block; margin-bottom: 0.75rem; }
.settings-section div.settings-row label { display: block; margin-bottom: 0.25rem; font-size: 0.875rem; font-weight: 500; color: var(--text-secondary); }
.settings-section div.settings-row input[type="number"] { display: block; width: 100%; max-width: 10rem; }
.settings-section input[type="checkbox"] { width: 1.125rem; height: 1.125rem; flex-shrink: 0; accent-color: var(--accent); }
.settings-section select, .settings-section input[type="number"] { display: block; width: 100%; margin-top: 0.25rem; padding: 0.5rem 0.75rem; min-height: 40px; border: 1px solid var(--border); border-radius: var(--radius-md); font-size: 0.9375rem; font-family: var(--font); background: var(--bg); color: var(--text); }

.modal-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.btn-primary { padding: 0.625rem 1.25rem; min-height: 40px; border-radius: var(--radius-md); border: none; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; font-size: 0.875rem; font-family: var(--font); transition: background var(--transition); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { padding: 0.625rem 1.25rem; min-height: 40px; border-radius: var(--radius-md); border: 1px solid var(--border); background: transparent; color: var(--text); cursor: pointer; font-size: 0.875rem; font-family: var(--font); transition: background var(--transition); }
.btn-secondary:hover { background: var(--bg-alt); }
.btn-danger { padding: 0.625rem 1.25rem; min-height: 40px; border-radius: var(--radius-md); border: none; background: var(--danger); color: #fff; cursor: pointer; font-size: 0.875rem; font-family: var(--font); transition: opacity var(--transition); }
.btn-danger:hover { opacity: 0.85; }
.settings-hint { display: block; font-size: 0.6875rem; font-weight: 400; color: var(--muted-light); margin-top: 2px; line-height: 1.3; }
.settings-status { font-size: 0.8125rem; color: var(--success); margin: 0.75rem 0 0; }

/* Status modal */
.status-section { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 1rem 0 0.5rem; }
.status-section:first-of-type { margin-top: 0.25rem; }
.status-ok { color: var(--success); }
.status-fail { color: var(--danger); }
.status-extra { font-size: 0.875rem; color: var(--muted); font-weight: normal; }
.status-hint { display: inline-block; font-size: 0.8125rem; color: var(--muted); margin-top: 0.25rem; margin-left: 1.25rem; }
.status-hint code { font-size: 0.75rem; background: var(--msg-code-bg); padding: 0.125rem 0.375rem; border-radius: 3px; }

/* Toast */
.toast { position: fixed; bottom: 5rem; left: 50%; transform: translateX(-50%) translateY(8px); padding: 0.5rem 1rem; border-radius: var(--radius-pill); background: var(--text); color: var(--bg); font-size: 0.875rem; box-shadow: var(--shadow-lg); z-index: 10000; opacity: 0; transition: opacity 0.2s, transform 0.2s; white-space: nowrap; }
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ═══ CITATIONS + SOURCE MODAL ═══ */
.citation-link { color: var(--accent); text-decoration: none; cursor: pointer; font-weight: 600; border-bottom: 1px dashed var(--accent); transition: opacity var(--transition); }
.citation-link:hover { opacity: 0.7; }
.article-link { font-weight: 500; border-bottom-style: dotted; color: var(--accent); opacity: 0.85; }
.article-link:hover { opacity: 1; }
.open-original-pdf { background: var(--accent-light) !important; color: var(--accent) !important; border-color: var(--accent) !important; font-weight: 600 !important; }
.citation-ref { color: var(--accent); font-weight: 600; }

.source-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); z-index: 10000; display: flex; align-items: center; justify-content: center; padding: 20px; }
.source-modal { background: var(--surface); border-radius: var(--radius-xl); max-width: 700px; width: 100%; max-height: 80vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); }
.source-modal-header { padding: 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.source-modal-header h3 { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.4; }
.source-modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--muted); padding: 0 4px; flex-shrink: 0; line-height: 1; transition: color var(--transition); }
.source-modal-close:hover { color: var(--text); }
.source-meta-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.source-tag { background: var(--bg-alt); padding: 2px 10px; border-radius: var(--radius-pill); font-size: 11px; font-weight: 500; }
.source-score { font-size: 11px; color: var(--muted); }
.source-modal-body { padding: 20px; overflow-y: auto; flex: 1; min-height: 0; }
.source-text { white-space: pre-wrap; word-wrap: break-word; font-family: var(--font); font-size: 0.875rem; line-height: 1.7; margin: 0; background: var(--bg-alt); padding: 16px; border-radius: var(--radius-md); }
.source-modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.source-citation { margin-bottom: 8px; }
.source-modal-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.source-action-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-secondary); font-size: 12px; font-family: var(--font);
  cursor: pointer; transition: all var(--transition);
}
.source-action-btn:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.source-action-btn:disabled { opacity: 0.5; cursor: wait; }
.source-action-btn svg { flex-shrink: 0; }

/* Jurisdiction tag colors */
.source-tag.jur-tag { font-weight: 600; }
.source-tag.type-tag { background: rgba(37, 99, 235, 0.08); color: var(--accent); }

/* Jurisdiction badge in source list */
.source-jur-badge {
  display: inline-block; padding: 1px 6px; border-radius: var(--radius-sm);
  font-size: 10px; font-weight: 700; margin-right: 6px; flex-shrink: 0;
  background: rgba(37, 99, 235, 0.1); color: var(--accent); letter-spacing: 0.02em;
}

/* Full document modal */
.full-doc-modal { max-width: 900px; max-height: 90vh; }
.full-doc-body { max-height: 70vh; }
.full-doc-text { max-height: none; font-size: 0.8125rem; line-height: 1.8; }

/* Glossary tooltips */
.glossary-term { border-bottom: 1px dotted var(--muted-light); cursor: help; position: relative; }
.glossary-term:hover::after { content: attr(data-tooltip); position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); background: var(--bg-tooltip); color: #fff; padding: 8px 12px; border-radius: var(--radius-md); font-size: 12px; line-height: 1.4; white-space: normal; width: max-content; max-width: 280px; z-index: 100; pointer-events: none; box-shadow: var(--shadow-lg); }
.glossary-term:hover::before { content: ''; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); border: 6px solid transparent; border-top-color: var(--bg-tooltip); z-index: 100; }

/* ═══ FOLLOW-UP CHIPS ═══ */
.followup-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 0 16px; max-width: 100%; }
.followup-chip { font-size: 0.8125rem; padding: 6px 14px; border-radius: var(--radius-pill); background: var(--surface); border: 1px solid var(--border); cursor: pointer; transition: all var(--transition); color: var(--text-secondary); font-family: var(--font); }
.followup-chip:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip-compare { border-color: var(--accent); color: var(--accent); }
.chip-compare:hover { background: var(--accent-light); }

/* ═══ PRAVNI ALATI (rokovi, zastara, datumi, PDV) ═══ */
.modal-calc { max-width: 720px; max-height: min(92vh, 900px); overflow-y: auto; }
.modal-header-calc {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12) 0%, rgba(168, 85, 247, 0.1) 50%, rgba(236, 72, 153, 0.08) 100%);
  border-bottom-color: rgba(99, 102, 241, 0.2);
}
body.dark .modal-header-calc {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.22) 0%, rgba(168, 85, 247, 0.15) 55%, rgba(236, 72, 153, 0.12) 100%);
  border-bottom-color: rgba(129, 140, 248, 0.25);
}
.modal-header-calc-inner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  flex: 1;
  min-width: 0;
}
.modal-header-calc-inner h2 { flex: 1; min-width: 0; }
.btn-calc-magic {
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  box-shadow: none;
  animation: calcMagicPulse 3s ease-in-out infinite;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.btn-calc-magic:hover {
  border-color: var(--accent); color: var(--accent); background: var(--accent-light);
}
.btn-calc-magic:active { transform: scale(0.97); }
.calc-surprise-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(99, 102, 241, 0.35) !important;
  animation: calcSurpriseIn 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.calc-surprise-card::before {
  content: "";
  position: absolute;
  inset: -40% -20%;
  background: radial-gradient(circle at 30% 20%, rgba(168, 85, 247, 0.15), transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(99, 102, 241, 0.12), transparent 40%);
  pointer-events: none;
  z-index: 0;
}
.calc-surprise-sparkle {
  font-size: 1.75rem;
  line-height: 1;
  margin-bottom: 0.5rem;
  position: relative;
  z-index: 1;
  animation: calcSparkleSpin 6s linear infinite;
}
@keyframes calcSparkleSpin {
  to { transform: rotate(360deg); }
}
.calc-surprise-quote {
  position: relative;
  z-index: 1;
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.55;
  font-weight: 500;
  color: var(--text);
}
.calc-surprise-tag {
  position: relative;
  z-index: 1;
  margin: 1rem 0 0;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  font-weight: 600;
}
@keyframes calcSurpriseIn {
  from { opacity: 0; transform: scale(0.92) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.calc-hint-tight { margin-top: 0; margin-bottom: 0.65rem; }
.calc-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 1.25rem; background: var(--bg-alt); border-radius: var(--radius-md); padding: 4px; }
.calc-tab {
  flex: 1 1 auto;
  min-width: 5.5rem;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
  font-family: var(--font);
}
.calc-tab.active { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: var(--shadow-sm); border: 1px solid var(--accent-muted); }
.calc-tab:hover:not(.active) { color: var(--text); }
.calc-panel { display: none; }
.calc-panel.active { display: block; }
.calc-field { margin-bottom: 1rem; }
.calc-field label { display: block; font-size: 0.8125rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 0.35rem; }
.calc-field select, .calc-field input { width: 100%; padding: 0.55rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-md); font-size: 0.875rem; background: var(--bg); color: var(--text); font-family: var(--font); transition: border-color var(--transition); }
.calc-field select:focus, .calc-field input:focus { border-color: var(--accent); outline: none; }
.calc-btn { width: 100%; margin-top: 0.5rem; }
.calc-result { margin-top: 1.25rem; animation: msgFadeIn 0.25s ease; }
.calc-result-card { background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem; }
.calc-result-card h3 { margin: 0 0 0.75rem; font-size: 1rem; color: var(--text); }
.calc-status { display: inline-block; padding: 0.25rem 0.75rem; border-radius: var(--radius-pill); font-size: 0.8125rem; font-weight: 600; margin-bottom: 1rem; }
.calc-ok { background: rgba(16,185,129,0.08); color: #059669; }
.calc-urgent { background: rgba(245,158,11,0.08); color: #d97706; }
.calc-expired { background: rgba(239,68,68,0.08); color: #dc2626; }
body.dark .calc-ok { background: rgba(52,211,153,0.1); color: #34d399; }
body.dark .calc-urgent { background: rgba(251,191,36,0.1); color: #fbbf24; }
body.dark .calc-expired { background: rgba(248,113,113,0.1); color: #f87171; }
.calc-detail { display: flex; justify-content: space-between; align-items: center; padding: 0.4rem 0; font-size: 0.875rem; }
.calc-detail span { color: var(--muted); }
.calc-detail strong { color: var(--text); }
.calc-detail.calc-total { border-top: 2px solid var(--border); margin-top: 0.35rem; padding-top: 0.6rem; font-size: 1rem; }
.calc-interest-amount { color: var(--accent) !important; }
.calc-law { margin-top: 0.75rem; padding: 0.5rem 0.75rem; background: var(--accent-light); border-left: 3px solid var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: 0.8125rem; color: var(--accent); font-weight: 500; }
.calc-desc { margin: 0.75rem 0 0; font-size: 0.8125rem; color: var(--muted); line-height: 1.5; }
.calc-note { margin: 0.75rem 0 0; font-size: 0.8125rem; color: var(--muted); font-style: italic; }
.calc-error { color: var(--danger); font-size: 0.875rem; margin: 0; padding: 0.75rem; background: rgba(239,68,68,0.04); border-radius: var(--radius-md); }
body.dark .calc-error { background: rgba(239,68,68,0.08); }
.calc-subhead { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 1.25rem 0 0.65rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.calc-panel .calc-subhead:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
.calc-field-inline { display: flex; align-items: flex-start; gap: 0.5rem; font-size: 0.8125rem; color: var(--text-secondary); cursor: pointer; margin-bottom: 0.75rem; }
.calc-field-inline input { margin-top: 0.2rem; }
.calc-textarea { width: 100%; min-height: 140px; padding: 0.65rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-md); font-size: 0.875rem; font-family: var(--font); background: var(--bg); color: var(--text); resize: vertical; line-height: 1.45; }
.calc-textarea:focus { border-color: var(--accent); outline: none; }
.calc-draft-stats { font-size: 0.8125rem; color: var(--muted); margin-top: 0.5rem; padding: 0.5rem 0.75rem; background: var(--bg-alt); border-radius: var(--radius-md); }
.calc-draft-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.calc-btn-sm { padding: 0.4rem 1rem; font-size: 0.8125rem; width: auto; }

/* Search panel */
.calc-search-wrap { display: flex; gap: 0.5rem; }
.calc-search-wrap input { flex: 1; }
.calc-search-btn { white-space: nowrap; padding: 0.55rem 1.25rem; }
.calc-search-results { margin-top: 0.75rem; max-height: 300px; overflow-y: auto; }
.calc-search-item { padding: 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: 0.5rem; cursor: pointer; transition: all var(--transition); }
.calc-search-item:hover { border-color: var(--accent); background: var(--accent-light); }
.calc-search-item-title { font-size: 0.8125rem; font-weight: 600; color: var(--text); margin-bottom: 0.25rem; }
.calc-search-item-meta { font-size: 0.6875rem; color: var(--muted); margin-bottom: 0.25rem; }
.calc-search-item-text { font-size: 0.75rem; color: var(--text-secondary); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Tip at bottom of calc modal */
.calc-tip { margin-top: 1rem; padding: 0.75rem 1rem; border-top: 1px solid var(--border); font-size: 0.75rem; color: var(--muted); line-height: 1.5; }
.calc-tip-label { font-weight: 600; color: var(--text-secondary); margin-right: 0.25rem; }

/* Status modal improvements */
.modal-sm .modal-body { font-size: 0.875rem; line-height: 1.6; }
.status-component { padding: 0.375rem 0; display: flex; align-items: center; gap: 0.5rem; }
.status-ok { color: var(--success); font-weight: 700; }
.status-fail { color: var(--danger); font-weight: 700; }
.status-section { font-weight: 600; color: var(--text); margin: 0.75rem 0 0.25rem; font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.03em; }
.calc-hint { font-size: 0.75rem; color: var(--muted); margin: 0.5rem 0 0; line-height: 1.45; }
.calc-taksa-card h4 { margin: 0.75rem 0 0.35rem; font-size: 0.9375rem; color: var(--text); }
.calc-taksa-block:first-of-type h4 { margin-top: 0; }
.calc-taksa-sources { margin: 0.35rem 0 0; padding-left: 1.1rem; font-size: 0.8125rem; color: var(--muted); }
.calc-taksa-sources li { margin: 0.2rem 0; }

/* ═══ ANALYTICS ═══ */
#analyticsModal { position: fixed; inset: 0; z-index: 10002; align-items: center; justify-content: center; padding: 1rem; background: transparent; box-shadow: none; border-radius: 0; max-height: none; width: 100%; max-width: none; flex-direction: column; }
#analyticsModal .modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
#analyticsModal .modal-content { position: relative; z-index: 1; background: var(--surface); border-radius: var(--radius-xl); width: 95%; max-width: 800px; max-height: 85dvh; overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); }
#analyticsModal .modal-content .modal-body { flex: 1; min-height: 0; }
.analytics-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--bg-alt); border-radius: var(--radius-lg); padding: 20px; text-align: center; border: 1px solid var(--border); }
.analytics-stats .stat-value { font-size: 1.75rem; font-weight: 700; color: var(--accent); }
.analytics-stats .stat-label { font-size: 0.8125rem; color: var(--muted); margin-top: 4px; }
.analytics-section-title { font-size: 0.875rem; font-weight: 600; margin: 20px 0 12px; }
.analytics-bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 12px; }
.bar-label { width: 120px; font-size: 0.8125rem; text-align: right; flex-shrink: 0; color: var(--text-secondary); }
.bar-track { flex: 1; height: 20px; background: var(--bg-alt); border-radius: var(--radius-sm); overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: var(--radius-sm); transition: width 0.5s; }
.bar-count { width: 40px; font-size: 0.8125rem; font-weight: 600; }
.analytics-table { overflow-x: auto; }
.analytics-table table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.analytics-table th { text-align: left; padding: 8px 12px; border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-secondary); }
.analytics-table td { padding: 6px 12px; border-bottom: 1px solid var(--border-light); }
.query-cell { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-cache { background: var(--success); color: #fff; padding: 2px 8px; border-radius: var(--radius-pill); font-size: 10px; font-weight: 600; }
.analytics-loading, .analytics-error { padding: 40px; text-align: center; color: var(--muted); }

/* ═══ DESKTOP ═══ */
@media (min-width: 769px) {
  .sidebar-backdrop { display: none !important; }
  .sidebar {
    position: relative;
    width: 300px;
    min-width: 300px;
    max-width: 300px;
    transform: none;
    box-shadow: none;
    transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1), min-width 0.28s cubic-bezier(0.4, 0, 0.2, 1), max-width 0.28s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease, border-color 0.2s ease, padding 0.2s ease;
  }
  .sidebar.open { transform: none; box-shadow: none; }
  .sidebar-collapse-btn { display: flex; }

  body.sidebar-desktop-collapsed .sidebar {
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    padding-left: 0;
    padding-right: 0;
    border-right-width: 0;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
  }
  body.sidebar-desktop-collapsed .sidebar-reopen-btn {
    display: flex;
  }

  .main-header { display: none; }
  .main { width: auto; }
  .chat { padding: 0 2rem; }

  /* Desktop welcome — push to vertical center of messages area */
  .welcome-hero { padding: 0 2rem; }
  .welcome-title { font-size: 1.75rem; }
  .welcome-subtitle { font-size: 1rem; margin-bottom: 1.25rem; }
  .welcome-chips { max-width: 520px; gap: 0.5rem; }
  .chip { font-size: 0.8125rem; padding: 0.75rem 1rem; min-height: 48px; }
  .welcome-stats { margin-top: 1rem; gap: 2rem; }
  .welcome-stat strong { font-size: 1.25rem; }
  .welcome-stat span { font-size: 0.75rem; }
  .logo-icon-img.welcome-icon { width: 52px; }
  .modal-overlay { align-items: center; padding: 1rem; }
  .modal { border-radius: var(--radius-xl); max-width: 560px; max-height: 92vh; box-shadow: var(--shadow-lg); }
  .modal.modal-sm { max-width: 380px; max-height: 60vh; }
  .settings-section select { width: auto; min-width: 12rem; display: inline-block; margin-left: 0.5rem; }
}

/* ═══ MOBILE ═══ */
@media (max-width: 768px) {
  .app { height: 100vh; height: 100dvh; }
  .chat { padding: 0 0.75rem; }
  .logo-icon-img.sidebar-icon { width: 32px; }
  .logo-icon-img.header-icon { width: 30px; }
  .header-theme-btn { display: flex; align-items: center; justify-content: center; }
  .logo-icon-img.welcome-icon { width: 60px; }
  .welcome-brand-name { font-size: 1.625rem; }
  .welcome-brand-sub { font-size: 0.6875rem; }
  .welcome-hero { padding: 1rem 0.75rem 0.5rem; }
  .welcome-title { font-size: 1.125rem; }
  .welcome-subtitle { font-size: 0.8125rem; margin-bottom: 0.5rem; }
  .welcome-chips { gap: 0.375rem; max-width: 100%; }
  .chip { padding: 0.625rem 0.75rem; font-size: 0.75rem; min-height: 44px; -webkit-tap-highlight-color: transparent; }
  .welcome-stats { gap: 1.5rem; margin: 12px 0; }
  .welcome-stat strong { font-size: 1rem; }

  .msg { padding: 0.875rem 0; }
  .msg.assistant .msg-avatar { width: 1.625rem; height: 1.625rem; padding: 4px; }
  .msg.assistant .msg-assistant-icon { width: 100%; height: 100%; }
  .msg.assistant .msg-body { font-size: 0.9375rem; line-height: 1.65; }

  /* Touch: always show actions (no hover on mobile) */
  .msg-actions { opacity: 1; margin-top: 0.5rem; }
  .msg-feedback {
    margin-left: 0;
    padding-left: 0;
    border-left: none;
    border-top: 1px solid var(--border-light);
    padding-top: 6px;
    margin-top: 4px;
    flex-basis: 100%;
    justify-content: flex-end;
  }
  .msg .feedback-btn { opacity: 0.6; }
  .msg-action-btn { padding: 6px 10px; font-size: 0.75rem; min-height: 36px; }
  .msg-action-btn span { display: none; }

  /* Format selector — compact on mobile */
  .format-selector { gap: 4px; padding: 2px 0 4px; }
  .format-chip { font-size: 0.75rem; padding: 5px 12px; min-height: 30px; }

  /* Input area — compact on mobile */
  .input-area { padding: 2px 0 0; padding-bottom: max(3px, calc(env(safe-area-inset-bottom) + 1px)); }
  .input-wrap { padding: 0.25rem 0.375rem 0.25rem 0.75rem; min-height: 40px; border-radius: 1.25rem; }
  #input { padding: 0.25rem 0; font-size: 0.9375rem; }
  .btn-send, .btn-stop { width: 34px; height: 34px; min-width: 34px; min-height: 34px; }
  .voice-btn { padding: 8px; }
  .char-counter { right: 5rem; bottom: 1rem; font-size: 0.625rem; }

  .scroll-to-bottom-btn { bottom: 0.5rem; right: 0.5rem; width: 36px; height: 36px; }

  .toast { bottom: calc(6rem + env(safe-area-inset-bottom)); left: 1rem; right: 1rem; transform: translateY(8px); text-align: center; }
  .toast.visible { transform: translateY(0); }

  .btn-new, .hamburger, .modal-close, .link { min-height: 44px; min-width: 44px; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
  .btn-send, .btn-stop, .voice-btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
  .chip, .format-chip, .followup-chip { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

  /* Sidebar footer — bigger tap targets */
  .sidebar-footer { padding: 0.75rem; gap: 0.25rem; flex-wrap: wrap; }
  .sidebar-footer .link { font-size: 0.875rem; padding: 0.375rem 0.5rem; min-height: 44px; }

  #convList li.conv-item { min-height: 44px; padding: 0.625rem; }
  #convList li.conv-item .conv-actions-btn { opacity: 0.5; }

  .modal-overlay { padding: 1rem; padding-bottom: max(1rem, env(safe-area-inset-bottom)); align-items: center; }
  .modal { border-radius: 1rem; max-height: 85dvh; max-height: 85vh; }
  .modal-body { padding: 1rem; max-height: none; padding-bottom: max(1rem, env(safe-area-inset-bottom)); }

  .analytics-stats { grid-template-columns: 1fr; }
  #analyticsModal { align-items: flex-end; padding: 0; }
  #analyticsModal .modal-content { width: 100%; max-height: 92dvh; border-radius: 1rem 1rem 0 0; }

  /* Follow-up chips */
  .followup-chip { font-size: 0.875rem; padding: 8px 16px; min-height: 40px; }

  /* Source modal */
  .source-modal-overlay { padding: 1rem; align-items: center; }
  .source-modal { max-width: 100%; max-height: 85dvh; border-radius: 1rem; }

  /* Calculator */
  .calc-tab { min-height: 44px; font-size: 0.9375rem; }
  .calc-field select, .calc-field input { min-height: 44px; font-size: 1rem; }
  .calc-btn { min-height: 48px; font-size: 1rem; }

  /* Settings */
  .settings-section select, .settings-section input[type="number"] { min-height: 44px; font-size: 1rem; }
  .settings-section label.checkbox { min-height: 48px; font-size: 1rem; }
  .settings-section input[type="checkbox"] { width: 1.25rem; height: 1.25rem; }
  .modal-actions { gap: 0.625rem; }
  .modal-actions .btn-primary, .modal-actions .btn-secondary, .modal-actions .btn-danger { min-height: 48px; font-size: 1rem; flex: 1; }
}

@media (max-width: 420px) {
  .welcome-chips { grid-template-columns: repeat(2, 1fr); gap: 0.25rem; }
  .chip { padding: 0.5rem 0.5rem; font-size: 0.6875rem; min-height: 40px; }
  .welcome-stats { gap: 1rem; flex-wrap: wrap; justify-content: center; }
  .format-chip { font-size: 0.6875rem; padding: 4px 10px; min-height: 26px; }
  .msg.assistant .msg-body { font-size: 0.9375rem; }
  .input-area { padding-bottom: max(2px, calc(env(safe-area-inset-bottom) + 1px)); }
  .jurisdiction-bar { display: none; }
}

/* ═══ iOS KEYBOARD HANDLING ═══ */
@supports (-webkit-touch-callout: none) {
  #input { font-size: 16px; }
  .settings-section select, .settings-section input[type="number"],
  .calc-field select, .calc-field input { font-size: 16px; }
  .input-area { padding-bottom: max(0.5rem, calc(env(safe-area-inset-bottom) + 0.25rem)); }
}

/* ═══ STANDALONE (PWA) MODE ═══ */
@media (display-mode: standalone) {
  .main-header { padding-top: max(0.625rem, calc(env(safe-area-inset-top) + 0.25rem)); }
  .sidebar { padding-top: max(1rem, calc(env(safe-area-inset-top) + 0.25rem)); }
}

/* ═══ SMALL PHONES (Galaxy S22, iPhone SE) ═══ */
@media (max-width: 380px) {
  .main-header { min-height: 36px; padding: 0.25rem 0.75rem; gap: 0.375rem; }
  .main-header .logo-name { font-size: 0.8125rem; }
  .main-header .logo-sub { font-size: 0.4375rem; }
  .logo-icon-img.header-icon { width: 22px; }
  .hamburger { min-width: 34px; min-height: 34px; }
  .format-selector { gap: 2px; padding: 1px 0 3px; }
  .format-chip { font-size: 0.625rem; padding: 3px 8px; min-height: 24px; }
  .input-wrap { min-height: 40px; padding: 0.25rem 0.375rem 0.25rem 0.625rem; }
  .btn-send, .btn-stop { width: 34px; height: 34px; min-width: 34px; min-height: 34px; }
  .voice-btn { padding: 6px; }
  #input { font-size: 0.875rem; padding: 0.375rem 0; }
  .welcome-title { font-size: 1rem; }
  .welcome-subtitle { font-size: 0.75rem; }
  .welcome-chips { gap: 0.25rem; }
  .chip { font-size: 0.625rem; padding: 0.375rem 0.5rem; min-height: 36px; }
  .welcome-stats { gap: 0.75rem; margin-top: 0.25rem; }
  .welcome-stat strong { font-size: 0.875rem; }
  .welcome-stat span { font-size: 0.5625rem; }
  .msg.assistant .msg-body { font-size: 0.8125rem; line-height: 1.5; }
  .msg-action-btn { padding: 4px 8px; font-size: 0.6875rem; }
}

/* Lock body scroll when modal open */
body.modal-open { overflow: hidden; }

/* ═══ SMOOTH THEME TRANSITION ═══ */
body { transition: background-color 0.3s ease, color 0.3s ease; }
.sidebar, .main-header, .input-area, .modal, .msg.assistant .msg-body blockquote,
.msg.assistant .msg-body th, .msg.assistant .msg-body td,
.chip, .format-chip, .btn-new, .btn-icon, .input-wrap { transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease; }

/* ═══ LOADING SKELETON ═══ */
.skeleton-wrap { padding: 1.5rem 0; display: flex; flex-direction: column; gap: 1rem; }
.skeleton-line, .skeleton-block { border-radius: var(--radius-md); background: var(--bg-alt); animation: skeleton-pulse 1.2s ease-in-out infinite; }
.skeleton-line { height: 1rem; }
.skeleton-line.w60 { width: 60%; }
.skeleton-line.w80 { width: 80%; }
.skeleton-block { height: 4rem; width: 100%; }
.skeleton-block.tall { height: 6rem; }
@keyframes skeleton-pulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 0.2; } }

/* ═══ ANIMATIONS ═══ */
@keyframes msgFadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes msgEnter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ═══ PRINT ═══ */
@media print {
  body { background: #fff !important; color: #000 !important; }
  .sidebar, .main-header, .input-area, .msg-actions, .msg-feedback, .scroll-to-bottom-btn,
  .toast, .modal-overlay, .sidebar-backdrop, #analyticsModal, .source-modal-overlay, .conv-context-menu,
  .format-selector, .followup-chips { display: none !important; }
  .app { display: block; }
  .main, .chat { max-width: 100%; padding: 0; }
  .messages { overflow: visible; }
  .msg { border-top: 1px solid #e5e5e5 !important; }
}

/* Secondary action row: DOCX/PDF + feedback on separate line */
.msg-secondary-actions { }
.msg-secondary-actions .msg-feedback { border-left: none; padding-left: 0; margin-left: 0; }

/* Vertical divider after attach button */
.attach-divider {
  flex: 0 0 auto;
  width: 1px;
  height: 20px;
  background: var(--border);
  margin-right: 0.5rem;
  margin-left: 0.25rem;
  align-self: center;
}
@media (max-width: 768px) {
  .attach-divider { height: 18px; margin-right: 0.375rem; }
}

/* Attached file chip in user message bubble */
.msg.user .msg-attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  font-weight: 500;
  margin-bottom: 0.4rem;
  margin-right: auto;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg.user .msg-attach-chip + .msg-user-text { display: block; margin-top: 0.25rem; }

/* Citation footer + disclaimer */
.citation-footer {
  margin-top: 1.25rem;
  padding: 0.875rem 1rem;
  background: var(--bg-alt);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font-size: 0.8125rem;
}
.citation-footer-title {
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text);
}
.citation-list {
  margin: 0 0 0.75rem 1rem;
  padding: 0;
  color: var(--muted);
  line-height: 1.55;
}
.citation-list li {
  margin-bottom: 0.25rem;
  list-style: square;
}
.legal-disclaimer {
  margin-top: 0.75rem;
  padding-top: 0.625rem;
  border-top: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  font-style: italic;
}

/* Source reference [Izvor N] — clickable tooltip */
.source-ref {
  display: inline;
  color: var(--accent);
  cursor: pointer;
  background: rgba(59,130,246,0.06);
  padding: 0.05rem 0.25rem;
  border-radius: 0.25rem;
  font-size: 0.92em;
  transition: background 0.15s;
  text-decoration: none;
}
.source-ref:hover, .source-ref:focus {
  background: rgba(59,130,246,0.16);
  outline: none;
}

.source-tooltip {
  position: fixed;
  z-index: 10050;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.875rem 1rem 1rem;
  max-width: 360px;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--text);
  animation: src-tip-in 0.12s ease-out;
}
.src-tip-title {
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text);
  padding-right: 1.5rem;
}
.src-tip-art {
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 0.2rem;
  font-weight: 500;
}
.src-tip-sln {
  color: var(--muted);
  font-size: 0.78rem;
  font-style: italic;
  margin-bottom: 0.5rem;
}
.src-tip-text {
  color: var(--text);
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.83rem;
  line-height: 1.55;
}
.src-tip-close {
  position: absolute;
  top: 0.25rem;
  right: 0.4rem;
  background: none;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  border-radius: 0.25rem;
}
.src-tip-close:hover { background: var(--bg-alt); color: var(--text); }
@keyframes src-tip-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Source preview tooltip — Pregled originala button */
.src-tip-preview {
  display: block;
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.6rem 0.875rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.83rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  text-align: center;
}
.src-tip-preview:hover { background: var(--accent-hover, #2563eb); }
.src-tip-preview:active { transform: scale(0.98); }

/* Doc preview modal text */
.doc-preview-text p {
  margin: 0 0 0.75rem;
  line-height: 1.65;
}
.doc-preview-text p:last-child { margin-bottom: 0; }
