/**
 * Markdown Viewer & Toolkit — Markdown Table Generator Stylesheet
 * Spreadsheet-like interactive table editor, alignment toggles,
 * output tabs, and responsive layout tokens.
 */

/* =====================================================================
   Table Generator Workspace Grid
   ===================================================================== */
.table-workspace-panes {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  flex: 1;
  min-height: 620px;
  background-color: var(--bg-surface);
  min-width: 0;
  max-width: 100%;
  width: 100%;
}

@media (max-width: 1024px) {
  .table-workspace-panes {
    grid-template-columns: minmax(0, 1fr);
    min-height: auto;
  }
}

/* =====================================================================
   Spreadsheet Editor Pane (Left)
   ===================================================================== */
.pane-table-editor {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-light);
  background-color: var(--bg-surface);
  position: relative;
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
  width: 100%;
}

@media (max-width: 1024px) {
  .pane-table-editor {
    border-right: none;
    border-bottom: 1px solid var(--border-light);
  }
}

/* Secondary Quick-Action Strip */
.table-editor-actions-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.5rem 1rem;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
}

.table-stats-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.table-stats-info strong {
  color: var(--text-main);
}

/* Subtle Accessible Horizontal Scroll Hint for Mobile */
.table-scroll-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--brand-primary);
  background-color: var(--brand-accent-subtle);
  border: 1px solid rgba(194, 94, 26, 0.2);
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  user-select: none;
  animation: fadeInHint 200ms ease;
  transition: opacity var(--transition);
}

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

.table-quick-btns {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Spreadsheet Grid Wrapper & Container */
.spreadsheet-scroll-area {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  padding: 1.25rem;
  background-color: var(--bg-page);
  position: relative;
  min-height: 380px;
  min-width: 0;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-medium) transparent;
  transition: box-shadow var(--transition);
}

/* Subtle visual edge indication when more columns exist horizontally */
.spreadsheet-scroll-area.has-overflow.can-scroll-right {
  box-shadow: inset -14px 0 12px -8px rgba(194, 94, 26, 0.18);
}

.spreadsheet-scroll-area.has-overflow.can-scroll-left {
  box-shadow: inset 14px 0 12px -8px rgba(0, 0, 0, 0.12);
}

.spreadsheet-scroll-area.has-overflow.can-scroll-left.can-scroll-right {
  box-shadow: inset 14px 0 12px -8px rgba(0, 0, 0, 0.12), inset -14px 0 12px -8px rgba(194, 94, 26, 0.18);
}

@media (max-width: 768px) {
  .spreadsheet-scroll-area {
    padding: 0.75rem 0.5rem;
  }
}

.spreadsheet-card {
  display: inline-block;
  min-width: 100%;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 0.5rem;
  box-sizing: border-box;
}

/* Spreadsheet Table Elements */
.spreadsheet-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  table-layout: auto;
  font-family: var(--font-sans);
}

/* Corner cell & row index header */
.row-header-th {
  width: 44px;
  min-width: 44px;
  max-width: 44px;
  background-color: var(--bg-surface-alt);
  border-bottom: 1px solid var(--border-medium);
  border-right: 1px solid var(--border-medium);
  padding: 0.25rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-subtle);
  font-weight: 600;
  user-select: none;
}

/* Column Header Cells */
.col-header-th {
  background-color: var(--bg-surface-alt);
  border-bottom: 1px solid var(--border-medium);
  border-right: 1px solid var(--border-light);
  padding: 0.35rem 0.45rem;
  min-width: 130px;
  position: relative;
}

.col-header-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.col-header-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  font-size: 0.7rem;
}

/* Column Alignment & Delete Buttons */
.btn-col-control {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem 0.3rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  font-size: 0.7rem;
  line-height: 1;
}

.btn-col-control:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-main);
  border-color: var(--border-light);
}

.btn-col-align {
  font-weight: 600;
  color: var(--brand-primary);
  background-color: var(--brand-accent-subtle);
}

.btn-col-delete:hover {
  color: var(--color-danger);
  background-color: rgba(220, 38, 38, 0.08);
}

/* Add Column Cell at the right of Header */
.add-col-th {
  background-color: transparent;
  border-bottom: 1px solid var(--border-medium);
  padding: 0.25rem;
  width: 36px;
  min-width: 36px;
  vertical-align: middle;
  text-align: center;
}

.btn-add-col {
  border: 1px dashed var(--border-medium);
  background: var(--bg-surface-alt);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.btn-add-col:hover {
  background-color: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #ffffff;
}

/* Row Action & Index Cell */
.row-index-td {
  background-color: var(--bg-surface-alt);
  border-bottom: 1px solid var(--border-light);
  border-right: 1px solid var(--border-medium);
  padding: 0.2rem;
  text-align: center;
  vertical-align: middle;
  user-select: none;
}

.row-index-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
}

.row-num-text {
  font-size: 0.75rem;
  color: var(--text-subtle);
  font-weight: 600;
  min-width: 14px;
}

.btn-row-delete {
  border: none;
  background: transparent;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 0.15rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
  transition: all var(--transition);
}

.row-index-td:hover .btn-row-delete,
.btn-row-delete:focus-visible {
  opacity: 1;
}

.btn-row-delete:hover {
  color: var(--color-danger);
  background-color: rgba(220, 38, 38, 0.1);
}

/* Data Cell */
.table-data-td {
  border-bottom: 1px solid var(--border-light);
  border-right: 1px solid var(--border-light);
  padding: 0;
  background-color: var(--bg-surface);
  position: relative;
  touch-action: pan-x pan-y;
}

/* Text Input inside Cell */
.cell-input {
  width: 100%;
  height: 100%;
  min-height: 38px;
  padding: 0.5rem 0.6rem;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text-main);
  background-color: transparent;
  border: 1px solid transparent;
  border-radius: 0;
  outline: none;
  box-sizing: border-box;
  touch-action: pan-x pan-y;
  transition: border-color var(--transition), background-color var(--transition);
}

.col-header-th .cell-input {
  font-weight: 600;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  min-height: 32px;
  padding: 0.3rem 0.5rem;
}

.cell-input:focus {
  background-color: var(--bg-surface);
  border-color: var(--brand-primary);
  box-shadow: inset 0 0 0 1px var(--brand-primary);
  z-index: 2;
  position: relative;
}

/* Cell alignment styling reflecting column state */
.cell-input.align-left {
  text-align: left;
}

.cell-input.align-center {
  text-align: center;
}

.cell-input.align-right {
  text-align: right;
}

/* Add Row Button Row */
.table-footer-controls {
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-add-row-block {
  border: 1px dashed var(--border-medium);
  background-color: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all var(--transition);
}

.btn-add-row-block:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

/* =====================================================================
   Markdown Output & Preview Pane (Right)
   ===================================================================== */
.pane-table-output {
  display: flex;
  flex-direction: column;
  background-color: var(--bg-surface);
  position: relative;
  overflow: hidden;
}

/* Output View Mode Tabs (Segmented Control) */
.view-tabs-control {
  display: inline-flex;
  align-items: center;
  background-color: var(--bg-surface-alt);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.tab-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.3rem 0.65rem;
  border-radius: calc(var(--radius-sm) - 1px);
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  user-select: none;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-main);
  background-color: var(--bg-surface-hover);
}

.tab-btn:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 1px;
}

.tab-btn.active {
  background-color: var(--bg-surface);
  color: var(--brand-primary);
  border-color: var(--border-light);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
}

[data-theme="dark"] .view-tabs-control {
  background-color: var(--bg-page);
  border-color: var(--border-medium);
}

[data-theme="dark"] .tab-btn.active {
  background-color: var(--bg-surface-alt);
  color: var(--brand-accent);
  border-color: var(--border-medium);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* Source code pre container */
.table-markdown-container {
  flex: 1;
  position: relative;
  overflow: auto;
  min-height: 480px;
  max-height: 720px;
  background-color: var(--bg-page);
  scrollbar-width: thin;
  scrollbar-color: var(--border-medium) transparent;
}

.table-markdown-container.hidden {
  display: none !important;
}

.table-markdown-pre {
  margin: 0;
  padding: 1.25rem 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  white-space: pre;
  word-break: normal;
  overflow-x: auto;
  color: var(--text-main);
  background-color: transparent;
  border: none;
  box-sizing: border-box;
  tab-size: 2;
}

/* Rendered Preview Container */
.table-preview-container {
  flex: 1;
  position: relative;
  overflow: auto;
  min-height: 480px;
  max-height: 720px;
  padding: 1.5rem;
  background-color: var(--bg-surface);
}

.table-preview-container.hidden {
  display: none !important;
}

/* Highlighted Copy Button */
.btn-copy-highlight {
  background-color: var(--brand-primary);
  color: #ffffff !important;
  font-weight: 600;
  border-color: var(--brand-primary);
  box-shadow: var(--shadow-sm);
}

.btn-copy-highlight:hover {
  background-color: var(--brand-primary-hover);
  border-color: var(--brand-primary-hover);
}

/* Modal Dialog for Import (CSV / TSV / Markdown) */
.import-modal-textarea {
  width: 100%;
  min-height: 180px;
  max-height: 300px;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.5;
  padding: 0.75rem;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface-alt);
  color: var(--text-main);
  box-sizing: border-box;
  outline: none;
  resize: vertical;
  margin-top: 0.5rem;
  margin-bottom: 0.75rem;
}

.import-modal-textarea:focus {
  border-color: var(--brand-primary);
}

.import-warning-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 1rem;
}

.import-error-banner {
  display: none;
  padding: 0.5rem 0.75rem;
  background-color: rgba(220, 38, 38, 0.1);
  color: var(--color-danger);
  border: 1px solid rgba(220, 38, 38, 0.2);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  margin-bottom: 0.75rem;
}

.import-error-banner.show {
  display: block;
}
