/* ==========================================================================
   Orquestrador de Alertas — UI admin
   Layout: topbar + sidebar (stepper) + conteúdo + painel de logs recolhível.
   Tema escuro slate/azul via tokens em :root.
   ========================================================================== */
:root {
  --bg: #0b1120;
  --bg-2: #0f172a;
  --surface: #111a2e;
  --surface-2: #0b1424;
  --surface-3: #16213a;
  --border: #1f2a44;
  --border-strong: #2b3a5c;
  --text: #e6edf7;
  --text-soft: #c2cde0;
  --muted: #8b98b5;
  --accent: #3b82f6;
  --accent-strong: #2563eb;
  --accent-soft: #93c5fd;
  --accent-bg: rgba(59, 130, 246, 0.12);
  --success: #22c55e;
  --danger: #ef4444;
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.45);
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 68px;
  --sidebar-w: 268px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ----------------------------------------------------------------- Topbar -- */
.page-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 24px;
  background: linear-gradient(180deg, #0f1c34, #0c1526);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 20px;
  border-radius: 10px;
  background: var(--accent-bg);
  border: 1px solid var(--border-strong);
}

.brand-text h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: 0.2px; }
.brand-text p { margin: 0; font-size: 12.5px; color: var(--muted); }

/* -------------------------------------------------------------- Login view -- */
.auth-screen {
  min-height: calc(100vh - var(--header-h));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-screen .card {
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow);
}

.auth-hidden { display: none !important; }

/* ------------------------------------------------------------- App layout -- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: calc(100vh - var(--header-h));
}

/* Sidebar / stepper --------------------------------------------------------- */
.sidebar {
  position: sticky;
  top: var(--header-h);
  align-self: start;
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 14px;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
}

.sidebar-title {
  margin: 4px 10px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.tabs { display: flex; flex-direction: column; gap: 4px; }

.tab {
  position: relative;
  text-align: left;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-soft);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.tab:hover:not(:disabled):not(.disabled) {
  background: var(--surface-3);
  color: var(--text);
}

.tab.active {
  background: var(--accent-bg);
  color: #fff;
  border-color: var(--border-strong);
}

.tab.active::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.tab.disabled,
.tab:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.sidebar-logout { margin-top: auto; }

/* Content area -------------------------------------------------------------- */
.content {
  min-width: 0;
  padding: 28px 32px 40px;
}

.tab-content { display: none; flex-direction: column; gap: 18px; max-width: 1080px; }
.tab-content.active { display: flex; }

.tab-content > h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: 0.2px;
}

/* Texto de ajuda / lead — mais didático */
.tab-content > .hint {
  margin: -6px 0 4px;
  padding: 12px 14px;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--accent-bg);
  color: var(--text-soft);
  font-size: 13.5px;
}

.hint { margin: 0; color: var(--muted); font-size: 12.5px; }

/* Cards --------------------------------------------------------------------- */
.card {
  background: var(--surface);
  padding: 22px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.card h2 { margin: 0 0 10px; font-size: 18px; }
.card h3 { margin: 0 0 12px; font-size: 15px; color: var(--text); font-weight: 600; }

/* Forms --------------------------------------------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
}

label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding-top: 22px;
}

input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder, textarea::placeholder { color: #5b6a88; }

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

input.is-readonly {
  background: var(--surface-3);
  color: var(--muted);
  cursor: not-allowed;
}

textarea { font-family: "Cascadia Code", "Courier New", monospace; resize: vertical; }
select[multiple] { min-height: 130px; }

/* Buttons ------------------------------------------------------------------- */
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.step-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 4px;
}

button {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 13.5px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
button:active { transform: translateY(1px); }

button.primary { background: var(--accent-strong); color: #fff; }
button.primary:hover { background: var(--accent); }

button.ghost {
  background: transparent;
  color: var(--accent-soft);
  border: 1px solid var(--border-strong);
}
button.ghost:hover { border-color: var(--accent); color: #fff; }

button + button { margin-left: 0; }

/* Toast --------------------------------------------------------------------- */
.ui-toast {
  position: fixed;
  right: 24px;
  bottom: 72px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-3);
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 999;
}
.ui-toast.show { opacity: 1; transform: translateY(0); }
.hidden { display: none !important; }

/* Logs panel (recolhível no rodapé) ---------------------------------------- */
.logs-panel {
  grid-column: 1 / -1;
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
}

.logs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
}

.logs-toggle {
  background: transparent;
  border: none;
  color: var(--text-soft);
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
}
.logs-toggle .chev { display: inline-block; transition: transform 0.15s ease; color: var(--muted); }
.logs-panel:not(.collapsed) .logs-toggle .chev { transform: rotate(90deg); }

.logs-body { padding: 0 16px 14px; }
.logs-panel.collapsed .logs-body { display: none; }

pre#output, textarea#output {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 14px;
  border-radius: var(--radius-sm);
  overflow: auto;
  width: 100%;
  font-family: "Cascadia Code", "Courier New", monospace;
  font-size: 12.5px;
  line-height: 1.4;
  white-space: pre;
  min-height: 200px;
  height: clamp(200px, 30vh, 480px);
  resize: vertical;
}

textarea#adminTokensOutput {
  width: 100%;
  min-height: 300px;
  height: clamp(300px, 42vh, 720px);
  resize: vertical;
  white-space: pre;
  overflow: auto;
  line-height: 1.4;
}

/* Resultado de cadastro ----------------------------------------------------- */
.result-mount:empty { display: none; }
.result-mount { margin-top: 16px; }

.result-card {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  padding: 14px 16px;
}
.result-card.success { border-color: rgba(34, 197, 94, 0.5); background: rgba(34, 197, 94, 0.08); }
.result-title { font-weight: 600; color: var(--success); margin-bottom: 8px; }
.result-row { display: flex; gap: 12px; padding: 3px 0; font-size: 13px; }
.result-key { min-width: 130px; color: var(--muted); }
.result-val { color: var(--text); word-break: break-all; }

/* Banner de edição ---------------------------------------------------------- */
.edit-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-bg);
  border: 1px solid var(--border-strong);
  color: var(--text-soft);
  font-size: 13px;
}
.edit-banner .edit-id { font-weight: 700; color: #fff; }

/* Checklist de contatos (seleção de membros do grupo) ----------------------- */
.checklist {
  margin: 6px 0 4px;
  max-height: 240px;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.checklist > .hint { padding: 10px; }
.check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-soft);
  transition: background 0.12s ease;
}
.check-item:hover { background: var(--accent-bg); }
.check-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex: 0 0 auto;
}

/* Tabela de registros ------------------------------------------------------- */
.entity-mount { margin-top: 4px; }
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.entity-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.entity-table th, .entity-table td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.entity-table thead th {
  background: var(--surface-3);
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.entity-table tbody tr:last-child td { border-bottom: none; }
.entity-table tbody tr:hover { background: var(--surface-3); }
.row-actions { display: flex; gap: 6px; }

button.mini {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--accent-soft);
}
button.mini:hover { border-color: var(--accent); color: #fff; }

/* Responsivo ---------------------------------------------------------------- */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-title { display: none; }
  .tabs { flex-direction: row; }
  .tab { white-space: nowrap; }
  .tab.active::before { display: none; }
  .sidebar-logout { margin-top: 0; }
  .content { padding: 20px 16px 32px; }
}

@media (max-width: 640px) {
  .page-header { padding: 0 16px; }
  .brand-text h1 { font-size: 15px; }
}
