/* ── VISUAL EDITOR (PREMIUM) ── */

.editor-overlay {
  --ed-radius: 8px;
  --ed-card-radius: 12px;
  --ed-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  --ed-hover-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  --ed-focus-ring: 0 0 0 3px rgba(128, 128, 128, 0.2);
  --ed-transition: all 0.25s cubic-bezier(0.25, 0.8, 0.25, 1);
}

[data-theme="dark"] .editor-overlay {
  --ed-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  --ed-hover-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  --ed-focus-ring: 0 0 0 3px rgba(255, 255, 255, 0.15);
}

/* Overlay */
.editor-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  font-family: 'Google Sans Flex', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--t1);
  overflow: hidden;
  animation: edFadeIn 0.3s ease-out;
}

@keyframes edFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Top Bar ── */
.ed-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 10;
  gap: 16px;
}

.ed-topbar-left, .ed-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ed-topbar-left {
  background: var(--tb-bg);
  padding: 4px;
  border-radius: var(--ed-radius);
  gap: 2px;
}

.ed-tab {
  padding: 6px 20px;
  border: none;
  background: transparent;
  color: var(--t2);
  font-family: inherit;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: calc(var(--ed-radius) - 2px);
  transition: var(--ed-transition);
}

.ed-tab:hover {
  color: var(--t1);
}

.ed-tab.active {
  background: var(--bg);
  color: var(--t1);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

[data-theme="dark"] .ed-tab.active {
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.ed-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  background: var(--tb-bg);
  border: none;
  border-radius: var(--ed-radius);
  color: var(--t1);
  font-family: inherit;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: var(--ed-transition);
  white-space: nowrap;
}

.ed-btn:hover {
  background: var(--tb-hbg);
  transform: translateY(-1px);
}

.ed-btn:active {
  transform: translateY(1px);
}

.ed-btn--save {
  background: var(--t1);
  color: var(--bg);
}

.ed-btn--save:hover {
  opacity: 0.9;
  background: var(--t1);
  box-shadow: var(--ed-shadow);
}

.ed-btn--danger {
  color: #e05555;
  background: rgba(224, 85, 85, 0.08);
}

.ed-btn--danger:hover {
  background: rgba(224, 85, 85, 0.15);
  color: #ff3333;
}

/* ── Layout ── */
.ed-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ── */
.ed-sidebar {
  width: 280px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.015);
  z-index: 5;
}

[data-theme="dark"] .ed-sidebar {
  background: rgba(255, 255, 255, 0.015);
}

.ed-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.ed-sidebar-title {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--t3);
}

.ed-sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px;
}

.ed-sec-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  border-radius: var(--ed-radius);
  transition: var(--ed-transition);
  margin-bottom: 4px;
  border: 1px solid transparent;
}

.ed-sec-item:hover {
  background: var(--tb-bg);
}

.ed-sec-item.active {
  background: var(--tb-bg);
  border-color: var(--border);
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.ed-sec-item-label {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--t1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ed-sec-item-type {
  font-size: 0.5rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--t2);
  padding: 2px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  flex-shrink: 0;
}

.ed-sec-arrows {
  display: flex;
  flex-direction: column;
}

.ed-arrow-btn {
  width: 24px;
  height: 18px;
  background: none;
  border: none;
  color: var(--t3);
  cursor: pointer;
  border-radius: 2px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ed-arrow-btn:hover {
  color: var(--t1);
  background: var(--tb-hbg);
}

.ed-arrow-btn:disabled {
  opacity: 0.1;
  cursor: default;
}

/* ── Main Content ── */
.ed-main {
  flex: 1;
  overflow-y: auto;
  padding: 40px 48px 80px;
  scroll-behavior: smooth;
}

.ed-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--t3);
  font-size: 0.88rem;
  font-weight: 500;
}

/* ── Section Header Editor ── */
.ed-section-header {
  margin-bottom: 32px;
}

.ed-section-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.ed-section-meta {
  display: flex;
  gap: 12px;
  align-items: center;
}

.ed-section-type-badge {
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--t2);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--tb-bg);
}

/* ── Form Elements ── */
.ed-field-group {
  margin-bottom: 20px;
}

.ed-field-label {
  display: block;
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--t2);
  margin-bottom: 8px;
}

.ed-field-row {
  display: flex;
  gap: 16px;
}

.ed-field-col {
  flex: 1;
  min-width: 0;
}

.ed-field-col-label {
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--t3);
  margin-bottom: 6px;
}

.ed-input,
.ed-textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--tb-bg);
  border: 1px solid transparent;
  border-radius: var(--ed-radius);
  color: var(--t1);
  font-family: inherit;
  font-size: 0.88rem;
  transition: var(--ed-transition);
  outline: none;
}

.ed-input:focus,
.ed-textarea:focus {
  background: transparent;
  border-color: var(--t1);
  box-shadow: var(--ed-focus-ring);
}

.ed-input::placeholder {
  color: var(--t3);
  opacity: 0.6;
}

.ed-textarea {
  resize: vertical;
  min-height: 60px;
  line-height: 1.5;
}

select.ed-input {
  appearance: none;
  cursor: pointer;
  background-image: url('data:image/svg+xml;utf8,<svg fill="%237d7d7d" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/><path d="M0 0h24v24H0z" fill="none"/></svg>');
  background-repeat: no-repeat;
  background-position-x: 98%;
  background-position-y: 50%;
  padding-right: 30px;
}

[data-theme="dark"] select.ed-input {
  background-image: url('data:image/svg+xml;utf8,<svg fill="%238e8e8e" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/><path d="M0 0h24v24H0z" fill="none"/></svg>');
}

/* ── Select Add Section ── */
.ed-select-add {
  appearance: none;
  cursor: pointer;
  background-color: var(--tb-bg);
  border: 1px solid transparent;
  border-radius: calc(var(--ed-radius) - 2px);
  color: var(--t1);
  font-family: inherit;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 6px 24px 6px 12px;
  background-image: url('data:image/svg+xml;utf8,<svg fill="%237d7d7d" height="18" viewBox="0 0 24 24" width="18" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/><path d="M0 0h24v24H0z" fill="none"/></svg>');
  background-repeat: no-repeat;
  background-position: right 4px center;
  outline: none;
  transition: var(--ed-transition);
}

.ed-select-add:focus, .ed-select-add:hover {
  background-color: var(--tb-hbg);
  border-color: var(--t2);
}

[data-theme="dark"] .ed-select-add {
  background-image: url('data:image/svg+xml;utf8,<svg fill="%238e8e8e" height="18" viewBox="0 0 24 24" width="18" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/><path d="M0 0h24v24H0z" fill="none"/></svg>');
}

/* ── Shared Toggle ── */
.ed-shared-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 10px;
  cursor: pointer;
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--t3);
  user-select: none;
  transition: var(--ed-transition);
}

.ed-shared-toggle:hover {
  color: var(--t1);
}

.ed-shared-toggle input {
  margin: 0;
  cursor: pointer;
}

/* ── Item Cards ── */
.ed-items-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ed-item-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--ed-card-radius);
  overflow: hidden;
  transition: var(--ed-transition);
}

.ed-item-card:hover {
  border-color: var(--t3);
  box-shadow: var(--ed-shadow);
}

.ed-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
  gap: 12px;
  background: rgba(0,0,0,0.015);
  transition: background .2s;
}

[data-theme="dark"] .ed-item-header {
  background: rgba(255,255,255,0.015);
}

.ed-item-header:hover {
  background: var(--tb-bg);
}

.ed-item-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--t1);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ed-item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.ed-item-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  color: var(--t3);
  cursor: pointer;
  border-radius: 50%;
  font-size: 14px;
  transition: var(--ed-transition);
}

.ed-item-action-btn:hover {
  background: var(--tb-hbg);
  color: var(--t1);
  transform: scale(1.05);
}

.ed-item-action-btn--danger:hover {
  background: rgba(224, 85, 85, 0.12);
  color: #ff4d4d;
}

.ed-item-body {
  padding: 24px 20px;
  display: none;
  border-top: 1px solid var(--border);
  animation: edSlideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes edSlideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.ed-item-card.open {
  border-color: var(--t2);
  box-shadow: var(--ed-shadow);
}

.ed-item-card.open .ed-item-body {
  display: block;
}

/* ── Highlights (Bullet Points) ── */
.ed-highlights-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ed-highlight-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.ed-highlight-inputs {
  flex: 1;
  display: flex;
  gap: 16px;
}

.ed-highlight-inputs .ed-field-col {
  flex: 1;
}

.ed-highlight-remove {
  margin-top: 6px;
  flex-shrink: 0;
}

/* ── Tags Input ── */
.ed-tags-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--tb-bg);
  border: 1px solid transparent;
  border-radius: var(--ed-radius);
  color: var(--t1);
  font-family: inherit;
  font-size: 0.84rem;
  outline: none;
  transition: var(--ed-transition);
}

.ed-tags-input:focus {
  background: transparent;
  border-color: var(--t1);
  box-shadow: var(--ed-focus-ring);
}

/* ── Publication Editor ── */
.ed-pub-authors {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.ed-pub-author-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ed-pub-author-row .ed-input {
  flex: 1;
}

.ed-pub-bold-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--t3);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: var(--ed-transition);
}

.ed-pub-bold-toggle:hover {
  color: var(--t1);
}

.ed-pub-bold-toggle input {
  margin: 0;
  cursor: pointer;
}

.ed-pub-preview {
  font-size: 0.84rem;
  line-height: 1.75;
  color: var(--t2);
  border-left: 2px solid var(--t1);
  padding: 12px 16px;
  margin-top: 16px;
  background: var(--tb-bg);
  border-radius: 0 var(--ed-radius) var(--ed-radius) 0;
}

/* ── Info Row Editor ── */
.ed-info-rows {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ed-info-row-card {
  border: 1px solid var(--border);
  border-radius: var(--ed-card-radius);
  padding: 16px;
  display: flex;
  gap: 20px;
  align-items: flex-start;
  transition: var(--ed-transition);
  background: var(--bg);
}

.ed-info-row-card:hover {
  border-color: var(--t3);
  box-shadow: var(--ed-shadow);
}

.ed-info-row-fields {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.ed-info-row-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

/* ── Add Section Dialog ── */
.ed-add-section-form {
  padding: 24px;
  border: 1px dashed var(--border2);
  border-radius: var(--ed-card-radius);
  margin-top: 12px;
  background: var(--tb-bg);
  transition: var(--ed-transition);
}

.ed-add-section-form:hover {
  border-color: var(--t1);
  background: transparent;
}

.ed-add-section-form .ed-field-group {
  margin-bottom: 16px;
}

/* ── Toast Notification ── */
.ed-toast {
  position: fixed;
  bottom: 32px;
  right: 32px;
  padding: 14px 24px;
  background: var(--t1);
  color: var(--bg);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  border-radius: var(--ed-radius);
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  z-index: 10001;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.ed-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.ed-toast.error {
  background: #e05555;
  color: #fff;
}

/* ── Confirm Dialog ── */
.ed-confirm-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  z-index: 10002;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: edFadeIn 0.2s ease-out;
}

.ed-confirm-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--ed-card-radius);
  padding: 32px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
  animation: edSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes edSlideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.ed-confirm-msg {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--t1);
  margin-bottom: 24px;
  line-height: 1.6;
}

.ed-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.ed-mobile-back-btn {
  display: none;
}

/* ── Responsive ── */
@media (max-width: 840px) {
  .ed-layout {
    display: block;
  }

  .ed-sidebar {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0; left: 0;
    border-right: none;
    transition: transform 0.35s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.35s ease;
    z-index: 1;
    background: var(--bg);
  }

  .ed-main {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0; left: 0;
    padding: 24px 20px 60px;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 2;
    background: var(--bg);
    box-shadow: -10px 0 30px rgba(0,0,0,0.05);
  }

  .ed-layout.show-detail .ed-sidebar {
    transform: translateX(-30%);
    opacity: 0;
    pointer-events: none;
  }

  .ed-layout.show-detail .ed-main {
    transform: translateX(0);
  }

  [data-theme="dark"] .ed-main {
    box-shadow: -10px 0 30px rgba(0,0,0,0.5);
  }

  .ed-mobile-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: none;
    color: var(--t2);
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    padding: 8px 0 24px 0;
    margin-bottom: 8px;
    transition: color 0.2s;
  }
  .ed-mobile-back-btn:hover {
    color: var(--t1);
  }

  .ed-field-row {
    flex-direction: column;
    gap: 12px;
  }

  .ed-info-row-fields {
    grid-template-columns: 1fr;
  }

  .ed-highlight-inputs {
    flex-direction: column;
    gap: 12px;
  }

  .ed-section-header-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .ed-info-row-card {
    flex-direction: column;
  }

  .ed-info-row-actions {
    flex-direction: row;
    align-self: flex-end;
    margin-top: 16px;
  }
}

@media (max-width: 540px) {
  .ed-topbar {
    padding: 12px 16px;
    height: auto;
    min-height: 60px;
    flex-wrap: wrap;
    gap: 12px;
  }

  .ed-topbar-left, .ed-topbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .ed-sidebar-header {
    flex-wrap: wrap;
    gap: 12px;
  }
}

/* ── Passcode Status Badges ── */
.ed-pc-status {
  font-size: 0.5rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1;
}

.ed-pc-status--active {
  color: #1a8a3f;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.25);
}

[data-theme="dark"] .ed-pc-status--active {
  color: #4ade80;
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.3);
}

.ed-pc-status--expired {
  color: #c53030;
  background: rgba(224, 85, 85, 0.1);
  border: 1px solid rgba(224, 85, 85, 0.2);
}

[data-theme="dark"] .ed-pc-status--expired {
  color: #fc8181;
  background: rgba(224, 85, 85, 0.15);
  border-color: rgba(224, 85, 85, 0.3);
}

/* ── Scrollbar styling ── */
.ed-sidebar-list::-webkit-scrollbar,
.ed-main::-webkit-scrollbar {
  width: 6px;
}

.ed-sidebar-list::-webkit-scrollbar-thumb,
.ed-main::-webkit-scrollbar-thumb {
  background: var(--t3);
  border-radius: 3px;
}

.ed-sidebar-list::-webkit-scrollbar-track,
.ed-main::-webkit-scrollbar-track {
  background: transparent;
}