/* base.css — Robot iframe, editor layout, top toolbar, action bar, main editor area, right sidebar panel, status bar, responsive rules */
/* Editor page: remove default main-content padding (handled by internal components) */
.main-content:has(.editor-toolbar),
.main-content:has(.fullpage-chat) {
  padding: 0;
}

/* ============ ROBOT IFRAME — full-bleed, no chrome ============ */
.main-content:has(#robot-frame) {
  padding: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

/* Hide navbar when robot tool is active */
.main-content:has(#robot-frame) .top-navbar {
  display: none;
}

#robot-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: none;
  display: block;
}

@media (max-width: 767px) {
  .main-content:has(#robot-frame) {
    padding: 0;
    padding-bottom: 0;
  }
}

/* Editor page layout: 3-column */
.editor-layout {
  display: flex;
  height: calc(100vh - 64px); /* account for status bar */
  gap: 0;
}

/* Top toolbar */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  background: var(--color-card);
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.08);
  flex-wrap: wrap;
}

.toolbar-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--color-text-secondary);
  transition: background 200ms, color 200ms;
}

.toolbar-btn:hover {
  background: rgba(0,0,0,0.05);
  color: var(--color-text-primary);
}

.toolbar-btn.active {
  background: rgba(0, 0, 0, 0.04);
  color: rgb(19, 19, 19);
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: rgba(0, 0, 0, 0.08);
  margin: 0 4px;
}

/* Action bar (AI tools) */
.action-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--color-bg);
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.08);
  overflow-x: auto;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  border: 0.5px solid rgba(0, 0, 0, 0.08);
  background: var(--color-card);
  color: var(--color-text-primary);
  transition: all 200ms;
}

.action-btn:hover {
  border-color: rgba(31, 31, 30, 0.2);
  color: rgb(19, 19, 19);
}

.action-btn.primary {
  background: rgb(19, 19, 19);
  color: white;
  border-color: rgba(31, 31, 30, 0.2);
}

.action-btn.primary:hover {
  background: rgb(50, 50, 48);
}

.action-btn svg {
  width: 16px;
  height: 16px;
}

/* Main editor area */
.editor-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.editor-area {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
  position: relative; /* for ghost text overlays */
}

.editor-placeholder {
  min-height: 400px;
  padding: 16px;
  font-size: 1rem;
  line-height: 1.8;
  outline: none;
  border: 2px dashed rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  background: var(--color-card);
}

.editor-placeholder .placeholder-text {
  color: rgb(115, 113, 108);
  font-style: italic;
}

/* Right sidebar panel */
.editor-panel {
  width: 360px;
  background: var(--color-card);
  border-left: 0.5px solid rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.editor-panel-header {
  display: flex;
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.08);
}

.panel-tab {
  flex: 1;
  padding: 12px 8px;
  text-align: center;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  border-bottom: 2px solid transparent;
  transition: all 200ms;
}

.panel-tab:hover {
  color: var(--color-text-primary);
}

.panel-tab.active {
  color: rgb(19, 19, 19);
  border-bottom-color: rgb(19, 19, 19);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: none;
}

.panel-content.active {
  display: block;
}

.panel-placeholder {
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  font-size: 0.875rem;
  text-align: center;
  padding: 32px;
}

/* Status bar */
.editor-status {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: var(--color-card);
  border-top: 0.5px solid rgba(0, 0, 0, 0.08);
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-spacer {
  flex: 1;
}

.status-save {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--color-success);
}

.autoforslag-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
}

.autoforslag-toggle .toggle-track {
  width: 32px;
  height: 18px;
}

.autoforslag-toggle .toggle-track::after {
  width: 14px;
  height: 14px;
}

.autoforslag-toggle input:checked + .toggle-track::after {
  transform: translateX(14px);
}

/* Responsive: tablet */
@media (max-width: 1279px) {
  .editor-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 90;
    box-shadow: -4px 0 12px rgba(0,0,0,0.1);
    transform: translateX(100%);
    transition: transform 200ms ease;
  }
  .editor-panel.open {
    transform: translateX(0);
  }
}

/* Mobile */
@media (max-width: 767px) {
  .editor-area {
    padding: 16px;
  }
  .editor-panel {
    width: 100%;
  }
  .editor-status {
    flex-wrap: wrap;
    gap: 8px;
  }
  .action-bar {
    padding: 8px;
  }

  /* ══════════════════════════════════════════════════════
     MOBILE REDESIGN — Maximum editor space, minimal chrome
     Design: Apple Notes / Google Docs mobile approach
     Bottom nav = 60px fixed. Everything else → editor.
     ══════════════════════════════════════════════════════ */

  /* ── 1. Container sizing — fill viewport minus bottom nav ── */
  /* Height must propagate: robot-container → #grammar-bot-container → .new-korrektur → .ss-app-content → .text-area-container */
  .grammar-page .main-content {
    padding-bottom: 0 !important;
    overflow: hidden !important;
  }

  .robot-container {
    height: calc(100vh - 78px) !important;
    height: calc(100dvh - 78px) !important;
    overflow: hidden !important;
  }

  #grammar-bot-container,
  .new-korrektur,
  .ss-app-content {
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
  }

  .text-area-container {
    height: 100% !important;
    max-height: 100% !important;
    min-height: 0 !important;
    overflow: hidden !important;
    gap: 0 !important;
    flex: 1 !important;
  }

  .inner-textarea-bottom {
    flex: 1 1 auto !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }

  /* ── 2. Top bar — compact: title + icons only ── */
  .main-textarea-section {
    padding: 0 !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
  }

  .top-controls {
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 6px 10px !important;
    border: none !important;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.08) !important;
    box-shadow: none !important;
    background: var(--color-card, #fff) !important;
    position: relative;
    z-index: 10000;
  }

  .ed-title-wrap {
    margin-right: 4px;
  }
  .ed-title-wrap .doc-title-input {
    font-size: 14px;
  }

  /* Paste button visible on mobile — users copy-paste between apps */

  /* ── 3. HIDE format toolbar entirely on mobile ── */
  /* Nobody uses B/I/List/audio/copy/download on phone */
  .format-toolbar {
    display: none !important;
  }

  /* Also hide the counter-nav-div wrapper (contains hidden counter + toolbar) */
  .counter-nav-div {
    display: none !important;
  }

  /* ── 4. Editor — full remaining space, comfortable padding ── */
  .textarea-wrapper {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    /* Extra scroll space so format bar (Kopiér/Læs op) doesn't cover last text line */
    padding-bottom: 80px !important;
  }

  #inputText {
    flex: 1 !important;
    padding: 12px 16px !important;
  }

  #inputText .ql-editor {
    min-height: 100px !important;
    padding: 0 !important;
    font-size: 16px !important;
    line-height: 1.7 !important;
  }

  /* Placeholder text — bigger, readable */
  .ql-editor.ql-blank::before {
    font-size: 16px !important;
    left: 0 !important;
    right: 0 !important;
  }

  /* ── 5. Mobile controls — HIDDEN (replaced by AI sparkle FAB) ── */
  /* Language auto-detected by AI — no need for mobileControlsContainer */
  .mobile-controls-container {
    display: none !important;
  }

  /* ── 5b. Mobile AI bottom sheet (clean architecture) ── */
  /* Wrapper is hidden by default; .open shows everything */
  .mobile-ai-wrap {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9000;
  }
  .mobile-ai-wrap.open {
    display: block;
  }
  /* When sheet is open, nav sits above it so FAB can toggle close */
  .mobile-nav.ai-sheet-open {
    z-index: 9001;
  }

  /* Overlay — same stacking context as sheet, so z-index works cleanly */
  .mobile-ai-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    z-index: 1;
  }

  /* Bottom sheet — slides up from bottom */
  .mobile-ai-sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 70vh;
    background: #fafaf8;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
    z-index: 2;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: mobileAiSlideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  }

  /* Drag handle */
  .mobile-ai-drag {
    width: 36px;
    height: 4px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    margin: 10px auto 4px;
    flex-shrink: 0;
  }
  [data-theme="dark"] .mobile-ai-drag {
    background: rgba(255, 255, 255, 0.2);
  }

  /* ── Segmented tab toggle (Korrektur / Tone) ── */
  .mobile-tab-toggle {
    display: flex;
    margin: 6px auto 2px;
    padding: 3px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    width: fit-content;
    gap: 2px;
  }
  .mobile-tab-btn {
    padding: 6px 20px;
    border: none;
    border-radius: 8px;
    background: transparent;
    font-family: var(--font-family, 'Nunito Sans', sans-serif);
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary, #8a8d98);
    cursor: pointer;
    transition: all 0.2s ease;
  }
  .mobile-tab-btn.active {
    background: #fff;
    color: var(--color-text-primary, #2b333b);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  }
  [data-theme="dark"] .mobile-tab-toggle {
    background: rgba(255, 255, 255, 0.08);
  }
  [data-theme="dark"] .mobile-tab-btn.active {
    background: rgba(255, 255, 255, 0.14);
    color: #e2e8f0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  }

  /* Content area — the moved .ai-card lives here */
  .mobile-ai-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  /* Instant tap feedback on chips — removes perceived delay */
  .mobile-ai-body .ai-chip:active {
    transform: scale(0.96);
    opacity: 0.7;
    transition: transform 50ms ease, opacity 50ms ease;
  }
  .mobile-ai-body .ai-chip {
    transition: transform 120ms ease, opacity 120ms ease;
  }

  /* Mobile-friendly sizing for chips inside our sheet */
  .mobile-ai-body .ai-chip {
    min-height: 48px;
  }
  .mobile-ai-body .ai-action-item {
    min-height: 44px;
  }
  .mobile-ai-body .ai-card-messages {
    padding: 12px 20px;
  }
  .mobile-ai-body .ai-card-input-row {
    padding: 10px 20px 10px;
  }
  .mobile-ai-body .ai-card-input-wrap {
    margin: 2px 0;
  }
  /* Hide the X/new-chat header inside bottom sheet — FAB toggle handles close */
  .mobile-ai-body .ai-card-header {
    display: none;
  }

  @keyframes mobileAiSlideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }

  /* Sheet close — smooth slide down instead of abrupt snap */
  .mobile-ai-wrap.closing .mobile-ai-sheet {
    animation: mobileAiSlideDown 0.2s ease forwards;
  }
  .mobile-ai-wrap.closing .mobile-ai-overlay {
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  @keyframes mobileAiSlideDown {
    from { transform: translateY(0); }
    to   { transform: translateY(100%); }
  }

  /* ── Sparkle FAB in mobile nav — matches desktop "Tjek hele teksten" charcoal ── */
  .ai-sparkle-fab {
    width: 52px !important;
    height: 52px !important;
    margin-top: -10px !important;
    background: linear-gradient(135deg, #4f5e6f 0%, #3b4857 100%) !important;
    box-shadow: 0 3px 14px rgba(59, 72, 87, 0.4) !important;
  }
  .ai-sparkle-fab svg {
    width: 24px !important;
    height: 24px !important;
  }

  .mobile-nav .ai-sparkle-icon {
    transform-origin: center;
  }
  .mobile-nav .ai-sparkle-icon path,
  .mobile-nav .ai-sparkle-icon line {
    stroke: #fff;
  }
  .mobile-nav .ai-spark-main {
    animation: ai-sparkle-spin 3s ease-in-out infinite;
    transform-origin: 12px 12px;
    will-change: transform, opacity;
  }
  .mobile-nav .ai-spark-plus {
    animation: ai-plus-blink 1.8s ease infinite;
    transform-origin: 21px 5px;
    will-change: transform, opacity;
  }
  .mobile-nav .ai-spark-plus:last-child {
    animation-delay: 0.9s;
  }

  @media (prefers-reduced-motion: reduce) {
    .mobile-nav .ai-spark-main,
    .mobile-nav .ai-spark-plus {
      animation: none !important;
      opacity: 0.85;
    }
  }

  /* ── 6. Word count (injected right) — show in top bar ── */
  .ed-injected-right {
    gap: 4px !important;
    padding-left: 4px !important;
  }
  .ed-injected-right::before {
    display: none !important;
  }
  .ed-word-count {
    font-size: 11px;
  }

  /* ── 8. Correction popup — clear mobile nav bar ── */
  .correction-popup {
    padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  }

  /* ── 7. Overflow menu — position from top, not bottom ── */
  .ed-overflow-menu {
    bottom: auto !important;
    top: calc(100% + 4px) !important;
  }

  /* ── 9. Mobile Format Bar — inline strip above bottom nav ── */
  .mobile-format-bar {
    position: fixed;
    /* bottom set by JS — measures nav height at runtime */
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 6px 0;
    background: var(--color-card, #fff);
    border-top: 0.5px solid rgba(0, 0, 0, 0.06);
  }

  .mobile-format-btn {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 10px 24px;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--color-text-secondary, #566a7f);
    font-family: 'Nunito Sans', sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: color 150ms;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-format-btn:active {
    background: rgba(0, 0, 0, 0.06);
  }
  .mobile-format-btn svg {
    flex-shrink: 0;
  }

  /* Copy done state */
  .mobile-format-btn.done {
    color: #22c55e;
  }

  /* TTS playing state */
  .mobile-format-btn.playing {
    color: rgb(19, 19, 19);
  }
  .mobile-format-btn.loading {
    opacity: 0.6;
    pointer-events: none;
  }

  .mobile-format-btn svg {
    width: 18px;
    height: 18px;
  }

  .mobile-format-sep {
    width: 1px;
    height: 20px;
    background: rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
  }

  /* Mere sheet must sit above format bar (z-index: 1001) */
  .mobile-more-sheet {
    z-index: 1100 !important;
  }
  .mobile-more-overlay {
    z-index: 1099 !important;
  }

  /* Dark mode */
  [data-theme="dark"] .mobile-format-bar {
    background: var(--color-card, #1a2035);
    border-color: rgba(255, 255, 255, 0.08);
  }
  [data-theme="dark"] .mobile-format-btn {
    color: rgba(255, 255, 255, 0.6);
  }
  [data-theme="dark"] .mobile-format-btn:active {
    background: rgba(255, 255, 255, 0.06);
  }
  [data-theme="dark"] .mobile-format-sep {
    background: rgba(255, 255, 255, 0.1);
  }

  /* ── 10. Editor Skeleton — shimmer while AI analyses ── */
  /* Overlay sits in .textarea-wrapper, covers everything including ql-container */
  .textarea-wrapper {
    position: relative;
  }
  .editor-skeleton {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    background: var(--color-card, #fff);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
    overflow: hidden;
  }
  .editor-skeleton.active {
    opacity: 1;
    visibility: visible;
  }
  .editor-skeleton-lines {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px 16px;
  }
  .editor-skeleton-line {
    height: 14px;
    min-height: 14px;
    flex-shrink: 0;
    border-radius: 6px;
    background: linear-gradient(90deg, #f0f0ee 25%, #e8e8e4 50%, #f0f0ee 75%);
    background-size: 200% 100%;
    animation: editorShimmer 1.5s ease infinite;
  }
  .editor-skeleton-line:nth-child(even) { animation-delay: 0.1s; }
  .editor-skeleton-line:nth-child(3n) { animation-delay: 0.2s; }
  .editor-skeleton-line:nth-child(5n) { animation-delay: 0.15s; }
  .editor-skeleton-line:nth-child(7n) { animation-delay: 0.25s; }

  @keyframes editorShimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
  }

  [data-theme="dark"] .editor-skeleton {
    background: var(--color-card, #1a2035);
  }
  [data-theme="dark"] .editor-skeleton-line {
    background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 75%);
    background-size: 200% 100%;
  }

  @media (prefers-reduced-motion: reduce) {
    .editor-skeleton-line { animation: none; opacity: 0.5; }
  }
}

/* ── Desktop sidebar layout fix — anchor content to top ── */
/* Korrektur/Tone/Assistent panels: push content up, not centered */
.correction-sidebar .sidebar-controls {
  margin-top: auto;
}

.correction-sidebar .correction-inner,
.correction-sidebar .improv-inner,
.correction-sidebar .style-inner {
  flex: 1;
}

/* Language selector — tighter to button */
.sidebar-controls .dk-translation-box {
  margin-top: 8px;
}

/* Inactive sidebar tabs — subtle affordance so they look clickable */
.hk-dropdown-option:not(.active) {
  border-radius: 8px;
  transition: background 0.15s ease;
}
.hk-dropdown-option:not(.active):hover {
  background: rgba(0, 0, 0, 0.04);
}

/* ── Hide Korrektur tab — duplicated by AI writing form ── */
#option-stave { display: none !important; }
.sidebar-icon-btn[data-option="improve-text"] { display: none !important; }

