/* ============================================================
   Instituto Unittà — Sistema de Receituário
   styles.css
   ============================================================ */

:root {
  --teal: #7FC2B1; --teal-light: #A8D4CB; --teal-dark: #3A5865;
  --gray-dark: #2C2C2C; --gray-mid: #777; --gray-light: #DADADA;
  --gray-bg: #F5F5F5; --white: #fff;
  --danger: #C0392B; --danger-light: #FDECEA;
  --bg: #F0EFED;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Jost', sans-serif; background: var(--bg); color: var(--gray-dark); min-height: 100vh; }

/* ── LOGIN ── */
#loginScreen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #3A5865 0%, #1e2f36 100%);
  position: relative; overflow: hidden;
}
#loginScreen::before { content:''; position:absolute; width:500px; height:500px; border-radius:50%; border:1px solid rgba(255,255,255,0.08); top:-100px; right:-100px; }
#loginScreen::after  { content:''; position:absolute; width:350px; height:350px; border-radius:50%; border:1px solid rgba(255,255,255,0.06); bottom:-80px; left:-80px; }
.login-card { background:white; border-radius:18px; padding:48px 44px; width:100%; max-width:400px; box-shadow:0 32px 80px rgba(0,0,0,0.25); position:relative; z-index:1; animation:fadeUp .4s ease; }
@keyframes fadeUp { from{opacity:0;transform:translateY(20px)} to{opacity:1;transform:translateY(0)} }
.login-logo { text-align:center; margin-bottom:32px; }
.login-logo-circles { display:flex; justify-content:center; margin-bottom:12px; }
.login-instituto { font-size:10px; letter-spacing:2px; text-transform:lowercase; color:var(--gray-mid); font-weight:300; }
.login-unitta { font-size:28px; font-weight:500; color:var(--gray-dark); letter-spacing:-0.5px; }
.login-subtitle { font-size:11px; color:var(--gray-mid); margin-top:4px; letter-spacing:0.5px; }
.login-field { margin-bottom:16px; }
.login-field label { display:block; font-size:10px; text-transform:uppercase; letter-spacing:1.2px; color:var(--gray-mid); margin-bottom:6px; font-weight:500; }
.login-field input { width:100%; border:1.5px solid var(--gray-light); border-radius:8px; padding:12px 14px; font-family:'Jost',sans-serif; font-size:14px; outline:none; transition:border-color .2s; background:var(--gray-bg); }
.login-field input:focus { border-color:var(--teal); background:white; }
.login-btn { width:100%; padding:14px; background:var(--teal); color:white; border:none; border-radius:8px; font-family:'Jost',sans-serif; font-size:14px; font-weight:500; cursor:pointer; margin-top:8px; letter-spacing:0.5px; transition:all .2s; box-shadow:0 4px 14px rgba(58,88,101,0.4); }
.login-btn:hover { background:var(--teal-dark); transform:translateY(-1px); }
.login-error { background:var(--danger-light); color:var(--danger); border-radius:6px; padding:10px 12px; font-size:12px; margin-top:12px; display:none; text-align:center; }

/* ── APP ── */
#appShell { display:none; }

/* ── NAV ── */
.nav-bar { display:flex; align-items:center; background:white; border-bottom:1px solid var(--gray-light); position:sticky; top:0; z-index:100; box-shadow:0 2px 8px rgba(0,0,0,0.05); padding:0 8px; }
.nav-brand { padding:12px 16px; display:flex; align-items:center; gap:8px; border-right:1px solid var(--gray-light); margin-right:4px; }
.nav-brand-name { font-size:13px; font-weight:500; color:var(--gray-dark); letter-spacing:-0.3px; }
.nav-brand-sub { font-size:9px; color:var(--gray-mid); letter-spacing:1px; text-transform:lowercase; }
.nav-tabs { display:flex; flex:1; }
.nav-tab { padding:16px 22px; font-size:12px; font-weight:500; letter-spacing:0.6px; text-transform:uppercase; cursor:pointer; border:none; background:transparent; color:var(--gray-mid); border-bottom:2px solid transparent; margin-bottom:-1px; transition:all .2s; white-space:nowrap; }
.nav-tab:hover { color:var(--teal-dark); }
.nav-tab.active { color:var(--teal-dark); border-bottom-color:var(--teal-dark); font-weight:600; }
.nav-tab .badge { background:var(--teal); color:white; font-size:9px; padding:1px 6px; border-radius:10px; margin-left:5px; font-weight:600; }
.nav-right { margin-left:auto; padding-right:8px; }
.logout-btn { font-size:11px; color:var(--gray-mid); background:none; border:1px solid var(--gray-light); border-radius:6px; padding:6px 12px; cursor:pointer; font-family:'Jost',sans-serif; transition:all .15s; }
.logout-btn:hover { color:var(--danger); border-color:var(--danger); background:var(--danger-light); }

/* ── VIEWS ── */
.view { display:none; }
.view.active { display:block; }
.page-wrapper { max-width:900px; margin:0 auto; padding:32px 20px 60px; }
.page-header { margin-bottom:28px; padding-bottom:18px; border-bottom:1px solid var(--gray-light); display:flex; align-items:center; justify-content:space-between; }
.page-header h1 { font-family:'Cormorant Garamond',serif; font-size:22px; font-weight:400; letter-spacing:0.5px; }
.page-header span { font-size:12px; color:var(--gray-mid); font-weight:300; }

/* ── CARDS ── */
.card { background:white; border-radius:14px; padding:28px 32px; margin-bottom:22px; box-shadow:0 2px 14px rgba(0,0,0,0.07); }
.card-title { font-family:'Cormorant Garamond',serif; font-size:17px; font-weight:600; color:var(--teal-dark); text-transform:uppercase; letter-spacing:1.5px; font-style:normal; margin-bottom:18px; }

/* ── FIELDS ── */
.fields-grid { display:grid; grid-template-columns:1fr 1fr 1fr; gap:16px; }
.field-group { display:flex; flex-direction:column; gap:5px; }
.field-group label { font-size:10px; text-transform:uppercase; letter-spacing:1.2px; color:var(--gray-mid); font-weight:500; }
.field-group input,.field-group textarea,.field-group select { border:1px solid var(--gray-light); border-radius:8px; padding:11px 14px; font-family:'Jost',sans-serif; font-size:15px; color:var(--gray-dark); outline:none; transition:border-color .2s; background:var(--gray-bg); }
.field-group input:focus,.field-group textarea:focus,.field-group select:focus { border-color:var(--teal); background:white; }
.field-group textarea { resize:vertical; min-height:72px; line-height:1.5; }

/* ── SEARCH ── */
.search-wrap { margin-bottom:14px; position:relative; }
.search-input { width:100%; border:1.5px solid var(--gray-light); border-radius:8px; padding:10px 14px 10px 36px; font-family:'Jost',sans-serif; font-size:14px; outline:none; background:var(--gray-bg); transition:border-color .2s; }
.search-input:focus { border-color:var(--teal); background:white; }
.search-icon { position:absolute; left:11px; top:50%; transform:translateY(-50%); color:#aaa; font-size:14px; pointer-events:none; }
.no-result { text-align:center; padding:20px; font-size:13px; color:var(--gray-mid); font-style:italic; display:none; }

/* ── SECTION ── */
.section-card { background:white; border-radius:14px; padding:26px 32px; margin-bottom:20px; box-shadow:0 2px 14px rgba(0,0,0,0.07); }
.section-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:18px; cursor:pointer; user-select:none; }
.section-header h2 { font-family:'Cormorant Garamond',serif; font-size:19px; font-weight:600; color:var(--teal-dark); text-transform:uppercase; letter-spacing:1.5px; font-style:normal; }
.toggle-icon { width:22px; height:22px; border-radius:50%; background:var(--gray-bg); display:flex; align-items:center; justify-content:center; font-size:14px; color:var(--gray-mid); }
.section-body.collapsed { display:none; }
.cat-label { font-size:10px; text-transform:uppercase; letter-spacing:1.2px; color:#aaa; margin:12px 0 6px; font-weight:500; }
.med-divider { height:1px; background:var(--gray-bg); margin:10px 0; }

/* ── MED ITEM ── */
.med-item { display:flex; align-items:flex-start; gap:14px; padding:14px 16px; border-radius:10px; cursor:pointer; transition:all .15s; border:1.5px solid transparent; margin-bottom:6px; }
.med-item:hover { background:#F8FBFA; }
.med-item.selected { background:#EEF7F5; border-color:var(--teal-light); }
.med-item.hidden { display:none !important; }
.custom-check { width:22px; height:22px; min-width:22px; border-radius:5px; border:2px solid var(--gray-light); margin-top:2px; transition:all .15s; display:flex; align-items:center; justify-content:center; font-size:13px; color:white; flex-shrink:0; }
.med-item.selected .custom-check { background:var(--teal); border-color:var(--teal); }
.med-item.selected .custom-check::after { content:'✓'; }
.med-info { flex:1; min-width:0; }
.med-name { font-size:15px; font-weight:500; line-height:1.4; }
.med-detail { font-size:13px; color:var(--gray-mid); margin-top:3px; line-height:1.4; font-weight:300; }

/* ── PROTOCOL CARD ── */
.proto-item { border:1.5px solid transparent; }
.proto-item.selected { background:#EEF7F5; border-color:var(--teal-light); }
.proto-badge { font-size:10px; background:#EEF7F5; color:var(--teal-dark); border:1px solid var(--teal-light); border-radius:20px; padding:2px 8px; font-weight:500; letter-spacing:0.5px; white-space:nowrap; display:inline-block; margin-top:4px; }
.proto-item.selected .proto-badge { background:var(--teal); color:white; border-color:var(--teal); }
.proto-count-tag { font-size:11px; color:var(--teal-dark); font-weight:500; margin-top:4px; display:none; }
.proto-item.selected .proto-count-tag { display:block; }

/* ── ACTION BAR ── */
.action-bar { display:flex; gap:12px; justify-content:flex-end; margin-top:28px; flex-wrap:wrap; }
.btn { padding:12px 28px; border-radius:8px; font-family:'Jost',sans-serif; font-size:14px; font-weight:500; cursor:pointer; border:none; letter-spacing:0.5px; transition:all .2s; }
.btn-secondary { background:white; color:var(--gray-mid); border:1px solid var(--gray-light); }
.btn-secondary:hover { background:var(--gray-bg); }
.btn-primary { background:var(--teal); color:white; box-shadow:0 4px 14px rgba(58,88,101,0.4); }
.btn-primary:hover { background:var(--teal-dark); transform:translateY(-1px); }
.btn-danger { background:var(--danger-light); color:var(--danger); border:1px solid #f5c6c2; }
.btn-danger:hover { background:#f8d7d4; }
.btn-sm { padding:7px 16px; font-size:11px; }
.selected-count { font-size:14px; color:var(--teal-dark); align-self:center; font-weight:500; }

/* ── HISTÓRICO ── */
.history-list { display:flex; flex-direction:column; gap:10px; }
.history-empty { text-align:center; padding:48px 20px; color:var(--gray-mid); font-size:13px; font-style:italic; }
.history-item { background:white; border-radius:10px; border:1px solid var(--gray-light); overflow:hidden; transition:border-color .15s; }
.history-item:hover { border-color:var(--teal-light); }
.history-head { display:flex; align-items:center; justify-content:space-between; padding:14px 18px; cursor:pointer; user-select:none; }
.history-patient { font-size:16px; font-weight:500; }
.history-meta { font-size:13px; color:var(--gray-mid); margin-top:2px; }
.history-acts { display:flex; gap:8px; align-items:center; }
.history-tog { font-size:12px; color:var(--gray-mid); margin-left:6px; }
.history-detail { display:none; padding:12px 18px 16px; border-top:1px solid var(--gray-bg); }
.history-detail.open { display:block; }
.history-group-title { font-size:9px; text-transform:uppercase; letter-spacing:1.5px; color:var(--teal-dark); font-weight:600; margin:10px 0 5px; }
.history-group-title:first-child { margin-top:0; }
.history-med-line { font-size:12px; color:var(--gray-dark); padding:3px 0; border-bottom:1px dotted var(--gray-light); display:flex; gap:8px; }
.history-med-line:last-child { border-bottom:none; }
.history-med-via { font-size:10px; color:var(--gray-mid); margin-left:auto; white-space:nowrap; }
.icon-btn { width:30px; height:30px; border-radius:6px; border:1px solid var(--gray-light); background:white; cursor:pointer; display:flex; align-items:center; justify-content:center; font-size:13px; transition:all .15s; }
.icon-btn:hover { border-color:var(--teal); background:#EEF7F5; }
.icon-btn.danger:hover { border-color:var(--danger); background:var(--danger-light); }

/* ── ADMIN ── */
.admin-section { background:white; border-radius:12px; margin-bottom:20px; box-shadow:0 2px 12px rgba(0,0,0,0.06); overflow:hidden; }
.adm-sec-hdr { display:flex; align-items:center; justify-content:space-between; padding:20px 28px; border-bottom:1px solid var(--gray-bg); cursor:pointer; user-select:none; transition:background .15s; }
.adm-sec-hdr:hover { background:#FAFAFA; }
.adm-sec-title { font-family:'Cormorant Garamond',serif; font-size:19px; font-weight:600; color:var(--teal-dark); text-transform:uppercase; letter-spacing:1.5px; font-style:normal; }
.count-pill { background:var(--gray-bg); color:var(--gray-mid); font-size:11px; font-weight:500; padding:3px 10px; border-radius:20px; }
.adm-sec-body { padding:20px 28px; }
.adm-sec-body.collapsed { display:none; }
.adm-item-list { margin-bottom:20px; }
.adm-item-row { display:flex; align-items:flex-start; gap:12px; padding:12px 14px; border-radius:8px; border:1px solid var(--gray-light); margin-bottom:8px; background:var(--gray-bg); transition:all .15s; }
.adm-item-row:hover { border-color:var(--teal-light); background:#F8FBFA; }
.adm-item-info { flex:1; min-width:0; }
.adm-item-name { font-size:15px; font-weight:500; line-height:1.4; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.adm-item-sub { font-size:13px; color:var(--gray-mid); margin-top:2px; font-weight:300; }
.adm-item-acts { display:flex; gap:6px; flex-shrink:0; }
.add-form { border:1.5px dashed var(--teal-light); border-radius:10px; padding:20px; background:#F8FBFA; }
.add-form h3 { font-family:'Cormorant Garamond',serif; font-size:14px; font-weight:600; color:var(--teal-dark); font-style:italic; margin-bottom:16px; }
.form-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-bottom:12px; }
.form-grid.full { grid-template-columns:1fr; }
.form-grid.three { grid-template-columns:1fr 1fr 1fr; }
.form-field { display:flex; flex-direction:column; gap:4px; position:relative; }
.form-field label { font-size:10px; text-transform:uppercase; letter-spacing:1px; color:var(--gray-mid); font-weight:500; }
.form-field input,.form-field select,.form-field textarea { border:1px solid var(--gray-light); border-radius:6px; padding:8px 12px; font-family:'Jost',sans-serif; font-size:13px; color:var(--gray-dark); outline:none; background:white; transition:border-color .2s; }
.form-field input:focus,.form-field select:focus,.form-field textarea:focus { border-color:var(--teal); }
.form-field input,.form-field select { font-size:14px; padding:10px 14px; }
.form-field textarea { resize:vertical; min-height:72px; line-height:1.5; }
.form-actions { display:flex; gap:8px; justify-content:flex-end; margin-top:4px; }

/* ── AUTOCOMPLETE ── */
.ac-dropdown { position:absolute; top:100%; left:0; right:0; background:white; border:1px solid var(--gray-light); border-top:none; border-radius:0 0 8px 8px; box-shadow:0 8px 20px rgba(0,0,0,0.1); z-index:200; max-height:180px; overflow-y:auto; display:none; }
.ac-dropdown.open { display:block; }
.ac-item { padding:11px 14px; font-size:14px; cursor:pointer; color:var(--gray-dark); transition:background .1s; border-bottom:1px solid var(--gray-bg); }
.ac-item:last-child { border-bottom:none; }
.ac-item:hover,.ac-item.highlighted { background:#EEF7F5; color:var(--teal-dark); }
.ac-match { font-weight:600; color:var(--teal-dark); }

/* ── PROTO MED ROWS ── */
.proto-meds-editor { margin-top:8px; }
.proto-med-row { display:flex; gap:8px; margin-bottom:6px; align-items:center; }
.proto-med-row input { flex:1; border:1px solid var(--gray-light); border-radius:6px; padding:7px 10px; font-family:'Jost',sans-serif; font-size:12px; outline:none; background:white; }
.proto-med-row input:focus { border-color:var(--teal); }
.proto-med-remove { width:26px; height:26px; border-radius:5px; border:1px solid var(--gray-light); background:white; cursor:pointer; font-size:14px; color:var(--gray-mid); display:flex; align-items:center; justify-content:center; transition:all .15s; flex-shrink:0; }
.proto-med-remove:hover { border-color:var(--danger); color:var(--danger); background:var(--danger-light); }
.add-med-line { font-size:12px; color:var(--teal-dark); cursor:pointer; padding:4px 0; font-weight:500; display:flex; align-items:center; gap:4px; border:none; background:none; font-family:'Jost',sans-serif; transition:opacity .15s; }
.add-med-line:hover { opacity:.7; }

/* ── MODAL ── */
.modal-overlay { display:none; position:fixed; inset:0; background:rgba(0,0,0,0.45); z-index:1000; align-items:center; justify-content:center; padding:20px; }
.modal-overlay.open { display:flex; }
.modal-box { background:white; border-radius:14px; padding:28px; max-width:600px; width:100%; max-height:85vh; overflow-y:auto; box-shadow:0 20px 60px rgba(0,0,0,0.2); animation:modalIn .2s ease; }
@keyframes modalIn { from{opacity:0;transform:translateY(12px) scale(.98)} to{opacity:1;transform:translateY(0) scale(1)} }
.modal-title { font-family:'Cormorant Garamond',serif; font-size:18px; font-weight:600; color:var(--teal-dark); font-style:italic; margin-bottom:20px; }
.confirm-msg { font-size:14px; color:var(--gray-dark); margin-bottom:20px; line-height:1.6; }
.confirm-msg strong { color:var(--teal-dark); }

/* ── TOAST ── */
.toast { position:fixed; bottom:24px; right:24px; background:var(--gray-dark); color:white; padding:14px 22px; border-radius:9px; font-size:14px; box-shadow:0 8px 24px rgba(0,0,0,0.2); transform:translateY(60px); opacity:0; transition:all .3s ease; z-index:9999; max-width:320px; }
.toast.show { transform:translateY(0); opacity:1; }
.toast.success { border-left:3px solid var(--teal); }
.toast.error { border-left:3px solid var(--danger); }

/* ── PRINT ── */
@media print {
  @page { size:A4; margin:0; }
  html,body { background:white !important; }
  #loginScreen,#appShell { display:block !important; }
  .nav-bar,.view,#loginScreen { display:none !important; }
  .print-page { display:block !important; }
}
.print-page { display:none; width:210mm; min-height:297mm; background:white; position:relative; font-family:'Jost',sans-serif; color:#333; }
.print-header { padding:20mm 18mm 8mm; display:flex; align-items:flex-start; justify-content:space-between; }
.logo-area { display:flex; align-items:center; gap:10px; }
.logo-text-area { display:flex; flex-direction:column; justify-content:center; }
.logo-instituto { font-size:8px; letter-spacing:1.5px; text-transform:lowercase; color:#777; font-weight:300; line-height:1; margin-bottom:2px; }
.logo-unitta { font-size:22px; font-weight:500; color:#3D3D3D; letter-spacing:-0.5px; line-height:1; }
.watermark { position:absolute; right:-10mm; top:30mm; opacity:.06; pointer-events:none; }
.print-divider { height:1.5px; background:linear-gradient(to right,var(--teal),transparent); margin:0 18mm; }
.print-patient { padding:8mm 18mm 6mm; display:flex; gap:20mm; align-items:flex-end; border-bottom:1px solid #EBEBEB; margin-bottom:6mm; margin-left:18mm; margin-right:18mm; }
.print-patient-field { display:flex; flex-direction:column; gap:3px; }
.print-patient-field label { font-size:7px; text-transform:uppercase; letter-spacing:1.2px; color:#999; font-weight:500; }
.print-patient-field span { font-size:13px; font-weight:400; color:#333; border-bottom:1px solid #DADADA; padding-bottom:3px; min-width:60mm; }
.print-rx-title { text-align:center; margin:0 18mm 5mm; padding:4mm 0; }
.print-rx-title span { font-family:'Cormorant Garamond',serif; font-size:15px; font-weight:600; letter-spacing:3px; text-transform:uppercase; color:var(--teal-dark); font-style:italic; }
.print-body { padding:0 18mm; }

/* Print: grupo de protocolo */
.print-proto-group { margin-bottom:5mm; page-break-inside:avoid; }
.print-proto-label {
  font-size:8px; text-transform:uppercase; letter-spacing:2px; color:var(--teal-dark);
  font-weight:600; margin-bottom:2mm; padding-bottom:1.5mm;
  border-bottom:1px solid var(--teal-light); display:flex; align-items:center; gap:6px;
}
.print-proto-label::before { content:''; display:block; width:3px; height:10px; background:var(--teal); border-radius:2px; }

/* Print: grupo avulso */
.print-avulso-label {
  font-size:8px; text-transform:uppercase; letter-spacing:2px; color:#999;
  font-weight:500; margin-bottom:2mm; padding-bottom:1.5mm;
  border-bottom:1px solid #E8E8E8;
}

.print-med-item { padding:3mm 0; border-bottom:1px dotted #E8E8E8; display:flex; align-items:flex-start; gap:8px; page-break-inside:avoid; }
.print-med-item:last-child { border-bottom:none; }
.print-num { font-size:9px; color:var(--teal); font-weight:600; min-width:16px; padding-top:1px; font-family:'Cormorant Garamond',serif; font-style:italic; }
.print-med-content { flex:1; }
.print-med-name { font-size:11.5px; font-weight:500; color:#333; line-height:1.45; }
.print-med-pos { font-size:10px; color:#666; margin-top:2px; line-height:1.5; }
.print-med-tags { display:flex; gap:8px; margin-top:3px; flex-wrap:wrap; }
.print-tag { font-size:8.5px; color:var(--teal-dark); background:#EEF7F5; border:.5px solid var(--teal-light); border-radius:10px; padding:1px 6px; font-weight:500; }
.print-signature { margin:8mm 18mm 0; display:flex; justify-content:flex-end; }
.signature-block { text-align:center; min-width:60mm; }
.sig-line { width:60mm; height:1px; background:#555; margin-bottom:4px; }
.sig-name { font-size:11px; font-weight:500; color:#333; }
.sig-crm { font-size:10px; color:#777; }
.print-footer { position:fixed; bottom:0; left:0; width:100%; background:white; padding:5mm 18mm 8mm; border-top:1px solid #EBEBEB; }
.print-footer-inner { display:flex; justify-content:space-between; align-items:flex-start; gap:10mm; }
.pf-col { display:flex; flex-direction:column; gap:3px; }
.pf-item { display:flex; align-items:center; gap:5px; font-size:8px; color:#777; line-height:1.4; }
.pf-icon { width:10px; height:10px; min-width:10px; }

@media (max-width:600px) {
  .fields-grid { grid-template-columns:1fr 1fr; }
  .form-grid.three { grid-template-columns:1fr; }
  .nav-tab { padding:14px 12px; font-size:10px; }
}