/**
 * Grid Editor CSS - Shared styles for matrix-seq grid-editor component
 *
 * Usage:
 *   import '../../libs/matrix-seq/grid-editor.css';
 *
 * CSS Custom Properties Required:
 *   --notes-height: Dynamic height calculated by grid-editor.js (maxVoices * 60px)
 *   --column-width: Fixed column width in scroll mode (optional)
 *   --column-min-height: Fixed column min-height in scroll mode (optional)
 *   --select-color: Highlight/accent color (default: #FFBB33)
 *   --text-color: Main text color (default: #333)
 *   --text-dark: Dark theme text color (default: #e0e0e0)
 *
 * Dependencies:
 *   - None (standalone)
 */

/* ========== GRID EDITOR (Dynamic Columns by Pulse) ========== */
.matrix-grid-editor {
  display: flex;
  gap: 0px;
  margin: 0px 20px;
  padding: 0px;
  font-family: 'Courier New', monospace;
  font-size: 2.25rem; /* Reduced 25% from 3rem */
}

/* Label column (fixed on left) */
.grid-label-column {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  flex-shrink: 0;
  padding: 10px 35px;
}

.grid-row-label {
  font-weight: 600;
  font-size: 2.25rem; /* Reduced 25% from 3rem */
  color: var(--text-color, #333);
  text-align: center;
}

.grid-row-label--n {
  min-height: var(--notes-height, 120px); /* Dynamic height based on max voices */
  display: flex;
  align-items: flex-start;
  padding-top: 0px;
    margin-bottom: -25px; /* NUEVO: gap explícito (reducción 1/3) */
}

.grid-row-label--p {
  height: 0px; /* Reduced for minimal N-P gap */
  display: flex;
  align-items: flex-start;
}

[data-theme="dark"] .grid-row-label {
  color: var(--text-dark, #e0e0e0);
}

/* Columns container */
.grid-columns-container {
  display: flex;
  gap: 1px;
  flex-wrap: wrap;
}

/* Scroll mode: Fixed container size with overflow */
.matrix-grid-editor--scrollable {
  overflow: auto;
  scroll-behavior: smooth;
}

/* Scroll mode: Columns container becomes scrollable horizontally */
.grid-columns-container--scrollable {
  flex-wrap: nowrap; /* No wrap in scroll mode */
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 10px; /* Space for scrollbar */
}

/* Hide scrollbar in columns container for cleaner look */
.grid-columns-container--scrollable::-webkit-scrollbar {
  height: 8px;
}

.grid-columns-container--scrollable::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}

.grid-columns-container--scrollable::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

[data-theme="dark"] .grid-columns-container--scrollable::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .grid-columns-container--scrollable::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
}

/* Pulse column */
.pulse-column {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid transparent;
  padding: 3px 10px; /* Reduced vertical padding for compact N-P spacing */
  border-radius: 4px;
  transition: all 0.15s ease;
}

/* Scroll mode: Fixed column width */
.matrix-grid-editor--scrollable .pulse-column {
  flex-shrink: 0; /* Prevent shrinking */
  width: var(--column-width, auto);
  min-height: var(--column-min-height, auto);
}

.pulse-column.highlighted {
  background: rgba(255, 187, 51, 0.15);
  border-color: var(--select-color, #FFBB33);
  box-shadow: 0 0 10px var(--select-color, #FFBB33);
}

/* ========== Interval Zigzag Helpers ========== */
.zigzag-cell--hidden {
  display: none !important;
}

.zigzag-cell--ghost {
  visibility: hidden;
  pointer-events: none;
}

/* Validation tooltips: Now using shared styles from libs/shared-ui/index.css (.hover-tip.validation-warning) */

/* Notes area (dynamic height for vertical alignment) */
.column-notes-area {
  height: var(--notes-height, 120px); /* Fixed height to maintain P row alignment */
  min-height: var(--notes-height, 120px); /* Fallback */
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: flex-start; /* Align items to top */
}

/* Pulse area */
.column-pulse-area {
  height: 3px; /* Reduced for minimal N-P gap */
  display: flex;
  align-items: center;
}

.pulse-input {
  /* Invisible borders and background */
  border: 1px solid transparent;
  background: transparent;

  /* Layout - same size as note-input */
  width: 52.5px; /* Reduced 25% from 70px */
  padding: 6px 9px; /* Reduced 25% from 8px 12px */
  text-align: center;

  /* Typography - same size as note-input */
  font-size: 2.25rem; /* Reduced 25% from 3rem */
  font-weight: 700;
  font-family: 'Courier New', monospace;
  color: var(--text-color, #333);

  /* Interaction */
  outline: none;
  cursor: text;
  transition: all 0.15s ease;

  /* Caret color */
  caret-color: var(--select-color, #FFBB33);
}

[data-theme="dark"] .pulse-input {
  color: var(--text-dark, #e0e0e0);
}

.pulse-input:focus {
  background: color-mix(in srgb, var(--select-color, #FFBB33) 15%, transparent);
  border-color: color-mix(in srgb, var(--select-color, #FFBB33) 30%, transparent);
}

[data-theme="dark"] .pulse-input:focus {
  background: color-mix(in srgb, var(--select-color, #FFBB33) 12%, transparent);
  border-color: color-mix(in srgb, var(--select-color, #FFBB33) 25%, transparent);
}

.note-input {
  /* Invisible borders and background */
  border: 1px solid transparent;
  background: transparent;

  /* Layout */
  width: 52.5px; /* Reduced 25% from 70px */
  padding: 6px 9px; /* Reduced 25% from 8px 12px */
  text-align: center;

  /* Typography */
  font-size: 2.25rem; /* Reduced 25% from 3rem */
  font-weight: 700;
  font-family: 'Courier New', monospace;
  color: var(--text-color, #333);

  /* Interaction */
  outline: none;
  cursor: text;
  transition: all 0.15s ease;

  /* Caret color */
  caret-color: var(--select-color, #FFBB33);
}

[data-theme="dark"] .note-input {
  color: var(--text-dark, #e0e0e0);
}

.note-input:focus {
  background: color-mix(in srgb, var(--select-color, #FFBB33) 15%, transparent);
  border-color: color-mix(in srgb, var(--select-color, #FFBB33) 30%, transparent);
}

[data-theme="dark"] .note-input:focus {
  background: color-mix(in srgb, var(--select-color, #FFBB33) 12%, transparent);
  border-color: color-mix(in srgb, var(--select-color, #FFBB33) 25%, transparent);
}

.note-input::placeholder {
  color: #ccc;
  opacity: 0.5;
}

[data-theme="dark"] .note-input::placeholder {
  color: #666;
}

/* Responsive sizing for grid editor */
@media (max-width: 1024px) {
  .matrix-grid-editor {
    font-size: 2.5rem;
    margin: 20px 50px;
    gap: 10px; /* Reduced for tablets */
  }

  .grid-row-label {
    font-size: 2.5rem;
  }

  .grid-row-label--n,
  .column-notes-area {
    /* Dynamic height maintained at all screen sizes */
    min-height: var(--notes-height, 120px);
  }

  .grid-row-label--p,
  .column-pulse-area {
    height: 0px;
  }

  .note-input,
  .pulse-input {
    font-size: 2.5rem;
    width: 60px;
    padding: 6px 10px;
  }
}

@media (max-width: 900px) {
  .matrix-grid-editor {
    font-size: 1.4rem;
    margin: 10px 20px;
    gap: 8px; /* Compact gap for mobile landscape */
  }

  .grid-row-label {
    font-size: 1.4rem;
  }

  .grid-row-label--n,
  .column-notes-area {
    /* Dynamic height maintained at all screen sizes */
    min-height: var(--notes-height, 120px);
  }

  .grid-row-label--p,
  .column-pulse-area {
    height: 3px; /* Reduced for minimal N-P gap on mobile */
  }

  .note-input,
  .pulse-input {
    font-size: 1.4rem;
    width: 40px;
    padding: 4px 6px;
  }
}

@media (max-width: 480px) {
  .matrix-grid-editor {
    font-size: 1.1rem;
    margin: 8px 15px;
    gap: 6px; /* Even more compact for tiny screens */
  }

  .grid-row-label {
    font-size: 1.1rem;
  }

  .grid-row-label--n,
  .column-notes-area {
    /* Dynamic height maintained at all screen sizes */
    min-height: var(--notes-height, 120px);
  }

  .grid-row-label--p,
  .column-pulse-area {
    height: 3px; /* Reduced for minimal N-P gap on small screens */
  }

  .note-input,
  .pulse-input {
    font-size: 1.1rem;
    width: 35px;
    padding: 3px 5px;
  }
}

/* ========== NRX-IT MODE STYLES ========== */

/* NrX-iT mode container */
.matrix-grid-editor--nrx-it {
  flex-direction: column;
  gap: 0.5rem;
}

/* NrX zigzag container */
.grid-zigzag-container--nrx {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* NrX rows */
.zigzag-row--nrx,
.zigzag-row--it {
  display: flex;
  align-items: center;
  gap: 0;
}

/* NrX left labels (N and iT) */
.zigzag-left-label {
  font-weight: 600;
  font-size: 3rem;
  font-family: 'Courier New', monospace;
  color: var(--text-color, #333);
  text-align: center;
  min-width: 2.5rem;
  padding-right: 0.5rem;
}

[data-theme="dark"] .zigzag-left-label {
  color: var(--text-dark, #e0e0e0);
}

/* NrX cell (note + 'r' + registry) */
.zigzag-cell--nrx {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--grid-line-color, rgba(0, 0, 0, 0.15));
  border-radius: 4px;
  margin-right: 0.5rem;
  background: var(--bg-color, #fff);
}

[data-theme="dark"] .zigzag-cell--nrx {
  background: var(--bg-dark, #2a2a2a);
  border-color: var(--grid-line-color, rgba(255, 255, 255, 0.15));
}

/* NrX inputs */
.nrx-note-input,
.nrx-registry-input {
  width: 2.5rem;
  font-size: 1.5rem;
  font-family: 'Courier New', monospace;
  font-weight: 600;
  text-align: center;
  border: none;
  background: transparent;
  color: var(--text-color, #333);
  padding: 0.25rem;
}

.nrx-note-input:focus,
.nrx-registry-input:focus {
  outline: 2px solid var(--select-color, #FFBB33);
  border-radius: 2px;
}

[data-theme="dark"] .nrx-note-input,
[data-theme="dark"] .nrx-registry-input {
  color: var(--text-dark, #e0e0e0);
}

/* 'r' separator */
.nrx-separator {
  font-size: 1.2rem;
  font-weight: 400;
  color: var(--text-color, #333);
  opacity: 0.6;
  margin: 0 0.1rem;
}

[data-theme="dark"] .nrx-separator {
  color: var(--text-dark, #e0e0e0);
}

/* NrX-iT cell (temporal interval) */
.zigzag-cell--nrx-it {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--grid-line-color, rgba(0, 0, 0, 0.15));
  border-radius: 4px;
  margin-right: 0.5rem;
  background: var(--bg-color, #fff);
}

[data-theme="dark"] .zigzag-cell--nrx-it {
  background: var(--bg-dark, #2a2a2a);
  border-color: var(--grid-line-color, rgba(255, 255, 255, 0.15));
}

/* iT input */
.nrx-it-input {
  width: 2.5rem;
  font-size: 1.5rem;
  font-family: 'Courier New', monospace;
  font-weight: 600;
  text-align: center;
  border: none;
  background: transparent;
  color: var(--text-color, #333);
  padding: 0.25rem;
}

.nrx-it-input:focus {
  outline: 2px solid var(--select-color, #FFBB33);
  border-radius: 2px;
}

[data-theme="dark"] .nrx-it-input {
  color: var(--text-dark, #e0e0e0);
}

/* Invalid state for NrX inputs */
.nrx-note-input.invalid,
.nrx-registry-input.invalid,
.nrx-it-input.invalid {
  outline: 2px solid #dc3545;
  background: rgba(220, 53, 69, 0.1);
}

/* Placeholder styling */
.nrx-note-input::placeholder,
.nrx-registry-input::placeholder,
.nrx-it-input::placeholder {
  color: var(--text-color, #333);
  opacity: 0.3;
}

[data-theme="dark"] .nrx-note-input::placeholder,
[data-theme="dark"] .nrx-registry-input::placeholder,
[data-theme="dark"] .nrx-it-input::placeholder {
  color: var(--text-dark, #e0e0e0);
  opacity: 0.3;
}

/* ========== N-iT MODE STYLES (App20+) ========== */

/* N-iT note cell container (unified box with border) */
.zigzag-cell--n-it-note {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--select-color, #FFBB33);
  border-radius: 4px;
  margin-right: 0.5rem;
  background: color-mix(in srgb, var(--select-color, #FFBB33) 8%, transparent);
}

[data-theme="dark"] .zigzag-cell--n-it-note {
  background: color-mix(in srgb, var(--select-color, #FFBB33) 12%, transparent);
  border-color: var(--select-color, #FFBB33);
}

/* N-iT inputs inside the unified cell - NO borders */
.zigzag-cell--n-it-note .n-it-note-input,
.zigzag-cell--n-it-note .n-it-registry-input {
  width: 2.5rem;
  font-size: 1.5rem;
  font-family: 'Courier New', monospace;
  font-weight: 600;
  text-align: center;
  border: none;
  background: transparent;
  color: var(--text-color, #333);
  padding: 0.25rem;
  outline: none;
}

[data-theme="dark"] .zigzag-cell--n-it-note .n-it-note-input,
[data-theme="dark"] .zigzag-cell--n-it-note .n-it-registry-input {
  color: var(--text-dark, #e0e0e0);
}

/* Focus state - highlight individual input subtly */
.zigzag-cell--n-it-note .n-it-note-input:focus,
.zigzag-cell--n-it-note .n-it-registry-input:focus {
  background: color-mix(in srgb, var(--select-color, #FFBB33) 15%, transparent);
  border-radius: 2px;
}

/* Focus on cell container */
.zigzag-cell--n-it-note:focus-within {
  box-shadow: 0 0 6px color-mix(in srgb, var(--select-color, #FFBB33) 50%, transparent);
}

/* N-iT temporal cell */
.zigzag-cell--n-it-temporal {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--grid-line-color, rgba(0, 0, 0, 0.15));
  border-radius: 4px;
  margin-right: 0.5rem;
  background: var(--bg-color, #fff);
}

[data-theme="dark"] .zigzag-cell--n-it-temporal {
  background: var(--bg-dark, #2a2a2a);
  border-color: var(--grid-line-color, rgba(255, 255, 255, 0.15));
}

/* N-iT temporal input */
.n-it-temporal-input {
  width: 2.5rem;
  font-size: 1.5rem;
  font-family: 'Courier New', monospace;
  font-weight: 600;
  text-align: center;
  border: none;
  background: transparent;
  color: var(--text-color, #333);
  padding: 0.25rem;
}

.n-it-temporal-input:focus {
  outline: 2px solid var(--select-color, #FFBB33);
  border-radius: 2px;
}

[data-theme="dark"] .n-it-temporal-input {
  color: var(--text-dark, #e0e0e0);
}

/* NrX-iT mode responsive */
@media (max-width: 768px) {
  .nrx-note-input,
  .nrx-registry-input,
  .nrx-it-input {
    width: 2rem;
    font-size: 1.2rem;
  }

  .nrx-separator {
    font-size: 1rem;
  }

  .zigzag-cell--nrx,
  .zigzag-cell--nrx-it,
  .zigzag-cell--n-it-note,
  .zigzag-cell--n-it-temporal {
    padding: 0.15rem 0.35rem;
    margin-right: 0.35rem;
  }

  .zigzag-cell--n-it-note .n-it-note-input,
  .zigzag-cell--n-it-note .n-it-registry-input,
  .n-it-temporal-input {
    width: 2rem;
    font-size: 1.2rem;
  }
}

@media (max-width: 480px) {
  .nrx-note-input,
  .nrx-registry-input,
  .nrx-it-input {
    width: 1.8rem;
    font-size: 1rem;
    padding: 0.15rem;
  }

  .nrx-separator {
    font-size: 0.9rem;
  }

  .zigzag-cell--nrx,
  .zigzag-cell--nrx-it,
  .zigzag-cell--n-it-note,
  .zigzag-cell--n-it-temporal {
    padding: 0.1rem 0.25rem;
    margin-right: 0.25rem;
  }

  .zigzag-cell--n-it-note .n-it-note-input,
  .zigzag-cell--n-it-note .n-it-registry-input,
  .n-it-temporal-input {
    width: 1.8rem;
    font-size: 1rem;
    padding: 0.15rem;
  }
}

/* ========== SILENCE CELLS ========== */

/* Silence cell styling (when note = 's') */
.zigzag-cell--silence {
  border-style: dashed !important;
  border-color: var(--silence-color, #888) !important;
  background: color-mix(in srgb, var(--silence-color, #888) 8%, transparent) !important;
}

[data-theme="dark"] .zigzag-cell--silence {
  border-color: var(--silence-color, #aaa) !important;
  background: color-mix(in srgb, var(--silence-color, #888) 12%, transparent) !important;
}

/* Silence input shows 's' in italic, grayed */
.zigzag-cell--silence .n-it-note-input,
.zigzag-cell--silence .zigzag-input--is {
  font-style: italic;
  color: var(--silence-color, #888) !important;
}

[data-theme="dark"] .zigzag-cell--silence .n-it-note-input,
[data-theme="dark"] .zigzag-cell--silence .zigzag-input--is {
  color: var(--silence-color, #aaa) !important;
}

/* ========== DEGREE MODE ========== */
/* Simple single-row editor for scale degrees */

.matrix-grid-editor--degree {
  flex-direction: column;
  padding: 10px 15px;
}

.degree-main-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.grid-label-column--degree {
  padding: 5px 15px;
  flex-shrink: 0;
}

.grid-row-label--degree {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-color, #333);
  min-width: 50px;
}

[data-theme="dark"] .grid-row-label--degree {
  color: var(--text-dark, #e0e0e0);
}

.degree-columns-container {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding: 5px 0;
}

.degree-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  min-width: 45px;
}

.degree-column-header {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted, #888);
  text-align: center;
}

[data-theme="dark"] .degree-column-header {
  color: var(--text-muted-dark, #aaa);
}

.degree-input {
  width: 38px;
  height: 38px;
  border: 2px solid var(--border-color, #ccc);
  border-radius: 6px;
  text-align: center;
  font-size: 1.2rem;
  font-family: 'Courier New', monospace;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.02);
  color: var(--text-color, #333);
  transition: all 0.15s ease;
}

[data-theme="dark"] .degree-input {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-dark, #555);
  color: var(--text-dark, #e0e0e0);
}

.degree-input:focus {
  outline: none;
  border-color: var(--select-color, #FFBB33);
  background: rgba(255, 187, 51, 0.1);
  box-shadow: 0 0 8px rgba(255, 187, 51, 0.3);
}

.degree-input[data-filled="true"] {
  background: rgba(255, 187, 51, 0.15);
  border-color: var(--select-color, #FFBB33);
}

[data-theme="dark"] .degree-input[data-filled="true"] {
  background: rgba(255, 187, 51, 0.2);
}

/* Silence styling */
.degree-input[value="s"] {
  font-style: italic;
  color: var(--silence-color, #888);
}

/* Responsive - Tablet */
@media (max-width: 900px) {
  .matrix-grid-editor--degree {
    padding: 8px 10px;
  }

  .grid-row-label--degree {
    font-size: 1.2rem;
    min-width: 45px;
  }

  .degree-column {
    min-width: 40px;
  }

  .degree-input {
    width: 34px;
    height: 34px;
    font-size: 1.1rem;
  }

  .degree-column-header {
    font-size: 0.75rem;
  }
}

/* Responsive - Mobile */
@media (max-width: 600px) {
  .matrix-grid-editor--degree {
    padding: 6px 8px;
  }

  .grid-row-label--degree {
    font-size: 1rem;
    min-width: 40px;
  }

  .degree-column {
    min-width: 35px;
  }

  .degree-input {
    width: 30px;
    height: 30px;
    font-size: 1rem;
  }

  .degree-column-header {
    font-size: 0.7rem;
  }
}

/* ========== DEGREE-INTERVAL MODE ==========
   Editor for degree intervals (iSº): +2, -1, 0, +3
   ========================================== */

.matrix-grid-editor--degree-interval {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  gap: 8px;
}

.degree-interval-main-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.grid-label-column--degree-interval {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.grid-row-label--degree-interval {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--interval-sound-color, #F28AAD);
  min-width: 50px;
  text-align: center;
}

[data-theme="dark"] .grid-row-label--degree-interval {
  color: var(--interval-sound-color, #F28AAD);
}

.degree-interval-columns-container {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding: 5px 0;
}

.degree-interval-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 45px;
}

.degree-interval-input {
  width: 42px;
  height: 42px;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 600;
  border: 2px solid var(--interval-sound-color, #F28AAD);
  border-radius: 8px;
  background: var(--bg-secondary, #f5f5f5);
  color: var(--text-color, #333);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.degree-interval-input:focus {
  border-color: var(--interval-sound-color, #F28AAD);
  box-shadow: 0 0 0 3px rgba(242, 138, 173, 0.3);
}

.degree-interval-input[data-filled="true"] {
  background: rgba(242, 138, 173, 0.15);
}

[data-theme="dark"] .degree-interval-input {
  background: var(--bg-dark-secondary, #2a2a2a);
  color: var(--text-dark, #e0e0e0);
  border-color: var(--interval-sound-color, #F28AAD);
}

[data-theme="dark"] .degree-interval-input[data-filled="true"] {
  background: rgba(242, 138, 173, 0.2);
}

/* Responsive - Tablet */
@media (max-width: 900px) {
  .matrix-grid-editor--degree-interval {
    padding: 8px 10px;
  }

  .grid-row-label--degree-interval {
    font-size: 1.2rem;
    min-width: 45px;
  }

  .degree-interval-column {
    min-width: 40px;
  }

  .degree-interval-input {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }
}

/* Responsive - Mobile */
@media (max-width: 600px) {
  .matrix-grid-editor--degree-interval {
    padding: 6px 8px;
  }

  .grid-row-label--degree-interval {
    font-size: 1rem;
    min-width: 40px;
  }

  .degree-interval-column {
    min-width: 35px;
  }

  .degree-interval-input {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }
}
