/* Painel administrativo — tema claro, azul primário (#1565C0), verde só para pago/sucesso. */
:root {
  /* Marca Quero Freela: azul-marinho e laranja do logo */
  --primary: #012d60;
  --primary-dark: #001a3a;
  --primary-soft: #e3eaf4;
  --accent: #fe6601;
  --success: #2e7d32;
  --success-soft: #e6f4e7;
  --danger: #c62828;
  --danger-soft: #fdecea;
  --warning: #8a5300;
  --warning-soft: #fff4e0;
  --info: #01579b;
  --info-soft: #e1f2fb;
  --text: #1c2430;
  --muted: #5b6676;
  --border: #d7dde5;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --focus: #ffb300;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
  --sidebar-w: 248px;
  --topbar-h: 56px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
body.modal-open { overflow: hidden; }

a { color: var(--primary); }
a:hover { color: var(--primary-dark); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75rem; }
pre { margin: 0; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
h1:focus, h1:focus-visible, main:focus { outline: none; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 8px; top: -48px; z-index: 1000;
  background: var(--primary); color: #fff; padding: 8px 12px; border-radius: var(--radius);
}
.skip-link:focus { top: 8px; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--mono); font-size: 0.85em; }
.nowrap { white-space: nowrap; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.noscript { padding: 2rem; text-align: center; }

/* ------------------------------------------------------------ layout */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "top top" "side main";
  min-height: 100vh;
}
.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-name { color: var(--muted); font-size: 0.9rem; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-mark { width: 32px; height: 32px; object-fit: contain; flex: none; }
.brand-logo { display: block; width: min(280px, 80%); height: auto; margin: 0 auto; }
.brand-sub { text-align: center; margin: 8px 0 0; }
.menu-toggle { display: none; }

.sidebar {
  grid-area: side;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 8px 24px;
  overflow-y: auto;
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
}
.nav-group { margin-bottom: 12px; }
.nav-group-title {
  display: block; padding: 6px 12px; font-size: 0.75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.nav-link {
  display: block; padding: 8px 12px; border-radius: 6px; color: var(--text); text-decoration: none; font-size: 0.95rem;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }

.content { grid-area: main; padding: 24px; min-width: 0; }

.screen { max-width: 1400px; }
.screen-header { margin-bottom: 16px; }
.screen-header-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.subscreen { margin-top: 24px; }
.subscreen .screen-header h1 { font-size: 1.15rem; }

/* ------------------------------------------------------------ cards / métricas */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card-title { font-size: 1rem; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow);
}
.metric-warning { border-left-color: #f59e0b; }
.metric-danger { border-left-color: var(--danger); }
.metric-label { color: var(--muted); font-size: 0.85rem; }
.metric-value { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.metric-hint { color: var(--muted); font-size: 0.8rem; }
.breakdown { margin: 0; }
.breakdown-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--bg); }
.breakdown-row dt { color: var(--text); }
.breakdown-row dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }
.breakdown-row.is-alert dt, .breakdown-row.is-alert dd { color: var(--danger); }

.integrations { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.integration-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.integration.is-simulated { border-left: 4px solid #f59e0b; }

/* ------------------------------------------------------------ botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 8px 14px; border-radius: 6px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #e05a00; }
.btn-secondary { background: var(--surface); color: var(--primary-dark); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--primary-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #a31515; }
.btn-link { background: none; border: none; color: var(--primary); padding: 8px 0; text-decoration: underline; font-weight: 500; }
.icon-btn {
  background: none; border: 1px solid transparent; border-radius: 6px; font-size: 1.4rem; line-height: 1;
  width: 38px; height: 38px; cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--bg); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ------------------------------------------------------------ badges / avisos / chips */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap;
}
.badge-neutral { background: #eef1f5; color: #3b4656; border-color: #dde3ea; }
.badge-primary { background: var(--primary-soft); color: var(--primary-dark); border-color: #bcd6f5; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: #b9def2; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: #b7dfba; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: #f5d49a; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: #f3b9b3; }

.notice { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; border: 1px solid; }
.notice-info { background: var(--info-soft); border-color: #b9def2; color: #0b3c5d; }
.notice-warning { background: var(--warning-soft); border-color: #f5d49a; color: #5c3900; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.chip { padding: 4px 10px; border-radius: 999px; font-size: 0.85rem; text-decoration: none; border: 1px solid var(--border); }
.chip-danger { color: var(--danger); background: var(--danger-soft); border-color: #f3b9b3; }

/* ------------------------------------------------------------ formulários / filtros */
.form { display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 16px; }
.field-wide { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-weight: 600; font-size: 0.9rem; }
.field-check { flex-direction: row; align-items: center; gap: 8px; }
.req { color: var(--danger); }
.hint { color: var(--muted); font-size: 0.8rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid #b8c2cf; border-radius: 6px; padding: 8px 10px; min-height: 38px; width: 100%;
}
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--primary); }
textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--primary); }
.form-error { color: var(--danger); font-weight: 600; min-height: 1.2em; }
.form-error:empty { min-height: 0; }

.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 12px;
}
.field-inline { min-width: 170px; flex: 1 1 170px; max-width: 280px; }
.filter-actions { display: flex; gap: 8px; }

/* ------------------------------------------------------------ tabela */
.table-wrap {
  overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid #e8ecf1; }
.table th { background: #f8fafc; font-weight: 700; color: #344054; position: sticky; top: 0; white-space: nowrap; }
.table tbody tr:hover { background: #fafcff; }
.table tr.row-alert { background: #fff7f6; }
.table tr.row-alert td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
.clamp {
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; max-width: 320px; overflow-wrap: anywhere;
}
.audit-data {
  font-family: var(--mono); font-size: 0.75rem; white-space: pre-wrap; overflow-wrap: anywhere;
  max-width: 420px; max-height: 140px; overflow: auto; background: #f8fafc; padding: 6px; border-radius: 4px;
}

.pagination { display: flex; align-items: center; gap: 12px; justify-content: flex-end; padding: 12px 0; flex-wrap: wrap; }

/* ------------------------------------------------------------ estados */
.state { padding: 32px 16px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.state-error { color: var(--danger); border-color: #f3b9b3; background: var(--danger-soft); }
.state-error p { margin-bottom: 12px; }
.spinner {
  display: inline-block; width: 18px; height: 18px; margin-right: 8px; vertical-align: -3px;
  border: 3px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  * { transition: none !important; }
}

/* ------------------------------------------------------------ modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 24, 40, 0.5); display: grid; place-items: center; z-index: 100; padding: 16px;
}
.modal {
  background: var(--surface); border-radius: 10px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  box-shadow: 0 20px 50px rgba(16, 24, 40, 0.3);
}
.modal:focus { outline: none; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 20px 0; }
.modal-title { font-size: 1.1rem; margin: 0; }
.modal-body { padding: 12px 20px 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 8px; }

/* ------------------------------------------------------------ toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  background: #1f2937; color: #fff; padding: 12px 16px; border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  transition: opacity 0.4s ease;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: #7a4a00; }
.toast-hide { opacity: 0; }

/* ------------------------------------------------------------ autenticação */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: min(460px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.08); padding: 28px;
}
.brand-auth { margin-bottom: 20px; }
.auth-title { font-size: 1.35rem; }
.steps { padding-left: 20px; margin: 0 0 16px; }
.steps li { margin-bottom: 6px; }
.secret-box {
  display: flex; flex-direction: column; gap: 8px; padding: 12px; margin-bottom: 12px;
  background: var(--primary-soft); border: 1px solid #bcd6f5; border-radius: var(--radius);
}
.secret-label { font-weight: 700; font-size: 0.85rem; }
.secret { font-family: var(--mono); font-size: 1.15rem; letter-spacing: 0.08em; word-spacing: 0.3em; overflow-wrap: anywhere; user-select: all; }
.details { margin-bottom: 12px; }
.details summary { cursor: pointer; color: var(--primary); margin-bottom: 8px; }
.uri { font-family: var(--mono); font-size: 0.8rem; margin-bottom: 8px; }
.input-code { font-family: var(--mono); font-size: 1.4rem; letter-spacing: 0.4em; text-align: center; }

/* ------------------------------------------------------------ responsivo */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  .menu-toggle { display: inline-block; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: min(300px, 85vw); height: auto;
    transform: translateX(-100%); transition: transform 0.2s ease; z-index: 30; box-shadow: 4px 0 16px rgba(0, 0, 0, 0.12);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .content { padding: 16px; }
  .user-name { display: none; }
  .field-inline { max-width: none; }
}
@media (max-width: 640px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  .table td { border: none; padding: 4px 12px; }
  .table td::before { content: attr(data-label); display: block; font-size: 0.75rem; font-weight: 700; color: var(--muted); }
  .pagination { justify-content: center; }
}
