/* Foldize Studio — compact beige workbench: square controls, dense rhythm, no decoration. */
:root {
  --paper: #d9d3c7; --panel: #e7e1d5; --panel-raised: #eee9df; --ink: #171713; --muted: #68655e;
  --line: #b8b1a5; --line-strong: #8f897f; --active: #ee7d32;
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  color: var(--ink); background: var(--paper); font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; display: flex; flex-direction: column; overflow: hidden; font-size: 11px; line-height: 1.35; -webkit-font-smoothing: antialiased; }
button, a, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .38; cursor: not-allowed; }
a { color: inherit; }

/* Topbar */
.topbar { height: 32px; display: flex; align-items: stretch; gap: 0; padding: 0; border-bottom: 1px solid var(--line-strong); background: var(--panel); flex-shrink: 0; }
.brand { min-width: 78px; display: flex; align-items: center; padding: 0 9px; border-right: 1px solid var(--line); font-weight: 700; letter-spacing: -.035em; text-decoration: none; font-size: 11px; text-transform: uppercase; }
.status { flex: 1; display: flex; align-items: center; gap: 5px; padding: 0 8px; font-size: 9px; color: var(--muted); min-width: 0; }
.status span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 5px; height: 5px; border-radius: 0; background: var(--line-strong); flex-shrink: 0; transition: background .2s; }
.dot.live { background: #1a7a2e; }
.dot.dirty { background: #b7790a; }
.dot.sync { opacity: .5; }

.top-actions { display: flex; align-items: stretch; border-left: 1px solid var(--line); }

.view-switcher { display: flex; align-items: stretch; border-left: 1px solid var(--line); }
.view-toggle { min-width: 68px; border: 0; border-right: 1px solid var(--line); background: transparent; padding: 0 8px; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .035em; }
.view-toggle:hover { background: var(--panel-raised); color: var(--ink); }
.view-toggle.active { color: var(--ink); background: var(--panel-raised); box-shadow: inset 0 -2px 0 var(--active); }
.text-btn { display: inline-flex; align-items: center; border: 0; background: transparent; padding: 0 8px; border-radius: 0; color: var(--muted); font-size: 9.5px; text-decoration: none; }
.text-btn:hover { background: var(--panel-raised); color: var(--ink); }
.icon-btn { width: 25px; height: 31px; display: grid; place-items: center; border: 0; border-right: 1px solid var(--line); background: transparent; border-radius: 0; color: var(--muted); font-size: 11px; line-height: 1; padding: 0; }
.icon-btn:hover:not(:disabled) { background: var(--panel-raised); color: var(--ink); }
.primary { border: 1px solid var(--ink); background: var(--ink); color: var(--panel-raised); padding: 3px 8px; border-radius: 1px; font-size: 9.5px; font-weight: 700; letter-spacing: .015em; text-transform: uppercase; }
.primary:hover:not(:disabled) { background: var(--active); border-color: var(--active); color: var(--ink); }
.primary.block { width: 100%; justify-content: center; display: flex; margin-top: 8px; }
.text-btn.block { width: 100%; min-height: 25px; justify-content: center; display: flex; margin-top: 5px; border: 1px solid var(--line-strong); color: var(--ink); }

/* Workspace */
.workspace { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(272px, 304px); }
.conversation { grid-column: 2; grid-row: 1; min-width: 0; min-height: 0; background: var(--panel); border-left: 1px solid var(--line-strong); }
.preview-panel { grid-column: 1; grid-row: 1; position: relative; min-width: 0; min-height: 0; background: var(--paper); display: flex; overflow: hidden; }
.preview-panel iframe { flex: 1; width: 100%; border: 0; background: #fff; display: block; min-height: 0; }
.toast { position: absolute; left: 50%; bottom: 7px; transform: translateX(-50%); background: var(--ink); color: var(--panel-raised); border-left: 3px solid var(--active); font-size: 9.5px; padding: 4px 7px; border-radius: 0; max-width: 80%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; z-index: 5; }
.toast[hidden] { display: none; }

.structure-tree button:focus-visible, .structure-add:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }
.conversation { display: flex; flex-direction: column; }
.thread { flex: 1; min-height: 0; overflow: auto; padding: 8px; scrollbar-gutter: stable; }
.message { margin-bottom: 9px; font-size: 10.5px; line-height: 1.4; }
.message .meta { font-size: 9px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.message p { margin: 0; white-space: pre-wrap; overflow-wrap: break-word; }
.message.user { color: #2b2b28; }
.message.error { color: #8f2a22; }
.change-list { margin-top: 5px; padding: 5px 0 0; border-top: 1px solid var(--line); font-size: 10.5px; color: var(--muted); }
.copilot-choices { display: grid; gap: 4px; margin-top: 8px; }
.copilot-choices button { width: 100%; border: 1px solid var(--line); border-radius: 0; padding: 4px 5px; background: var(--panel-raised); color: var(--ink); text-align: left; font: inherit; font-size: 9.5px; line-height: 1.3; }
.copilot-choices button:hover { border-color: var(--ink); background: var(--panel-raised); }
.copilot-choices button:last-child { color: var(--muted); }
.suggestions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 7px; }
.suggestions button { border: 1px solid var(--line); background: var(--panel-raised); padding: 2px 5px; border-radius: 0; color: var(--muted); font-size: 9px; }
.suggestions button:hover { border-color: var(--line-strong); color: var(--ink); }
.composer { border-top: 1px solid var(--line-strong); padding: 5px; background: var(--panel); }
.draft-bar { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 3px 5px; border-top: 1px solid var(--line); color: var(--muted); font-size: 9px; }
.composer textarea { width: 100%; resize: none; min-height: 44px; border: 1px solid var(--line-strong); border-radius: 0; padding: 5px; background: var(--panel-raised); outline: none; font-size: 10.5px; }
.composer textarea:focus { border-color: var(--ink); box-shadow: inset 2px 0 0 var(--active); }
.chat-attachments { display: flex; gap: 5px; overflow-x: auto; padding: 0 0 7px; }
.chat-attachment { position: relative; width: 36px; height: 36px; flex: 0 0 36px; border: 1px solid var(--line); border-radius: 0; overflow: hidden; background: var(--paper); }
.chat-attachment img { display: block; width: 100%; height: 100%; object-fit: cover; }
.chat-attachment button { position: absolute; top: 1px; right: 1px; width: 14px; height: 14px; border: 0; border-radius: 0; background: rgba(17,17,16,.82); color: #fff; padding: 0; line-height: 1; font-size: 10px; }
.chat-attach { color: var(--muted); cursor: pointer; }
.chat-attach:hover { color: var(--ink); }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 5px; margin-top: 4px; }
.hint { font-size: 8.5px; color: var(--muted); }

/* Structure */
.structure-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--panel); }
.structure-head { min-height: 40px; flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 6px 5px 8px; border-bottom: 1px solid var(--line-strong); }
.structure-head h1 { margin: 0; font-size: 10px; font-weight: 700; letter-spacing: .035em; text-transform: uppercase; }
.structure-head p { margin: 1px 0 0; color: var(--muted); font-size: 9.5px; }
.structure-add { border: 1px solid var(--line-strong); background: var(--panel-raised); color: var(--ink); padding: 2px 5px; border-radius: 0; font-size: 9px; text-transform: uppercase; }
.structure-add:hover:not(:disabled) { border-color: var(--ink); background: var(--active); }
.structure-tree { flex: 1; min-height: 0; overflow: auto; padding: 3px 0 8px; scrollbar-gutter: stable; }
.structure-tree ul { list-style: none; margin: 0; padding: 0; }
.tree-fold, .tree-block { position: relative; }
.tree-row { --depth: 0; min-height: 23px; display: flex; align-items: center; gap: 2px; padding: 1px 4px 1px calc(4px + var(--depth) * 11px); border-top: 1px solid transparent; border-bottom: 1px solid transparent; }
.tree-row:hover { background: var(--panel-raised); }
.tree-row.current { background: var(--panel-raised); box-shadow: inset 2px 0 0 var(--active); }
.tree-row.dragging { opacity: .35; }
.tree-row.drop-before { border-top-color: var(--ink); }
.tree-row.drop-after { border-bottom-color: var(--ink); }
.tree-row.drop-inside { background: var(--panel-raised); box-shadow: inset 2px 0 0 var(--ink); }
.tree-disclosure { flex: 0 0 14px; width: 14px; height: 19px; display: grid; place-items: center; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 8px; }
.tree-disclosure:hover { color: var(--ink); }
.tree-title, .tree-block-main { flex: 1; min-width: 0; border: 0; background: transparent; padding: 2px 0; text-align: left; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-title { font-size: 10px; font-weight: 600; }
.tree-title-input { flex: 1; min-width: 0; height: 22px; border: 0; border-bottom: 1px solid var(--ink); border-radius: 0; padding: 1px 0; background: transparent; outline: 0; color: var(--ink); font-size: 11px; font-weight: 560; }
.tree-meta { flex: 0 0 auto; color: var(--muted); font-size: 8px; }
.tree-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 1px; opacity: 0; }
.tree-row:hover .tree-actions, .tree-row:focus-within .tree-actions { opacity: 1; }
.tree-action { width: 16px; height: 19px; display: grid; place-items: center; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 10px; }
.tree-action:hover { color: var(--ink); }
.tree-grip { cursor: grab; font-size: 8px; letter-spacing: -1px; }
.tree-grip:active { cursor: grabbing; }
.tree-children { position: relative; }
.tree-children::before { content: ""; position: absolute; top: 0; bottom: 0; left: calc(12px + var(--guide-depth, 0) * 11px); width: 1px; background: var(--line); pointer-events: none; }
.tree-block .tree-row { min-height: 21px; }
.tree-block-mark { flex: 0 0 14px; width: 14px; text-align: center; color: var(--muted); font-size: 7px; text-transform: uppercase; }
.tree-block-main { display: flex; align-items: baseline; gap: 4px; font-size: 9.5px; }
.tree-block-type { flex: 0 0 auto; color: #555550; }
.tree-block-summary { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.tree-insert { display: flex; flex-wrap: wrap; gap: 1px; padding: 1px 4px 4px calc(23px + var(--depth) * 11px); }
.tree-insert button { border: 0; background: transparent; padding: 1px 3px; color: var(--muted); font-size: 8.5px; }
.tree-insert button:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 2px; }
.tree-empty { margin: 18px 12px; color: var(--muted); font-size: 10.5px; line-height: 1.5; }
.tree-pages { margin-top: 6px; padding-top: 4px; border-top: 1px solid var(--line); }
.tree-pages > p { margin: 0; padding: 0 12px 4px; color: var(--muted); font-size: 9px; letter-spacing: .06em; text-transform: uppercase; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tree-pages > p button { border: 0; background: transparent; padding: 0; color: var(--muted); font: inherit; letter-spacing: 0; text-transform: none; cursor: pointer; }
.tree-pages > p button:hover { color: var(--ink); }
.structure-help { display: none; }
.tree-pages { margin-top: 8px; }
.tree-pages > summary { padding: 0 7px 3px; color: var(--muted); font-size: 8px; letter-spacing: .06em; text-transform: uppercase; cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; }
.tree-pages > summary::-webkit-details-marker { display: none; }
.tree-pages > summary::before { content: '›'; margin-right: 5px; font-size: 12px; }
.tree-pages[open] > summary::before { content: '⌄'; }
.tree-pages > summary button { border: 0; background: transparent; padding: 0; color: var(--muted); font: inherit; letter-spacing: 0; text-transform: none; cursor: pointer; }
.tree-pages > summary button:hover { color: var(--ink); }
.mobile-actions { display: none; }

/* Command palette */
.palette { border: 1px solid var(--ink); border-radius: 0; padding: 4px; background: var(--panel); width: min(92vw, 360px); }
.palette::backdrop { background: rgba(17, 17, 16, .12); }
.palette input { width: 100%; border: 1px solid var(--line-strong); border-radius: 0; padding: 5px; background: var(--panel-raised); outline: none; font-size: 10px; }
#paletteResults { margin-top: 6px; display: grid; gap: 1px; }
#paletteResults button { border: 0; background: transparent; text-align: left; padding: 4px 5px; border-radius: 0; font-size: 10px; }
#paletteResults button:hover { background: var(--panel-raised); box-shadow: inset 2px 0 0 var(--active); }
.palette-empty { padding: 8px; color: var(--muted); font-size: 11px; }

/* Auth */
.auth { position: fixed; inset: 32px 0 0; background: var(--paper); z-index: 10; display: grid; place-items: center; padding: 16px; }
.auth[hidden] { display: none; }
.auth-card { width: min(92vw, 340px); }
.eyebrow { font-size: 9px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0; }
.auth h1 { font-size: 18px; letter-spacing: -.035em; line-height: 1; margin: 4px 0 10px; }
.auth input { width: 100%; border: 1px solid var(--line-strong); border-radius: 0; padding: 6px; background: var(--panel-raised); outline: none; font-size: 10.5px; }
.auth input:focus { border-color: var(--line-strong); }
.auth-status { font-size: 10.5px; color: var(--muted); min-height: 0; margin: 6px 0 0; }

@media (max-width: 860px) {
  .brand { min-width: 64px; padding: 0 7px; }
  .view-switcher { display: none; }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(184px, 32dvh); }
  .preview-panel { grid-column: 1; grid-row: 1; border-right: 0; border-bottom: 1px solid var(--line); }
  .conversation { position: relative; grid-column: 1; grid-row: 2; width: 100%; transform: none; visibility: visible; box-shadow: none; }
  .mobile-actions { display: flex; position: fixed; z-index: 8; left: 0; right: 0; bottom: 0; min-height: 30px; padding: 0; gap: 0; border-top: 1px solid var(--line-strong); border-radius: 0; background: var(--panel); box-shadow: none; }
  .mobile-actions button { flex: 1; border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 8.5px; text-transform: uppercase; }
  .mobile-actions button.active, .mobile-actions button:not(:disabled):hover { color: var(--ink); }
  .mobile-actions [data-mobile-publish] { background: var(--ink); color: var(--panel-raised); border-radius: 0; }
  .structure-head { min-height: 38px; padding: 5px; }
  .structure-head h1 { font-size: 11px; }
  .structure-add { padding: 3px 5px; }
  .tree-row { padding-right: 4px; padding-left: calc(4px + var(--depth) * 10px); }
  .tree-actions { display: none; }
  .tree-insert { padding-left: calc(20px + var(--depth) * 10px); }
  .structure-help { display: none; }
  .thread { padding: 9px 9px 58px; }
  .composer { padding: 7px; }
  .composer-row { align-items: flex-end; }
  .hint { display: none; }
}
@media (min-width: 861px) and (max-width: 1120px) {
  .structure-side, .conversation { width: min(320px, 42vw); }
}
@media (prefers-reduced-motion: reduce) { .dot.sync { opacity: 1; } }

/* Design Panel */
.design-panel { border: 1px solid var(--ink); border-radius: 0; padding: 0; background: var(--panel); width: min(92vw, 340px); max-height: 80vh; }
.design-panel::backdrop { background: rgba(17, 17, 16, .18); }
.design-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; border-bottom: 1px solid var(--line-strong); margin: 0; }
.design-head span { font-size: 10px; font-weight: 700; letter-spacing: .035em; text-transform: uppercase; }
.design-close { width: 20px; height: 20px; border: 0; background: transparent; color: var(--muted); font-size: 14px; cursor: pointer; display: grid; place-items: center; padding: 0; }
.design-close:hover { color: var(--ink); }
.design-body { padding: 8px; overflow-y: auto; max-height: calc(80vh - 32px); }
.ds-section { margin-bottom: 10px; }
.ds-section h3 { margin: 0 0 5px; font-size: 8px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.ds-row { display: grid; grid-template-columns: 60px 1fr; align-items: center; gap: 5px; margin-bottom: 4px; }
.ds-row span { font-size: 9px; color: var(--muted); }
.ds-row input[type="text"] { width: 100%; height: 22px; border: 1px solid var(--line-strong); border-radius: 0; padding: 0 5px; background: var(--panel-raised); outline: none; font-size: 9.5px; }
.ds-row input[type="text"]:focus { border-color: var(--ink); }
.ds-row input[type="color"] { width: 100%; height: 22px; border: 1px solid var(--line-strong); border-radius: 0; padding: 1px; background: var(--panel-raised); cursor: pointer; }
.ds-font-preview { display: none; font-size: 9px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ds-font-preview.active { display: block; }
.ds-gradient-preview { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 0; margin-bottom: 3px; }
.ds-hint { margin: 0; font-size: 8px; color: var(--muted); }
.ds-textures { display: flex; gap: 3px; }
.ds-tex { flex: 1; height: 26px; border: 1px solid var(--line); border-radius: 0; background: var(--panel-raised); color: var(--muted); font-size: 8px; text-transform: uppercase; letter-spacing: .03em; cursor: pointer; }
.ds-tex:hover { border-color: var(--line-strong); color: var(--ink); }
.ds-tex.active { border-color: var(--ink); color: var(--ink); background: var(--panel); }
.ds-font-results { position: absolute; z-index: 20; width: calc(100% - 65px); max-height: 160px; overflow-y: auto; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 0; margin-top: 1px; }
.ds-font-results button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 4px 6px; font-size: 9.5px; color: var(--ink); cursor: pointer; border-bottom: 1px solid var(--line); }
.ds-font-results button:hover { background: var(--panel-raised); }
.ds-font-results button:last-child { border-bottom: 0; }

.ds-toggle { grid-template-columns: 60px 1fr !important; }
.ds-tog-btn { height: 22px; border: 1px solid var(--line-strong); border-radius: 0; background: var(--panel-raised); color: var(--muted); font-size: 8px; text-transform: uppercase; letter-spacing: .03em; cursor: pointer; }
.ds-tog-btn:hover { border-color: var(--line-strong); color: var(--ink); }
.ds-tog-btn.active { border-color: var(--ink); color: var(--ink); background: var(--panel); }
