/**
 * Task 3 — табличный редактор в стиле LibreOffice Calc
 * NeuroEGE
 */

/* Переопределение сетки task_2: calc слева на всю ширину, statement справа */
.task-3-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.task-3-page .task-3__layout {
  display: grid;
  grid-template-columns: minmax(0, 70%) 1fr;
  gap: 1.5rem;
  flex: 1;
  min-height: 0;
  padding: 1rem 2rem;
}

.task-3__calc {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

@media (max-width: 900px) {
  .task-3__layout {
    grid-template-columns: 1fr;
  }
}

.task-3__statement {
  position: sticky;
  top: 1rem;
  height: fit-content;
}

.task-3-statement {
  background: var(--card-bg, rgba(30, 35, 40, 0.8));
  border: 1px solid var(--border, rgba(255,255,255,0.1));
  border-radius: 8px;
  padding: 1rem 1.25rem;
  font-size: 0.95rem;
  line-height: 1.5;
}

.task-3-statement p {
  margin: 0 0 0.75rem;
}

.task-3-statement p:last-child {
  margin-bottom: 0;
}

/* ========== LibreOffice Calc-style widget ========== */
.calc-widget {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 300px;
  background: #f0f0f0;
  border: 1px solid #999;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

[data-theme="dark"] .calc-widget {
  background: #2b2b2b;
  border-color: #555;
}

/* Toolbar — серая полоса как в LibreOffice */
.calc-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
  background: #e8e8e8;
  border-bottom: 1px solid #ccc;
  min-height: 36px;
}

[data-theme="dark"] .calc-toolbar {
  background: #404040;
  border-color: #555;
}

.calc-toolbar__btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: #333;
  font-size: 14px;
  cursor: pointer;
}

.calc-toolbar__btn:hover {
  background: #d0d0d0;
  border-color: #aaa;
}

[data-theme="dark"] .calc-toolbar__btn {
  color: #ddd;
}

[data-theme="dark"] .calc-toolbar__btn:hover {
  background: #505050;
  border-color: #666;
}

.calc-toolbar__sep {
  width: 1px;
  height: 20px;
  background: #bbb;
  margin: 0 6px;
}

[data-theme="dark"] .calc-toolbar__sep {
  background: #555;
}

/* Строка формул */
.calc-formula-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: #e0e0e0;
  border-bottom: 1px solid #bbb;
  min-height: 32px;
}

[data-theme="dark"] .calc-formula-bar {
  background: #3a3a3a;
  border-color: #555;
}

.calc-cell-name {
  min-width: 48px;
  padding: 4px 8px;
  background: #fff;
  border: 1px solid #999;
  border-radius: 2px;
  font-family: Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  color: #333;
  text-align: center;
}

[data-theme="dark"] .calc-cell-name {
  background: #2b2b2b;
  border-color: #555;
  color: #ddd;
}

.calc-formula-input {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid #999;
  border-radius: 2px;
  font-family: Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  background: #fff;
  color: #000;
}

[data-theme="dark"] .calc-formula-input {
  background: #1e1e1e;
  border-color: #555;
  color: #e0e0e0;
}

.calc-formula-input:focus {
  outline: none;
  border-color: #0078d4;
  box-shadow: 0 0 0 1px #0078d4;
}

/* Вкладки листов */
.calc-sheets {
  display: flex;
  gap: 0;
  padding: 0 8px 0;
  background: #d8d8d8;
  border-bottom: 1px solid #aaa;
  min-height: 28px;
}

[data-theme="dark"] .calc-sheets {
  background: #363636;
  border-color: #555;
}

.calc-sheet {
  padding: 4px 16px;
  margin: 0 -1px 0 0;
  border: 1px solid #999;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  background: #e8e8e8;
  color: #333;
  font-size: 13px;
  cursor: pointer;
}

[data-theme="dark"] .calc-sheet {
  background: #404040;
  border-color: #555;
  color: #ddd;
}

.calc-sheet:hover {
  background: #eee;
}

[data-theme="dark"] .calc-sheet:hover {
  background: #4a4a4a;
}

.calc-sheet--active {
  background: #fff !important;
  font-weight: 500;
  z-index: 1;
  margin-bottom: -1px;
  padding-bottom: 5px;
}

[data-theme="dark"] .calc-sheet--active {
  background: #2b2b2b !important;
}

/* Фильтр */
.calc-filter-bar {
  padding: 8px 12px;
  background: #e0e0e0;
  border-bottom: 1px solid #bbb;
  font-size: 12px;
}

[data-theme="dark"] .calc-filter-bar {
  background: #3a3a3a;
  border-color: #555;
}

.calc-filter-bar__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 6px;
}

.calc-filter-bar__row:last-child {
  margin-bottom: 0;
}

.calc-filter-bar label {
  margin: 0;
  color: #333;
}

[data-theme="dark"] .calc-filter-bar label {
  color: #ddd;
}

.calc-filter__select {
  min-width: 140px;
  padding: 4px 8px;
  font-size: 12px;
}

.calc-filter__input {
  width: 90px;
  padding: 4px 8px;
  font-size: 12px;
}

.calc-filter__btn {
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}

.calc-row--hidden {
  display: none !important;
}

/* Таблица */
.calc-table-wrap {
  flex: 1;
  overflow: auto;
  min-height: 300px;
  background: #fff;
}

[data-theme="dark"] .calc-table-wrap {
  background: #1e1e1e;
}

.calc-table {
  border-collapse: collapse;
  font-size: 12px;
  table-layout: auto;
}

.calc-th,
.calc-td {
  border: 1px solid #d0d0d0;
  padding: 2px 6px;
  white-space: nowrap;
}

[data-theme="dark"] .calc-th,
[data-theme="dark"] .calc-td {
  border-color: #444;
}

.calc-th {
  background: #e8e8e8;
  color: #333;
  font-weight: 500;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 2;
}

[data-theme="dark"] .calc-th {
  background: #404040;
  color: #ddd;
}

.calc-th--corner {
  min-width: 36px;
  max-width: 36px;
  background: #d8d8d8;
}

[data-theme="dark"] .calc-th--corner {
  background: #363636;
}

.calc-td--rownum {
  background: #e8e8e8;
  text-align: right;
  min-width: 36px;
  max-width: 36px;
  font-weight: 500;
  position: sticky;
  left: 0;
  z-index: 1;
}

[data-theme="dark"] .calc-td--rownum {
  background: #404040;
}

.calc-td--editable {
  background: #fff;
  cursor: cell;
}

[data-theme="dark"] .calc-td--editable {
  background: #252525;
}

.calc-td--editable:hover {
  background: #f5f9ff;
}

[data-theme="dark"] .calc-td--editable:hover {
  background: #333;
}

.calc-td--selected {
  outline: 2px solid #0078d4;
  outline-offset: -2px;
  z-index: 1;
}

.calc-td--readonly {
  background: #f8f8f8;
  color: #555;
}

[data-theme="dark"] .calc-td--readonly {
  background: #2a2a2a;
  color: #999;
}

.calc-filter-btn {
  margin-left: 4px;
  padding: 0 4px;
  border: none;
  background: transparent;
  color: #666;
  cursor: pointer;
  font-size: 10px;
}

.calc-filter-btn:hover {
  color: #0078d4;
}

/* Ответ */
.calc-answer {
  padding: 12px 16px;
  background: #e8e8e8;
  border-top: 1px solid #ccc;
}

[data-theme="dark"] .calc-answer {
  background: #363636;
  border-color: #555;
}

.task-3-page .task-answer-form {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.task-3-page .task-answer-form__label {
  margin: 0;
}

.task-3-page .task-answer-form__input {
  min-width: 120px;
}

.task-messages {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
}

.task-message--success {
  color: var(--green, #05b87d);
}

.task-message--error {
  color: #e74c3c;
}

.task-statement__hint {
  font-size: 0.9em;
  opacity: 0.85;
  margin-top: 0.5rem;
}
