/* ============================================================
   Estúdio de Carrosséis — folha de estilo original
   ============================================================ */
:root {
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --ink: #1b1d2a;
  --ink-soft: #3a3e55;
  --muted: #8a90a6;
  --line: #e7e8f2;
  --line-strong: #d6d8e6;

  --primary: #6c5ce7;
  --primary-strong: #5746d8;
  --primary-soft: #efeefc;
  --accent: #14b8a6;
  --accent-soft: #e3f9f5;
  --danger: #e5484d;
  --danger-soft: #fdebec;
  --warn: #e8960c;
  --warn-soft: #fdf3e0;
  --ok: #16a34a;
  --ok-soft: #e6f7ec;

  --sidebar-bg: #171a2b;
  --sidebar-ink: #c9cce0;
  --sidebar-active: #6c5ce7;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(20, 22, 40, 0.06);
  --shadow: 0 4px 16px rgba(20, 22, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(20, 22, 40, 0.16);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo,
    monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- primitives ---------- */
h1, h2, h3 { margin: 0 0 0.4em; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
p { margin: 0 0 0.6em; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.mono { font-family: var(--mono); font-size: 12px; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s,
    transform 0.05s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: #c4c7db; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn.primary {
  color: #fff;
  background: linear-gradient(180deg, #7c6cf0, var(--primary));
  border-color: transparent;
  box-shadow: 0 3px 10px rgba(108, 92, 231, 0.28);
}
.btn.primary:hover { background: linear-gradient(180deg, #6a5ae4, var(--primary-strong)); }
.btn.primary:disabled { box-shadow: none; }

.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: rgba(108, 92, 231, 0.08); color: var(--primary); border-color: transparent; }

.btn.danger { color: var(--danger); border-color: #f2c6c9; background: var(--danger-soft); }
.btn.danger:hover { background: #fbdadd; }

.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }

.btn.loading { pointer-events: none; }
.btn .spinner {
  width: 14px; height: 14px; flex: 0 0 auto;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1;
}
.icon-btn:hover { background: rgba(20, 22, 40, 0.06); color: var(--ink); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- forms ---------- */
.form label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.form .grid2 label, .form .grid3 label { margin-top: 8px; }

input, textarea, select {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}
textarea { resize: vertical; min-height: 38px; }
input[type="color"] { padding: 3px; height: 38px; width: 100%; cursor: pointer; }
input[type="checkbox"] { width: auto; accent-color: var(--primary); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; }

.row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.row.grow > * { flex: 1; }

.error { color: var(--danger); font-size: 13px; min-height: 1.2em; margin-top: 8px; }

hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

/* ---------- layout ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}
.logo {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo .mark {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, #7c6cf0, #14b8a6);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px; font-weight: 800;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.ws-select { width: auto; min-width: 160px; max-width: 260px; }

.layout { display: flex; min-height: calc(100vh - 55px); }

.sidebar {
  width: 224px;
  flex: 0 0 auto;
  background: var(--sidebar-bg);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-item {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--sidebar-ink);
  text-align: left;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item .ico { width: 18px; text-align: center; opacity: 0.85; }
.sidebar .side-foot { margin-top: auto; padding: 10px 6px; color: #5c5f7a; font-size: 11.5px; }

.content { flex: 1; min-width: 0; padding: 22px; }

.panel { display: none; max-width: 1080px; margin: 0 auto; }
.panel.active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

/* ---------- auth ---------- */
#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1100px 500px at 15% -10%, rgba(108, 92, 231, 0.16), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(20, 184, 166, 0.14), transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 30px;
  box-shadow: var(--shadow-lg);
}
.auth-card h1 { display: flex; align-items: center; gap: 10px; }
.auth-card h1 .mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #7c6cf0, #14b8a6);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 800;
}
.tabs {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  margin: 16px 0 18px;
}
.tab {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  padding: 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.auth-card .form label { margin-top: 10px; }
.auth-card .form label:first-child { margin-top: 0; }
.auth-card .btn { width: 100%; margin-top: 16px; }

/* ---------- cards / lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.list li:hover { border-color: var(--line-strong); }
.list li .li-main { flex: 1; min-width: 0; }
.list li .li-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li .li-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: #0f766e; }
.badge.neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  padding: 26px 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

/* status dots */
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.18); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(232, 150, 12, 0.18); }
.dot.off { background: #c1c4d6; box-shadow: 0 0 0 3px rgba(150, 153, 175, 0.14); }

/* ---------- dashboard ---------- */
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.status-cell { display: flex; align-items: center; gap: 10px; padding: 13px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.status-cell .k { font-size: 12px; color: var(--muted); }
.status-cell .v { font-weight: 700; font-size: 14px; }

/* ---------- editor ---------- */
.editor-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.editor-head h2 { margin: 0; flex: 1; min-width: 140px; }

.editor-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.editor-grid {
  display: grid;
  grid-template-columns: 172px minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
}

.slide-list { display: flex; flex-direction: column; gap: 10px; }
.slide-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1080 / 1350;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--line);
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.slide-thumb:hover { border-color: var(--line-strong); }
.slide-thumb.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.18); }
.slide-thumb .idx {
  position: absolute; top: 4px; left: 4px; z-index: 5;
  background: rgba(20, 22, 40, 0.62); color: #fff;
  font-size: 10.5px; font-weight: 700;
  padding: 1px 6px; border-radius: 5px;
}
.slide-actions { display: flex; gap: 4px; justify-content: center; }

.canvas-wrap { min-width: 0; }
.canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 1080 / 1350;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: none;
}
.canvas-meta { text-align: center; margin-top: 8px; }

.layer-el {
  position: absolute;
  cursor: grab;
  user-select: none;
  border: 1px solid transparent;
}
.layer-el:hover { border-color: rgba(108, 92, 231, 0.5); }
.layer-el.selected { border: 1.5px solid var(--primary); }
.layer-el.selected::after {
  content: "";
  position: absolute;
  right: -7px; bottom: -7px;
  width: 13px; height: 13px;
  background: var(--primary);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: nwse-resize;
}
/* Prévia e exportação usam exatamente os mesmos arquivos de fonte. */
@font-face { font-family: StudioExport; src: url('/fonts/DejaVuSans.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: StudioExport; src: url('/fonts/DejaVuSans-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }
.layer-text {
  font-family: StudioExport, 'DejaVu Sans', sans-serif;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.28;
}
.layer-image { overflow: hidden; }
.layer-image img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }

.layer-panel .btn { margin: 0 4px 6px 0; }

.bg-props { margin-top: 4px; }

/* export result */
.export-links { display: flex; gap: 10px; flex-wrap: wrap; }
.export-thumbs { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.export-thumbs img {
  width: 90px; height: 112px; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--line);
}

/* invite link box */
.invite-link {
  display: flex; gap: 8px; align-items: center;
}
.invite-link input {
  font-family: var(--mono); font-size: 12.5px;
  background: var(--surface-2);
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  max-width: 380px;
  padding: 13px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: flex-start;
  gap: 9px;
  transform: translateY(16px);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  pointer-events: none;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast .t-ico { flex: 0 0 auto; font-size: 16px; line-height: 1.2; }
.toast.success { background: #0e9f6e; }
.toast.error { background: #d92d3f; }
.toast.warn { background: #b45309; }

/* ---------- responsive ---------- */
.menu-toggle {
  display: none;
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 8px;
  width: 38px; height: 38px;
  font-size: 18px; cursor: pointer;
  color: var(--ink);
}

@media (max-width: 1040px) {
  .editor-grid { grid-template-columns: 140px minmax(0, 1fr); }
  .layer-panel { grid-column: 1 / -1; }
}

@media (max-width: 820px) {
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .topbar { padding: 10px 14px; }
  .topbar-right { flex-wrap: wrap; }
  .topbar-right .user-chip { display: none; }
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 8px;
    display: none;
  }
  .sidebar.open { display: flex; }
  .nav-item { flex: 1 1 auto; justify-content: center; text-align: center; }
  .sidebar .side-foot { display: none; }
  .content { padding: 14px; }
  .editor-grid { grid-template-columns: 1fr; }
  .slide-list { flex-direction: row; align-items: flex-start; overflow-x: auto; padding-bottom: 4px; }
  .slide-list > .btn { flex: 0 0 auto; height: 42px; }
  .slide-list .slide-thumb { width: 74px; flex: 0 0 auto; }
  .slide-list .slide-actions { flex-wrap: nowrap; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .auth-card { padding: 22px; }
}

@media (max-width: 480px) {
  .btn { padding: 9px 12px; font-size: 13px; }
  .editor-meta { grid-template-columns: 1fr; }
}
