.tb-app {
  --tb-blue: #254e64;
  --tb-blue-strong: #176b9b;
  --tb-blue-soft: #e8f0f5;
  --tb-orange: #cc6633;
  --tb-green: #539a4c;
  --tb-red: #b42318;
  --tb-border: #d5dde5;
  --tb-muted: #607080;
  --tb-surface: #fff;
  --tb-surface-soft: #f6f8fa;
  --tb-text: #17212b;
  color: var(--tb-text);
  margin: 1.5rem 0 2.5rem;
  position: relative;
}

html[data-theme="dark"] .tb-app {
  --tb-blue: #aac8da;
  --tb-blue-soft: #293741;
  --tb-border: #46535d;
  --tb-muted: #b7c5cf;
  --tb-surface: #1e2429;
  --tb-surface-soft: #252e34;
  --tb-text: #f3f5f7;
}

.tb-app *,
.tb-app *::before,
.tb-app *::after {
  box-sizing: border-box;
}

.tb-app button,
.tb-app input,
.tb-app select {
  font: inherit;
}

.tb-app-loading,
.tb-notice {
  border: 1px solid var(--tb-border);
  border-radius: 12px;
  padding: 1rem;
  background: var(--tb-surface-soft);
}

.tb-notice-error {
  border-color: #e8a09a;
  color: var(--tb-red);
}

.tb-shell {
  border: 1px solid var(--tb-border);
  border-radius: 18px;
  background: var(--tb-surface);
  box-shadow: 0 16px 42px rgba(37, 78, 100, 0.12);
  overflow: hidden;
}

.tb-toolbar {
  align-items: center;
  background: linear-gradient(135deg, #254e64 0%, #3b6f89 100%);
  color: #fff;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: space-between;
  padding: 0.9rem 1rem;
}

.tb-brand {
  align-items: center;
  display: flex;
  gap: 0.65rem;
  min-width: 13rem;
}

.tb-brand-icon {
  height: 38px;
  width: 38px;
}

.tb-brand strong,
.tb-brand small {
  display: block;
}

.tb-brand small {
  opacity: 0.78;
}

.tb-toolbar-actions,
.tb-inline-actions,
.tb-card-actions,
.tb-export-actions,
.tb-student-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.tb-button {
  align-items: center;
  background: var(--tb-surface);
  border: 1px solid var(--tb-border);
  border-radius: 9px;
  color: var(--tb-text);
  cursor: pointer;
  display: inline-flex;
  font-weight: 650;
  gap: 0.35rem;
  justify-content: center;
  line-height: 1.2;
  min-height: 2.45rem;
  padding: 0.58rem 0.8rem;
  text-decoration: none !important;
}

.tb-button:hover:not(:disabled) {
  border-color: var(--tb-blue-strong);
  transform: translateY(-1px);
}

.tb-button:focus-visible,
.tb-app input:focus-visible,
.tb-app select:focus-visible,
.tb-tab:focus-visible,
.tb-dropzone:focus-visible,
.tb-palette-option:focus-visible {
  outline: 3px solid rgba(204, 102, 51, 0.42);
  outline-offset: 2px;
}

.tb-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.tb-toolbar .tb-button {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.28);
  color: #fff;
}

.tb-button-primary {
  background: var(--tb-orange) !important;
  border-color: var(--tb-orange) !important;
  color: #fff !important;
}

.tb-button-danger {
  color: var(--tb-red);
}

.tb-button-icon {
  min-width: 2.4rem;
  padding-inline: 0.6rem;
}

.tb-main {
  display: grid;
  grid-template-columns: minmax(22rem, 1.08fr) minmax(20rem, 0.92fr);
  min-height: 690px;
}

.tb-builder,
.tb-side {
  min-width: 0;
  padding: 1rem;
}

.tb-builder {
  border-right: 1px solid var(--tb-border);
}

.tb-field-row {
  align-items: end;
  display: grid;
  gap: 0.7rem;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 0.85rem;
}

.tb-palette-fieldset {
  border: 0;
  margin: 0 0 0.9rem;
  padding: 0;
}

.tb-palette-fieldset legend {
  color: var(--tb-muted);
  font-size: 0.87rem;
  font-weight: 700;
  margin-bottom: 0.42rem;
  padding: 0;
}

.tb-palette-options {
  display: grid;
  gap: 0.42rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tb-palette-option {
  align-items: center;
  background: var(--tb-surface);
  border: 1px solid var(--tb-border);
  border-radius: 9px;
  color: var(--tb-text);
  cursor: pointer;
  display: flex;
  font-size: 0.78rem;
  font-weight: 700;
  gap: 0.42rem;
  min-width: 0;
  padding: 0.38rem 0.45rem;
  text-align: left;
}

.tb-palette-option:hover {
  border-color: var(--tb-blue-strong);
}

.tb-palette-option[aria-pressed="true"] {
  border-color: var(--tb-orange);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--tb-orange) 22%, transparent);
}

.tb-palette-swatch {
  border: 1px solid color-mix(in srgb, var(--tb-text) 14%, transparent);
  border-radius: 5px;
  display: grid;
  flex: 0 0 2.35rem;
  grid-template-columns: repeat(4, 1fr);
  height: 1.35rem;
  overflow: hidden;
}

.tb-palette-swatch i:nth-child(1) { background: var(--tb-swatch-header); }
.tb-palette-swatch i:nth-child(2) { background: var(--tb-swatch-rubric); }
.tb-palette-swatch i:nth-child(3) { background: var(--tb-swatch-total); }
.tb-palette-swatch i:nth-child(4) { background: var(--tb-swatch-grand); }

.tb-field,
.tb-field label {
  display: grid;
  gap: 0.32rem;
}

.tb-field label,
.tb-label {
  color: var(--tb-muted);
  font-size: 0.87rem;
  font-weight: 700;
}

.tb-app input,
.tb-app select {
  background: var(--tb-surface);
  border: 1px solid var(--tb-border);
  border-radius: 8px;
  color: var(--tb-text);
  min-height: 2.45rem;
  padding: 0.5rem 0.62rem;
  width: 100%;
}

.tb-app input[type="number"] {
  min-width: 5.2rem;
}

.tb-app input[aria-invalid="true"] {
  border-color: var(--tb-red);
  box-shadow: 0 0 0 2px rgba(180, 35, 24, 0.12);
}

.tb-counter {
  align-items: center;
  display: flex;
  gap: 0.45rem;
}

.tb-counter input {
  width: 5.4rem;
}

.tb-exercises {
  display: grid;
  gap: 0.8rem;
  margin-top: 0.85rem;
  max-height: 555px;
  overflow: auto;
  padding: 0.15rem 0.15rem 0.8rem;
}

.tb-exercise {
  background: var(--tb-surface-soft);
  border: 1px solid var(--tb-border);
  border-radius: 13px;
  overflow: hidden;
}

.tb-exercise-header {
  align-items: center;
  display: grid;
  gap: 0.55rem;
  grid-template-columns: minmax(10rem, 1fr) auto;
  padding: 0.72rem;
}

.tb-exercise-name {
  font-weight: 750;
}

.tb-total-badge,
.tb-status-badge {
  background: var(--tb-blue-soft);
  border-radius: 999px;
  color: var(--tb-blue);
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 750;
  padding: 0.25rem 0.58rem;
  white-space: nowrap;
}

.tb-questions {
  border-top: 1px solid var(--tb-border);
  display: grid;
  gap: 0.45rem;
  padding: 0.7rem;
}

.tb-question {
  align-items: center;
  background: var(--tb-surface);
  border: 1px solid var(--tb-border);
  border-radius: 9px;
  display: grid;
  gap: 0.45rem;
  grid-template-columns: minmax(6.5rem, 1fr) 7rem auto;
  padding: 0.48rem;
}

.tb-question-sub {
  background: color-mix(in srgb, var(--tb-blue-soft) 72%, var(--tb-surface));
  border-left: 4px solid var(--tb-blue-strong);
  margin-left: 1.2rem;
}

.tb-question-kind {
  color: var(--tb-muted);
  font-size: 0.75rem;
  grid-column: 1 / -1;
  margin-bottom: -0.25rem;
}

.tb-empty {
  color: var(--tb-muted);
  padding: 1.3rem;
  text-align: center;
}

.tb-tabs {
  border-bottom: 1px solid var(--tb-border);
  display: flex;
  gap: 0.15rem;
  overflow-x: auto;
}

.tb-tab {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--tb-muted);
  cursor: pointer;
  font-weight: 750;
  padding: 0.75rem 0.85rem;
  white-space: nowrap;
}

.tb-tab[aria-selected="true"] {
  border-bottom-color: var(--tb-orange);
  color: var(--tb-text);
}

.tb-panel {
  display: none;
  min-height: 555px;
  padding-top: 1rem;
}

.tb-panel.tb-active {
  display: block;
}

.tb-mode-switch {
  display: grid;
  gap: 0.55rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 1rem;
}

.tb-radio-card {
  align-items: center;
  background: var(--tb-surface-soft);
  border: 1px solid var(--tb-border);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem;
}

.tb-radio-card input {
  min-height: auto;
  width: auto;
}

.tb-dropzone {
  background: var(--tb-surface-soft);
  border: 2px dashed var(--tb-border);
  border-radius: 12px;
  color: var(--tb-muted);
  cursor: pointer;
  margin: 0.8rem 0;
  padding: 1.2rem;
  text-align: center;
}

.tb-dropzone.tb-dragover {
  background: var(--tb-blue-soft);
  border-color: var(--tb-blue-strong);
}

.tb-student-table-wrap,
.tb-preview-wrap {
  border: 1px solid var(--tb-border);
  border-radius: 10px;
  max-height: 390px;
  overflow: auto;
}

.tb-student-table,
.tb-preview-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.86rem;
  margin: 0;
  min-width: 100%;
  width: max-content;
}

.tb-student-table {
  width: 100%;
}

.tb-student-table th,
.tb-student-table td,
.tb-preview-table th,
.tb-preview-table td {
  border-bottom: 1px solid var(--tb-border);
  border-right: 1px solid var(--tb-border);
  padding: 0.45rem 0.55rem;
}

.tb-student-table th,
.tb-preview-table th {
  background: var(--tb-preview-header, var(--tb-blue-strong));
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 2;
}

.tb-student-table tr:last-child td,
.tb-preview-table tr:last-child td {
  border-bottom: 0;
}

.tb-student-table input {
  border: 0;
  min-height: 2rem;
  padding: 0.25rem;
}

.tb-preview-title {
  background: var(--tb-surface);
  color: var(--tb-text);
  font-size: 1rem;
}

.tb-preview-table th,
.tb-preview-table td {
  border-color: var(--tb-preview-border, var(--tb-border));
}

.tb-preview-table tbody tr:nth-child(even) td:not(.tb-preview-exercise-total):not(.tb-preview-grand-total) {
  background: var(--tb-preview-stripe, var(--tb-surface-soft));
}

.tb-preview-rubric {
  background: var(--tb-preview-rubric, #3e92e3) !important;
}

.tb-preview-exercise-total {
  background: var(--tb-preview-exercise-total, #dce8f2) !important;
  color: #17212b !important;
  font-weight: 700;
}

.tb-preview-grand-total {
  background: var(--tb-preview-grand-total, #245b84) !important;
  color: #fff !important;
  font-weight: 700;
}

.tb-structure {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tb-structure > li {
  border-bottom: 1px solid var(--tb-border);
  padding: 0.65rem 0;
}

.tb-structure ul {
  color: var(--tb-muted);
  margin: 0.35rem 0 0;
}

.tb-footer {
  align-items: center;
  background: var(--tb-surface-soft);
  border-top: 1px solid var(--tb-border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  padding: 0.8rem 1rem;
}

.tb-status {
  align-items: center;
  display: flex;
  gap: 0.5rem;
}

.tb-status-dot {
  background: var(--tb-green);
  border-radius: 50%;
  height: 0.65rem;
  width: 0.65rem;
}

.tb-status-error .tb-status-dot {
  background: var(--tb-red);
}

.tb-errors {
  background: color-mix(in srgb, var(--tb-red) 7%, var(--tb-surface));
  border: 1px solid color-mix(in srgb, var(--tb-red) 42%, transparent);
  border-radius: 10px;
  color: var(--tb-red);
  margin-bottom: 0.8rem;
  padding: 0.7rem 0.9rem;
}

.tb-errors ul {
  margin-bottom: 0;
}

.tb-privacy {
  align-items: start;
  background: color-mix(in srgb, var(--tb-green) 9%, var(--tb-surface));
  border: 1px solid color-mix(in srgb, var(--tb-green) 35%, transparent);
  border-radius: 10px;
  display: flex;
  gap: 0.55rem;
  margin-bottom: 0.9rem;
  padding: 0.7rem;
}

.tb-modal {
  background: var(--tb-surface);
  border: 1px solid var(--tb-border);
  border-radius: 14px;
  color: var(--tb-text);
  max-width: min(31rem, calc(100vw - 2rem));
  padding: 0;
  width: 100%;
}

.tb-modal::backdrop {
  background: rgba(12, 22, 28, 0.58);
}

.tb-modal-body {
  padding: 1rem;
}

.tb-modal h2 {
  margin-top: 0;
}

.tb-modal-actions {
  border-top: 1px solid var(--tb-border);
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  padding: 0.8rem 1rem;
}

.tb-toast-region {
  bottom: 1rem;
  display: grid;
  gap: 0.5rem;
  max-width: min(24rem, calc(100% - 2rem));
  pointer-events: none;
  position: fixed;
  right: 1rem;
  z-index: 10000;
}

.tb-toast {
  background: #17212b;
  border-radius: 9px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  color: #fff;
  padding: 0.7rem 0.9rem;
}

.tb-download-desktop {
  background: var(--parigaux-orange, #cc6633);
  border-radius: 10px;
  color: #fff !important;
  display: inline-block;
  font-weight: 700;
  padding: 0.65rem 0.9rem;
  text-decoration: none !important;
}

.tb-download-desktop-wrap {
  text-align: center;
}

@media (max-width: 1000px) {
  .tb-main {
    grid-template-columns: 1fr;
  }

  .tb-builder {
    border-bottom: 1px solid var(--tb-border);
    border-right: 0;
  }

  .tb-exercises,
  .tb-panel {
    max-height: none;
  }
}

@media (max-width: 620px) {
  .tb-toolbar,
  .tb-footer {
    align-items: stretch;
  }

  .tb-toolbar-actions,
  .tb-export-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .tb-main {
    display: block;
  }

  .tb-builder,
  .tb-side {
    padding: 0.7rem;
  }

  .tb-field-row,
  .tb-exercise-header,
  .tb-question {
    grid-template-columns: 1fr;
  }

  .tb-card-actions {
    justify-content: flex-start;
  }

  .tb-question-sub {
    margin-left: 0.5rem;
  }

  .tb-mode-switch {
    grid-template-columns: 1fr;
  }

  .tb-palette-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .tb-app *,
  .tb-app *::before,
  .tb-app *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
