:root {
  --bg: #0f1115;
  --card: #171a21;
  --card-2: #1d212a;
  --border: #262b36;
  --text: #e8eaf0;
  --muted: #8f97a8;
  --amber: #f0a92b;
  --ok: #37c98a;
  --err: #f0685a;
  --warn: #e3b341;
  --info: #58a6ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ------------------------------------------------------------------ *
 * Card simples — usado pelo template.html (pagina de registro do menu)
 * ------------------------------------------------------------------ */

.card {
  width: 100%;
  max-width: 520px;
  padding: 32px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--amber);
}

h1 { margin: 0 0 8px; font-size: 32px; line-height: 1.2; }

.lead { margin: 0 0 28px; color: var(--muted); }

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.label { font-size: 14px; color: var(--muted); }

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge--loading { background: #2a2f3a; color: var(--muted); }
.badge--ok      { background: rgba(55, 201, 138, 0.14); color: var(--ok); }
.badge--err     { background: rgba(240, 104, 90, 0.14); color: var(--err); }
.badge--warn    { background: rgba(227, 179, 65, 0.14); color: var(--warn); }
.badge--info    { background: rgba(88, 166, 255, 0.14); color: var(--info); }
.badge--muted   { background: #2a2f3a; color: var(--muted); }

.output {
  margin: 0 0 16px;
  padding: 14px;
  max-height: 180px;
  overflow: auto;
  background: #0c0e13;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.btn {
  padding: 9px 16px;
  background: var(--amber);
  color: #1a1205;
  border: 0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn--ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn--ghost:hover { background: var(--card-2); filter: none; }

.btn--danger { background: transparent; color: var(--err); border: 1px solid rgba(240, 104, 90, 0.4); }
.btn--danger:hover { background: rgba(240, 104, 90, 0.1); filter: none; }

.btn--sm { padding: 6px 11px; font-size: 13px; }

.foot {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}

/* ------------------------------------------------------------------ *
 * Aplicacao — index.html (CRUD de templates)
 * ------------------------------------------------------------------ */

.app { width: 100%; max-width: 1100px; align-self: start; }

.app__head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 20px;
}

.app__title h1 { font-size: 26px; margin: 0; }
.app__title p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.app__actions { display: flex; gap: 8px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; color: var(--muted); }

select, input[type="text"], input[type="url"], input[type="number"], textarea {
  padding: 9px 11px;
  background: #0c0e13;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}

textarea { resize: vertical; min-height: 90px; line-height: 1.5; }

select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--amber);
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

@media (max-width: 720px) {
  .toolbar { grid-template-columns: 1fr; }
  .app__head { flex-direction: column; align-items: stretch; }
}

/* Lista de templates */

.tpl-list { display: flex; flex-direction: column; gap: 10px; }

.tpl {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.tpl__main { min-width: 0; flex: 1; }
.tpl__name { font-weight: 600; font-size: 15px; word-break: break-all; }
.tpl__meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tpl__body {
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.tpl__acts { display: flex; gap: 6px; flex-shrink: 0; }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* Modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 12, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.modal[hidden] { display: none; }

.modal__box {
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.modal__head h2 { margin: 0; font-size: 20px; }
.modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Editor — caixa de tamanho fixo, com cabecalho e rodape presos e scroll
   apenas na coluna de conteudo. */

.modal__box--editor {
  width: 60vw;
  height: 90vh;
  max-width: 100%;
  max-height: 100%;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal__box--editor .modal__head {
  flex-shrink: 0;
  margin: 0;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.modal__box--editor .modal__foot {
  flex-shrink: 0;
  margin: 0;
  padding: 16px 22px;
  background: var(--card);
}

.editor-split {
  flex: 1;
  /* Sem o min-height:0 o filho flex nunca encolhe e o overflow-y da coluna
     de conteudo simplesmente nao rola. */
  min-height: 0;
  display: grid;
  grid-template-columns: 300px 1fr;
}

.editor-col { padding: 18px 22px; }

.editor-col--meta {
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.editor-col--content {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

@media (max-width: 900px) {
  .modal__box--editor { width: 100%; height: 100%; }
  .editor-split { grid-template-columns: 1fr; overflow-y: auto; }
  .editor-col--meta { border-right: 0; border-bottom: 1px solid var(--border); }
  .editor-col--content { overflow-y: visible; }
}

.editor { display: flex; flex-direction: column; gap: 16px; }

.editor__row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 620px) { .editor__row { grid-template-columns: 1fr; } }

.block {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  background: var(--card-2);
}

.block__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.block__title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; line-height: 1.5; }
.hint--warn { color: var(--warn); }
.hint--err { color: var(--err); }

.counter { font-size: 12px; color: var(--muted); }
.counter--over { color: var(--err); font-weight: 600; }

.vars { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.var-row { display: grid; grid-template-columns: 92px 1fr; gap: 8px; align-items: center; }
.var-row code { font-size: 12px; color: var(--amber); }

.btn-row {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
@media (max-width: 620px) { .btn-row { grid-template-columns: 1fr; } }

/* Biblioteca de midia */

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.media {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: var(--card-2);
  cursor: pointer;
  text-align: center;
}

.media[aria-selected="true"] { border-color: var(--amber); }
.media img { width: 100%; height: 74px; object-fit: cover; border-radius: 5px; display: block; }
.media__none {
  height: 74px;
  display: grid;
  place-items: center;
  background: #0c0e13;
  border-radius: 5px;
  font-size: 11px;
  color: var(--muted);
}
.media__name {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media__url {
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
  margin-top: 8px;
  line-height: 1.4;
}

/* Toast — usado so fora do AmberChat; dentro dele usamos o alert nativo */

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Acima de qualquer pilha de modais: o toast e feedback e nunca pode ficar
     escondido atras de um modal aberto por cima de outro. */
  z-index: 1000;
  max-width: 360px;
}

.toast {
  padding: 11px 14px;
  border-radius: 9px;
  font-size: 14px;
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  line-height: 1.45;
}

.toast--success { border-color: rgba(55, 201, 138, 0.45); }
.toast--error   { border-color: rgba(240, 104, 90, 0.45); }
.toast--warning { border-color: rgba(227, 179, 65, 0.45); }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.spacer { flex: 1; }
