*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #d97706;
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --sidebar-w: 220px;
  --topbar-h: 60px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
}

body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* ---- SCREENS ---- */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }
#screen-login.active { display: flex; }
#screen-admin.active { display: block; }
#screen-client.active { display: block; }

/* ---- LOGIN ---- */
.login-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 50%, #3b82f6 100%);
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.login-logo img, .login-logo-img {
  width: 140px;
  height: auto;
  object-fit: contain;
}

.topbar-logo, .topbar-logo-img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 6px;
}

.login-card h1 {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 28px;
  font-size: 13px;
}

/* ---- TOPBAR ---- */
.topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  color: var(--primary);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-muted);
}

.topbar-user svg { width: 16px; height: 16px; }

/* ---- ADMIN LAYOUT ---- */
.admin-layout {
  display: flex;
  min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  width: 100%;
  text-align: left;
  transition: background .15s, color .15s;
  font-weight: 500;
}

.sidebar-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-item:hover { background: var(--primary-light); color: var(--primary); }
.sidebar-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.admin-content { flex: 1; padding: 28px; overflow-y: auto; }

/* ---- PANELS ---- */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}

.panel-header h2 { font-size: 20px; font-weight: 700; }
.panel-header .text-muted { font-size: 13px; margin-top: 2px; }

/* ---- SEARCH BAR ---- */
.search-bar {
  position: relative;
  margin-bottom: 16px;
}

.search-bar svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  stroke: var(--text-light);
  pointer-events: none;
}

.search-bar input {
  width: 100%;
  max-width: 360px;
  padding: 9px 14px 9px 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: #fff;
  transition: border .15s;
}

.search-bar input:focus { border-color: var(--primary); }

/* ---- CARD LIST ---- */
.card-list { display: flex; flex-direction: column; gap: 10px; }

.item-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  transition: box-shadow .15s;
}

.item-card:hover { box-shadow: var(--shadow-md); }

.item-card-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.item-card-icon svg { width: 20px; height: 20px; stroke: var(--primary); }
.item-card-icon.pdf-icon { background: #fef2f2; }
.item-card-icon.pdf-icon svg { stroke: var(--danger); }

.item-card-info { flex: 1; min-width: 0; }
.item-card-info h4 { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-card-info p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.item-card-meta { display: flex; align-items: center; gap: 10px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.badge-active { background: var(--success-light); color: var(--success); }
.badge-inactive { background: #f1f5f9; color: var(--text-muted); }

.item-card-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ---- CLIENT PORTAL ---- */
.client-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px;
}

.client-welcome { margin-bottom: 20px; }
.client-welcome h2 { font-size: 22px; font-weight: 700; }
.client-welcome .text-muted { font-size: 13px; margin-top: 4px; }

.laudos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.laudo-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
  transition: box-shadow .15s, transform .15s;
  cursor: pointer;
}

.laudo-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.laudo-card-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: #fef2f2;
  display: flex;
  align-items: center;
  justify-content: center;
}

.laudo-card-icon svg { width: 24px; height: 24px; stroke: var(--danger); }

.laudo-card h4 { font-size: 14px; font-weight: 600; line-height: 1.4; }
.laudo-card p { font-size: 12px; color: var(--text-muted); flex: 1; }

.laudo-card-footer {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

/* ---- EMPTY STATE ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
  gap: 12px;
}

.empty-state svg { width: 48px; height: 48px; stroke: var(--text-light); }
.empty-state p { font-size: 14px; }

/* ---- SETTINGS ---- */
.settings-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  max-width: 640px;
}

.settings-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; }

.settings-card.danger-zone { border-color: #fca5a5; }
.settings-card.danger-zone h3 { color: var(--danger); }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

/* ---- FORMS ---- */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text); }

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: #fff;
  color: var(--text);
  transition: border .15s;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }

.form-group textarea { resize: vertical; min-height: 60px; }

.input-icon-wrap { position: relative; display: flex; align-items: center; }
.input-icon-wrap input { flex: 1; }
.input-icon-wrap .btn { margin-left: 8px; flex-shrink: 0; }

.toggle-pass {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-muted);
  display: flex;
}

.toggle-pass svg { width: 18px; height: 18px; }

/* ---- FILE DROP ---- */
.file-drop {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.file-drop:hover, .file-drop.drag-over { border-color: var(--primary); background: var(--primary-light); }

.file-drop svg { width: 32px; height: 32px; stroke: var(--text-light); }
.file-drop p { font-size: 13px; color: var(--text-muted); }
.file-drop .file-name { font-size: 12px; color: var(--primary); font-weight: 500; }

.file-drop input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
  text-decoration: none;
  font-family: inherit;
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: #f1f5f9; color: var(--text); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 7px;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}

.btn-icon svg { width: 15px; height: 15px; }
.btn-icon:hover { background: #f1f5f9; color: var(--text); }
.btn-icon.danger:hover { background: var(--danger-light); color: var(--danger); border-color: #fca5a5; }

.btn-copy {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  display: flex;
  border-radius: 4px;
  transition: color .15s;
}
.btn-copy:hover { color: var(--primary); }
.btn-copy svg { width: 15px; height: 15px; }

/* ---- MODALS ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn .15s ease;
}

.modal-overlay.hidden { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

.modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  animation: slideUp .2s ease;
}

.modal-sm { max-width: 400px; }

.modal-pdf {
  max-width: 900px;
  display: flex;
  flex-direction: column;
  height: 90vh;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
  margin-bottom: 16px;
}

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-header-actions { display: flex; align-items: center; gap: 8px; }

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: background .15s;
}
.modal-close:hover { background: #f1f5f9; }

.modal form { padding: 0 24px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 20px 24px 24px;
}

/* PDF viewer */
.pdf-viewer-container {
  flex: 1;
  padding: 0 24px 24px;
  overflow: hidden;
}

.pdf-viewer-container iframe {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* Credentials */
.credentials-box { padding: 4px 24px 8px; }
.credentials-box .text-muted { font-size: 13px; margin-bottom: 16px; }

.credential-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 10px;
}

.credential-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  font-weight: 600;
  width: 54px;
  flex-shrink: 0;
}

.credential-value {
  flex: 1;
  font-family: 'Courier New', monospace;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* Confirm */
.confirm-message { padding: 8px 24px 20px; font-size: 14px; color: var(--text-muted); }

/* ---- MISC ---- */
.error-msg {
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-light);
  border: 1px solid #fca5a5;
  border-radius: 7px;
  padding: 8px 12px;
  margin-bottom: 12px;
}

.text-muted { color: var(--text-muted); }
.hidden { display: none !important; }

/* ---- TOAST ---- */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #1e293b;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
  animation: slideUp .2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 320px;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.fade-out { opacity: 0; transition: opacity .3s; }

/* ---- LOADING SPINNER ---- */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .admin-content { padding: 16px; }
  .client-content { padding: 16px; }
  .laudos-grid { grid-template-columns: 1fr; }
  .modal-pdf { height: 95vh; }
  .panel-header { flex-direction: column; align-items: flex-start; }
  .topbar { padding: 0 16px; }
  .topbar-brand span { display: none; }
}

/* ---- AVATAR ---- */
.avatar-upload-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
}

.avatar-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--primary-light);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.avatar-preview svg { width: 28px; height: 28px; color: var(--text-light); stroke: var(--text-light); }

.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-upload-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hidden-input { display: none; }

.avatar-upload-btn {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.avatar-upload-btn svg { width: 14px; height: 14px; }

/* avatar no card de cliente (admin) */
.client-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary-light);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.client-avatar svg { width: 20px; height: 20px; stroke: var(--text-light); }

.client-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* avatar na topbar do cliente */
.topbar-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary-light);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.topbar-avatar svg { width: 16px; height: 16px; stroke: var(--text-light); }

.topbar-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---- FORM HINT ---- */
.form-hint {
  display: block;
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
}

/* ---- LISTA DE CHECKBOXES (visitante) ---- */
.clients-check-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fafafa;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 0;
}

.check-item input[type=checkbox] {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

/* ---- LINK EXTERNO NA TOPBAR ---- */
.topbar-ext-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  text-decoration: none;
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 7px;
  padding: 5px 10px;
  transition: background .15s, color .15s;
}

.topbar-ext-link:hover {
  background: var(--primary);
  color: #fff;
}

.topbar-ext-link svg { width: 14px; height: 14px; }
