:root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --accent: #2563eb;
    --shadow: 0 6px 20px rgba(0,0,0,.08);
    --radius: 16px;
    --header-h: 68px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: ui-sans-serif, system-ui, Segoe UI, Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }

/* Sign-in screen */
.signin-wrap { min-height: 100vh; display: grid; place-items: center; padding: 32px; }
.signin-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px 28px 32px; max-width: 560px; width: 100%; text-align: center; }
.signin-brand { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 18px; }
.signin-brand img { height: 40px; }
.signin-card h1 { margin: 0 0 6px; font-size: 1.4rem; font-weight: 700; letter-spacing: .2px; }
.signin-card p  { margin: 0 0 20px; color: var(--muted); }
.btn { display:inline-flex; align-items:center; justify-content:center; gap:8px; border:0; border-radius:999px; padding:12px 18px; font-weight:600; cursor:pointer; box-shadow:var(--shadow); background:var(--card); }
.btn.primary { background: var(--accent); color:#fff; }
.btn:hover { filter: brightness(.98); }

/* App shell */
.app.hidden, .signin-wrap.hidden { display: none; }
.topbar { height: var(--header-h); background: var(--card); display:flex; align-items:center; justify-content:space-between; padding:0 16px; position:sticky; top:0; z-index:10; box-shadow: var(--shadow); }
.brand { display:flex; align-items:center; gap:10px; }
.brand img { height: 34px; }
.brand .appname { font-size: 1.05rem; font-weight:700; letter-spacing:.3px }
.userbox { display:flex; align-items:center; gap:12px; }
/* Avatar supports either a photo (background-image) or initials (text content) */
.avatar { width:34px; height:34px; border-radius:50%; background:#e5e7eb; display:flex; align-items:center; justify-content:center; font-weight:600; color: #374151; overflow:hidden; }
.avatar.photo { background-size: cover; background-position: center; }
.avatar.initials { font-size: .85rem; }
.content { padding: 16px; }

/* Grid + preview layout */
.app-grid { display:grid; grid-template-columns: 1fr 42vw; gap:16px; }
.app-grid.preview-off { grid-template-columns: 1fr; }
#grid { height: calc(100vh - var(--header-h) - 32px); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.preview { overflow:hidden; }
.preview-header { display:flex; align-items:center; justify-content:space-between; padding:10px 12px; border-bottom:1px solid #e5e7eb; }
.preview-body { position:relative; height: calc(100vh - var(--header-h) - 32px - 44px); }
.preview-empty, .preview-loading, .preview-error { position:absolute; inset:0; display:grid; place-items:center; color: var(--muted); }
#pdfFrame { border:0; width:100%; height:100%; display:none; }
.btn.small { padding:8px 12px; border-radius:999px; font-size:.9rem; }
#pdfEmbed { border: 0; width: 100%; height: 100%; display: none; }
.pdf-container { width:100%; height:100%; overflow:auto; background:#fff; }
.pdf-page { display:block; margin: 8px auto; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.app-mode-contacts #contactsView { display:block !important; }

.dx-toolbar-multiline .tb-break  { flex: 0 0 100%; height: 0; }  /* new line */
.dx-toolbar-multiline .tb-spacer { flex: 1 1 auto; }             /* right push */

@media (max-width: 600px) {
  .app-grid { 
    grid-template-columns: 1fr !important; /* stack columns */
  }
  #preview { grid-column: 1 / -1; } /* optional: ensure preview takes full width if displayed */
}

/* Original spool file display */
#originalContainer {
  display: none;
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 16px;
  margin: 0;
  background: #fafafa;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 11px;
  line-height: 1.35;
  white-space: pre;
  color: #1f2937;
  tab-size: 8;
  -moz-tab-size: 8;
}

/* DevExtreme Popup for full-screen spool viewer */
.spool-popup-content {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.spool-popup-content pre {
  flex: 1;
  margin: 0;
  padding: 12px 16px;
  background: #fafafa;
  color: #1f2937;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.4;
  white-space: pre;
  overflow: auto;
  tab-size: 8;
  -moz-tab-size: 8;
}

/* Sent status indicator */
.sent-yes { color: #16a34a; font-weight: bold; font-size: 1.1rem; }
.sent-no { color: #d1d5db; }

/* Notes indicator */
.notes-has { color: #2563eb; font-size: 1rem; opacity: 1; }
.notes-empty { color: #d1d5db; font-size: 1rem; opacity: 0.5; }
.notes-has:hover, .notes-empty:hover { opacity: 1; transform: scale(1.1); }

/* No contact warning */
.no-contact-warning { color: #f59e0b; font-size: 0.9rem; }
.no-contact-warning:hover { color: #d97706; transform: scale(1.15); }

/* Quick filter chips */
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0;
  margin-bottom: 8px;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid #e5e7eb;
  background: var(--card);
  color: var(--text);
  transition: all 0.15s ease;
}
.filter-chip:hover {
  border-color: var(--accent);
  background: #f0f7ff;
}
.filter-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.filter-chip .chip-count {
  background: rgba(0,0,0,0.1);
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 0.75rem;
}
.filter-chip.active .chip-count {
  background: rgba(255,255,255,0.25);
}

/* Status bar */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  font-size: 0.8rem;
  color: var(--muted);
  border-top: 1px solid #e5e7eb;
  background: #fafafa;
}
.status-bar .status-left {
  display: flex;
  align-items: center;
  gap: 16px;
}
.status-bar .status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.status-bar .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
}
.status-bar .status-dot.offline {
  background: #ef4444;
}
.status-bar .status-dot.refreshing {
  background: #f59e0b;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}