:root {
  --navy: #14213a;
  --amber: #f2a93b;
  --teal: #14a38b;
  --coral: #ff6b5a;
  --cream: #fbf6ee;
  --bg: #f4f1ea;
  --card: #ffffff;
  --line: #e4ddd0;
  --text: #1d2433;
  --muted: #6b7285;
  --radius: 10px;
  font-family: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
code { background: #f1ece2; padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: #c0392b; margin: 0; }
[hidden] { display: none !important; }

/* ---------- botões e inputs ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--navy); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #22345a; }
.btn.danger { color: #c0392b; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.ghost { background: transparent; }
button.link { background: none; border: 0; color: inherit; font: inherit; cursor: pointer; padding: 0; }
input, select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--amber); outline-offset: -1px; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; background: var(--navy); }
.login-card {
  background: var(--cream); padding: 32px; border-radius: 14px; width: min(360px, 92vw);
  display: grid; gap: 14px;
}
.login-card h1 { margin: 0; font-size: 1.5rem; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }

/* ---------- topo ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 56px;
  background: var(--navy); color: #fff;
}
.brand { font-size: 1.1rem; }
.brand span { color: var(--amber); font-weight: 500; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs button {
  background: none; border: 0; color: #c9d1e2; font: inherit; font-weight: 600; padding: 8px 14px;
  border-radius: 8px; cursor: pointer;
}
.tabs button.active, .tabs button:hover { background: rgba(255,255,255,.1); color: #fff; }
.topbar-links { display: flex; gap: 16px; font-size: .9rem; }
.topbar-links a { color: #c9d1e2; text-decoration: none; }
.topbar-links a:hover { color: #fff; }

/* ---------- páginas com cards ---------- */
.view { padding: 24px; max-width: 1200px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.card h2 { margin: 0 0 12px; font-size: 1.15rem; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.actions .btn { margin-left: 4px; }
.table.dns td:nth-child(3) { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; word-break: break-all; }
.tag { display: inline-block; background: #eef6f4; color: var(--teal); border-radius: 999px; padding: 1px 8px; font-size: .8rem; margin: 1px 2px; }
.tag.live { background: #fff3df; color: #a76500; font-weight: 700; }
.tag.warn { background: #ffe9e6; color: #c0392b; }

/* ---------- limites e uso das caixas ---------- */
.limits { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 14px; }
.limit-tile { display: grid; gap: 4px; align-content: start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--cream); }
.limit-tile > strong { font-size: 1.35rem; color: var(--navy); }
.limit-tile.wide { grid-column: span 2; }
.usage-col { width: 34%; }
.usage { display: grid; gap: 4px; font-size: .85rem; }
.usage em { color: var(--muted); }
.bar { height: 10px; border-radius: 999px; background: #ece6da; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: inherit; transition: width .4s; }
.bar.ok span { background: var(--teal); }
.bar.warn span { background: var(--amber); }
.bar.crit span { background: var(--coral); }
@media (max-width: 700px) { .limit-tile.wide { grid-column: auto; } }

/* ---------- editor ---------- */
.view.editor {
  max-width: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: 400px 1fr; height: calc(100vh - 56px);
}
.chat { display: flex; flex-direction: column; background: var(--cream); border-right: 1px solid var(--line); min-height: 0; }
.chat-head { display: flex; gap: 6px; padding: 12px; border-bottom: 1px solid var(--line); }
.chat-head select { flex: 1; min-width: 0; }
.ai-warning { margin: 12px; padding: 10px; border-radius: 8px; background: #fff3df; font-size: .85rem; }
.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 10px 12px; border-radius: 12px; line-height: 1.4; white-space: pre-wrap; font-size: .92rem; }
.msg.user { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.error { align-self: stretch; background: #ffe9e6; color: #8a2a1f; font-size: .85rem; }
.msg.pending { align-self: flex-start; background: #fff; border: 1px dashed var(--line); color: var(--muted); }
.version-chip {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; padding: 6px 8px;
  border-radius: 8px; background: #f5f1e8; font-size: .8rem; white-space: normal; cursor: pointer; border: 2px solid transparent;
}
.version-chip.selected { border-color: var(--amber); background: #fff7e8; }
.version-chip .files { color: var(--muted); }
.empty-chat { color: var(--muted); text-align: center; margin: auto 20px; font-size: .92rem; line-height: 1.5; }
.composer { border-top: 1px solid var(--line); padding: 12px; display: grid; gap: 8px; }
.composer textarea { resize: vertical; min-height: 64px; }
.composer-row { display: flex; justify-content: space-between; align-items: center; }
.base-info { font-size: .8rem; color: var(--muted); }

.preview { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.preview-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fff;
}
.preview-title { display: flex; gap: 8px; align-items: center; min-width: 0; }
.preview-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: #eef6f4; color: var(--teal); font-weight: 700; }
.badge.draft { background: #fff3df; color: #a76500; }
.badge.warn { background: #ffe9e6; color: #c0392b; }
.preview-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 5px 10px; font: inherit; font-size: .82rem; cursor: pointer; }
.seg button.active { background: var(--navy); color: #fff; }
.frame-wrap { flex: 1; overflow: auto; background: #e9e4d9; display: flex; justify-content: center; }
.frame-wrap iframe { width: 100%; height: 100%; border: 0; background: #fff; transition: width .2s; }

/* ---------- diff / toast ---------- */
dialog { width: min(1000px, 94vw); max-height: 86vh; border: 0; border-radius: 12px; padding: 0; }
dialog::backdrop { background: rgba(20, 33, 58, .5); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.diff { margin: 0; padding: 12px 16px; overflow: auto; max-height: calc(86vh - 56px); font-size: .78rem; line-height: 1.45; }
.diff .add { background: #e6f7ef; color: #0f6b4b; display: block; }
.diff .del { background: #fdecea; color: #a1281b; display: block; }
.diff .hunk { color: #6b5bd2; display: block; }
.diff .file { font-weight: 700; display: block; margin-top: 8px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff;
  padding: 10px 18px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.2); z-index: 10; max-width: 90vw;
}
.toast.err { background: #c0392b; }

@media (max-width: 900px) {
  .view.editor { grid-template-columns: 1fr; grid-template-rows: 50vh 1fr; height: auto; min-height: calc(100vh - 56px); }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .view.editor { min-height: calc(100vh - 100px); }
}
