/* ===========================================================
   WebOptos - Painel Administrativo
   Tema: roxo profundo + violeta com toques de menta e coral
   =========================================================== */

:root {
  --brand-50:  #f4f1ff;
  --brand-100: #ebe4ff;
  --brand-200: #d6caff;
  --brand-300: #b8a3ff;
  --brand-400: #9777ff;
  --brand-500: #7c4dff;
  --brand-600: #6d28d9;
  --brand-700: #5b21b6;
  --brand-800: #4c1d95;
  --brand-900: #2e1065;

  --mint:   #10b981;
  --mint-2: #34d399;
  --coral:  #f43f5e;
  --amber:  #f59e0b;
  --sky:    #0ea5e9;

  --ink-900: #0b1020;
  --ink-800: #111933;
  --ink-700: #1a2348;

  --surface:    #ffffff;
  --surface-2:  #fafaff;
  --border:     #ecebf5;
  --border-2:   #e3e1f0;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --shadow-card: 0 1px 0 rgba(15, 23, 42, 0.04),
                 0 8px 24px -10px rgba(76, 29, 149, 0.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: #0f172a;
  letter-spacing: -0.005em;
}

/* ===== Background do app ===== */
.bg-app {
  background:
    radial-gradient(1100px 600px at -10% -20%, rgba(124, 77, 255, 0.10), transparent 60%),
    radial-gradient(800px 500px at 110% 10%, rgba(16, 185, 129, 0.08), transparent 60%),
    linear-gradient(180deg, #fbfaff 0%, #f4f3fb 100%);
}

/* Scrollbar discreta */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #d6caff, #b8a3ff);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: #9777ff; background-clip: padding-box; }

/* ===========================================================
   SIDEBAR
   =========================================================== */
.sidebar {
  width: 264px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  color: #e7e5ff;
  background:
    radial-gradient(600px 300px at 0% 0%, rgba(124, 77, 255, 0.35), transparent 60%),
    linear-gradient(180deg, #0c1130 0%, #0b1020 60%, #0a0f1f 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.04);
  overflow-y: auto;
}

.sidebar .brand {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 10px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 14px;
}
.sidebar .brand .logo {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #7c4dff 0%, #34d399 100%);
  box-shadow: 0 10px 20px -10px rgba(124, 77, 255, 0.7);
  color: #fff;
  font-weight: 800;
}
.sidebar .brand h1 {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.02em;
  margin: 0;
  color: #ffffff;
}
.sidebar .brand p { margin: 0; font-size: 11px; color: #9aa3c7; letter-spacing: 0.02em; }

.nav-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #6b73a3;
  padding: 14px 14px 8px;
}

.nav-link {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  color: #c8cae6;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: background .25s ease, color .25s ease, transform .25s ease;
  user-select: none;
}
.nav-link svg { width: 18px; height: 18px; opacity: .85; }
.nav-link .badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(124, 77, 255, 0.18);
  color: #d6caff;
}
.nav-link:hover {
  background: rgba(255,255,255,0.04);
  color: #ffffff;
  transform: translateX(2px);
}
.nav-link.active {
  color: #ffffff;
  background: linear-gradient(90deg, rgba(124, 77, 255, 0.25), rgba(124, 77, 255, 0.05));
  box-shadow: inset 0 0 0 1px rgba(124, 77, 255, 0.25);
}
.nav-link.active::before {
  content: '';
  position: absolute;
  left: -4px; top: 8px; bottom: 8px;
  width: 4px;
  border-radius: 4px;
  background: linear-gradient(180deg, #7c4dff, #34d399);
  box-shadow: 0 0 14px rgba(124, 77, 255, 0.65);
}
.nav-link.active svg { opacity: 1; color: #b8a3ff; }

.sidebar-footer {
  margin-top: 24px;
  padding: 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(124, 77, 255, 0.20), rgba(16, 185, 129, 0.10));
  border: 1px solid rgba(124, 77, 255, 0.25);
}
.sidebar-footer h4 { color: #fff; font-size: 13px; font-weight: 700; margin: 0 0 4px; }
.sidebar-footer p  { color: #c8cae6; font-size: 11px; margin: 0 0 10px; line-height: 1.5; }
.sidebar-footer button {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  background: linear-gradient(135deg, #7c4dff, #6d28d9);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  border: 0;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease;
}
.sidebar-footer button:hover { transform: translateY(-1px); box-shadow: 0 10px 20px -10px rgba(124, 77, 255, 0.7); }

/* ===========================================================
   LOGIN
   =========================================================== */
#app.login-mode #sidebar,
#app.login-mode #topbar {
  display: none !important;
}

#app.login-mode #view {
  padding: 0 !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-card);
  padding: 28px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.login-brand .logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #7c4dff 0%, #34d399 100%);
  box-shadow: 0 10px 20px -10px rgba(124, 77, 255, 0.7);
  color: #fff;
  font-weight: 800;
}

.login-brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #0f172a;
}

.login-brand p {
  margin: 0;
  font-size: 12px;
  color: #64748b;
}

.login-hint {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #64748b;
}

.login-hint small {
  font-size: 12px;
}

/* ===========================================================
   TOPBAR
   =========================================================== */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 24px;
  background: rgba(255,255,255,0.75);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}

.search {
  flex: 1; max-width: 520px;
  position: relative;
}
.search input {
  width: 100%;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 0 14px 0 40px;
  font-size: 14px;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.search input:focus { border-color: var(--brand-400); box-shadow: 0 0 0 4px rgba(124, 77, 255, 0.12); }
.search svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: #94a3b8;
}
.search kbd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  background: #f1f0fa; color: #6b73a3;
  border: 1px solid #e3e1f0;
  border-radius: 6px;
  padding: 2px 6px;
}

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--border);
  color: #475569;
  cursor: pointer;
  transition: all .2s ease;
  position: relative;
}
.icon-btn:hover { color: var(--brand-600); border-color: var(--brand-200); transform: translateY(-1px); }
.icon-btn .dot {
  position: absolute; top: 8px; right: 9px;
  width: 8px; height: 8px; border-radius: 999px;
  background: linear-gradient(135deg, var(--coral), #fb7185);
  box-shadow: 0 0 0 2px #fff;
}

.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all .2s ease;
}
.user-chip:hover { border-color: var(--brand-300); }
.user-chip .avatar {
  width: 32px; height: 32px;
  border-radius: 999px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #7c4dff, #34d399);
  color: #fff; font-weight: 700; font-size: 13px;
}
.user-chip .meta strong { display: block; font-size: 12.5px; color: #0f172a; line-height: 1.2; }
.user-chip .meta span   { display: block; font-size: 10.5px; color: #64748b; }

/* ===========================================================
   COMPONENTES GENÉRICOS
   =========================================================== */

.page-title h2 {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: #0f172a;
  margin: 0;
}
.page-title p { margin: 4px 0 0; color: #64748b; font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}
.card-pad { padding: 22px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all .2s ease;
  border: 1px solid transparent;
}
.btn svg { width: 16px; height: 16px; }

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, #7c4dff 0%, #6d28d9 100%);
  box-shadow: 0 10px 24px -10px rgba(124, 77, 255, 0.6);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 14px 28px -10px rgba(124, 77, 255, 0.7); }

.btn-ghost {
  background: #fff;
  color: #475569;
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--brand-700); border-color: var(--brand-200); background: var(--brand-50); }

.btn-soft {
  background: var(--brand-50);
  color: var(--brand-700);
  border-color: var(--brand-100);
}
.btn-soft:hover { background: var(--brand-100); }

/* ===== KPI CARD ===== */
.kpi {
  position: relative;
  padding: 20px;
  border-radius: var(--radius-lg);
  background: #fff;
  border: 1px solid var(--border);
  overflow: hidden;
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease;
}
.kpi:hover {
  transform: translateY(-3px);
  box-shadow: 0 18px 38px -18px rgba(76, 29, 149, 0.25);
  border-color: var(--brand-100);
}
.kpi::before {
  content: '';
  position: absolute;
  inset: -50% -50% auto auto;
  width: 180px; height: 180px;
  background: radial-gradient(circle, var(--accent, rgba(124,77,255,0.18)), transparent 60%);
  opacity: .8;
  pointer-events: none;
}
.kpi .kpi-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent-bg, linear-gradient(135deg, #ede9fe, #ddd6fe));
  color: var(--accent-fg, #6d28d9);
  margin-bottom: 14px;
}
.kpi .kpi-label { font-size: 12.5px; color: #64748b; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; }
.kpi .kpi-value {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 28px; font-weight: 800; color: #0f172a;
  letter-spacing: -0.02em;
  margin-top: 4px;
}
.kpi .kpi-trend {
  margin-top: 10px;
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 700;
  padding: 4px 8px; border-radius: 999px;
}
.kpi .kpi-trend.up   { color: #047857; background: #d1fae5; }
.kpi .kpi-trend.down { color: #be123c; background: #ffe4e6; }

/* ===== Badge ===== */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.01em;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 999px; background: currentColor; opacity: .9; }
.badge-success { color: #047857; background: #d1fae5; }
.badge-warn    { color: #92400e; background: #fef3c7; }
.badge-danger  { color: #be123c; background: #ffe4e6; }
.badge-info    { color: #1d4ed8; background: #dbeafe; }
.badge-brand   { color: #5b21b6; background: #ede9fe; }
.badge-muted   { color: #475569; background: #e2e8f0; }

/* ===== Tabela ===== */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}
.table thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64748b;
  padding: 12px 16px;
  background: #faf9ff;
  border-bottom: 1px solid var(--border);
}
.table thead th:first-child { border-top-left-radius: 12px; }
.table thead th:last-child  { border-top-right-radius: 12px; }
.table tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr { transition: background .2s ease; }
.table tbody tr:hover { background: #fbfaff; }
.table tbody tr:last-child td { border-bottom: 0; }

/* ===== Avatar ===== */
.avatar-circle {
  width: 36px; height: 36px;
  border-radius: 999px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 12.5px; color: #fff;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

/* ===== Tabs (abas estilo software original, mas modernas) ===== */
.tabs {
  display: flex;
  gap: 4px;
  background: #f4f3fb;
  padding: 5px;
  border-radius: 14px;
  border: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  white-space: nowrap;
  transition: all .25s ease;
  border: 0; background: transparent;
}
.tab svg { width: 15px; height: 15px; }
.tab:hover { color: var(--brand-700); background: rgba(255,255,255,0.6); }
.tab.active {
  background: #fff;
  color: var(--brand-700);
  box-shadow: 0 4px 12px -6px rgba(76, 29, 149, 0.25), 0 0 0 1px var(--border);
}

/* ===== Form fields (estilo cadastro) ===== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 11.5px;
  font-weight: 600;
  color: #64748b;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.field .input,
.field input,
.field select,
.field textarea {
  width: 100%;
  background: #fbfaff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  color: #0f172a;
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
  font-family: inherit;
}
.field .input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brand-400);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(124, 77, 255, 0.10);
}
.field .input.readonly,
.field input.readonly {
  background: #f1f0fa; color: #475569; font-family: 'JetBrains Mono', monospace;
}
.field .hint { font-size: 11px; color: #94a3b8; }

/* Realce campos obrigatórios "verdes" - homenagem ao app original */
.field.required .input,
.field.required input,
.field.required select {
  background: #ecfdf5;
  border-color: #a7f3d0;
}
.field.required .input:focus,
.field.required input:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.15);
}

/* Campos sensíveis Supabase (mascarados até clicar no ícone) */
textarea.saas-secret-field:not(.saas-secret-visible) {
  -webkit-text-security: disc;
}
textarea.saas-secret-field.saas-secret-visible {
  -webkit-text-security: none;
}
@supports not (-webkit-text-security: disc) {
  textarea.saas-secret-field:not(.saas-secret-visible) {
    filter: blur(8px);
    user-select: none;
  }
  textarea.saas-secret-field.saas-secret-visible {
    filter: none;
    user-select: text;
  }
}
.icon-btn.saas-secret-eye {
  width: 32px;
  height: 32px;
  border-radius: 10px;
}

/* ===== Animações ===== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.view-fade > * { animation: fadeUp .35s ease both; }
.view-fade > *:nth-child(1) { animation-delay: .02s; }
.view-fade > *:nth-child(2) { animation-delay: .06s; }
.view-fade > *:nth-child(3) { animation-delay: .10s; }
.view-fade > *:nth-child(4) { animation-delay: .14s; }
.view-fade > *:nth-child(5) { animation-delay: .18s; }

@keyframes pulseSoft {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}
.pulse { animation: pulseSoft 1.8s ease-in-out infinite; }

/* ===== Toast ===== */
.toast {
  display: flex; align-items: center; gap: 12px;
  background: #fff;
  padding: 12px 16px 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 24px 48px -20px rgba(15, 23, 42, 0.30);
  min-width: 280px;
  animation: fadeUp .35s ease both;
}
.toast .ic {
  width: 32px; height: 32px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: #d1fae5; color: #047857;
}
.toast strong { display: block; font-size: 13px; color: #0f172a; }
.toast span   { font-size: 12px; color: #64748b; }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
  animation: fadeUp .2s ease both;
}
.modal {
  width: min(560px, 92vw);
  background: #fff;
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 30px 60px -20px rgba(15, 23, 42, 0.4);
  animation: fadeUp .25s ease both;
}

/* ===== Etapa de listagem - itens ricos ===== */
.list-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  transition: all .2s ease;
}
.list-row:hover {
  border-color: var(--brand-200);
  box-shadow: var(--shadow-card);
  transform: translateY(-1px);
}

/* ===== Quick action chip ===== */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: #f4f3fb;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  color: #475569;
  cursor: pointer;
  transition: all .2s ease;
}
.chip:hover { color: var(--brand-700); border-color: var(--brand-200); background: var(--brand-50); }
.chip.active {
  color: #fff;
  background: linear-gradient(135deg, var(--brand-600), var(--brand-500));
  border-color: transparent;
}
.chip svg { width: 14px; height: 14px; }

/* Linha decorativa lateral verde (homenagem ao app original) */
.deco-stripe {
  position: relative;
}
.deco-stripe::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 4px;
  border-radius: 4px;
  background: linear-gradient(180deg, #34d399 0%, #7c4dff 100%);
  opacity: .9;
}

/* Switch */
.switch {
  position: relative;
  width: 38px; height: 22px;
  background: #e2e8f0;
  border-radius: 999px;
  cursor: pointer;
  transition: background .25s ease;
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 999px;
  transition: transform .25s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
.switch.on { background: linear-gradient(135deg, #7c4dff, #6d28d9); }
.switch.on::after { transform: translateX(16px); }

/* Util */
.divider { height: 1px; background: var(--border); width: 100%; }
.dot-sep { width: 4px; height: 4px; background: #cbd5e1; border-radius: 999px; display: inline-block; }

/* Charts container ajuste */
.apexcharts-tooltip {
  border-radius: 12px !important;
  box-shadow: 0 14px 30px -10px rgba(15, 23, 42, 0.25) !important;
  border: 1px solid var(--border) !important;
}
.apexcharts-tooltip-title {
  background: #faf9ff !important;
  border-bottom: 1px solid var(--border) !important;
  font-weight: 700 !important;
}

/* Overlay do menu mobile (escondido por padrão) */
.sidebar-overlay { display: none; }

/* Responsivo */
@media (max-width: 980px) {
  /* Sidebar vira painel deslizante (off-canvas) em vez de sumir */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 280px;
    max-width: 86vw;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.6);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }

  /* Fundo escuro clicável quando o menu está aberto */
  body.sidebar-open .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(2, 6, 23, 0.55);
    backdrop-filter: blur(1px);
  }

  /* Conteúdo ocupa a largura toda no mobile */
  #view { padding-left: 16px !important; padding-right: 16px !important; }
}
