/* OpenMath Worksheet & Start Page Styles */

/* 1. Start Page View (Start.mw) */
.start-page-container {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-canvas);
  padding: 20px;
}

.start-page-card {
  width: 100%;
  max-width: 520px;
  background-color: var(--bg-cell);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.start-page-header {
  text-align: center;
}

.start-page-title {
  font-size: 24px;
  font-weight: bold;
  color: #1e3a8a;
  margin-bottom: 2px;
}

body.theme-dark .start-page-title {
  color: #38bdf8;
}

.start-page-subtitle {
  font-size: 11px;
  color: var(--text-secondary);
}

.start-page-sep {
  height: 1px;
  background-color: var(--border-light);
  border: none;
}

.start-page-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.start-action-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  height: 42px;
  padding: 0 16px;
  background-color: var(--btn-bg);
  border: 1.5px solid var(--btn-border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
}

.start-action-btn:hover {
  background-color: #eff6ff;
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.12);
}

body.theme-dark .start-action-btn:hover {
  background-color: #1e3a5f;
  border-color: #38bdf8;
  color: #38bdf8;
}

.start-action-btn svg {
  flex-shrink: 0;
}

.start-page-hint {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.4;
}

/* Developers section card on Start Page */
.start-page-dev-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.start-page-dev-title {
  font-size: 11px;
  color: var(--text-secondary);
}

.start-page-dev-links {
  display: flex;
  gap: 10px;
  width: 100%;
}

.start-dev-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  background-color: var(--bg-cell);
  border: 1px solid var(--btn-border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.start-dev-btn:hover {
  background-color: #eff6ff;
  border-color: var(--accent);
  color: var(--accent);
}

body.theme-dark .start-dev-btn:hover {
  background-color: #1e3a5f;
  border-color: #38bdf8;
  color: #38bdf8;
}

/* 2. Interactive Worksheet Canvas */
.worksheet-scroll-container {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: auto;
  padding: 16px 20px 80px 20px;
  background-color: var(--bg-canvas);
  cursor: text;
}

.worksheet-canvas {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  min-height: calc(100vh - 160px);
  background-color: var(--bg-cell);
  border: 1px solid var(--border);
  border-radius: 2px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  padding: 18px 24px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Continuous Section Scope Overlay */
.scope-overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* Execution Cell Group */
.worksheet-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 2px 4px 4px 18px;
  margin-bottom: 2px;
  border-radius: 2px;
  transition: background-color 0.1s;
}

.worksheet-cell.active {
  background-color: rgba(37, 99, 235, 0.02);
}

.worksheet-cell.selected {
  background-color: rgba(37, 99, 235, 0.06);
}

/* Left Group Bracket Indicator `[` - Disabled: brackets are only for section/subsection hierarchies */
.cell-bracket-bar {
  display: none !important;
}

/* Input Row */
.cell-input-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-height: 22px;
}

/* Cell Prompt `>` - Disabled: clean document presentation without command-line prompt */
.cell-prompt {
  display: none !important;
}

.cell-input-edit {
  flex: 1;
  min-height: 20px;
  outline: none;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: "Times New Roman", Times, serif;
  font-size: 13px;
  font-style: italic;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.cell-input-edit.mode-1d {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 12px;
  font-style: normal;
}

.cell-input-edit.mode-text {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 12px;
  font-style: normal;
}

.cell-input-edit img {
  max-width: 100%;
  height: auto;
  display: inline-block;
  vertical-align: middle;
  border-radius: 2px;
  margin: 4px 0;
}

/* Output Area */
.cell-output-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  padding: 4px 10px;
  background-color: transparent;
}

.cell-output-math {
  flex: 1;
  color: var(--math-blue);
  font-size: 14px;
  overflow-x: auto;
  text-align: center;
}

.cell-output-math.align-left {
  text-align: left;
}

.cell-equation-label {
  font-family: "Times New Roman", Times, serif;
  font-size: 12px;
  color: var(--text-secondary);
  user-select: none;
  margin-left: 14px;
  flex-shrink: 0;
}

/* Section Header Cell */
.section-header-cell {
  padding-left: 6px;
  margin-top: 8px;
  margin-bottom: 4px;
}

.section-header-cell > .cell-bracket-bar {
  display: none;
}

.section-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-toggle-btn {
  width: 14px;
  height: 14px;
  min-width: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: #1e293b;
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  margin: 0;
  user-select: none;
  flex-shrink: 0;
  transform: translateY(-1px);
}

body.theme-dark .section-toggle-btn {
  color: #f1f5f9;
}

.section-title-edit {
  font-weight: 700;
  font-size: 16px;
  color: var(--text-primary);
  outline: none;
  border: none;
  background: transparent;
  flex: 1;
  line-height: 1.35;
}

.section-title-edit span[style*="background-color"] {
  display: inline-block;
  vertical-align: middle;
  line-height: 1.2;
  margin-right: 5px;
}

.section-header-cell.level-0 .section-title-edit {
  font-size: 16px;
  font-weight: 700;
}

.section-header-cell.level-1 .section-title-edit {
  font-size: 14px;
  font-weight: 700;
}

.section-header-cell.level-2 .section-title-edit {
  font-size: 13px;
  font-weight: 600;
}

.section-header-cell.level-3 .section-title-edit,
.section-header-cell.level-4 .section-title-edit {
  font-size: 12.5px;
  font-weight: 600;
}

.worksheet-cell.table-cell .cell-bracket-bar,
.worksheet-cell.table-cell .cell-prompt {
  display: none !important;
}

.worksheet-cell table {
  max-width: 100%;
  border-collapse: collapse;
  background-color: var(--bg-cell);
  color: var(--text-primary);
  border-color: var(--border);
}

.worksheet-cell table td,
.worksheet-cell table th {
  border-color: var(--border);
  color: var(--text-primary);
}

/* Instant dark mode table styling with zero lag */
body.theme-dark .worksheet-cell table {
  background-color: var(--bg-cell) !important;
  border-color: var(--border) !important;
  color: var(--text-primary) !important;
}

body.theme-dark .worksheet-cell table td,
body.theme-dark .worksheet-cell table th {
  background-color: var(--bg-cell) !important;
  border-color: var(--border) !important;
  color: var(--text-primary) !important;
}

body.theme-dark .worksheet-cell table td *,
body.theme-dark .worksheet-cell table th * {
  color: inherit;
}

body.theme-dark .worksheet-cell table td [style*="color: #000088"],
body.theme-dark .worksheet-cell table td [style*="color:#000088"],
body.theme-dark .worksheet-cell table td [style*="color: #0000bb"],
body.theme-dark .worksheet-cell table td [style*="color:#0000bb"],
body.theme-dark .worksheet-cell table td [style*="color: blue"] {
  color: #93c5fd !important;
}

/* Plot Container inside Cell */
.cell-plot-container {
  margin: 8px auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 650px;
}

.cell-plot-canvas {
  width: 100%;
  height: 320px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background-color: #ffffff;
}

body.theme-dark .cell-plot-canvas {
  background-color: #16202c;
  border-color: #2b384c;
}

/* Error Box inside Cell */
.cell-error-box {
  margin-top: 6px;
  padding: 8px 12px;
  background-color: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 4px;
  color: #b91c1c;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

body.theme-dark .cell-error-box {
  background-color: #450a0a;
  border-color: #dc2626;
  color: #fca5a5;
}

.error-title {
  font-weight: bold;
}

.error-suggestion-btn {
  align-self: flex-start;
  margin-top: 4px;
  padding: 3px 8px;
  background-color: #ffffff;
  border: 1px solid #dc2626;
  border-radius: 3px;
  color: #b91c1c;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.error-suggestion-btn:hover {
  background-color: #fee2e2;
}

body.theme-dark .error-suggestion-btn {
  background-color: #1a2332;
  border-color: #ef4444;
  color: #fca5a5;
}

/* Click to insert spacer at bottom of canvas */
.worksheet-click-spacer {
  flex: 1;
  min-height: 120px;
  cursor: text;
}

/* Print / PDF Export Styling */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    overflow: visible !important;
  }

  .app-titlebar,
  .menu-bar,
  .toolbars-wrapper,
  .document-tabs-bar,
  .dock-widget,
  .status-bar,
  .context-menu,
  .modal-overlay,
  .start-page-view,
  .worksheet-click-spacer {
    display: none !important;
  }

  .app-body,
  .app-center,
  .document-views-container,
  .worksheet-view {
    display: block !important;
    position: static !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #ffffff !important;
  }

  .worksheet-view:not(.active) {
    display: none !important;
  }

  .worksheet-canvas {
    max-width: 800px !important;
    width: 100% !important;
    margin: 0 auto !important;
    padding: 10px 20px !important;
    box-shadow: none !important;
    border: none !important;
    background: #ffffff !important;
    position: relative !important;
  }

  .scope-overlay-canvas {
    display: block !important;
    position: absolute !important;
  }

  .section-toggle-btn {
    display: inline-flex !important;
    color: #475569 !important;
    background: transparent !important;
    border: none !important;
  }

  .worksheet-cell {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    margin-bottom: 8px !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
  }

  .worksheet-cell.active,
  .worksheet-cell.selected {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
  }

  .cell-bracket-bar {
    display: none !important;
  }

  .cell-prompt {
    display: none !important;
  }

  .cell-output {
    color: #0000aa !important;
  }

  .cell-input-edit,
  .cell-input-editor {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    background: transparent !important;
    resize: none !important;
  }
}

/* Desktop-Fidelity Loading Overlay Dark Mode */
body.theme-dark #loading-overlay {
  background-color: rgba(15, 23, 42, 0.85);
}
body.theme-dark #loadingCard {
  background-color: #1e293b !important;
  border-color: #334155 !important;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4) !important;
}
body.theme-dark #loading-title {
  color: #f1f5f9 !important;
}
body.theme-dark #loading-filename {
  color: #60a5fa !important;
}
body.theme-dark #loading-status {
  color: #94a3b8 !important;
}
body.theme-dark #loadingCard div[style*="background-color: #e2e8f0"] {
  background-color: #334155 !important;
}

/* ==========================================================================
   Interactive Table & Image Resizing / Dragging Overlays
   (Matches ui/worksheet_cell.py lines 9742-10350)
   ========================================================================== */

.table-interactive-wrapper {
  position: relative;
  display: inline-block;
  max-width: 100%;
  margin: 6px 0;
  vertical-align: top;
}

.table-move-handle {
  position: absolute;
  top: -16px;
  left: 0;
  width: 28px;
  height: 15px;
  background: #eff6ff;
  border: 1px solid #2563eb;
  border-radius: 3px 3px 0 0;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 10;
  user-select: none;
}

body.theme-dark .table-move-handle {
  background: #1e293b;
  border-color: #60a5fa;
}

.table-move-handle:active {
  cursor: grabbing;
}

.table-move-handle .grip-dot {
  width: 3px;
  height: 3px;
  background-color: #2563eb;
  border-radius: 50%;
}

body.theme-dark .table-move-handle .grip-dot {
  background-color: #60a5fa;
}

.table-interactive-wrapper:hover .table-move-handle,
.table-interactive-wrapper.table-active .table-move-handle {
  opacity: 1;
}

.table-interactive-wrapper table {
  border-collapse: collapse;
  position: relative;
}

.table-corner-handle {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 9px;
  height: 9px;
  background: #ffffff;
  border: 1.5px solid #2563eb;
  border-radius: 2px;
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 15;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

body.theme-dark .table-corner-handle {
  background: #1e293b;
  border-color: #60a5fa;
}

.table-interactive-wrapper:hover .table-corner-handle,
.table-interactive-wrapper.table-active .table-corner-handle {
  opacity: 1;
}

/* Table column resize guide line */
.col-resize-guideline {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background-color: #2563eb;
  z-index: 20;
  pointer-events: none;
}

/* Image Resizing Wrappers & Corner Handles */
.image-resize-wrapper {
  position: relative;
  display: inline-block;
  margin: 4px;
  line-height: 0;
  user-select: none;
}

.image-resize-wrapper.image-selected {
  outline: 1.5px solid #2563eb;
  outline-offset: 1px;
}

body.theme-dark .image-resize-wrapper.image-selected {
  outline-color: #60a5fa;
}

.image-resize-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background-color: #ffffff;
  border: 1.5px solid #2563eb;
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  display: none;
  z-index: 25;
}

body.theme-dark .image-resize-handle {
  background-color: #1e293b;
  border-color: #60a5fa;
}

.image-resize-wrapper.image-selected .image-resize-handle {
  display: block;
}

.image-resize-handle.handle-tl {
  top: -4px;
  left: -4px;
  cursor: nwse-resize;
}

.image-resize-handle.handle-tr {
  top: -4px;
  right: -4px;
  cursor: nesw-resize;
}

.image-resize-handle.handle-bl {
  bottom: -4px;
  left: -4px;
  cursor: nesw-resize;
}

.image-resize-handle.handle-br {
  bottom: -4px;
  right: -4px;
  cursor: nwse-resize;
}
