/* Editor */
.editor-page { height: 100vh; overflow: hidden; background: var(--bg); }

.ed-bar {
  height: 60px;
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: relative; z-index: 5;
}
.ed-bar .logo { font-size: 17px; }
.ed-bar-title { font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: .08em; padding-left: 16px; border-left: 1px solid var(--line); line-height: 20px; }
.ed-status { font-size: 12px; color: var(--text-2); margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ed-status::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; background: var(--line); }
.ed-status.is-dirty::before { background: #FF9F0A; }
.ed-status.is-clean::before { background: #30D158; }
.ed-actions { display: flex; gap: 8px; flex: none; }
.ed-actions .btn { height: 34px; padding: 0 18px; font-size: 13px; }
.btn-ghost.sm { height: 30px; padding: 0 12px; font-size: 12.5px; }
.btn-ghost:disabled { opacity: .35; pointer-events: none; }
.btn-ghost.danger:hover { border-color: #FF3B30; color: #FF3B30; }

.ed-user { display: flex; align-items: center; gap: 10px; padding-left: 16px; border-left: 1px solid var(--line); flex: none; }
.ed-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--text); color: #fff; display: grid; place-items: center; font-size: 12px; text-transform: uppercase; }
.ed-user-text { display: grid; line-height: 1.25; }
.ed-user-email { font-size: 11.5px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-signout { font-size: 11px; color: var(--text-2); }
.ed-signout:hover { color: var(--text); }

.ed { display: grid; grid-template-columns: 300px minmax(0, 1fr) 420px; height: calc(100vh - 60px); }

/* Shelves sidebar */
.ed-list { border-right: 1px solid var(--line); overflow-y: auto; padding: 20px 14px 32px; display: flex; flex-direction: column; gap: 14px; background: var(--bg); }
.ed-list-head { display: flex; justify-content: space-between; align-items: center; padding: 0 6px; }
.ed-list-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.035em; }
.shelves { display: flex; flex-direction: column; gap: 12px; }
.ed-tip { font-size: 11px; color: var(--text-2); padding: 0 6px; line-height: 1.5; }

.sg { background: var(--bg-2); border-radius: 18px; padding: 10px 8px 8px; transition: box-shadow .2s, background-color .2s; }
.sg.is-over { box-shadow: 0 0 0 2px var(--text) inset; background: #EFEFF2; }
.sg-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px; }
.sg-num { font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: .08em; }
.sg-tools { display: flex; gap: 2px; }
.sg-btn { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; color: var(--text-2); transition: background-color .2s, color .2s; }
.sg-btn:hover { background: rgba(0, 0, 0, .06); color: var(--text); }
.sg-btn:disabled { opacity: .3; pointer-events: none; }
.sg-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sg-btn.danger:hover { color: #FF3B30; }
.sg-name {
  width: 100%; margin: 4px 0 6px;
  padding: 4px 6px; border-radius: 8px;
  border: 1px solid transparent; background: none;
  font: inherit; font-size: 17px; font-weight: 650; letter-spacing: -0.025em; color: var(--text);
}
.sg-name:hover { border-color: var(--line); }
.sg-name:focus { outline: none; border-color: var(--text); background: var(--bg); }
.sg-list { list-style: none; display: flex; flex-direction: column; gap: 2px; min-height: 8px; }
.sg-empty { font-size: 11px; color: var(--text-2); padding: 14px 8px; text-align: center; border: 1px dashed var(--line); border-radius: 12px; }
.sg-add { width: 100%; margin-top: 4px; padding: 8px; border-radius: 10px; font-size: 12.5px; color: var(--text-2); text-align: left; transition: background-color .2s, color .2s; }
.sg-add:hover { background: rgba(0, 0, 0, .05); color: var(--text); }
.sg-add::before { content: '+'; display: inline-block; width: 22px; text-align: center; margin-right: 10px; font-size: 15px; }

.bag-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px; border-radius: 12px;
  cursor: grab; user-select: none;
  transition: background-color .2s, opacity .2s;
}
.bag-item:hover { background: rgba(255, 255, 255, .7); }
.bag-item.is-selected { background: var(--bg); box-shadow: 0 0 0 1px rgba(0, 0, 0, .06), 0 6px 16px -10px rgba(0, 0, 0, .3); }
.bag-item.is-dragging { opacity: .35; }
.bag-item.drop-before::before, .sg-list.drop-end::after {
  content: ''; position: absolute; left: 8px; right: 8px; height: 2px; border-radius: 2px; background: var(--text);
}
.bag-item.drop-before::before { top: -2px; }
.sg-list.drop-end { position: relative; padding-bottom: 6px; }
.sg-list.drop-end::after { bottom: 1px; }
.bag-item:focus-visible { outline: 2px solid var(--text); outline-offset: 0; }
.bag-swatch { position: relative; width: 22px; height: 30px; flex: none; border-radius: 3px 3px 6px 6px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); }
.bag-swatch.is-box { border-radius: 2px; width: 24px; }
.bag-swatch::before { content: ''; position: absolute; left: 0; right: 0; top: 4px; height: 1px; background: rgba(0, 0, 0, .18); }
.bag-item-text { min-width: 0; flex: 1; display: grid; }
.bag-item-name { font-size: 14px; font-weight: 600; letter-spacing: -0.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bag-item-sub { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bag-item-num { font-family: var(--mono); font-size: 11px; color: var(--text-2); }
.fav-dot { font-size: 9px; text-transform: uppercase; letter-spacing: .08em; padding: 2px 6px; border-radius: 980px; background: var(--text); color: #fff; }

/* Preview */
.ed-preview { position: relative; background: var(--bg-2); overflow: hidden; }
#preview-canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.ed-preview.is-dragging #preview-canvas { cursor: grabbing; }
.ed-preview-head { position: absolute; top: 20px; left: 24px; right: 24px; display: flex; justify-content: space-between; pointer-events: none; }
.ed-preview-head .mono { font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: .08em; }
.ed-view-btns {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%);
  display: flex; padding: 4px; gap: 2px;
  border-radius: 980px;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .05), 0 12px 32px -18px rgba(0, 0, 0, .3);
}
.ed-view-btns button { height: 32px; padding: 0 16px; border-radius: 980px; font-size: 13px; font-weight: 500; transition: background-color .25s, color .25s; }
.ed-view-btns button.is-active { background: var(--text); color: #fff; }
.no-webgl .ed-preview::after { content: '3D preview needs WebGL'; position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--mono); font-size: 12px; color: var(--text-2); }

/* Form */
.ed-form { border-left: 1px solid var(--line); overflow-y: auto; padding: 24px 24px 80px; }
.form-num { font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: .08em; }
.form-title { margin-top: 6px; font-size: 28px; font-weight: 700; letter-spacing: -0.04em; line-height: 1.08; word-break: break-word; }
.form-tools { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0 4px; }

.fieldset { border: 0; border-top: 1px solid var(--line); margin-top: 20px; padding-top: 18px; min-width: 0; }
.fieldset legend { float: left; width: 100%; margin-bottom: 14px; font-family: var(--mono); font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: .08em; }
.fieldset legend + * { clear: both; }

.field { display: grid; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > label, .field > span, .field-label { font-size: 12px; color: var(--text-2); font-weight: 500; }
.field input[type="text"], .field input[type="number"], .field select, .ed-dialog input {
  width: 100%; height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text);
  font: inherit; font-size: 14px; letter-spacing: -0.01em;
  transition: border-color .2s, box-shadow .2s;
}
.field select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2386868B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
  padding-right: 34px; cursor: pointer;
}
.field input:focus, .field select:focus, .ed-dialog input:focus { outline: none; border-color: var(--text); box-shadow: 0 0 0 3px rgba(29, 29, 31, .08); }
.field input.is-invalid { border-color: #FF3B30; }
.field-hint { font-size: 11.5px; color: var(--text-2); line-height: 1.4; }
.contrast-note {
  font-size: 12px; line-height: 1.45; color: var(--text);
  padding: 10px 12px; border-radius: 10px;
  background: var(--bg-2); border: 1px solid var(--line);
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.switch-row { display: flex; align-items: center; gap: 12px; padding: 4px 0 16px; }
.switch {
  position: relative; flex: none;
  width: 44px; height: 26px; border-radius: 980px;
  background: var(--line);
  transition: background-color .25s var(--ease);
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .3s var(--ease-out);
}
.switch[aria-checked="true"] { background: var(--text); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.switch-text { display: grid; }
.switch-text strong { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.switch-text span { font-size: 12px; color: var(--text-2); }

.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type="color"] {
  width: 38px; height: 38px; flex: none;
  padding: 3px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); cursor: pointer;
}
.color-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-row input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 7px; }
.color-row input[type="color"]::-moz-color-swatch { border: 0; border-radius: 7px; }
.color-row input[type="text"] { font-family: var(--mono); font-size: 13px; text-transform: uppercase; }
.swatches { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 4px; }
.swatches button { width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); transition: transform .2s var(--ease); }
.swatches button:hover { transform: scale(1.12); }
.swatches button.is-active { outline: 2px solid var(--text); outline-offset: 2px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { height: 32px; padding: 0 12px; border-radius: 980px; border: 1px solid var(--line); font-size: 13px; transition: background-color .2s, border-color .2s, color .2s; }
.seg button:hover { border-color: var(--text); }
.seg button.is-active { background: var(--text); border-color: var(--text); color: #fff; }

/* Toast + dialog */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: min(560px, calc(100% - 32px));
  background: var(--text); color: #fff;
  font-size: 12.5px; line-height: 1.45;
  padding: 12px 16px; border-radius: 14px;
  box-shadow: 0 20px 40px -20px rgba(0, 0, 0, .5);
  z-index: 50;
}
.ed-dialog { margin: auto; border: 0; border-radius: 20px; padding: 28px; width: min(420px, calc(100% - 32px)); box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .45); color: var(--text); }
.ed-dialog::backdrop { background: rgba(0, 0, 0, .25); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.ed-dialog h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.03em; }
.ed-dialog p { margin: 8px 0 16px; font-size: 14px; color: var(--text-2); }
.dialog-error { color: #FF3B30 !important; min-height: 1em; margin: 8px 0 0 !important; font-size: 13px !important; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }


/* Shelf / Blog switch */
.ed-tabs { display: flex; gap: 2px; padding: 3px; border-radius: 980px; background: var(--bg-2); margin-left: 4px; }
.ed-tabs a { padding: 5px 14px; border-radius: 980px; font-size: 12.5px; font-weight: 500; color: var(--text-2); transition: background-color .2s, color .2s; }
.ed-tabs a:hover { color: var(--text); }
.ed-tabs a[aria-current="page"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

/* Blog editor */
.field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text);
  font: inherit; font-size: 14px; line-height: 1.5; letter-spacing: -0.01em;
  resize: vertical; transition: border-color .2s, box-shadow .2s;
}
.field input[type="date"] {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 14px;
}
.field textarea:focus, .field input[type="date"]:focus { outline: none; border-color: var(--text); box-shadow: 0 0 0 3px rgba(29, 29, 31, .08); }
.field :disabled { opacity: .6; }
.body-input { font-family: var(--mono) !important; font-size: 13px !important; line-height: 1.6 !important; min-height: 360px; }
.cover-thumb { width: 100%; max-height: 160px; object-fit: cover; border-radius: 10px; background: var(--bg-2); }
.md-help { margin-top: 4px; font-size: 12px; color: var(--text-2); }
.md-help summary { cursor: pointer; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 4px 0; }
.md-help summary:hover { color: var(--text); }
.md-help dl { display: grid; gap: 4px; margin: 8px 0; font-size: 11.5px; }
.md-help dl div { display: grid; grid-template-columns: 150px 1fr; gap: 8px; }
.md-help dt { color: var(--text); }
.form-empty { color: var(--text-2); font-size: 14px; padding-top: 8px; }

.post-items { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.post-item {
  width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: baseline;
  padding: 10px 12px; border-radius: 12px; text-align: left;
  background: var(--bg-2); transition: background-color .2s, box-shadow .2s;
}
.post-item:hover { background: #EFEFF2; }
.post-item.is-selected { background: var(--bg); box-shadow: 0 0 0 1.5px var(--text) inset; }
.post-item-title { font-size: 14px; font-weight: 600; letter-spacing: -0.015em; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.post-item-meta { grid-column: 1; font-size: 11px; color: var(--text-2); }
.post-item-status { grid-column: 2; grid-row: 1; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-2); padding: 3px 7px; border-radius: 980px; border: 1px solid var(--line); }
.post-item-status.is-live { background: var(--text); border-color: var(--text); color: #fff; }

.ed-article { overflow-y: auto; padding: 40px clamp(24px, 4vw, 64px) 96px; background: var(--bg); }
.ed-article-label { font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 28px; }
.ed-article .post { max-width: 720px; margin: 0 auto; }
.ed-article .post-title { font-size: clamp(30px, 3.4vw, 48px); }
.ed-article .prose { font-size: 17px; }

@media (max-width: 1240px) {
  .ed { grid-template-columns: 260px minmax(0, 1fr) 380px; }
  .ed-bar-title, .ed-user-text { display: none; }
}

@media (max-width: 900px) {
  .editor-page { height: auto; overflow: auto; }
  .ed-bar { height: auto; flex-wrap: wrap; padding: 12px 16px; gap: 10px; }
  .ed-status { order: 3; width: 100%; margin: 0; }
  .ed-actions { order: 2; margin-left: auto; flex-wrap: wrap; }
  .ed-user { order: 1; border: 0; padding: 0; }
  #import-btn, #export-btn { display: none; }
  .ed { grid-template-columns: 1fr; height: auto; }
  .ed-preview { height: 48vh; position: sticky; top: 0; z-index: 2; }
  .ed-article { order: 2; border-top: 1px solid var(--line); }
  .ed-list { border-right: 0; border-bottom: 1px solid var(--line); order: -1; }
  .ed-tip { display: none; }
  .ed-form { border-left: 0; }
}
