/* AfroLex Editor — Google Docs style */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ae-bg: #f0f2f5;
  --ae-toolbar: #fff;
  --ae-border: #dadce0;
  --ae-text: #202124;
  --ae-muted: #5f6368;
  --ae-brand: #1a6b3c;
  --ae-brand-light: #e6f4ea;
  --ae-warn: #c5221f;
  --ae-warn-bg: #fce8e6;
  --ae-valid: #137333;
  --ae-valid-bg: #e6f4ea;
  --ae-page-shadow: 0 1px 3px rgba(60,64,67,.15), 0 4px 8px rgba(60,64,67,.1);
  --ae-font: 'Roboto', 'Manrope', system-ui, sans-serif;
  --ae-doc-font: 'Roboto', Georgia, serif;
}

body.afrolex-editor-page {
  margin: 0;
  font-family: var(--ae-font);
  background: var(--ae-bg);
  color: var(--ae-text);
  overflow: hidden;
}

.afrolex-editor-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* Toolbar */
.ae-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  height: 56px;
  background: var(--ae-toolbar);
  border-bottom: 1px solid var(--ae-border);
  flex-shrink: 0;
}

.ae-toolbar-left,
.ae-toolbar-center,
.ae-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ae-toolbar-center { flex: 1; justify-content: center; }

.ae-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ae-text);
  white-space: nowrap;
}

.ae-logo em { color: var(--ae-brand); font-style: normal; }

.ae-logo-mark {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--ae-brand);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ae-doc-title {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 0.95rem;
  font-weight: 500;
  font-family: var(--ae-font);
  min-width: 160px;
  max-width: 280px;
  color: var(--ae-text);
  background: transparent;
}

.ae-doc-title:hover { background: #f1f3f4; }
.ae-doc-title:focus {
  outline: none;
  border-color: var(--ae-brand);
  background: #fff;
}

.ae-tb-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--ae-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ae-tb-btn:hover { background: #f1f3f4; color: var(--ae-text); }
.ae-tb-sep { width: 1px; height: 20px; background: var(--ae-border); margin: 0 4px; }

/* API toggle */
.ae-api-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 0.8rem;
  color: var(--ae-muted);
}

.ae-api-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.ae-toggle-track {
  width: 36px;
  height: 20px;
  background: #bdc1c6;
  border-radius: 10px;
  position: relative;
  transition: background 0.2s;
}

.ae-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}

.ae-api-toggle input:checked + .ae-toggle-track { background: var(--ae-brand); }
.ae-api-toggle input:checked + .ae-toggle-track .ae-toggle-thumb { transform: translateX(16px); }
.ae-api-toggle input:disabled + .ae-toggle-track { opacity: 0.5; }

.ae-status {
  font-size: 0.75rem;
  color: var(--ae-muted);
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ae-status.is-connected { color: var(--ae-valid); }
.ae-status.is-error { color: var(--ae-warn); }

.ae-banner {
  padding: 8px 16px;
  font-size: 0.8rem;
  text-align: center;
  flex-shrink: 0;
}

.ae-banner-warn {
  background: #fef7e0;
  color: #7c4a03;
  border-bottom: 1px solid #f9e8b8;
}

/* Workspace */
.ae-workspace {
  flex: 1;
  overflow: auto;
  padding: 24px 16px 48px;
}

.ae-page-wrap {
  max-width: 816px;
  margin: 0 auto;
}

.ae-page {
  background: #fff;
  min-height: 1056px;
  box-shadow: var(--ae-page-shadow);
  border-radius: 2px;
}

.ae-editor-stack {
  position: relative;
  min-height: 960px;
}

.ae-editor {
  padding: 96px 96px 72px;
  font-family: var(--ae-doc-font);
  font-size: 11pt;
  line-height: 1.5;
  letter-spacing: 0.01em;
  word-wrap: break-word;
  min-height: 960px;
  outline: none;
  color: var(--ae-text);
}

.ae-editor:empty::before {
  content: attr(data-placeholder);
  color: #9aa0a6;
  pointer-events: none;
}

/* In AfroLex lexicon — invisible wrapper; spellcheck=false skips browser red underline */
.ae-editor .ae-lexicon-ok {
  background: none;
  text-decoration: none;
}

/* Misspelled name / spelling error - wavy red underline and red pipe */
.ae-editor .ae-mark-warn {
  text-decoration: none;
  cursor: pointer;
  background: #fce8e6;
  border-radius: 2px;
  transition: background 0.15s;
}

.ae-editor .ae-mark-warn:hover {
  background: #f5c6c3;
}

/* Name form */
.ae-form-card {
  margin-top: 24px;
  background: #fff;
  box-shadow: var(--ae-page-shadow);
  border-radius: 2px;
  padding: 32px 40px 40px;
}

.ae-form-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ae-text);
}

.ae-form-desc {
  font-size: 0.85rem;
  color: var(--ae-muted);
  margin-bottom: 24px;
}

.ae-name-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 20px;
}

.ae-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ae-field-ac-wrap {
  position: relative;
}

.ae-field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ae-muted);
}

.ae-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--ae-border);
  border-radius: 6px;
  font-family: var(--ae-font);
  font-size: 0.9rem;
  color: var(--ae-text);
  background: #fff;
}

.ae-input:focus {
  outline: none;
  border-color: var(--ae-brand);
  box-shadow: 0 0 0 2px var(--ae-brand-light);
}

.ae-input-readonly {
  background: #f8f9fa;
  color: var(--ae-muted);
}

.ae-form-autocomplete {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 50;
  background: #fff;
  border: 1px solid var(--ae-border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(60,64,67,.15);
  max-height: 220px;
  overflow-y: auto;
}

.ae-form-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 4px;
}

.ae-btn {
  padding: 10px 22px;
  border-radius: 6px;
  font-family: var(--ae-font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
}

.ae-btn-primary {
  background: var(--ae-brand);
  color: #fff;
}

.ae-btn-primary:hover {
  background: #155a32;
}

.ae-form-msg {
  font-size: 0.85rem;
  color: var(--ae-valid);
}

.ae-form-msg.is-error {
  color: var(--ae-warn);
}

@media (max-width: 640px) {
  .ae-name-form { grid-template-columns: 1fr; }
  .ae-form-card { padding: 24px 20px; }
}

/* Editor autocomplete (fixed) */
.ae-autocomplete {
  position: fixed;
  z-index: 1000;
  min-width: 260px;
  max-width: 360px;
  background: #fff;
  border: 1px solid var(--ae-border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(60,64,67,.2);
  max-height: 240px;
  overflow-y: auto;
}

.ae-ac-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: var(--ae-font);
  border-bottom: 1px solid #f1f3f4;
}

.ae-ac-item:last-child { border-bottom: none; }
.ae-ac-item:hover,
.ae-ac-item.is-active { background: #e8f0fe; }

.ae-ac-word {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ae-text);
}

.ae-ac-meta {
  font-size: 0.75rem;
  color: var(--ae-muted);
  margin-top: 2px;
}

/* Footer */
.ae-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 36px;
  background: var(--ae-toolbar);
  border-top: 1px solid var(--ae-border);
  font-size: 0.75rem;
  color: var(--ae-muted);
  flex-shrink: 0;
}

.ae-legend { display: flex; gap: 16px; }

.ae-legend-item::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: middle;
}

.ae-legend-ok::before {
  background: transparent;
  border-bottom: 2px solid var(--ae-valid);
}

.ae-legend-warn::before {
  background: transparent;
  border-bottom: 2px wavy var(--ae-warn);
}

@media (max-width: 768px) {
  .ae-editor { padding: 48px 32px; }
  .ae-doc-title { max-width: 140px; }
  .ae-toggle-label { display: none; }
}

/* ── Typo-correction hover popup ──────────────────────────────────────────── */

/* Replace-mode autocomplete item layout */
.ae-ac-item--replace {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
}

.ae-ac-item-inner {
  flex: 1;
  min-width: 0;
}

/* "Replace" badge shown on the right of each suggestion */
.ae-ac-replace-badge {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  background: var(--ae-warn);
  border-radius: 4px;
  padding: 2px 7px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.ae-ac-item--replace:hover .ae-ac-replace-badge,
.ae-ac-item--replace.is-active .ae-ac-replace-badge {
  opacity: 1;
}

/* Subtle header label for the popup when it's a correction */
.ae-autocomplete:not([hidden]) {
  /* ensure popup has a visible top border in correction context */
}
