/* =============================================================================
   Criative Links · Layout
   App shell com sidebar (fixa no desktop, compacta no tablet, gaveta no mobile),
   layout de autenticacao, filtros, formularios e tabelas que viram cards.
   ============================================================================= */

:root {
  --sidebar-w: 240px;
  --sidebar-w-compact: 72px;
}

/* ---- Shell do painel ---- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-3);
  background: var(--background);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  color: var(--foreground);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 17px;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
}

.brand .dot {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  background: var(--primary);
  flex: 0 0 auto;
}

.navlist {
  display: flex;
  flex-direction: column;
  gap: 2px;
  list-style: none;
}

.navgroup-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  padding: var(--space-2) 10px 4px;
}

.navitem {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--muted-foreground);
  font-family: var(--font-sans);
  font-size: 13px;
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
}

.navitem .icon {
  font-size: 16px;
  width: 16px;
}

.navitem:hover {
  background: var(--accent);
  color: var(--foreground);
  text-decoration: none;
}

.navitem[aria-current="page"] {
  background: var(--secondary);
  color: var(--foreground);
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  min-width: 0;
}

.sidebar-user .who {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-user .who strong {
  font-weight: 500;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user .who span {
  font-size: 12px;
  color: var(--muted-foreground);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-foot form {
  display: contents;
}

/* Botao de tema: mostra o icone da acao disponivel (sol no escuro, lua no claro) */
.theme-toggle .icon-moon {
  display: none;
}

[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}

[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}

.app-main {
  margin-left: var(--sidebar-w);
  min-width: 0;
}

.content {
  max-width: 1240px;
  margin: 0 auto;
  padding: var(--space-6);
}

.mobilebar {
  display: none;
}

.scrim {
  display: none;
}

/* Tablet: sidebar compacta (so icones) */
@media (min-width: 768px) and (max-width: 1099px) {
  .sidebar {
    width: var(--sidebar-w-compact);
    padding-inline: var(--space-2);
    align-items: stretch;
  }

  .sidebar .label,
  .sidebar .navgroup-label,
  .sidebar .who {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .sidebar .brand,
  .sidebar .navitem,
  .sidebar-user {
    justify-content: center;
  }

  .sidebar .navitem .icon {
    font-size: 18px;
    width: 18px;
  }

  .app-main {
    margin-left: var(--sidebar-w-compact);
  }
}

/* Mobile: gaveta */
@media (max-width: 767px) {
  .sidebar {
    width: min(280px, 86vw);
    transform: translateX(-100%);
    visibility: hidden;
  }

  .nav-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    box-shadow: var(--shadow-dialog);
  }

  .nav-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(0, 0, 0, 0.55);
  }

  .app-main {
    margin-left: 0;
  }

  .mobilebar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--background);
    border-bottom: 1px solid var(--border);
  }

  .content {
    padding: var(--space-4);
  }
}

@media (max-width: 767px) and (prefers-reduced-motion: no-preference) {
  .sidebar {
    transition: transform 0.2s ease, visibility 0.2s;
  }
}

/* ---- Layout de autenticacao / paginas publicas ---- */
.auth {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
  padding: var(--space-6) var(--space-4);
}

.auth-top {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
}

.auth-card {
  width: 100%;
  max-width: 400px;
}

.auth-card.wide {
  max-width: 680px;
}

.auth-card .brand {
  padding-left: 0;
  margin-bottom: var(--space-6);
}

.auth-card h1 {
  font-size: var(--text-display);
  line-height: var(--leading-display);
}

.auth-card .lead {
  color: var(--muted-foreground);
  margin: 4px 0 var(--space-6);
}

.auth-foot {
  color: var(--muted-foreground);
  font-size: 12px;
}

/* ---- Filtros ---- */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--space-3);
  align-items: end;
  margin-bottom: var(--space-4);
}

.filters .grow {
  grid-column: span 2;
}

.filters-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.filters-toggle-cell {
  display: none;
}

@media (max-width: 767px) {
  .js .filters-toggle-cell {
    display: block;
  }

  .filters .grow {
    grid-column: 1 / -1;
  }

  .filters.is-collapsed > .field:not(.grow) {
    display: none;
  }

  .filters.is-collapsed .filters-actions .btn-ghost {
    display: none;
  }
}

.results-summary {
  color: var(--muted-foreground);
  font-size: 12px;
  margin-bottom: var(--space-3);
}

/* ---- Formularios ---- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4) var(--space-6);
  align-items: start;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.form-section {
  grid-column: 1 / -1;
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

.form-grid > .form-section:first-of-type {
  padding-top: 0;
  border-top: 0;
}

.form-section h2 {
  font-size: var(--text-title);
  line-height: var(--leading-title);
}

.form-section p {
  color: var(--muted-foreground);
  font-size: 13px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.form-narrow {
  max-width: 460px;
}

.form-medium {
  max-width: 820px;
}

.inline-form {
  display: inline;
}

@media (max-width: 760px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

}

/* ---- Tabelas que viram cards (cada celula traz data-label) ---- */
.table-stack td.actions {
  text-align: right;
}

@media (max-width: 1000px) {
  .table-stack {
    display: block;
  }

  .table-stack thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .table-stack tbody,
  .table-stack tr,
  .table-stack td {
    display: block;
  }

  .table-stack tr {
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border);
  }

  .table-stack tbody tr:last-child {
    border-bottom: 0;
  }

  .table-stack td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-4);
    padding: 4px 0;
    border: 0;
    text-align: right;
    min-width: 0;
  }

  .table-stack td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted-foreground);
  }

  .table-stack td > * {
    min-width: 0;
  }

  .table-stack .cell-main {
    align-items: flex-end;
  }

  .table-stack td.actions {
    justify-content: flex-end;
    padding-top: var(--space-2);
  }

  .table-stack td.actions::before {
    content: none;
  }

  .table-stack .trunc {
    max-width: 62vw;
  }
}

@media (max-width: 1279px) {
  .table-stack-wide {
    display: block;
  }

  .table-stack-wide thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .table-stack-wide tbody,
  .table-stack-wide tr,
  .table-stack-wide td {
    display: block;
  }

  .table-stack-wide tr {
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border);
  }

  .table-stack-wide tbody tr:last-child {
    border-bottom: 0;
  }

  .table-stack-wide td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-4);
    padding: 4px 0;
    border: 0;
    text-align: right;
    min-width: 0;
  }

  .table-stack-wide td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted-foreground);
  }

  .table-stack-wide td > * {
    min-width: 0;
  }

  .table-stack-wide .cell-main {
    align-items: flex-end;
  }

  .table-stack-wide td.actions {
    justify-content: flex-end;
    padding-top: var(--space-2);
  }

  .table-stack-wide td.actions::before {
    content: none;
  }

  .table-stack-wide .trunc {
    max-width: 62vw;
  }
}

/* Tablet: os cards das tabelas empilhadas ficam em duas colunas */
@media (min-width: 768px) and (max-width: 1279px) {
  .table-stack-wide tbody {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
  }

  .table-stack-wide tbody tr,
  .table-stack-wide tbody tr:last-child {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-3) var(--space-4);
  }
}

@media (min-width: 768px) and (max-width: 1000px) {
  .table-stack tbody {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
  }

  .table-stack tbody tr,
  .table-stack tbody tr:last-child {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-3) var(--space-4);
  }
}

/* Em cards o menu de acoes abre para cima (a acao fica no rodape do card) */
@media (max-width: 1279px) {
  .table-stack-wide .menu {
    top: auto;
    bottom: calc(100% + 4px);
  }
}

@media (max-width: 1000px) {
  .table-stack .menu {
    top: auto;
    bottom: calc(100% + 4px);
  }
}
