/* ==========================================================================
   Lyllic Docs (Beta) — standalone editor. Reuses the design tokens from
   styles.css (:root --page/--ink/--accent/...). Layered on top here.
   ========================================================================== */
.docs-body {
  height: 100%;
  overflow: hidden;
}
.docs-loading::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--page);
  z-index: 80;
}

/* --- Signed-out gate ----------------------------------------------------- */
.docs-gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 18%, rgba(15, 143, 139, 0.16), transparent 34%),
    linear-gradient(140deg, #fffdf8, #ece7dc);
}
.docs-gate-card {
  text-align: center;
  padding: 40px 44px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  max-width: 380px;
}
.docs-gate-card .brand-mark { margin: 0 auto 16px; }
.docs-gate-card h1 { margin: 0 0 8px; font-size: 24px; letter-spacing: 0; }
.docs-gate-card p { margin: 0 0 22px; color: var(--muted); }

/* --- Docs home ----------------------------------------------------------- */
.docs-home {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  overflow: auto;
  background:
    radial-gradient(circle at 15% 12%, rgba(15, 143, 139, 0.12), transparent 30%),
    radial-gradient(circle at 85% 8%, rgba(239, 184, 75, 0.14), transparent 28%),
    linear-gradient(150deg, #fffdf8, #f1ebdf 60%, #ece7dc);
}
.docs-home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 24px clamp(20px, 5vw, 56px);
  flex-wrap: wrap;
}
.docs-home-header h1 {
  margin: 2px 0 0;
  font-size: clamp(20px, 2.3vw, 27px);
  letter-spacing: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.docs-home-header .auth-brand p { margin: 0; color: var(--muted); font-size: 13px; }
.docs-beta-chip, .docs-sidebar-model {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.docs-beta-chip {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-2);
  color: #fff8f2;
}
.docs-home-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.docs-home-main {
  flex: 1;
  width: 100%;
  max-width: 1140px;
  margin: 0 auto;
  padding: 8px clamp(20px, 5vw, 56px) 60px;
}
.docs-home-topline {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.docs-home-topline p { margin: 0; color: var(--muted); font-size: 13px; }
.docs-home-topline h2 { margin: 2px 0 0; font-size: 20px; letter-spacing: 0; }

.docs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
}
.docs-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  padding: 70px 20px;
}
.docs-empty i { width: 34px; height: 34px; opacity: 0.6; }
.docs-empty p { margin: 4px 0 0; font-weight: 600; color: var(--ink); }
.docs-empty span { font-size: 14px; }

.docs-card {
  position: relative;
  display: flex;
  align-items: stretch;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.docs-card:hover {
  transform: translateY(-4px);
  border-color: color-mix(in srgb, var(--accent), var(--line) 45%);
  box-shadow: 0 24px 60px rgba(23, 25, 31, 0.14);
}
.docs-card-open {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
  text-align: left;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
}
.docs-card-thumb {
  display: flex;
  flex-direction: column;
  gap: 7px;
  justify-content: center;
  padding: 22px 22px 20px;
  height: 122px;
  background: linear-gradient(160deg, #fbf7ef, #efe7d7);
  border-bottom: 1px solid var(--line);
}
.docs-card-thumb-line {
  height: 8px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--ink), transparent 80%);
}
.docs-card-thumb-line--title { height: 13px; width: 58%; background: color-mix(in srgb, var(--accent), transparent 25%); }
.docs-card-thumb-line--short { width: 40%; }
.docs-card-meta { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px 18px; }
.docs-card-title { font-weight: 650; letter-spacing: 0; color: var(--ink); }
.docs-card-sub { font-size: 12px; color: var(--muted); }
.docs-card-delete {
  position: absolute;
  top: 10px;
  right: 10px;
  opacity: 0;
  transition: opacity 0.2s;
  background: color-mix(in srgb, var(--panel), transparent 10%);
}
.docs-card:hover .docs-card-delete { opacity: 1; }

/* --- Editor shell -------------------------------------------------------- */
.docs-editor {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: #e8e3d8;
}
.docs-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px clamp(12px, 2vw, 20px);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.docs-toolbar-left, .docs-toolbar-right { display: flex; align-items: center; gap: 10px; }
.docs-toolbar-right { flex-wrap: wrap; justify-content: flex-end; }
.docs-title-input {
  border: 1px solid transparent;
  background: transparent;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  padding: 6px 10px;
  border-radius: 8px;
  min-width: 160px;
  max-width: 42vw;
}
.docs-title-input:hover { border-color: var(--line); }
.docs-title-input:focus { outline: none; border-color: var(--accent); background: var(--panel-soft); }
.docs-save-state {
  font-size: 12px;
  color: var(--muted);
  min-width: 62px;
}
.docs-save-state[data-state="saving"] { color: var(--accent); }
.docs-save-state[data-state="saved"] { color: var(--accent); }
.docs-save-state[data-state="error"] { color: var(--accent-2); }

/* Formatting bar */
.docs-format-bar {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.docs-fmt {
  min-width: 30px;
  height: 30px;
  padding: 0 7px;
  border: none;
  background: none;
  border-radius: 7px;
  color: var(--ink);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.docs-fmt:hover { background: color-mix(in srgb, var(--accent), transparent 84%); color: var(--accent); }
.docs-fmt i { width: 16px; height: 16px; }
.docs-fmt-sep { width: 1px; height: 18px; background: var(--line); margin: 0 3px; }

.docs-export { position: relative; }
.docs-export > summary { list-style: none; cursor: pointer; }
.docs-export > summary::-webkit-details-marker { display: none; }
.docs-export-list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 12;
  display: flex;
  flex-direction: column;
  min-width: 190px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.docs-export-list button {
  border: none;
  background: none;
  text-align: left;
  padding: 11px 14px;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
}
.docs-export-list button:hover { background: var(--panel-soft); color: var(--accent); }
.docs-editor .secondary-button.is-active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent), transparent 86%);
  color: var(--accent);
}

/* Workspace: canvas + sidebar */
.docs-workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}
.docs-canvas-wrap {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  padding: clamp(10px, 2vw, 26px);
  display: flex;
  justify-content: center;
}
.docs-canvas-host {
  width: 100%;
  max-width: 1000px;
  height: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 30px 80px rgba(23, 25, 31, 0.18);
  border: 1px solid rgba(23, 25, 31, 0.08);
}
.docs-canvas-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #ffffff;
}

/* Chat sidebar */
.docs-sidebar {
  width: min(400px, 40vw);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  transition: margin-right 0.28s cubic-bezier(0.2, 0.7, 0.2, 1);
}
body.chat-collapsed .docs-sidebar { margin-right: calc(-1 * min(400px, 40vw)); }
body.chat-collapsed .docs-canvas-host { max-width: 1200px; }
.docs-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.docs-sidebar-kicker { margin: 0; font-weight: 650; letter-spacing: 0; }
.docs-sidebar-model { margin: 2px 0 0; color: var(--accent-2); }

.docs-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.docs-msg { max-width: 100%; }
.docs-msg-body {
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.docs-msg--assistant .docs-msg-body {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  color: var(--ink);
}
.docs-msg--user { align-self: flex-end; max-width: 88%; }
.docs-msg--user .docs-msg-body {
  background: var(--accent);
  color: #f4fffd;
  border-bottom-right-radius: 5px;
}
.docs-msg.is-pending .docs-msg-body { color: var(--muted); font-style: italic; }
.docs-msg-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
}
.docs-msg-sources a {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
  padding: 3px 9px;
  border: 1px solid color-mix(in srgb, var(--accent), var(--line) 55%);
  border-radius: 999px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.docs-msg-sources a:hover { background: color-mix(in srgb, var(--accent), transparent 88%); }

.docs-chat-form {
  border-top: 1px solid var(--line);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.docs-prompt {
  width: 100%;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--panel-soft);
  max-height: 180px;
}
.docs-prompt:focus { outline: none; border-color: var(--accent); background: var(--panel); }
.docs-chat-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.docs-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.docs-toggle input { accent-color: var(--accent); }

/* Toast */
.docs-toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  background: var(--ink);
  color: #fff8e8;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  max-width: 90vw;
}

/* Responsive: sidebar becomes an overlay drawer on narrow screens */
@media (max-width: 860px) {
  .docs-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(400px, 92vw);
    z-index: 30;
    box-shadow: -20px 0 60px rgba(23, 25, 31, 0.22);
  }
  body.chat-collapsed .docs-sidebar { margin-right: calc(-1 * min(400px, 92vw)); }
  .docs-canvas-wrap { padding: 10px; }
  .docs-title-input { max-width: 40vw; }
}
