/* ============================================================
   CMS Editor — Estética Editorial Monocromática com Âmbar
   Fontes: sistema tipográfico refinado sem CDN externo
   ============================================================ */

/* --- Variáveis -------------------------------------------- */
:root {
  --bg:           #0e0d0b;
  --surface:      #161410;
  --surface-2:    #1e1b16;
  --surface-3:    #262119;
  --border:       #2e2a22;
  --border-soft:  #231f18;
  --text:         #e8e0cc;
  --text-muted:   #7a6e58;
  --text-faint:   #3d3828;
  --accent:       #c8920a;
  --accent-dim:   #8a640a;
  --accent-glow:  rgba(200, 146, 10, 0.18);
  --accent-line:  rgba(200, 146, 10, 0.35);
  --danger:       #c0392b;
  --danger-dim:   rgba(192, 57, 43, 0.15);
  --success:      #2ecc71;

  --font-ui:      'Gill Sans', 'GillSans', 'Optima', Candara, Calibri, 'Segoe UI', sans-serif;
  --font-serif:   'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, 'Times New Roman', serif;

  --radius:       3px;
  --radius-md:    6px;
  --panel-w:      320px;
  --header-h:     52px;
  --transition:   160ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset ------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* --- Header ----------------------------------------------- */
#header {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  z-index: 100;
  /* subtle top accent line */
  box-shadow: inset 0 2px 0 var(--accent-dim);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.logo-mark {
  color: var(--accent);
  font-size: 10px;
  letter-spacing: 0;
  line-height: 1;
  flex-shrink: 0;
}

.site-name {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 400;
  color: var(--text);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-center {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
}

.unsaved-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-glow);
  border: 1px solid var(--accent-line);
  padding: 3px 10px;
  border-radius: 2px;
  animation: badge-in var(--transition-slow) both;
}

.unsaved-badge[hidden] {
  display: none;
}

.badge-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: badge-pulse 2.4s ease-in-out infinite;
}

@keyframes badge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes badge-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* --- Buttons ---------------------------------------------- */
.btn {
  font-family: var(--font-ui);
  font-size: 12.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    background var(--transition),
    color var(--transition),
    border-color var(--transition),
    opacity var(--transition),
    transform 80ms ease;
  outline: none;
  white-space: nowrap;
}

.btn:active:not(:disabled) { transform: scale(0.97); }

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

.btn-primary {
  background: var(--accent);
  color: #0e0d0b;
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: #d9a012;
  border-color: #d9a012;
}

.btn-primary:disabled {
  background: var(--surface-3);
  border-color: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-soft);
}

.btn-ghost:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* --- Main Layout ------------------------------------------ */
#main {
  position: fixed;
  inset: var(--header-h) 0 0 0;
  display: flex;
  overflow: hidden;
}

/* --- Preview Pane ----------------------------------------- */
#preview-pane {
  flex: 1 1 0;
  position: relative;
  background: var(--bg);
  overflow: hidden;
}

.preview-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  z-index: 5;
  background: var(--bg);
  transition: opacity var(--transition-slow);
}

.preview-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#preview {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #fff;
}

/* --- Divider ---------------------------------------------- */
.pane-divider {
  width: 1px;
  background: var(--border);
  flex-shrink: 0;
  position: relative;
}

.pane-divider::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    var(--accent-dim) 40%,
    var(--accent-dim) 60%,
    transparent 100%
  );
}

/* --- Side Panel ------------------------------------------- */
#side-panel {
  width: var(--panel-w);
  flex-shrink: 0;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Tabs ------------------------------------------------- */
.tabs {
  display: flex;
  position: relative;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface-2);
}

.tab {
  flex: 1;
  padding: 13px 0;
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: color var(--transition);
  outline: none;
  position: relative;
  z-index: 1;
}

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

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); }

.tab-indicator {
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 50%;
  height: 2px;
  background: var(--accent);
  transition: transform var(--transition-slow);
  transform: translateX(0%);
}

.tabs[data-active="chat"] .tab-indicator {
  transform: translateX(100%);
}

/* --- Tab Panels ------------------------------------------- */
.tab-panel {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tab-panel:not(.active) { display: none; }

/* --- Edit Panel ------------------------------------------- */
.edit-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 24px;
  text-align: center;
  color: var(--text-faint);
}

.edit-empty-icon {
  font-size: 28px;
  color: var(--text-faint);
  opacity: 0.5;
}

.edit-empty p {
  font-size: 12px;
  letter-spacing: 0.04em;
  line-height: 1.7;
  color: var(--text-muted);
}

/* --- Edit Form -------------------------------------------- */
.edit-form {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.edit-form::-webkit-scrollbar { width: 4px; }
.edit-form::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.field-label {
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: block;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: field-in 180ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

@keyframes field-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- Inputs ----------------------------------------------- */
textarea,
input[type="text"],
input[type="url"] {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 9px 11px;
  border-radius: var(--radius);
  transition: border-color var(--transition), background var(--transition);
  outline: none;
  resize: vertical;
}

textarea:focus,
input[type="text"]:focus,
input[type="url"]:focus {
  border-color: var(--accent-dim);
  background: var(--surface-3);
}

textarea::placeholder,
input::placeholder {
  color: var(--text-faint);
}

/* --- Image Editor ----------------------------------------- */
.img-preview-wrap {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.img-preview-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.img-preview-empty {
  color: var(--text-faint);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* File input wrapper */
.file-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
}

.file-input-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 11.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  font-weight: 600;
  font-family: var(--font-ui);
  color: var(--text-muted);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
  white-space: nowrap;
}

.file-input-label:hover {
  color: var(--text);
  border-color: var(--accent-dim);
  background: var(--surface-2);
}

.file-input-label input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.file-name-display {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}

/* --- Validation errors ------------------------------------ */
.field-error {
  font-size: 11.5px;
  color: var(--danger);
  background: var(--danger-dim);
  border-left: 2px solid var(--danger);
  padding: 6px 10px;
  border-radius: 0 var(--radius) var(--radius) 0;
  animation: field-in 120ms both;
}

/* --- Apply Button ----------------------------------------- */
.btn-apply {
  width: 100%;
  margin-top: 4px;
  padding: 9px;
  font-size: 11.5px;
}

/* --- Separator -------------------------------------------- */
.field-sep {
  border: none;
  border-top: 1px solid var(--border-soft);
  margin: 4px 0;
}

/* --- Slot type badge -------------------------------------- */
.slot-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  background: var(--surface-3);
  border: 1px solid var(--border-soft);
  padding: 2px 7px;
  border-radius: 2px;
  margin-bottom: 12px;
  align-self: flex-start;
}

/* --- Chat Panel ------------------------------------------- */
.chat-disabled {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 24px;
  text-align: center;
}

.chat-disabled[hidden] { display: none; }

.chat-disabled-icon {
  font-size: 24px;
  color: var(--text-faint);
  opacity: 0.6;
}

.chat-disabled p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.7;
}

.chat-disabled code {
  font-size: 11.5px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 2px;
  font-family: 'Consolas', 'Menlo', 'Monaco', monospace;
  color: var(--accent);
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.chat-history::-webkit-scrollbar { width: 4px; }
.chat-history::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Chat bubbles */
.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  animation: field-in 180ms both;
  max-width: 100%;
}

.chat-msg-role {
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding-left: 2px;
}

.chat-msg-role.role-user { color: var(--accent-dim); }
.chat-msg-role.role-assistant { color: var(--text-faint); }

.chat-msg-body {
  font-size: 13px;
  line-height: 1.6;
  padding: 10px 13px;
  border-radius: var(--radius-md);
  word-break: break-word;
}

.chat-msg.msg-user .chat-msg-body {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 2px 8px 8px 8px;
}

.chat-msg.msg-assistant .chat-msg-body {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  color: var(--text);
  border-left: 2px solid var(--accent-dim);
  border-radius: 8px 8px 8px 2px;
}

.chat-msg.msg-notice .chat-msg-body {
  background: var(--danger-dim);
  border: 1px solid rgba(192, 57, 43, 0.25);
  color: #e07060;
  font-size: 11.5px;
  border-radius: var(--radius);
}

.chat-msg.msg-system .chat-msg-body {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-size: 11.5px;
  font-style: italic;
  border-radius: var(--radius);
}

/* Chat typing indicator */
.chat-typing .chat-msg-body {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 12px 16px;
}

.typing-dot {
  width: 4px;
  height: 4px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* Chat form */
.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
  align-items: flex-end;
}

.chat-form.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.chat-input {
  flex: 1;
  resize: none;
  font-size: 13px;
  padding: 8px 11px;
  border-radius: var(--radius-md);
  min-height: 40px;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
}

.btn-send {
  width: 38px;
  height: 38px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  font-size: 16px;
}

.send-arrow { line-height: 1; }

/* --- Slot hover/active in iframe (injected via JS) -------- */
/* These classes are set via inline styles in JS, no CSS needed here */

/* --- Upload progress indicator ---------------------------- */
.upload-progress {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}

.upload-progress .loading-spinner {
  width: 14px;
  height: 14px;
  border-width: 1.5px;
}

/* --- Applied highlight (briefly flashes on iframe element) */
/* Injected inline via JS */

/* --- Scrollbar global ------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Histórico ──────────────────────────────────────────────── */
.historico-lista {
  padding: 0 1rem;
  overflow-y: auto;
  flex: 1;
}

.versao-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .65rem 0;
  border-bottom: 1px solid #f0f0ea;
  font-size: .82rem;
  gap: .5rem;
}

.versao-data {
  color: #555;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-restaurar {
  padding: .28rem .65rem;
  background: transparent;
  border: 1px solid #ccc;
  cursor: pointer;
  font-size: .78rem;
  color: #333;
  flex-shrink: 0;
  white-space: nowrap;
}

.btn-restaurar:hover {
  border-color: #f5a623;
  color: #f5a623;
}

.btn-restaurar:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ── Richtext Editor ─────────────────────────────────────────── */
.rt-toolbar { display: flex; gap: .35rem; margin-bottom: .4rem; }
.rt-btn { width: 30px; height: 30px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; font-weight: 700; }
.rt-btn:hover { border-color: var(--accent); color: var(--accent); }
.rt-box { min-height: 120px; padding: .7rem .8rem; border: 1px solid var(--border); background: #fff; line-height: 1.5; overflow-y: auto; }
.rt-box:focus { outline: none; border-color: var(--accent); }
.rt-box a { color: var(--accent); }

/* ── Toast de publicação ─────────────────────────────────────── */
.publish-toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a1a;
  color: #fff;
  padding: .75rem 1.2rem;
  font-size: .88rem;
  display: flex;
  align-items: center;
  gap: .8rem;
  z-index: 200;
  max-width: 480px;
}

.publish-toast a { color: #f5a623; }
.publish-toast-error { background: #c0392b; }

.publish-toast-close {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 1rem;
  padding: 0;
  flex-shrink: 0;
}
