/* ─── IDENTIDADE VISUAL ─────────────────────────────────────
   Primária:  #232047  (azul-marinho / índigo profundo)
   Destaque:  #ec6853  (coral quente)
   Branco:    #ffffff
   Fonte:     Inter → substituto do Bw Modelica (sem instalação local)
───────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

:root {
  --navy:       #232047;
  --navy-dark:  #1a183a;
  --navy-light: #2d2a5e;
  --coral:      #ec6853;
  --coral-dark: #d45b47;
  --coral-bg:   #fdf1ef;
  --white:      #ffffff;
  --bg:         #f5f5f8;
  --border:     #e0dff0;
  --text:       #232047;
  --text-muted: #7875a8;
  --shadow:     0 1px 4px rgba(35,32,71,.1);
  --shadow-md:  0 4px 16px rgba(35,32,71,.14);
  --ref-color:  #1a5276; --ref-bg: #d6eaf8;
  --sim-color:  #6c3483; --sim-bg: #e8daef;
  --gen-color:  #1e8449; --gen-bg: #d5f5e3;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', 'Helvetica Neue', sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

/* ════════════════════════════════════════
   LOGIN
════════════════════════════════════════ */
#screen-login {
  position: fixed; inset: 0;
  background: var(--navy);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.login-bg-texture {
  position: absolute; inset: 0; opacity: .04;
  background-image: repeating-linear-gradient(45deg, #fff 0, #fff 1px, transparent 0, transparent 50%);
  background-size: 20px 20px;
}
.login-card {
  background: var(--white);
  border-radius: 20px;
  padding: 40px 44px 36px;
  width: 380px;
  box-shadow: 0 24px 64px rgba(0,0,0,.28);
  position: relative;
}
.login-logo {
  display: flex; justify-content: center; margin-bottom: 28px;
}
.login-logo svg { width: 200px; height: auto; }
.login-divider { width: 40px; height: 3px; background: var(--coral); border-radius: 2px; margin: 0 auto 28px; }
.login-title { text-align: center; font-size: 13px; font-weight: 500; color: var(--text-muted); letter-spacing: .5px; text-transform: uppercase; margin-bottom: 24px; }
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--text-muted); margin-bottom: 6px; }
.form-input {
  width: 100%; padding: 11px 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 14px; font-family: inherit; color: var(--text);
  background: var(--bg); outline: none; transition: border-color .15s;
}
.form-input:focus { border-color: var(--coral); background: white; }
.login-btn {
  width: 100%; padding: 13px;
  background: var(--coral); color: white;
  border: none; border-radius: 10px;
  font-size: 14px; font-weight: 700; font-family: inherit;
  cursor: pointer; letter-spacing: .3px;
  transition: background .15s, transform .1s;
  margin-top: 8px;
}
.login-btn:hover { background: var(--coral-dark); }
.login-btn:active { transform: scale(.98); }
.login-btn:disabled { opacity: .65; cursor: default; }
.login-error { color: var(--coral); font-size: 12px; text-align: center; margin-top: 10px; min-height: 18px; }

/* ════════════════════════════════════════
   APP SHELL
════════════════════════════════════════ */
#screen-app { display: none; flex-direction: column; height: 100vh; }
#screen-app.active { display: flex; }

header {
  background: var(--navy);
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,.2);
}
.header-logo svg { height: 34px; width: auto; }
.header-right { display: flex; align-items: center; gap: 10px; }
.header-badge { background: rgba(255,255,255,.1); border-radius: 20px; padding: 3px 10px; font-size: 11px; color: rgba(255,255,255,.75); }
.user-menu-btn {
  background: var(--coral); color: white;
  border: none; border-radius: 20px;
  padding: 5px 14px; font-size: 12px; font-weight: 700;
  cursor: pointer; font-family: inherit;
  transition: background .15s;
}
.user-menu-btn:hover { background: var(--coral-dark); }

.app-body { display: flex; flex: 1; overflow: hidden; }

/* ════════════════════════════════════════
   SIDEBAR
════════════════════════════════════════ */
.sidebar { width: 276px; background: white; border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-search { padding: 14px 12px 10px; border-bottom: 1px solid var(--border); }
.search-input {
  width: 100%; padding: 8px 12px 8px 32px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 13px; font-family: inherit; color: var(--text);
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237875a8' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E") no-repeat 10px center;
  outline: none;
}
.search-input:focus { border-color: var(--coral); background-color: white; }
.sidebar-filters { padding: 8px 12px; display: flex; gap: 5px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.filter-chip { padding: 3px 9px; border-radius: 20px; font-size: 10px; font-weight: 600; border: 1px solid var(--border); cursor: pointer; color: var(--text-muted); background: white; transition: all .15s; }
.filter-chip.active { background: var(--navy); color: white; border-color: var(--navy); }
.filter-chip:hover:not(.active) { border-color: var(--coral); color: var(--coral); }
.sidebar-list { overflow-y: auto; flex: 1; }
.mol-item { padding: 10px 14px; display: flex; align-items: center; gap: 10px; cursor: pointer; border-bottom: 1px solid var(--border); transition: background .1s; }
.mol-item:hover { background: var(--coral-bg); }
.mol-item.active { background: var(--coral-bg); border-left: 3px solid var(--coral); }
.mol-rank { font-size: 10px; color: var(--text-muted); width: 18px; text-align: right; flex-shrink: 0; }
.mol-info { flex: 1; min-width: 0; }
.mol-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mol-class { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.mol-badge { font-size: 10px; font-weight: 700; background: rgba(236,104,83,.12); color: var(--coral); padding: 2px 6px; border-radius: 10px; flex-shrink: 0; }
.sidebar-empty { padding: 24px 16px; text-align: center; font-size: 12px; color: var(--text-muted); }

/* ════════════════════════════════════════
   MAIN CONTENT
════════════════════════════════════════ */
.main { flex: 1; min-height: 0; overflow: hidden; padding: 20px; display: flex; flex-direction: column; }
.empty-state { flex: 1; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--text-muted); }
.empty-state .icon { font-size: 48px; opacity: .4; }
.empty-state h3 { font-size: 16px; font-weight: 700; color: var(--text); }
.empty-state p { font-size: 13px; max-width: 280px; text-align: center; line-height: 1.5; }

.mol-header { background: white; border-radius: 12px; padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; border-top: 3px solid var(--coral); flex-shrink: 0; }
.mol-header-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.mol-title { font-size: 22px; font-weight: 800; color: var(--navy); }
.mol-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.mol-actions { display: flex; gap: 8px; flex-shrink: 0; }
.btn { padding: 7px 14px; border-radius: 8px; font-size: 12px; font-weight: 700; cursor: pointer; border: none; transition: all .15s; font-family: inherit; }
.btn-outline { background: white; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--coral); color: var(--coral); }
.btn-primary { background: var(--coral); color: white; }
.btn-primary:hover { background: var(--coral-dark); }
.btn-navy { background: var(--navy); color: white; }
.btn-navy:hover { background: var(--navy-dark); }

.stats-row { display: flex; gap: 10px; margin-top: 14px; }
.stat-card { flex: 1; background: var(--bg); border-radius: 8px; padding: 10px 14px; border: 1px solid var(--border); }
.stat-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 700; }
.stat-value { font-size: 17px; font-weight: 800; color: var(--coral); margin-top: 2px; }
.stat-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.type-filters { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; flex-shrink: 0; }
.type-btn { padding: 6px 14px; border-radius: 20px; font-size: 12px; font-weight: 600; cursor: pointer; border: 1.5px solid var(--border); background: white; color: var(--text-muted); transition: all .15s; font-family: inherit; }
.type-btn.active-all { background: var(--navy); color: white; border-color: var(--navy); }
.type-btn.active-ref { background: var(--ref-bg); color: var(--ref-color); border-color: var(--ref-color); }
.type-btn.active-sim { background: var(--sim-bg); color: var(--sim-color); border-color: var(--sim-color); }
.type-btn.active-gen { background: var(--gen-bg); color: var(--gen-color); border-color: var(--gen-color); }

.table-container { background: white; border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.table-scroll { overflow: auto; flex: 1; min-height: 0; }
table { width: 100%; border-collapse: collapse; min-width: 880px; }
thead { background: var(--navy); }
th { padding: 10px 12px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: rgba(255,255,255,.7); text-align: left; border-bottom: none; white-space: nowrap; }
/* cabeçalho fixo no topo ao rolar a tabela (escopo: só a tabela de preços) */
.table-scroll thead th { position: sticky; top: 0; z-index: 3; background: var(--navy); }
.table-scroll th:first-child { position: sticky; top: 0; left: 0; background: var(--navy); z-index: 5; min-width: 260px; }
.pharmacy-th { text-align: center; min-width: 120px; padding: 6px 10px; }
.pharmacy-logo-cell { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pharm-logo-img { width: 36px; height: 36px; object-fit: contain; border-radius: 8px; background: white; padding: 3px; display: block; }
.pharm-name { font-size: 9px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: rgba(255,255,255,.65); }
.pharm-badge { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 10px; font-weight: 700; white-space: nowrap; }
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:hover { background: #faf9fd; }
tbody tr:last-child { border-bottom: none; }
td { padding: 11px 12px; font-size: 13px; vertical-align: middle; }
.table-scroll td:first-child { position: sticky; left: 0; background: white; z-index: 1; }
.table-scroll tbody tr:hover td:first-child { background: #faf9fd; }
.product-cell { display: flex; flex-direction: column; gap: 3px; }
.product-name { font-weight: 600; font-size: 13px; line-height: 1.3; }
.product-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tag-type { font-size: 10px; font-weight: 700; padding: 1px 7px; border-radius: 10px; text-transform: uppercase; letter-spacing: .3px; }
.tag-ref { background: var(--ref-bg); color: var(--ref-color); }
.tag-sim { background: var(--sim-bg); color: var(--sim-color); }
.tag-gen { background: var(--gen-bg); color: var(--gen-color); }
.tag-none { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.tag-lab { font-size: 11px; color: var(--text-muted); }
.tag-qty { font-size: 10px; font-weight: 600; padding: 1px 7px; border-radius: 10px; background: #f0effe; color: var(--navy); border: 1px solid #d8d5f5; white-space: nowrap; }
.qty-divider { width: 1px; height: 20px; background: var(--border); margin: 0 4px; flex-shrink: 0; }
.qty-label { font-size: 11px; color: var(--text-muted); font-weight: 600; white-space: nowrap; }
.qty-btn { font-size: 12px; font-weight: 600; padding: 6px 14px; border-radius: 20px; border: 1.5px solid var(--border); background: white; color: var(--text-muted); cursor: pointer; font-family: inherit; transition: all .15s; }
.qty-btn:hover { border-color: var(--navy); color: var(--navy); }
.qty-btn.active-qty { background: var(--navy); color: white; border-color: var(--navy); }
.price-cell { text-align: center; }
.price-value { font-weight: 700; font-size: 13px; color: var(--text); display: inline-block; padding: 3px 7px; border-radius: 6px; }
.price-value.cheapest { background: var(--gen-bg); color: var(--gen-color); }
.price-value.cheapest-overall { background: var(--coral); color: white; }
.price-link { font-size: 10px; color: var(--coral); text-decoration: none; display: block; margin-top: 2px; }
.price-link:hover { text-decoration: underline; }
.price-na { color: #ccc; font-size: 12px; }
.update-bar { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; background: var(--bg); border-top: 1px solid var(--border); font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.cache-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 4px; }

/* ════════════════════════════════════════
   ADMIN PANEL (overlay)
════════════════════════════════════════ */
#screen-admin { display: none; position: fixed; inset: 0; background: rgba(35,32,71,.55); z-index: 500; align-items: flex-start; justify-content: flex-end; padding-top: 56px; }
#screen-admin.active { display: flex; }
.admin-panel {
  width: 580px; height: calc(100vh - 56px);
  background: white; box-shadow: -8px 0 40px rgba(0,0,0,.2);
  display: flex; flex-direction: column; overflow: hidden;
}
.admin-header { background: var(--navy); padding: 18px 24px 0; flex-shrink: 0; }
.admin-header-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.admin-title { color: white; font-size: 16px; font-weight: 800; }
.admin-close { background: rgba(255,255,255,.15); border: none; color: white; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; font-size: 16px; display: flex; align-items: center; justify-content: center; }
.admin-close:hover { background: rgba(255,255,255,.25); }
.admin-tabs { display: flex; gap: 0; }
.admin-tab { padding: 10px 20px; font-size: 12px; font-weight: 600; color: rgba(255,255,255,.55); cursor: pointer; border-bottom: 3px solid transparent; transition: all .15s; font-family: inherit; background: none; border-top: none; border-left: none; border-right: none; }
.admin-tab:hover { color: rgba(255,255,255,.85); }
.admin-tab.active { color: white; border-bottom-color: var(--coral); }
.admin-body { flex: 1; overflow-y: auto; padding: 24px; }
.admin-section { display: none; }
.admin-section.active { display: block; }

/* Admin forms */
.form-row { margin-bottom: 20px; }
.field-group { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.admin-label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 6px; }
.admin-input { width: 100%; padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 13px; font-family: inherit; color: var(--text); outline: none; transition: border-color .15s; }
.admin-input:focus { border-color: var(--coral); }
.admin-input:disabled { background: var(--bg); color: var(--text-muted); }
.admin-input.readonly { background: var(--bg); }
.section-title { font-size: 14px; font-weight: 800; color: var(--navy); margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.section-divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.save-row { display: flex; justify-content: flex-end; margin-top: 12px; }

/* Users table */
.users-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.users-table th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); padding: 8px 10px; border-bottom: 2px solid var(--border); font-weight: 700; }
.users-table td { padding: 11px 10px; font-size: 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users-table tr:last-child td { border-bottom: none; }
.role-badge { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 10px; background: rgba(35,32,71,.1); color: var(--navy); }
.role-badge.admin { background: rgba(236,104,83,.15); color: var(--coral); }
.btn-sm { padding: 4px 10px; font-size: 11px; border-radius: 6px; }

/* Molecules CRUD */
.mol-list-admin { margin-top: 12px; }
.mol-admin-item { display: flex; align-items: center; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 10px; margin-bottom: 8px; gap: 10px; }
.mol-admin-item:hover { border-color: var(--coral); background: var(--coral-bg); }
.mol-admin-info { flex: 1; }
.mol-admin-name { font-weight: 700; font-size: 13px; }
.mol-admin-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.mol-admin-actions { display: flex; gap: 6px; }
.btn-edit { background: rgba(35,32,71,.08); color: var(--navy); border: none; border-radius: 6px; padding: 4px 10px; font-size: 11px; font-weight: 600; cursor: pointer; font-family: inherit; }
.btn-delete { background: rgba(236,104,83,.12); color: var(--coral); border: none; border-radius: 6px; padding: 4px 10px; font-size: 11px; font-weight: 600; cursor: pointer; font-family: inherit; }
.btn-edit:hover { background: var(--navy); color: white; }
.btn-delete:hover { background: var(--coral); color: white; }

/* Toast */
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--navy); color: white; padding: 10px 16px; border-radius: 8px; font-size: 13px; font-weight: 500; box-shadow: var(--shadow-md); transform: translateY(60px); opacity: 0; transition: all .3s; z-index: 900; }
.toast.coral { background: var(--coral); }
.toast.show { transform: translateY(0); opacity: 1; }

/* Loading overlay */
.loading-overlay { display: none; position: fixed; inset: 0; background: rgba(255,255,255,.8); z-index: 800; align-items: center; justify-content: center; flex-direction: column; gap: 12px; }
.loading-overlay.show { display: flex; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--coral); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
