/* ── DARK THEME (default) ─────────────────────────── */
:root {
  --bg:           #0f0f0f;
  --surface:      #1a1a1a;
  --surface2:     #222222;
  --surface3:     #2a2a2a;
  --border:       #2e2e2e;
  --border2:      #3a3a3a;
  --text:         #f0f0f0;
  --text2:        #b0b0b0;
  --text3:        #707070;
  --accent:       #00c46a;
  --accent2:      #00a055;
  --accent-light: rgba(0,196,106,0.10);
  --accent-text:  #00c46a;
  --topbar-bg:    #141414;
  --topbar-border:#2e2e2e;
  --danger:       #ff5252;
  --danger-bg:    rgba(255,82,82,0.10);
  --success:      #00c46a;
  --success-bg:   rgba(0,196,106,0.10);
  --radius:       6px;
  --radius-lg:    10px;
  --mono:         'Inter', sans-serif;
  --label-color:  #ffffff;
  --th-color:     #ffffff;
  --placeholder:  #606060;
}

/* ── LIGHT THEME ──────────────────────────────────── */
[data-theme="light"] {
  --bg:           #f0f4fa;
  --surface:      #ffffff;
  --surface2:     #f4f7fc;
  --surface3:     #e8eef8;
  --border:       #d0d9ec;
  --border2:      #b8c5e0;
  --text:         #0f1c36;
  --text2:        #3d5280;
  --text3:        #7a90b8;
  --accent:       #1a5cff;
  --accent2:      #1447d4;
  --accent-light: rgba(26,92,255,0.08);
  --accent-text:  #1a5cff;
  --topbar-bg:    #0f1c36;
  --topbar-border:#1e3260;
  --danger:       #d93025;
  --danger-bg:    rgba(217,48,37,0.08);
  --success:      #137333;
  --success-bg:   rgba(19,115,51,0.08);
  --label-color:  #0f1c36;
  --th-color:     #0f1c36;
  --placeholder:  #9aaac8;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  min-height: 100vh;
}
.topbar {
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  color: var(--text);
  padding: 0 2.5rem;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-brand {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #ffffff;
}
.topbar-brand .dot {
  width: 7px; height: 7px;
  background: var(--accent);
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 6px var(--accent);
}
.topbar-status { font-size: 11px; color: var(--accent); font-family: var(--mono); }
.layout { max-width: 1600px; margin: 0 auto; padding: 1.5rem 2.5rem 4rem; }

/* ── Sticky page header ───────────────────────────── */
.page-header {
  position: sticky;
  top: 48px;
  z-index: 90;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 2.5rem 0.625rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
}
.ph-title { flex: 1; min-width: 0; }
.ph-title h1 { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; color: var(--text); line-height: 1.2; }
.ph-title p  { font-size: 11px; color: var(--text2); margin-top: 2px; }
.ph-totals {
  order: 3;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.ph-total {
  background: var(--surface);
  padding: 7px 14px;
}
.ph-total-highlight { background: var(--accent-light); }
.ph-total-label {
  font-size: 9px; font-weight: 600; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--text3); margin-bottom: 2px; white-space: nowrap;
}
.ph-total-value {
  font-family: var(--mono); font-size: 14px; font-weight: 600;
  color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ph-total-danger  { color: var(--danger) !important; }
.ph-total-highlight .ph-total-value { color: var(--accent); }
.ph-total-sub { font-size: 10px; color: var(--text3); font-family: var(--mono); margin-top: 1px; }
.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.75rem;
  margin-bottom: 1.25rem;
}
.section-title {
  font-size: 10px; font-weight: 600; letter-spacing: 0.10em; text-transform: uppercase;
  color: #909090; margin-bottom: 1.25rem;
  display: flex; align-items: center; gap: 8px;
}
.section-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1.25rem; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full  { grid-column: 1 / -1; }
.form-group.span2 { grid-column: span 2; }
label { font-size: 10px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--label-color); }
input, select, textarea {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
  outline: none;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  background: var(--surface3);
  box-shadow: 0 0 0 2px rgba(0,196,106,0.12);
}
input::placeholder { color: var(--placeholder); }
select { cursor: pointer; }
select option { background: var(--surface2); }
.btn {
  font-family: 'Inter', sans-serif;
  font-size: 12px; font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface3); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent2); border-color: var(--accent2); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(255,82,82,0.25); }
.btn-danger:hover { background: rgba(255,82,82,0.18); }
.btn-sm   { padding: 5px 10px; font-size: 11px; }
.btn-icon { padding: 5px; border-radius: 5px; }
.items-table-wrap { overflow-x: visible; margin: 0 -1.75rem; padding: 0 1.75rem; }
.items-table { width: 100%; border-collapse: collapse; min-width: 0; table-layout: fixed; }
.items-table th {
  font-size: 9px; font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--th-color); padding: 5px 4px; text-align: left;
  border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden;
}
.items-table td { padding: 4px 4px; border-bottom: 1px solid var(--border); vertical-align: middle; overflow: hidden; }
.items-table tbody tr:last-child td { border-bottom: none; }
.items-table tbody tr:hover td { background: var(--surface2); }
.items-table input, .items-table select {
  font-size: 12px; padding: 5px 6px; min-width: 0; width: 100%; box-sizing: border-box; height: 30px;
}
.items-table .col-qty input::-webkit-outer-spin-button,
.items-table .col-qty input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.items-table .col-qty input[type=number] { -moz-appearance: textfield; }
.items-table .col-seq     { width: 28px; text-align: center; color: var(--text3); font-family: var(--mono); font-size: 11px; }
.items-table .col-qty     { width: 70px; }
.items-table .col-produto { width: 18%; position: relative; }
.items-table .col-medico  { width: 16%; }
.items-table .col-paciente{ width: 14%; }
.items-table .col-preco,
.items-table .col-disctype,
.items-table .col-disc    { width: 9%; }
.items-table .col-desc-val{ width: 9%; }
.items-table .col-total   { width: 9%; }
.items-table .col-final   { width: 9%; }
.items-table .col-receita { width: 88px; text-align: center; }
.items-table .col-del     { width: 32px; text-align: center; }
.receita-btn {
  font-size: 10px; font-weight: 500; padding: 4px 7px;
  border-radius: 5px; border: 1px dashed var(--border2);
  background: transparent; color: var(--text2); cursor: pointer;
  white-space: nowrap; display: flex; align-items: center; gap: 4px;
  width: 100%; justify-content: center;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.receita-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.receita-btn.attached { border-style: solid; border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.computed-val {
  font-family: var(--mono); font-size: 11px; color: var(--text2);
  white-space: nowrap; display: block; overflow: hidden; text-overflow: ellipsis;
}
.computed-val.negative { color: var(--danger); }
.computed-val.positive { color: var(--accent); }
.add-row-bar { padding: 10px 0 2px; display: flex; gap: 8px; align-items: center; }
.pedido-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); margin-bottom: 1rem; overflow: hidden; }
.pedido-group-header { background: var(--surface2); padding: 9px 14px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); }
.pedido-group-header .badge { font-size: 9px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; padding: 3px 8px; border-radius: 4px; background: var(--accent-light); color: var(--accent); border: 1px solid rgba(0,196,106,0.25); }
.pedido-group-header .medico-name { font-size: 13px; font-weight: 600; color: var(--text); }
.pedido-group-header .total-pill  { margin-left: auto; font-family: var(--mono); font-size: 13px; font-weight: 500; color: var(--accent); }
.pedido-group-body { padding: 12px 14px; }
.toast-area { position: fixed; top: 58px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface3); border: 1px solid var(--border2); color: var(--text); font-size: 13px; padding: 10px 16px; border-radius: var(--radius); min-width: 260px; animation: slideIn 0.2s ease; display: flex; align-items: center; gap: 8px; }
.toast.success { border-color: rgba(0,196,106,0.4); color: var(--accent); }
.toast.error   { border-color: rgba(255,82,82,0.4);  color: var(--danger); }
@keyframes slideIn { from { opacity:0; transform:translateX(16px); } to { opacity:1; transform:none; } }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.75); z-index: 300; display: flex; align-items: center; justify-content: center; padding: 2rem; }
.modal { background: var(--surface); border-radius: var(--radius-lg); padding: 2rem; max-width: 520px; width: 100%; border: 1px solid var(--border2); }
.modal h2  { font-size: 16px; font-weight: 600; margin-bottom: 0.5rem; color: var(--text); }
.modal .sub { font-size: 12px; color: var(--text2); margin-bottom: 1.5rem; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 1.5rem; }
.spinner { width: 13px; height: 13px; border: 2px solid rgba(0,0,0,0.2); border-top-color: #000; border-radius: 50%; animation: spin 0.6s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.status-badge { font-size: 10px; padding: 2px 8px; border-radius: 4px; font-weight: 600; }

.env-btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: 'Inter', sans-serif; font-size: 12px; font-weight: 600;
  padding: 7px 16px; border-radius: var(--radius);
  border: 1px solid var(--border2); background: var(--surface2);
  color: var(--text2); cursor: pointer;
  transition: all 0.15s;
}
.env-btn.active {
  border-color: var(--accent); background: var(--accent-light); color: var(--accent);
}
.env-btn:hover:not(.active) { background: var(--surface3); color: var(--text); }
.env-dot {
  width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex-shrink: 0;
}
.env-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 4px; font-family: 'Inter', sans-serif;
}
.env-badge.prod { background: rgba(0,196,106,0.15); color: #00c46a; border: 1px solid rgba(0,196,106,0.3); }
.env-badge.test { background: rgba(245,166,35,0.15); color: #f5a623; border: 1px solid rgba(245,166,35,0.3); }


.hidden { display: none !important; }
#itemsTbody [id^="sug-"] div:hover { background: var(--surface3); }
.config-toggle { background: none; border: none; cursor: pointer; color: var(--text2); font-size: 11px; font-family: 'Inter', sans-serif; display: flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 4px; transition: color 0.15s, background 0.15s; }
.config-toggle:hover { color: var(--text); background: var(--surface2); }
.config-panel { background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius-lg); padding: 1.5rem; margin-bottom: 1.5rem; }

/* ── LOGIN SCREEN ─────────────────────────────────── */
#login-screen {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 100%; max-width: 380px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo .dot {
  width: 10px; height: 10px; background: var(--accent);
  border-radius: 50%; display: inline-block;
  box-shadow: 0 0 8px var(--accent); margin-right: 6px;
}
.login-logo h1 {
  font-size: 20px; font-weight: 700; color: var(--text);
  display: inline; letter-spacing: -.01em;
}
.login-logo p { font-size: 12px; color: var(--text2); margin-top: 4px; }
.login-error {
  background: var(--danger-bg); border: 1px solid rgba(255,82,82,0.3);
  color: var(--danger); font-size: 12px; padding: 8px 12px;
  border-radius: var(--radius); margin-bottom: 1rem; display: none;
}

/* ── ADMIN ─────────────────────────────────────────── */
.admin-layout { max-width: 1000px; margin: 0 auto; padding: 2rem 2.5rem 4rem; }
.user-table { width: 100%; border-collapse: collapse; }
.user-table th {
  font-size: 10px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: #ffffff;
  padding: 8px 12px; text-align: left;
  border-bottom: 1px solid var(--border); background: var(--surface2);
}
.user-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--text); vertical-align: middle;
}
.user-table tbody tr:hover td { background: var(--surface2); }
.user-table tbody tr:last-child td { border-bottom: none; }
.role-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; padding: 2px 8px; border-radius: 4px;
}
.role-badge.admin { background: rgba(26,92,255,0.15); color: #4d8fff; border: 1px solid rgba(26,92,255,0.3); }
.role-badge.user  { background: var(--accent-light); color: var(--accent); border: 1px solid rgba(0,196,106,0.3); }
.avatar-sm {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-light); border: 1px solid var(--accent);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: var(--accent); flex-shrink: 0;
}
.topbar-user { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text2); }
.topbar-user strong { color: var(--text); font-weight: 600; }

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 1024px) {
  .layout, .admin-layout { padding: 1.25rem 1.25rem 4rem; }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .ph-totals { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  /* ── Topbar ── */
  .topbar { padding: 0 1rem; height: auto; min-height: 52px; flex-wrap: wrap; gap: 6px; padding-top: 8px; padding-bottom: 8px; }
  .layout, .admin-layout { padding: 1rem 0.75rem 5rem; }

  /* ── Sticky header (mobile) ── */
  .page-header { padding: 0.5rem 1rem; gap: 0.375rem 0.75rem; }
  .ph-title h1 { font-size: 15px; }
  .ph-title p  { font-size: 10px; }
  .page-header > .btn { flex-shrink: 0; height: 38px; }
  .ph-totals { grid-template-columns: repeat(4, 1fr); }
  .ph-total { padding: 5px 8px; }
  .ph-total-value { font-size: 12px; }
  .ph-total-label { font-size: 8px; letter-spacing: .04em; white-space: nowrap; overflow: hidden; }

  /* ── Formulário ── */
  .form-grid { grid-template-columns: 1fr; gap: 0.875rem; }
  .form-group.span2 { grid-column: 1; }
  input, select, textarea { font-size: 16px; padding: 10px 12px; }
  .section-card { padding: 1rem; margin-bottom: 1rem; }

  /* ── Tabela de itens — card por linha ── */
  .items-table-wrap { margin: 0 -1rem; padding: 0; }
  .items-table, .items-table thead, .items-table tbody,
  .items-table th, .items-table tr { display: block; }
  .items-table thead { display: none; }

  /* Cada linha vira um card flex-wrap */
  .items-table tbody tr {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: 10px;
    padding: 40px 12px 12px; position: relative;
  }
  .items-table tbody tr:hover td { background: transparent; }

  /* Reset de cada célula */
  .items-table td {
    display: flex; flex-direction: column; gap: 3px;
    border: none; padding: 0; overflow: visible; width: auto;
  }
  /* Labels via data-label */
  .items-table td::before {
    content: attr(data-label);
    font-size: 9px; font-weight: 700; letter-spacing: .07em;
    text-transform: uppercase; color: var(--text3); white-space: nowrap;
  }
  /* Inputs e selects dentro das células */
  .items-table td input,
  .items-table td select { height: 42px; font-size: 15px; width: 100%; }

  /* Colunas específicas */
  .items-table td.col-seq     { display: none; }
  .items-table td.col-del     { position: absolute; top: 8px; right: 10px; display: block; width: auto; }
  .items-table td.col-del::before { display: none; }
  .items-table td.col-produto  { width: 100%; }
  .items-table td.col-medico   { width: 100%; }
  .items-table td.col-paciente { width: 100%; }
  .items-table td.col-qty      { width: 72px; }
  .items-table td.col-preco    { flex: 1; min-width: 90px; }
  .items-table td.col-disctype { width: 72px; }
  .items-table td.col-disc     { flex: 1; min-width: 80px; }
  .items-table td.col-desc-val { display: none; }
  .items-table td.col-total    { flex: 1; }
  .items-table td.col-final    { flex: 1; }
  .items-table td.col-receita  { width: 100%; }
  .items-table td.col-receita .receita-btn { width: 100%; }
  .computed-val { font-size: 13px; text-align: left; }

  .add-row-bar .btn { flex: 1; justify-content: center; }

  /* ── Modais ── */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-width: 100%; max-height: 90vh; overflow-y: auto; padding: 1.5rem 1.25rem; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; justify-content: center; height: 44px; }

  /* ── Tabela admin ── */
  .user-table, .user-table thead, .user-table tbody,
  .user-table th, .user-table td, .user-table tr { display: block; width: 100%; }
  .user-table thead { display: none; }
  .user-table tbody tr { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; padding: 12px; position: relative; }
  .user-table td { border: none; padding: 3px 0; font-size: 13px; }
  .user-table td:first-child { display: none; }
  .user-table td:last-child { display: flex; gap: 6px; margin-top: 8px; }
  .user-table td:last-child .btn { flex: 1; justify-content: center; height: 38px; }

  /* ── Login ── */
  .login-box { padding: 2rem 1.25rem 2.5rem; border-radius: var(--radius-lg) var(--radius-lg) 0 0; align-self: flex-end; width: 100%; max-width: 100%; }
  #login-screen { align-items: flex-end; padding: 0; }
}
@media (hover: none) {
  .btn, button, select, input[type=checkbox] { min-height: 44px; }
  .btn-sm { min-height: 36px; }
  .btn-icon { min-height: 36px; min-width: 36px; }
  .items-table td input, .items-table td select { min-height: 40px; }
}
