/* =============================================
   GENERATOR KART PRACY — ZADANIA Z TREŚCIĄ
   Design system oparty na JaMamKtoMa
   ============================================= */

:root {
  --bg: #eef2f5;
  --panel: #ffffff;
  --ink: #10151f;
  --muted: #657184;
  --line: #d9e0ea;
  --accent: #4f883d;
  --accent-dark: #3d6f2e;
  --accent-light: #eef6ec;
  --paper: #ffffff;
  --task-font-size: 14px;
  --body-font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-family: var(--body-font);
}

/* --- RESET --- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

/* --- FORM ELEMENTS --- */
button, input, select, textarea { font: inherit; }

button {
  min-height: 42px;
  border: 1px solid #c6d1df;
  border-radius: 8px;
  background: #fff;
  color: #152033;
  cursor: pointer;
  font-weight: 700;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

button:hover { border-color: #8ea0b7; }

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

button.secondary-outline {
  border-color: var(--accent);
  color: var(--accent);
  background: transparent;
}

button.secondary-outline:hover {
  background: var(--accent-light);
}

button:disabled { opacity: 0.65; cursor: wait; }

input, select, textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

input, select { min-height: 40px; padding: 0 11px; }
textarea { resize: vertical; padding: 11px; line-height: 1.5; }

input[type="range"] { padding: 0; accent-color: var(--accent); }
input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  height: 16px;
  accent-color: var(--accent);
  margin: 0;
}

/* --- LAYOUT --- */
.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  min-height: 100vh;
}

.settings-panel {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 24px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

/* --- BRAND BLOCK --- */
.brand-block {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1 { margin: 0; font-size: 28px; line-height: 1.1; }
h2 { margin: 0; font-size: 16px; line-height: 1.1; }

/* --- PANEL SECTIONS --- */
.panel-section {
  display: grid;
  gap: 14px;
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
}

.two-column-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* --- FIELDS --- */
.field {
  display: grid;
  gap: 7px;
}

.field span, .field > label {
  color: #263244;
  font-size: 13px;
  font-weight: 800;
}

/* --- BUTTONS --- */
.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.ai-button { width: 100%; gap: 6px; display: flex; align-items: center; justify-content: center; }
.btn-icon { font-size: 16px; }

.sticky-actions {
  position: sticky;
  bottom: 0;
  padding-top: 8px;
  background: var(--panel);
}

/* --- FIELDSET (pills / checkboxes) --- */
.panel-fieldset {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  border: 0;
}

.panel-fieldset legend {
  color: #263244;
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 2px;
}

.checkbox-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #263244;
}

.pills-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill { cursor: pointer; }

.pill input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.pill span {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  padding: 0 13px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #fff;
  color: #263244;
  font-size: 13px;
  font-weight: 700;
  transition: border-color 0.15s, background 0.15s;
}

.pill input:checked + span {
  border-color: var(--accent);
  background: var(--accent-light);
  color: #24491b;
}

/* --- TASK LIST IN SIDEBAR --- */
.task-list {
  display: grid;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 2px;
}

.task-list-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  line-height: 1.4;
}

.task-item-sidebar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid #d8e1ee;
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.15s;
}

.task-item-sidebar:hover { border-color: var(--accent); }

.task-item-sidebar-text {
  font-size: 12px;
  line-height: 1.4;
  color: #263244;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.task-item-sidebar-num {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
}

.task-item-actions {
  display: flex;
  gap: 4px;
}

.task-action-btn {
  min-height: 28px;
  width: 28px;
  padding: 0;
  font-size: 14px;
  border-radius: 6px;
  line-height: 1;
}

/* --- VALIDATION BOX --- */
.validation-box {
  padding: 12px;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.validation-box strong { color: #172033; }
.validation-box.is-error { background: #fff0f0; color: #b91c1c; }
.validation-box.is-ok { background: #f0fdf4; color: #15803d; }

/* --- PREVIEW PANEL --- */
.preview-panel {
  min-width: 0;
  padding: 24px clamp(16px, 3vw, 42px);
}

.preview-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  max-width: 840px;
  margin: 0 auto 18px;
}

.preview-toolbar h2 { font-size: 22px; }

.preview-actions {
  display: grid;
  gap: 6px;
  justify-items: end;
}

.preview-actions button { min-height: 38px; padding: 0 16px; }
.preview-actions p { margin: 0; color: var(--muted); font-weight: 700; font-size: 13px; }

.pages {
  display: grid;
  gap: 22px;
  justify-content: center;
}

/* =============================================
   STRONA A4 I BLOK ZADANIA
   ============================================= */

.page {
  width: min(100%, 210mm);
  max-width: 210mm;
  min-width: 0;
  aspect-ratio: 210 / 297;
  display: flex;
  flex-direction: column;
  padding: 12mm 14mm 13mm;
  gap: 0;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 16px 44px rgba(15, 23, 42, 0.16);
  font-family: var(--body-font);
  position: relative;
}

.empty-preview-page {
  justify-content: flex-start;
}

.empty-preview-message {
  display: grid;
  place-items: center;
  flex: 1;
  min-height: 0;
  color: #657184;
  font-size: 4mm;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
  padding: 8mm;
}

/* Nagłówek karty na stronie */
.worksheet-header {
  display: grid;
  gap: 4mm;
  padding-bottom: 5mm;
  border-bottom: 0.5mm solid #d0d8e4;
  margin-bottom: 5mm;
  flex-shrink: 0;
}

.worksheet-header-title {
  margin: 0;
  font-size: 6mm;
  font-weight: 900;
  color: #0f172a;
  line-height: 1.1;
}

.worksheet-header-meta {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4mm;
}

.worksheet-header-meta.cols-2 { grid-template-columns: 1fr 1fr; }
.worksheet-header-meta.cols-1 { grid-template-columns: 1fr; }

.meta-field {
  display: grid;
  gap: 1.5mm;
}

.meta-field-label {
  font-size: 2.6mm;
  font-weight: 800;
  color: #657184;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.meta-field-line {
  height: 0.4mm;
  background: #9baab9;
  border-radius: 99px;
}

/* Treść zadań */
.tasks-area {
  display: flex;
  flex-direction: column;
  gap: 4mm;
  flex: 1;
  min-height: 0;
}

.task-block {
  --task-color: #4f883d;
  --task-soft: #eef6ec;
  --task-border-soft: #dcebd8;
  --task-workspace-border: #bdd0b6;
  --task-grid-line: rgba(79, 136, 61, 0.12);
  --task-line: #d3dfcf;
  --task-answer-line: #c9d9c3;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  border: 0.5mm solid var(--task-color);
  border-radius: 4mm;
  overflow: hidden;
  background: #fff;
}

.task-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2.5mm 4mm 2mm;
  background: var(--task-soft);
  border-bottom: 0.4mm solid var(--task-border-soft);
  flex-shrink: 0;
}

.task-number {
  font-size: 3mm;
  font-weight: 900;
  color: var(--task-color);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.task-points {
  font-size: 2.6mm;
  font-weight: 700;
  color: var(--task-color);
  opacity: 0.8;
}

.task-body {
  padding: 3mm 4mm;
  flex-shrink: 0;
}

.task-text {
  margin: 0;
  font-size: var(--task-font-size);
  line-height: 1.6;
  color: #0f172a;
}

/* Workspace (kratka/linijki/puste) */
.task-workspace {
  flex: 1;
  min-height: 0;
  margin: 0 4mm 3mm;
  border: 0.4mm solid var(--task-workspace-border);
  border-radius: 2mm;
  position: relative;
  overflow: hidden;
  background: #fafbfc;
}

.task-workspace.ws-grid {
  background-image:
    linear-gradient(to right, var(--task-grid-line) 0.4mm, transparent 0.4mm),
    linear-gradient(to bottom, var(--task-grid-line) 0.4mm, transparent 0.4mm);
  background-size: 5mm 5mm;
  background-color: #fafbfc;
}

.task-workspace.ws-lines {
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 7mm,
    var(--task-line) 7mm,
    var(--task-line) calc(7mm + 0.4mm)
  );
  background-color: #fafbfc;
}

/* Odpowiedź */
.task-answer-row {
  display: flex;
  align-items: center;
  gap: 3mm;
  padding: 2mm 4mm 3mm;
  flex-shrink: 0;
}

.task-answer-label {
  font-size: 3mm;
  font-weight: 800;
  color: var(--task-color);
  white-space: nowrap;
  flex-shrink: 0;
}

.task-answer-line {
  flex: 1;
  height: 0.4mm;
  background: var(--task-answer-line);
  border-radius: 99px;
}

.task-answer-key-text {
  font-size: 2.6mm;
  color: #9ba8bb;
  white-space: nowrap;
}

/* Strona klucza odpowiedzi */
.answer-key-page {
  padding: 12mm 14mm;
}

.answer-key-title {
  margin: 0 0 6mm;
  font-size: 7mm;
  font-weight: 900;
  color: #0f172a;
  border-bottom: 0.5mm solid #d0d8e4;
  padding-bottom: 4mm;
}

.answer-key-list {
  display: grid;
  gap: 3mm;
}

.answer-key-item {
  display: flex;
  gap: 3mm;
  align-items: baseline;
  font-size: 3.5mm;
}

.answer-key-num { font-weight: 800; color: #4f883d; min-width: 8mm; }
.answer-key-text { color: #263244; }

.page-watermark {
  position: absolute;
  left: 14mm;
  right: 14mm;
  bottom: 4mm;
  color: #8a96a8;
  font-size: 2.4mm;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0;
  pointer-events: none;
}

/* PDF export */
.pdf-export {
  width: 210mm;
  background: #fff;
}

.pdf-export .page {
  width: 210mm !important;
  height: 296mm !important;
  max-width: none;
  margin: 0;
  box-shadow: none;
  aspect-ratio: unset;
}

/* =============================================
   DIALOGI
   ============================================= */

.ai-dialog {
  width: min(580px, calc(100vw - 28px));
  max-height: min(90vh, 800px);
  overflow-y: auto;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
}

.ai-dialog[open] {
  margin-top: 50px;
  margin-bottom: auto;
}

.narrative-checkbox {
  width: fit-content;
}

.manual-dialog {
  width: min(480px, calc(100vw - 28px));
}

.ai-dialog::backdrop {
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(2px);
}

.ai-panel {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.picker-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.picker-header h2 { font-size: 22px; }

.icon-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

/* =============================================
   RESPONSIVE
   ============================================= */

@media (max-width: 799px) {
  .app-shell { display: block; }

  .settings-panel {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .two-column-fields,
  .checkbox-group { grid-template-columns: 1fr; }

  .preview-toolbar { align-items: start; flex-direction: column; }
}

/* =============================================
   PRINT
   ============================================= */

@media print {
  @page { size: A4 portrait; margin: 0; }

  body { background: #fff; }

  .settings-panel,
  .preview-toolbar { display: none !important; }

  .app-shell,
  .preview-panel,
  .pages { display: block; padding: 0; margin: 0; }

  .page {
    width: 210mm !important;
    height: 297mm !important;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
  }

  .page:last-child { break-after: auto; page-break-after: auto; }
}
