:root {
  --primary: #2563eb;
  --border: #e2e8f0;
  --muted: #64748b;
  --bg: #f8fafc;
  --error: #dc2626;
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  background: var(--bg);
  color: #0f172a;
}

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: white;
  padding: 2rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

input, textarea, button {
  font: inherit;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

button {
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
}

button.secondary {
  background: white;
  color: var(--primary);
  border: 1px solid var(--primary);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.link-btn {
  background: none;
  color: var(--muted);
  text-decoration: underline;
  border: none;
  padding: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: white;
  border-bottom: 1px solid var(--border);
  gap: 1.5rem;
  flex-wrap: wrap;
}

.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0;
  flex: 1 1 auto;
  flex-wrap: wrap;
}

.tab-btn {
  background: none;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.5rem 0.6rem;
  white-space: nowrap;
  font-size: 0.9rem;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

main {
  padding: 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.toolbar input[type="search"] {
  flex: 1;
}

.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--error); font-size: 0.9rem; }
.hidden { display: none !important; }

.grid {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 8px;
  overflow: hidden;
}

.grid th, .grid td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.grid th {
  background: #f1f5f9;
  color: var(--muted);
  font-weight: 600;
}

/* Useri + Grupuri tables: the whole row is a click target for the row's
   checkbox (see renderUsersTable/renderGroupsTable in app.js), not just the
   checkbox itself. Highlight is driven purely by the checkbox's own
   :checked state via :has() — not a separate class — so it can never drift
   out of sync with any of the several code paths that toggle it (row
   click, direct checkbox click, "select all", "golește selecția",
   re-render on search/realtime update). */
.grid tbody tr.selectable-row {
  cursor: pointer;
}
.grid tbody tr.selectable-row:hover {
  background: #f8fafc;
}
.grid tbody tr.selectable-row:has(input[type="checkbox"]:checked) {
  background: #eef2ff;
}
.grid tbody tr.row-disabled {
  opacity: 0.55;
}

/* "Acțiuni" bulk-actions menu on the Useri toolbar */
.dropdown {
  position: relative;
  display: inline-block;
}
.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0.25rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
  min-width: 160px;
  z-index: 10;
  overflow: hidden;
}
.dropdown-menu.hidden { display: none; }
.dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 0;
  padding: 0.55rem 0.8rem;
  color: #0f172a;
  cursor: pointer;
}
.dropdown-item:hover { background: #f1f5f9; }
.dropdown-item.danger { color: var(--error); }

.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.card h3 { margin-top: 0; }

.card label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.row-buttons {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.placeholder-buttons {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.placeholder-buttons button {
  background: #eef2ff;
  color: var(--primary);
  border: 1px solid #c7d2fe;
  font-size: 0.85rem;
}

#message-textarea, #bulk-accounts-textarea { width: 100%; }

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: -0.5rem;
}
.hint code {
  background: #f1f5f9;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

#bulk-accounts-report { margin-top: 1rem; }
.bulk-report-summary { font-weight: 600; margin-bottom: 0.5rem; }
.bulk-report-line {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  margin-bottom: 0.3rem;
  font-size: 0.9rem;
}
.bulk-report-line.created { background: #ecfdf5; color: #065f46; }
.bulk-report-line.exists { background: #fef3c7; color: #92400e; }
.bulk-report-line.error { background: #fef2f2; color: var(--error); }

.banner {
  background: #fef3c7;
  border: 1px solid #fbbf24;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#preview-list { list-style: none; padding: 0; }
#preview-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
#preview-list li:last-child { border-bottom: none; }
#preview-list .preview-name { font-weight: 600; }

.two-col-layout {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}
.two-col-main {
  flex: 1 1 480px;
  min-width: 320px;
}
.two-col-side {
  flex: 0 0 320px;
  min-width: 280px;
}
.selected-users-scroll {
  max-height: 40vh;
  overflow-y: auto;
  border-radius: 8px;
}
.selected-users-scroll .grid thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}
#selected-users-more, #compose-selected-users-more {
  margin-top: 0.5rem;
  margin-bottom: 0;
}

.history-layout {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}
.history-sidebar {
  flex: 0 0 280px;
}
.history-messages {
  flex: 1;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  min-height: 300px;
}
.conversation-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
  max-height: 60vh;
  overflow-y: auto;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.conversation-list li {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.conversation-list li:last-child { border-bottom: none; }
.conversation-list li:hover { background: #f8fafc; }
.conversation-list li.active { background: #eef2ff; }
.conversation-list .conv-name { font-weight: 600; }
.conversation-list .conv-preview {
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-messages-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.message-list { display: flex; flex-direction: column; gap: 0.5rem; }
.message-bubble {
  max-width: 70%;
  padding: 0.5rem 0.8rem;
  border-radius: 10px;
  background: #f1f5f9;
  position: relative;
}
.message-bubble.outgoing {
  align-self: flex-end;
  background: #dbeafe;
}
.message-bubble .msg-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.message-bubble .read-receipt {
  white-space: nowrap;
  color: var(--muted);
}
.message-bubble .read-receipt.seen {
  color: var(--primary);
  font-weight: 600;
}
.message-bubble .msg-delete-btn {
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0;
  text-decoration: underline;
}

.reply-bar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.reply-bar textarea {
  flex: 1;
  resize: vertical;
}
.reply-bar .row-buttons {
  align-items: center;
}
.reply-bar .row-buttons button:last-child {
  margin-left: auto;
}

.attach-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.5rem 0;
}
.attach-btn {
  display: inline-block;
  cursor: pointer;
}

.image-preview {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.5rem 0;
  padding: 0.5rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.image-preview img {
  max-height: 96px;
  max-width: 96px;
  border-radius: 6px;
  object-fit: cover;
}
.video-upload-progress-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}
.video-upload-progress-wrap progress {
  flex: 1;
  height: 8px;
}

.message-bubble a {
  color: var(--primary);
  text-decoration: underline;
  word-break: break-word;
}
.message-bubble .msg-thumbnail {
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  cursor: zoom-in;
  display: block;
}

.msg-video-thumbnail {
  position: relative;
  display: inline-block;
  cursor: pointer;
}
.msg-video-thumbnail .msg-thumbnail {
  cursor: pointer;
}
.msg-video-play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  pointer-events: none;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: zoom-out;
}
.lightbox-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
}
.lightbox-overlay.hidden { display: none; }
.lightbox-overlay video {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
}

/* Generic small modal — currently only the Useri tab's "Caută în CRM"
   result panel, but not named crm-* on purpose in case a second modal
   need ever comes up. */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay.hidden { display: none; }
.modal-card {
  background: white;
  border-radius: 10px;
  padding: 1.25rem;
  width: 420px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.modal-header h3 { margin: 0; }

.crm-contact-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.5rem;
}
.crm-contact-card:last-child { margin-bottom: 0; }
.crm-contact-name { font-weight: 600; }
