/**
 * rail.css — Rail lateral unificado + shell + paleta de comandos (Ctrl+K)
 * Usa os tokens de app.css (--bg, --surface-solid, --border, --accent, ...).
 * Colapsado: só ícones (64px). Expandido: 232px. Estado em localStorage.
 */

/* ── Shell (só nas páginas com rail: .app-shell.has-rail) ─────────────────── */
.app-shell.has-rail {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.app-shell.has-rail > .app-content {
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Páginas full-height existentes passam a ocupar o app-content, não a viewport */
.has-rail .mod-shell,
.has-rail .dashboard-page {
  height: 100%;
}

/* Launcher de módulos e estados vazios rolam dentro do app-content */
.has-rail #module-launcher,
.has-rail #no-modules-msg {
  height: 100%;
  overflow-y: auto;
}

/* ── Rail ─────────────────────────────────────────────────────────────────── */
.rail {
  --rail-w: 232px;
  --rail-w-collapsed: 64px;
  width: var(--rail-w);
  flex-shrink: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface-solid);
  border-right: 1px solid var(--border);
  padding: 14px 10px 12px;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 300;
}

.rail.collapsed {
  width: var(--rail-w-collapsed);
}

/* ── Marca ────────────────────────────────────────────────────────────────── */
.rail-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  margin-bottom: 14px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  min-height: 44px;
}

.rail-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rail-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 2px;
}

.rail-brand-text {
  min-width: 0;
  overflow: hidden;
}

.rail-brand-name {
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rail-brand-sub {
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ── Labels de seção ──────────────────────────────────────────────────────── */
.rail-section-label {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 10px;
  margin: 6px 0 6px;
  white-space: nowrap;
  overflow: hidden;
}

/* ── Itens ────────────────────────────────────────────────────────────────── */
.rail-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  transition: background 0.16s ease, color 0.16s ease;
  margin-bottom: 2px;
  position: relative;
  white-space: nowrap;
}

.rail-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.rail-item-label {
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.rail-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.rail-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.rail-item.active {
  background: hsla(213, 100%, 68%, 0.12);
  color: var(--accent);
  font-weight: 600;
}

html.light-mode .rail-item.active {
  background: hsla(213, 88%, 52%, 0.10);
}

.rail-item.active::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 22%;
  bottom: 22%;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

/* ── Rodapé ───────────────────────────────────────────────────────────────── */
.rail-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* Links legais no rodapé do rail (LGPD: sempre a um clique) */
.rail-legal {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  padding: 8px 10px 2px;
  font-size: 0.66rem;
  color: var(--muted);
  white-space: nowrap;
}
.rail-legal a {
  color: var(--muted);
  text-decoration: none;
  border-radius: 4px;
}
.rail-legal a:hover { color: var(--text); text-decoration: underline; }
.rail-legal a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.rail-brand:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.rail-kbd {
  font-family: inherit;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  margin-left: auto;
  white-space: nowrap;
}

/* ── Estado colapsado: esconde textos, centraliza ícones ──────────────────── */
.rail.collapsed .rail-brand-text,
.rail.collapsed .rail-item-label,
.rail.collapsed .rail-section-label,
.rail.collapsed .rail-legal {
  display: none;
}

.rail.collapsed .rail-brand {
  justify-content: center;
  padding: 6px 0;
}

.rail.collapsed .rail-item {
  justify-content: center;
  padding: 10px 0;
}

.rail.collapsed .rail-collapse-btn svg {
  transform: rotate(180deg);
}

/* ── Responsivo: colapsa sozinho abaixo de 768px ──────────────────────────── */
/* O botão "Recolher" some porque aqui a largura é imposta pelo CSS, não pela
   preferência do usuário — expandir num celular cobriria o conteúdo. */
@media (max-width: 768px) {
  .rail {
    width: var(--rail-w-collapsed);
    padding-left: 6px;
    padding-right: 6px;
  }
  .rail .rail-brand-text,
  .rail .rail-item-label,
  .rail .rail-section-label,
  .rail .rail-legal {
    display: none;
  }
  .rail .rail-brand { justify-content: center; padding: 6px 0; }
  .rail .rail-item  { justify-content: center; padding: 10px 0; }
  .rail-collapse-btn { display: none; }
  /* O conteúdo nunca rola na horizontal: o que não cabe quebra linha. */
  .app-shell.has-rail > .app-content { overflow-x: hidden; }
}

/* ── Wordmark AskIAData (login, telas de auth) ──────────────────────────── */
.brand-wordmark {
  font-family: 'Sora', 'Inter', sans-serif;
  font-weight: 700;
  font-size: 1.9rem;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--text);
}

.brand-wordmark .bw-ia {
  color: var(--accent);
}

/* ── Paleta de comandos (Ctrl+K) ──────────────────────────────────────────── */
.cmdk-overlay {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 14vh;
}

.cmdk-overlay[hidden] { display: none; }

.cmdk-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

html.light-mode .cmdk-backdrop {
  background: rgba(15, 23, 42, 0.30);
}

.cmdk-panel {
  position: relative;
  width: min(560px, 92vw);
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: cmdkIn 0.16s ease-out both;
}

@keyframes cmdkIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.cmdk-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.cmdk-input-row svg {
  width: 17px;
  height: 17px;
  color: var(--muted);
  flex-shrink: 0;
}

.cmdk-input-row input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0;
  font-size: 0.95rem;
  color: var(--text);
  border-radius: 0;
}

.cmdk-input-row input:focus {
  outline: none;
  box-shadow: none;
  border: none;
  background: transparent;
}

.cmdk-list {
  overflow-y: auto;
  padding: 8px;
}

.cmdk-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  text-align: left;
}

.cmdk-item svg {
  width: 16px;
  height: 16px;
  color: var(--muted);
  flex-shrink: 0;
}

.cmdk-item .cmdk-item-hint {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
}

.cmdk-item:hover,
.cmdk-item.selected {
  background: var(--surface-hover);
}

.cmdk-item.selected {
  box-shadow: inset 2px 0 0 var(--accent);
}

.cmdk-empty {
  padding: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}
