:root {
  --purple: #7c3aed;
  --purple-dark: #5b21b6;
  --orange: #f97316;
  --green: #22c55e;
  --red: #ef4444;
  --ink: #2d1b4e;
  --bg: #f6f4fb;
  --border: #e4defa;
  --card: #ffffff;
}

* { box-sizing: border-box; }

/* .login-screen e .app definem `display` explicitamente, o que por regra
   de cascata (mesma especificidade, origem "author") venceria o atributo
   HTML [hidden] do UA stylesheet — então isso precisa ser reafirmado aqui. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* Login */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 320px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(124, 58, 237, 0.08);
}

.login-card h1 {
  margin: 0;
  font-size: 20px;
  color: var(--purple);
}
.login-card h1 span { color: var(--ink); font-weight: 400; }

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
}

.login-card input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.login-card button {
  margin-top: 8px;
  background: var(--purple);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-weight: 700;
}

.muted { color: #6b6280; font-size: 13px; margin: 0; }
.error { color: var(--red); font-size: 13px; margin: 0; }

/* App shell */

.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: white;
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
}

/* Menu hambúrguer e backdrop: só existem/aparecem no layout mobile (ver
   media query abaixo), onde a sidebar vira um drawer sobreposto em vez de
   ficar sempre visível ao lado do conteúdo. */
.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: none;
  flex-shrink: 0;
}
.menu-toggle span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
}

.sidebar-backdrop {
  display: none;
}

.brand {
  font-weight: 800;
  color: var(--purple);
  padding: 0 8px 16px;
  font-size: 16px;
}
.brand span { color: var(--ink); font-weight: 400; font-size: 12px; }

#nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

#nav a {
  display: block;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
}
#nav a:hover { background: var(--bg); }
#nav a.active { background: var(--purple); color: white; }
#nav .nav-group {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #9b93b5;
  padding: 14px 10px 4px;
}

.link-btn {
  background: none;
  border: none;
  text-align: left;
  padding: 9px 10px;
  color: #9b3b3b;
  font-size: 14px;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: white;
}

.build-status {
  font-size: 13px;
  color: #6b6280;
}
.build-status.success { color: var(--green); }
.build-status.failed { color: var(--red); }
.build-status.running, .build-status.queued { color: var(--orange); }

.btn-primary {
  background: var(--purple);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 700;
  font-size: 13px;
}
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.view {
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  max-width: 900px;
}

.view h2 {
  margin-top: 0;
  color: var(--purple-dark);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}
.field label {
  font-size: 13px;
  font-weight: 600;
}
.field input, .field textarea, .field select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.field textarea { min-height: 100px; resize: vertical; }
.field .hint { font-size: 12px; color: #9b93b5; }

.form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.save-status {
  font-size: 13px;
  color: var(--green);
}

.color-field {
  display: flex;
  align-items: center;
  gap: 10px;
}
.color-field input[type="color"] {
  width: 44px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
}
.color-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: #6b6280;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: 10px;
}

table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: top;
}
th { background: var(--bg); font-size: 12px; text-transform: uppercase; color: #6b6280; }
tr:last-child td { border-bottom: none; }

.row-actions { display: flex; gap: 6px; }
.btn-small {
  border: 1px solid var(--border);
  background: white;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
}
.btn-small.danger { color: var(--red); border-color: #fbd5d5; }

.card-form {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: #6b6280;
}
.badge.active { background: #dcfce7; color: #166534; }

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.media-item {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  font-size: 11px;
}
.media-item img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 6px;
  background: var(--bg);
}
.media-item code {
  display: block;
  word-break: break-all;
  background: var(--bg);
  padding: 2px 4px;
  border-radius: 4px;
  margin: 4px 0;
}

/* Responsividade mobile: a barra lateral fixa de 220px não cabe ao lado do
   conteúdo em telas pequenas. Em vez de virar uma barra horizontal rolável
   (ruim: exigia deslizar para os lados para achar itens), abaixo de 768px
   a sidebar vira um drawer — fica escondida fora da tela por padrão e
   desliza por cima do conteúdo (com um backdrop escurecido atrás) quando o
   botão de menu (☰) na topbar é clicado. */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
  }

  .menu-toggle {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 50;
    width: 260px;
    max-width: 82vw;
    height: 100vh;
    box-shadow: 2px 0 16px rgba(45, 27, 78, 0.18);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    overflow-y: auto;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(45, 27, 78, 0.4);
  }

  .brand {
    padding: 0 8px 16px;
    white-space: nowrap;
  }

  .topbar {
    padding: 10px 14px;
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .view {
    padding: 16px;
    max-width: 100%;
  }

  .card-form {
    padding: 12px;
  }

  .toolbar {
    flex-wrap: wrap;
    gap: 10px;
  }

  .row-actions {
    flex-wrap: wrap;
  }

  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
}

@media (max-width: 480px) {
  .btn-primary {
    padding: 9px 12px;
    font-size: 12px;
  }

  .build-status {
    font-size: 12px;
  }

  table, thead, tbody, th, td, tr {
    font-size: 12px;
  }
}

/* Desktop/telas largas: o teto de 900px sobrava muito espaço em branco à
   direita em monitores wide (a sidebar é fixa em 220px, então o resto da
   largura ficava sem uso). A partir de 1100px, aumenta o teto e centraliza
   melhor o conteúdo; a partir de 1400px, um pouco mais ainda. Não altera
   nenhuma regra de max-width:768px/480px acima, que seguem controlando o
   mobile normalmente. */
@media (min-width: 1100px) {
  .view {
    max-width: 1160px;
  }

  /* Formulários (Configurações, Serviços, etc.): em telas largas, campos
     curtos (texto/cor/número) ficam lado a lado em 2 colunas; campos que
     precisam de mais espaço (textarea, com .field-wide) continuam ocupando
     a largura toda. */
  .card-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 20px;
    align-items: start;
  }

  .card-form .field-wide,
  .card-form .form-actions {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1400px) {
  .view {
    max-width: 1320px;
  }
}
