/* ========== Abiocon Registro de Procedimentos ========== */
:root {
  --abiocon-red: #c8102e;
  --abiocon-red-dark: #9b0c22;
  --primary: #6b5ce7;
  --primary-dark: #5545c2;
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --shadow: 0 4px 16px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, #6b5ce7 0%, #8b7fe8 100%);
  color: var(--text);
  min-height: 100vh;
  padding: 12px;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  max-width: 900px;
  margin: 0 auto;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ---------- Top Bar (Abiocon brand) ---------- */
.brand-bar {
  background: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid var(--abiocon-red);
}
.brand-bar .logo { display: flex; align-items: center; gap: 10px; }
.brand-bar .logo-drop {
  width: 28px; height: 34px;
  background: var(--abiocon-red);
  clip-path: path('M14 0 C14 0, 0 14, 0 22 a14 12 0 0 0 28 0 C28 14, 14 0, 14 0 Z');
}
.brand-bar .brand-text { font-weight: 700; font-size: 20px; color: #333; letter-spacing: -.5px; }
.brand-bar .brand-subtitle { font-size: 11px; color: var(--muted); margin-top: -2px; }
.brand-bar .install-btn {
  background: var(--abiocon-red); color: #fff; border: none;
  padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer;
  display: none;
  box-shadow: 0 2px 6px rgba(200,16,46,.25);
  transition: all .2s;
}
.brand-bar .install-btn:hover { background: var(--abiocon-red-dark); transform: translateY(-1px); }
.brand-bar .install-btn.visible,
.brand-bar .install-btn.always-visible { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Banner de Instalação ---------- */
.install-banner {
  display: none;
  background: linear-gradient(135deg, #c8102e 0%, #e63e5c 100%);
  color: #fff;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(0,0,0,.1);
  animation: slideDown .35s ease;
}
.install-banner.show { display: block; }
.install-banner-content {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 900px;
  margin: 0 auto;
  flex-wrap: wrap;
}
.install-banner-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: rgba(255,255,255,.22);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.install-banner-text {
  flex: 1; min-width: 180px;
  display: flex; flex-direction: column; gap: 2px;
}
.install-banner-text strong { font-size: 15px; font-weight: 700; }
.install-banner-text span { font-size: 12px; opacity: .92; }
.install-banner-actions {
  display: flex; gap: 8px; align-items: center; flex-shrink: 0;
}
.install-banner-actions .btn-primary {
  background: #fff; color: var(--abiocon-red); font-weight: 700;
  border: none; padding: 10px 16px; border-radius: 8px;
}
.install-banner-actions .btn-primary:hover { background: #ffe7ec; }
.install-banner-actions .btn-outline {
  background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.5);
}
.install-banner-actions .btn-outline:hover { background: rgba(255,255,255,.15); }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Modal "Como Instalar" ---------- */
.install-step {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
}
.install-step-num {
  background: var(--abiocon-red); color: #fff;
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; flex-shrink: 0; font-size: 12px;
}
.install-step-text { flex: 1; line-height: 1.5; }
.install-step-text i { color: var(--abiocon-red); margin: 0 2px; }
.install-platform-title {
  font-weight: 700; color: #111; margin: 10px 0 8px;
  display: flex; align-items: center; gap: 8px;
  font-size: 14px;
}
.install-platform-title i { color: var(--abiocon-red); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  overflow-x: auto;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
}
.tab {
  flex: 1 0 auto;
  min-width: 110px;
  padding: 14px 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  transition: all .2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.tab:hover { background: #f3f4f6; color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); background: #fff; }
.tab i { font-size: 16px; }

/* ---------- Panels ---------- */
.panel { display: none; padding: 20px; }
.panel.active { display: block; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.panel-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
  display: flex; align-items: center; gap: 8px;
}
.panel-subtitle { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

/* ---------- Forms ---------- */
.section-title {
  font-size: 16px;
  font-weight: 600;
  margin: 20px 0 12px;
  display: flex; align-items: center; gap: 8px;
  color: var(--text);
}
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}
.field label .req { color: var(--danger); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(107,92,231,.15);
}
.field textarea { min-height: 70px; resize: vertical; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Buttons ---------- */
.btn {
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .15s;
  font-family: inherit;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.05); }
.btn-info { background: var(--info); color: #fff; }
.btn-info:hover { filter: brightness(1.05); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: #6b7280; color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #f9fafb; }
.btn-red { background: var(--abiocon-red); color: #fff; }
.btn-red:hover { background: var(--abiocon-red-dark); }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.btn-row .btn { flex: 1 1 auto; justify-content: center; }

/* ---------- Materials table ---------- */
.materials-table {
  display: grid;
  gap: 8px;
}
.material-row {
  display: grid;
  grid-template-columns: 70px 1fr 130px 50px 50px;
  gap: 6px;
  align-items: center;
}
.material-row input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.material-row .btn-icon {
  padding: 8px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  height: 36px;
  display: flex; align-items: center; justify-content: center;
}
.btn-icon.btn-list { background: #6b7280; color: #fff; }
.btn-icon.btn-remove { background: var(--danger); color: #fff; }
@media (max-width: 640px) {
  .material-row { grid-template-columns: 55px 1fr 95px 40px 40px; }
  .material-row input { padding: 8px 6px; font-size: 12px; }
}

.total-banner {
  background: linear-gradient(135deg, #4f8bff, #6b5ce7);
  color: #fff;
  padding: 16px;
  border-radius: 10px;
  text-align: center;
  margin: 12px 0;
}
.total-banner .n { font-size: 28px; font-weight: 700; }
.total-banner .l { font-size: 13px; opacity: .9; }

/* ---------- Report output (LEGADO - ainda usado) ---------- */
.report-output {
  width: 100%;
  min-height: 380px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  background: #fafafa;
  white-space: pre-wrap;
  line-height: 1.5;
}

/* ---------- Novo layout de Relatório ---------- */
.titulo-email-box {
  background: #eaf3ff;
  border: 1px solid #b5d4ff;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.titulo-email-header {
  color: #1e40af;
  font-size: 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.titulo-email-header i { color: #3b82f6; }
.titulo-email-text {
  font-size: 13px;
  color: #333;
  line-height: 1.55;
  text-align: justify;
  margin-bottom: 10px;
  word-break: break-word;
}
.btn-copiar-titulo { padding: 7px 14px; font-size: 13px; }

.report-view {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.65;
  color: #1f2937;
  text-align: justify;
  min-height: 260px;
}
.report-view .report-placeholder {
  color: var(--muted);
  font-style: italic;
  text-align: center;
  padding: 40px 20px;
}

.rel-corpo p { margin: 0 0 12px; text-align: justify; }

.rel-linha { margin: 4px 0 !important; }
.rel-label {
  color: #1e40af;
  font-weight: 600;
}
.rel-label-bloco {
  color: #1e40af;
  font-weight: 600;
  margin-top: 16px !important;
  margin-bottom: 6px !important;
}
.rel-destaque {
  color: #dc2626;
  font-weight: 600;
  margin-top: 0 !important;
}
.rel-total {
  font-size: 14px;
  margin: 14px 0 !important;
}
.rel-total strong { color: #2563eb; }
.rel-lista {
  margin: 0 0 10px 0;
  padding-left: 22px;
}
.rel-lista li {
  margin-bottom: 4px;
  text-align: justify;
}

.anexos-indicator {
  margin-top: 14px;
  padding: 10px 14px;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: 8px;
  color: #92400e;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.anexos-indicator i { font-size: 15px; }

/* ---------- Comunicados de Uso (aba própria) ---------- */
.comunicado-item {
  border-left: 4px solid var(--abiocon-red) !important;
}
.comunicado-numero-badge {
  display: inline-block;
  background: var(--abiocon-red);
  color: #fff;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  margin-right: 6px;
  vertical-align: middle;
  font-family: 'Courier New', monospace;
}

/* ---------- Convênio select + botão adicionar ---------- */
.convenio-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.btn-mini {
  padding: 10px 12px;
  font-size: 14px;
  flex-shrink: 0;
  border-radius: 8px;
}
.convenio-warning {
  margin-top: 6px;
  padding: 8px 12px;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: 6px;
  color: #92400e;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* GEAP button */
.btn-geap {
  background: #2d7d46;
  color: #fff;
}
.btn-geap:hover { background: #256937; }

/* Especialista info */
.especialista-info {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.especialista-info.info-uenderson {
  background: #dcfce7;
  border: 1px solid #86efac;
  color: #166534;
}
.especialista-info.info-uenderson i {
  color: #16a34a;
}
.especialista-info.info-outro {
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
}
.especialista-info.info-outro i {
  color: #d97706;
}

/* ---------- Ficha GEAP layout ---------- */
.geap-doc {
  font-family: Arial, Helvetica, sans-serif;
  color: #000;
  background: #fff;
  width: 1123px;
  min-height: 794px;
  margin: 0 auto;
  padding: 10px 14px;
  font-size: 8pt;
  box-sizing: border-box;
  position: relative;
}
.geap-doc * { box-sizing: border-box; }
.geap-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid #000;
}
.geap-logo-box { display: flex; align-items: center; gap: 10px; }
.geap-logo-svg { width: 46px; height: 46px; }
.geap-logo-text {
  font-family: Arial, sans-serif;
  font-size: 20pt;
  font-weight: bold;
  color: #0e5c36;
  line-height: 1;
}
.geap-logo-text small { font-size: 14pt; font-weight: normal; color: #0e5c36; }

.geap-title {
  flex: 1;
  text-align: center;
  font-size: 9pt;
  font-weight: bold;
  line-height: 1.3;
  padding: 0 20px;
  text-transform: uppercase;
}
.geap-via { font-size: 7pt; margin-top: 2px; font-weight: normal; }

.geap-reg-num {
  font-size: 14pt;
  font-weight: bold;
  border: 1.5px solid #000;
  padding: 4px 12px;
  background: #fff;
}

.geap-grid { display: grid; gap: 2px; margin-bottom: 2px; }
.geap-row { display: grid; gap: 2px; }
.geap-cell {
  border: 1px solid #000;
  padding: 3px 6px;
  min-height: 28px;
  position: relative;
  background: #fff;
}
.geap-cell .geap-label {
  font-size: 6.5pt;
  color: #000;
  display: block;
  line-height: 1.1;
  margin-bottom: 1px;
}
.geap-cell .geap-label-num {
  font-weight: bold;
  margin-right: 3px;
}
.geap-cell .geap-value {
  font-size: 10pt;
  font-weight: 500;
  color: #1a1a5e;
  line-height: 1.2;
  word-break: break-word;
}
.geap-cell.big .geap-value { font-size: 11pt; }
.geap-section-title {
  background: #e5e7eb;
  padding: 3px 8px;
  font-size: 7.5pt;
  font-weight: bold;
  border: 1px solid #000;
  border-bottom: none;
  text-transform: uppercase;
}

.geap-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 4px;
}
.geap-table th, .geap-table td {
  border: 1px solid #000;
  padding: 3px 4px;
  font-size: 8pt;
  text-align: center;
  vertical-align: middle;
  height: 24px;
}
.geap-table th {
  background: #e5e7eb;
  font-weight: bold;
  font-size: 6.5pt;
  line-height: 1.1;
}
.geap-table td .geap-label-num {
  font-size: 6pt;
  font-weight: bold;
  display: block;
  text-align: left;
  color: #444;
}
.geap-table td .val {
  font-size: 9pt;
  color: #1a1a5e;
  font-weight: 500;
}

.geap-assinatura-box {
  border: 1px solid #000;
  padding: 4px 8px;
  min-height: 70px;
  position: relative;
}
.geap-assinatura-box .assinatura-img { max-height: 55px; margin-top: 4px; }

/* ---------- History ---------- */
.history-item {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  background: #fff;
  transition: all .15s;
}
.history-item:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.history-item .head {
  display: flex; justify-content: space-between; align-items: start;
  gap: 8px; flex-wrap: wrap;
}
.history-item h4 { margin: 0; font-size: 15px; }
.history-item .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.history-item .actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.history-item .actions .btn { padding: 6px 10px; font-size: 12px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge-particular { background: #fef3c7; color: #92400e; }
.badge-convenio { background: #dbeafe; color: #1e40af; }
.badge-sus { background: #d1fae5; color: #065f46; }
.badge-rascunho { background: #e5e7eb; color: #374151; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state i { font-size: 40px; margin-bottom: 12px; opacity: .4; }

/* ---------- Photos ---------- */
.photo-upload {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  background: #fafafa;
}
.photo-upload:hover { border-color: var(--primary); background: #f5f3ff; }
.photo-upload i { font-size: 36px; color: var(--muted); margin-bottom: 8px; }
.photo-upload p { margin: 0; color: var(--muted); font-size: 13px; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.photo-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.photo-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-item .photo-remove {
  position: absolute; top: 4px; right: 4px;
  background: rgba(239,68,68,.9); color: #fff;
  border: none; width: 24px; height: 24px; border-radius: 50%;
  cursor: pointer; font-size: 12px;
}

/* ---------- Médicos Cards ---------- */
.medicos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.medico-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  background: #fff;
}
.medico-card h4 { margin: 0 0 4px; font-size: 15px; }
.medico-card .crm { font-size: 12px; color: var(--muted); }
.medico-card .especialidade { font-size: 13px; color: var(--primary); margin: 4px 0 10px; }
.medico-card .assinatura-preview {
  background: #f9fafb;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 8px;
  min-height: 70px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
}
.medico-card .assinatura-preview img { max-width: 100%; max-height: 60px; }
.medico-card .assinatura-preview .no-img { color: var(--muted); font-size: 12px; }
.medico-card .actions { display: flex; gap: 6px; }
.medico-card .actions .btn { flex: 1; padding: 6px 8px; font-size: 12px; justify-content: center; }

/* ---------- Comunicado PDF layout ---------- */
.comunicado-preview {
  background: #fff;
  border: 1px solid #333;
  padding: 14px;
  margin: 14px 0;
  font-family: Arial, sans-serif;
  color: #000;
  max-width: 780px;
  margin-left: auto; margin-right: auto;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-backdrop.active { display: flex; animation: fadeIn .2s; }
.modal {
  background: #fff;
  border-radius: 12px;
  padding: 22px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 { margin: 0 0 14px; font-size: 18px; }
.modal .modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 2000;
  font-size: 14px;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }

/* ---------- Switch / Select helpers ---------- */
.faturamento-badge {
  padding: 3px 8px; border-radius: 4px; font-size: 12px; font-weight: 600;
}

/* ---------- Mobile ---------- */
@media (max-width: 500px) {
  body { padding: 4px; }
  .app-container { border-radius: 8px; }
  .panel { padding: 14px; }
  .tab { min-width: 90px; font-size: 11px; padding: 10px 6px; }
  .panel-title { font-size: 17px; }
  .brand-bar .brand-text { font-size: 16px; }
}

/* Print */
@media print {
  body { background: #fff; padding: 0; }
  .app-container { box-shadow: none; }
  .tabs, .brand-bar, .btn-row, .tab, .install-btn { display: none !important; }
  .panel { display: block !important; padding: 0; }
}
