/* ===== Painel do operador ===== */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --green: #059669;
  --amber: #d97706;
  --red: #dc2626;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
img { display: block; max-width: 100%; }
.hidden { display: none !important; }

button, input, textarea, select { font-family: inherit; font-size: 14px; }
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-save { border-color: var(--primary); color: var(--primary); }
.btn-approve { background: var(--green); border-color: var(--green); color: #fff; }
.btn-approve:hover { background: #047857; }
.btn-reject { color: var(--amber); border-color: var(--amber); }
.btn-danger { color: var(--red); border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  background: var(--surface);
  padding: 36px 30px;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-logo { font-size: 40px; }
.login-card h1 { font-size: 22px; margin: 10px 0 4px; }
.login-sub { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.login-card input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
}
.login-error { color: var(--red); font-size: 13px; margin: 10px 0 0; }

/* Topbar */
.admin-topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}
.admin-brand { font-weight: 700; font-size: 16px; }
.admin-stats { display: flex; gap: 16px; flex: 1; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.stat b { color: var(--text); font-size: 15px; }
.admin-actions { display: flex; gap: 8px; }

.module-nav {
  display: flex;
  gap: 8px;
  padding: 12px 20px 0;
  background: var(--surface);
}
.module-tab {
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  padding: 10px 14px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 650;
}
.module-tab.active { color: var(--primary); border-color: var(--primary); }

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  padding: 12px 20px;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 57px;
  z-index: 9;
  flex-wrap: wrap;
}
.tab {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
}
.tab.active { background: #eff6ff; color: var(--primary); }
.tab-badge {
  background: var(--amber);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  margin-left: 4px;
}
.admin-search {
  margin-left: auto;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 180px;
}

/* Lista */
.admin-main { max-width: 900px; margin: 0 auto; padding: 20px; }
.admin-list { display: flex; flex-direction: column; gap: 16px; }
.admin-empty { text-align: center; color: var(--muted); padding: 50px; }

.ad {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.ad-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.src-badge { font-size: 12px; background: #f1f5f9; padding: 3px 10px; border-radius: 999px; color: var(--muted); }
.status-badge { font-size: 12px; padding: 3px 10px; border-radius: 999px; font-weight: 600; }
.status-backlog { background: #fef3c7; color: #92400e; }
.status-published { background: #d1fae5; color: #065f46; }
.status-rejected { background: #fee2e2; color: #991b1b; }
.status-archived { background: #e5e7eb; color: #374151; }
.status-sold { background: #e0e7ff; color: #3730a3; }
.ad-date { color: var(--muted); font-size: 12px; margin-left: auto; }

.ad-images { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.thumb { position: relative; width: 84px; height: 84px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.thumb-del {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--red);
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.no-img { color: var(--muted); font-size: 13px; padding: 20px; }
.thumb-add {
  width: 84px;
  height: 84px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  color: var(--muted);
  cursor: pointer;
}
.thumb-add:hover { border-color: var(--primary); color: var(--primary); }

.ad-fields { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.fld { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.fld input, .fld textarea, .fld select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-weight: 400;
  resize: vertical;
}
.fld input:focus, .fld textarea:focus { outline: none; border-color: var(--primary); }
.fld-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ad-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); }
.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: 14px;
  padding: 24px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.modal-card h2 { margin: 0 0 16px; }
.modal-close { position: absolute; top: 12px; right: 14px; border: none; background: none; font-size: 26px; cursor: pointer; color: var(--muted); }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
.form input, .form textarea, .form select { padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-weight: 400; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.file-drop {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
}
.file-drop:hover { border-color: var(--primary); }
.file-drop input { display: none; }
.preview-row { display: flex; gap: 8px; flex-wrap: wrap; }
.preview-row img { width: 70px; height: 70px; object-fit: cover; border-radius: 8px; }
.form-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.check { flex-direction: row !important; align-items: center; gap: 6px; font-weight: 400 !important; }

/* Financeiro */
.finance-main { max-width: 1240px; margin: 0 auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.controls-row { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
.controls-row label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 600; }
.controls-row input, .controls-row select, .inline-actions select { min-height: 36px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px; box-shadow: var(--shadow); }
.metric span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.metric strong { display: block; font-size: 20px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 14px; }
.section-head h2 { margin: 0 0 4px; font-size: 18px; }
.section-head p { margin: 0; color: var(--muted); font-size: 13px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 11px 9px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; }
.state-pill { display: inline-block; border-radius: 999px; padding: 3px 8px; font-size: 11px; font-weight: 650; background: #f1f5f9; }
.state-pending { background: #fef3c7; color: #92400e; }
.state-batched, .state-ready { background: #dbeafe; color: #1e40af; }
.state-paid { background: #d1fae5; color: #065f46; }
.state-cancelled { background: #fee2e2; color: #991b1b; }
.batch-list { display: grid; gap: 10px; }
.batch { border: 1px solid var(--border); border-radius: 9px; padding: 13px; display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.batch-title { font-weight: 700; margin-bottom: 4px; }
.batch-meta { color: var(--muted); font-size: 12px; }
.batch-actions, .inline-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.company-list { display: grid; gap: 8px; margin-bottom: 18px; }
.company-row { border: 1px solid var(--border); border-radius: 8px; padding: 10px; display: flex; align-items: center; gap: 10px; }
.company-row strong { min-width: 38px; }
.company-row input { min-width: 0; flex: 1; padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px; }
.compact-form { border-top: 1px solid var(--border); padding-top: 16px; }
.modal-copy { color: var(--muted); font-size: 14px; }
.report-status { padding: 10px 14px; border-radius: 8px; background: #e0f2fe; color: #075985; font-size: 13px; }

@media print {
  .admin-topbar, .module-nav, .tabs, .controls-row, #report-status, #ads-section, #finance-section, .inline-actions { display: none !important; }
  #app, #reports-section { display: block !important; }
  #reports-section { max-width: none; padding: 0; }
  .panel, .metric { box-shadow: none; break-inside: avoid; }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 12px 22px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  z-index: 100;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }

/* Barra de filtros */
.filters-bar {
  display: flex;
  gap: 8px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  align-items: center;
  position: sticky;
  top: 106px;
  z-index: 8;
}
.filters-bar .admin-search { margin: 0; flex: 1; min-width: 200px; }
.filter-select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}

/* Lista em linhas */
.admin-rows { display: flex; flex-direction: column; gap: 6px; }
.row-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 14px 4px 4px;
}
.row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto auto auto auto;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.row:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.row:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.row-thumb { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; }
.row-thumb--empty { display: flex; align-items: center; justify-content: center; background: #eef0f3; color: var(--muted); }
.row-main { min-width: 0; }
.row-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 12px; color: var(--muted); display: flex; gap: 8px; margin-top: 2px; }
.row-ref { font-family: ui-monospace, Menlo, monospace; color: var(--primary); }
.row-price { font-weight: 700; color: var(--green); font-size: 14px; white-space: nowrap; }
.row-badges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.row-metrics { display: flex; gap: 10px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.row-date { font-size: 12px; color: var(--muted); white-space: nowrap; }

.status-sold { background: #dbeafe; color: #1e40af; }
.status-reserved { background: #fef3c7; color: #92400e; }

/* Detalhe (modal largo) */
.modal-card--wide { max-width: 640px; }
.detail-head h2 { display: flex; align-items: center; gap: 8px; font-size: 18px; margin: 0 0 4px; flex-wrap: wrap; }
.detail-sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }

/* Reservas */
.res-block { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 12px; }
.res-block h3 { font-size: 14px; margin: 0 0 8px; }
.res-empty { color: var(--muted); font-size: 13px; }
.res-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.res-meta { color: var(--muted); font-size: 12px; }
.res-status { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.res-badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.res-active { background: #fef3c7; color: #92400e; }
.res-confirmed { background: #d1fae5; color: #065f46; }
.res-released, .res-expired { background: #e5e7eb; color: #374151; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-sold { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
.btn-sold:hover { background: #1e3a8a; }

/* Empresas */
.companies-hint { color: var(--muted); font-size: 13px; margin: -6px 0 12px; }
.companies-list { display: flex; flex-direction: column; margin-bottom: 14px; max-height: 300px; overflow-y: auto; }
.company-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.company-name { flex: 1; font-weight: 600; }
.company-count { color: var(--muted); font-size: 12px; white-space: nowrap; }
.company-actions { display: flex; gap: 6px; }
.form-row--company { grid-template-columns: 90px 1fr; }
.company-form select, .form select { padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-weight: 400; background: var(--surface); }
.fld select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-weight: 400; background: var(--surface); }

/* Analytics */
.tab-analytics { margin-left: auto; }
.analytics { display: flex; flex-direction: column; gap: 16px; }
.analytics-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.analytics-toolbar h2 { font-size: 18px; margin: 0; }
.analytics-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.detail-chart-wrap { position: relative; }
.detail-views-total { color: var(--muted); font-weight: 400; font-size: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.tile-value { font-size: 30px; font-weight: 800; line-height: 1.1; }
.tile-label { color: var(--muted); font-size: 13px; margin-top: 4px; font-weight: 600; }
.tile-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  position: relative;
}
.chart-card h3 { margin: 0 0 10px; font-size: 14px; }
.chart { width: 100%; overflow-x: auto; }
.chart-tooltip {
  position: absolute;
  background: #0f172a;
  color: #fff;
  font-size: 12px;
  line-height: 1.5;
  padding: 8px 10px;
  border-radius: 8px;
  pointer-events: none;
  z-index: 5;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  max-width: 160px;
}
.top-ads { overflow-x: auto; }
.top-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.top-table th {
  text-align: left;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.top-table td { padding: 8px; border-bottom: 1px solid var(--border); }
.top-table tbody tr { cursor: pointer; }
.top-table tbody tr:hover { background: #f8fafc; }
.top-table .num { text-align: right; }
.top-title { max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 640px) {
  .row { grid-template-columns: 44px minmax(0, 1fr) auto; }
  .row-badges, .row-metrics, .row-date { grid-column: 2 / -1; justify-content: flex-start; }
  .row-price { grid-column: 3; }
}
@media (max-width: 560px) {
  .fld-row, .form-row { grid-template-columns: 1fr; }
  .admin-stats { display: none; }
  .admin-topbar { position: static; }
  .module-nav { overflow-x: auto; padding-left: 10px; }
  .module-tab { white-space: nowrap; }
  .tabs { top: 0; }
  .finance-main { padding: 12px; }
  .section-head { align-items: flex-start; flex-direction: column; }
}
