:root {
  --ivy-body-bg: #eef4fb;
  --ivy-surface: #ffffff;
  --ivy-surface-alt: #f7f9fc;
  --ivy-border: #d9e2ef;
  --ivy-text: #1f2a44;
  --ivy-muted: #64748b;
  --ivy-primary: #0f6cbd;
  --ivy-primary-dark: #0b4f8c;
  --ivy-accent: #dceeff;
  --ivy-shadow: 0 18px 40px rgba(15, 108, 189, 0.12);
}

body {
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(15, 108, 189, 0.14), transparent 32%),
    linear-gradient(180deg, #f9fbfe 0%, var(--ivy-body-bg) 100%);
  color: var(--ivy-text);
}

.page-shell {
  min-height: 100vh;
}

.page-main {
  padding-top: 2rem;
  padding-bottom: 3rem;
}

.app-navbar {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(15, 108, 189, 0.08);
  box-shadow: 0 8px 24px rgba(15, 108, 189, 0.08);
}

.navbar-brand-mark {
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.85rem;
  background: linear-gradient(135deg, var(--ivy-primary) 0%, #49a4f2 100%);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(15, 108, 189, 0.24);
}

.page-hero {
  margin-bottom: 1.5rem;
  padding: 1.75rem;
  border: 1px solid rgba(15, 108, 189, 0.08);
  border-radius: 1.5rem;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(220, 238, 255, 0.86));
  box-shadow: var(--ivy-shadow);
}

.surface-card,
.panel-card,
.preview-sheet,
.auth-card {
  border: 1px solid var(--ivy-border);
  border-radius: 1rem;
  background: var(--ivy-surface);
  box-shadow: var(--ivy-shadow);
}

.panel-card .card-header,
.surface-card .card-header {
  background: var(--ivy-surface-alt);
  border-bottom: 1px solid var(--ivy-border);
  font-weight: 600;
}

.editor-panel,
.preview-panel {
  height: 100%;
}

.editor-panel .card-body,
.preview-panel .card-body {
  min-height: 18rem;
}

.scroll-panel {
  max-height: 31rem;
  overflow-y: auto;
}

.step,
.exp-input-item,
.exp-preview-item,
.note-container,
.note-preview-item,
.step-explanation {
  padding: 1rem;
  border: 1px solid var(--ivy-border);
  border-radius: 0.9rem;
  background: var(--ivy-surface-alt);
}

.step:not(:last-child),
.exp-input-item:not(:last-child),
.exp-preview-item:not(:last-child),
.note-container:not(:last-child),
.note-preview-item:not(:last-child),
.step-explanation:not(:last-child) {
  margin-bottom: 0.9rem;
}

.note-container {
  position: relative;
}

.note-input,
.step textarea,
.exp-input-item textarea {
  min-height: 6rem;
  resize: vertical;
}

.delete-note {
  position: absolute;
  top: 0.65rem;
  right: 0.75rem;
  cursor: pointer;
  font-size: 1.1rem;
}

#chartContainer,
#explanationsContainer,
#notes1Preview,
#notes2Preview,
#expPreviewContainer {
  min-height: 16rem;
}

#chartContainer {
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

#chartContainer svg {
  max-width: 100%;
  height: auto;
  display: block;
}

#chartContainer .ivyflow-diagram {
  width: 100%;
  height: auto;
  display: block;
}

#chartContainer .edgeLabel rect {
  fill: #ffffff;
  opacity: 1;
}

.flowchart-toolbar {
  gap: 0.75rem;
}

.builder-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  align-items: start;
}

.builder-column,
.preview-column {
  min-width: 0;
}

.step-editor-card {
  padding: 1.1rem;
  border: 1px solid var(--ivy-border);
  border-radius: 1rem;
  background: linear-gradient(180deg, #fff 0%, var(--ivy-surface-alt) 100%);
}

.step-editor-card:not(:last-child) {
  margin-bottom: 1rem;
}

.stepper-shell {
  display: grid;
  gap: 1rem;
}

.stepper-track {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  align-items: center;
}

.stepper-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: 999px;
  border: 2px solid var(--ivy-primary);
  background: #fff;
  color: var(--ivy-primary-dark);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.stepper-item:hover,
.stepper-item:focus-visible {
  transform: translateY(-1px);
}

.stepper-item.active {
  background: var(--ivy-primary);
  color: #fff;
  box-shadow: 0 10px 20px rgba(15, 108, 189, 0.2);
}

.stepper-caption {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  color: var(--ivy-muted);
  font-size: 0.95rem;
}

.active-step-panel {
  border: 1px solid var(--ivy-border);
  border-radius: 1rem;
  background: linear-gradient(180deg, #fff 0%, var(--ivy-surface-alt) 100%);
  padding: 1.25rem;
}

.active-step-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) repeat(2, minmax(220px, 0.85fr));
  gap: 1rem;
  align-items: start;
}

.active-step-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.active-step-title {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.active-step-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.step-editor-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.step-editor-title {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.step-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.65rem;
  border-radius: 999px;
  background: var(--ivy-primary);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 700;
}

.builder-section-note {
  color: var(--ivy-muted);
  font-size: 0.95rem;
}

.builder-notes-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.note-group {
  padding: 1rem;
  border: 1px solid var(--ivy-border);
  border-radius: 1rem;
  background: var(--ivy-surface-alt);
}

.note-group textarea {
  min-height: 12rem;
}

.note-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.empty-mini-state {
  padding: 0.9rem;
  border: 1px dashed var(--ivy-border);
  border-radius: 0.8rem;
  color: var(--ivy-muted);
  text-align: center;
  background: rgba(255, 255, 255, 0.65);
}

.delete-note {
  top: 0.75rem;
  right: 0.75rem;
}

.delete-note button {
  white-space: nowrap;
}

.a4-preview-stage {
  padding: 1rem;
  border-radius: 1rem;
  background: linear-gradient(180deg, #dfe9f5 0%, #eef3f9 100%);
  overflow: auto;
  width: 100%;
}

.a4-preview-scale {
  transform-origin: top center;
  margin: 0 auto;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.dt-container .dt-search input,
.dt-container .dt-length select,
div.dataTables_wrapper div.dataTables_filter input,
div.dataTables_wrapper div.dataTables_length select {
  border-radius: 0.5rem;
  border: 1px solid var(--ivy-border);
  padding: 0.375rem 0.75rem;
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: min(100%, 440px);
  padding: 2rem;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.45);
  z-index: 1080;
}

.preview-pages {
  display: flex;
  flex-direction: column;
  gap: 5mm;
  align-items: center;
}

.preview-sheet {
  width: 210mm;
  min-height: 297mm;
  height: 297mm;
  margin: 0 auto;
  padding: 4mm;
  display: flex;
  flex-direction: column;
  gap: 2.5mm;
  overflow: hidden;
  color: #1f2937;
}

.preview-sheet--measure {
  position: fixed;
  top: 0;
  left: -10000px;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
  box-shadow: none;
}

.preview-sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding-bottom: 2mm;
  border-bottom: 1px solid #cbd5e1;
}

.preview-sheet-title {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.preview-sheet-subtitle {
  color: #64748b;
  font-size: 0.72rem;
}

.preview-sheet-meta {
  text-align: right;
  color: #64748b;
  font-size: 0.68rem;
}

.preview-sheet-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) repeat(3, minmax(0, 0.9fr));
  gap: 2.5mm;
  align-items: stretch;
}

.preview-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 2mm;
  border: 1px solid #dbe3ef;
  border-radius: 2.5mm;
  background: #f8fafc;
  overflow: hidden;
}

.preview-section-body {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.preview-section-title {
  margin-bottom: 2mm;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #334155;
}

.preview-chart-section {
  min-width: 0;
  align-self: stretch;
}

.preview-explanation-section {
  min-width: 0;
}

.preview-notes-section {
  min-width: 0;
}

.preview-continuation-marker {
  position: absolute;
  left: 50%;
  z-index: 2;
  transform: translateX(-50%);
  pointer-events: none;
  color: #64748b;
  font-size: 0.58rem;
  font-style: italic;
  font-weight: 500;
  line-height: 1.1;
  white-space: nowrap;
}

.preview-continuation-marker-top {
  top: 0.5mm;
}

.preview-continuation-marker-bottom {
  bottom: 0.5mm;
}

.preview-column-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.preview-chart-body {
  align-items: stretch;
  justify-content: flex-start;
  overflow: hidden;
}

.preview-text-body {
  position: relative;
  display: block;
  min-height: 0;
  overflow: hidden;
}

.preview-row-slot {
  position: relative;
  flex: 0 0 auto;
}

.preview-row-slot-empty {
  height: 100%;
}

.note-preview-item,
.step-explanation {
  white-space: pre-wrap;
}

.preview-sheet .note-preview-item,
.preview-sheet .step-explanation,
.preview-sheet .exp-preview-item {
  margin: 0;
  padding: 2mm;
  border-radius: 2mm;
  background: #fff;
  font-size: 0.7rem;
  line-height: 1.3;
  box-shadow: none;
}

.preview-positioned-card {
  position: absolute;
  left: 0;
  right: 0;
}

.preview-sheet .note-preview-item p,
.preview-sheet .step-explanation p,
.preview-sheet .exp-preview-item p {
  margin-bottom: 0;
}

.preview-chart-svg-wrap {
  width: 100%;
  min-height: 0;
}

.preview-chart-svg-wrap svg {
  width: 100% !important;
  height: 100% !important;
  max-height: none !important;
}

.preview-empty-message {
  min-height: 100%;
  padding: 0.9rem;
  border: 1px dashed #cbd5e1;
  border-radius: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.preview-fit-status {
  font-size: 0.875rem;
}

.empty-state {
  padding: 2rem;
  border: 1px dashed var(--ivy-border);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.65);
  text-align: center;
  color: var(--ivy-muted);
}

@media (max-width: 1199.98px) {
}

@media (max-width: 991.98px) {
  .page-hero {
    padding: 1.25rem;
  }

  .scroll-panel {
    max-height: none;
  }

  .builder-notes-grid,
  .active-step-workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 767.98px) {
  .page-main {
    padding-top: 1.25rem;
  }

  .auth-card {
    padding: 1.5rem;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-navbar,
  .hide-for-pdf {
    display: none !important;
  }

  .page-main {
    padding: 0;
  }

  .builder-layout {
    display: block;
  }

  .preview-column,
  .preview-panel,
  .preview-panel .card-body {
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  .preview-sheet {
    box-shadow: none;
    border: 0;
    width: 210mm;
    height: 297mm;
    margin: 0;
    page-break-after: always;
    break-after: page;
  }

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

  .preview-pages {
    gap: 0;
    align-items: stretch;
  }

  .a4-preview-stage,
  .a4-preview-scale {
    padding: 0;
    background: transparent;
    transform: none !important;
    height: auto !important;
    width: auto !important;
  }

  .preview-sheet--measure {
    display: none !important;
  }
}
  