/**
 * Shared Handwriting workspace screen shell.
 * Restores established .sidebar / .section-card / .preview-area appearance
 * from assets/css/style.css. Handwriting-only layout tweaks are scoped here.
 * A4 print geometry lives in includes/handwriting/layout.php — do not change it here.
 */

/* Desktop: keep site fixed sidebar; add 24px gap; left-align preview (no centering). */
.app-container:has(.sidebar.kl-hw-ws-sidebar) > .preview-area.kl-hw-ws-preview {
  margin-left: calc(var(--sidebar-width) + 24px);
  align-items: flex-start;
  padding-left: 24px;
  padding-right: 24px;
  width: auto;
  max-width: none;
  box-sizing: border-box;
}

.app-container:has(.sidebar.kl-hw-ws-sidebar) > .breadcrumb-container {
  left: calc(var(--sidebar-width) + 24px);
  width: calc(100% - var(--sidebar-width) - 24px);
}

.sidebar.kl-hw-ws-sidebar .kl-hw-ws-revise-rows {
  margin-top: 10px;
  margin-bottom: 4px;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-ws-revise-rows .kl-hw-seg {
  margin-bottom: 10px;
}

.sidebar.kl-hw-ws-sidebar {
  /* Inherit background, border, fixed position, width, UI font from .sidebar */
}

.sidebar.kl-hw-ws-sidebar .section-title {
  /* Inherit uppercase brand-primary section titles from style.css */
}

.sidebar.kl-hw-ws-sidebar .kl-hw-ws-label {
  display: block;
  margin: 0 0 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #495057;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-ws-hint,
.sidebar.kl-hw-ws-sidebar .small.text-muted {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: #6c757d;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-ws-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 10px;
}

.sidebar.kl-hw-ws-sidebar .form-check {
  margin-bottom: 8px;
}

/* Segmented radios — brand-blue selected state, scoped to handwriting sidebar */
.sidebar.kl-hw-ws-sidebar .kl-hw-seg {
  display: flex;
  width: 100%;
  border: 1px solid #dfe6e9;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  margin-bottom: 8px;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-seg__item {
  flex: 1 1 0;
  margin: 0;
  cursor: pointer;
  text-align: center;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-seg__item input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-seg__item span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 6px;
  font-size: 0.875rem;
  font-weight: 600;
  color: #495057;
  border-right: 1px solid #dfe6e9;
  background: #fff;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-seg__item:last-child span {
  border-right: none;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-seg__item input:checked + span,
.sidebar.kl-hw-ws-sidebar .kl-hw-seg__item.is-selected span {
  background: var(--brand-primary, var(--primary-color, #2f80ed));
  color: #fff;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-letter-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-letter-btn {
  min-width: 0;
  min-height: 36px;
  width: 100%;
  font-weight: 600;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-letter-btn.is-selected,
.sidebar.kl-hw-ws-sidebar .kl-hw-letter-btn.btn-primary {
  background: var(--brand-primary, var(--primary-color, #2f80ed));
  border-color: var(--brand-primary, var(--primary-color, #2f80ed));
  color: #fff;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-reorder {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-reorder__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-reorder__chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--brand-primary, var(--primary-color, #2f80ed));
  color: #fff;
  font-weight: 600;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-ws-details > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-ws-details > summary::-webkit-details-marker {
  display: none;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-ws-details > summary::after {
  content: ' ▾';
  font-size: 12px;
}

.sidebar.kl-hw-ws-sidebar .kl-hw-ws-details[open] > summary::after {
  content: ' ▴';
}

.sidebar.kl-hw-ws-sidebar .kl-hw-ws-details__body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 8px;
}

.sidebar.kl-hw-ws-sidebar .print-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.preview-area.kl-hw-ws-preview .activity-sheets {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 16px;
  width: 100%;
}

/* Narrow: stack controls then preview; scale preview uniformly */
@media (max-width: 1099.98px) {
  .app-container:has(.sidebar.kl-hw-ws-sidebar) {
    display: block;
  }

  .app-container:has(.sidebar.kl-hw-ws-sidebar) > .breadcrumb-container {
    position: static;
    left: auto;
    width: 100%;
    height: auto;
  }

  .app-container:has(.sidebar.kl-hw-ws-sidebar) > .sidebar.kl-hw-ws-sidebar {
    position: static;
    top: auto;
    width: 100%;
    height: auto;
    max-height: none;
    overflow: visible;
    border-right: none;
    border-bottom: 1px solid #dfe6e9;
    box-shadow: none;
  }

  .app-container:has(.sidebar.kl-hw-ws-sidebar) > .preview-area.kl-hw-ws-preview {
    margin-left: 0;
    padding: 16px;
    align-items: flex-start;
  }

  .preview-area.kl-hw-ws-preview .activity-sheets {
    transform-origin: top left;
  }
}

@media print {
  .sidebar.kl-hw-ws-sidebar {
    display: none !important;
  }

  .app-container:has(.sidebar.kl-hw-ws-sidebar) > .preview-area.kl-hw-ws-preview {
    margin: 0 !important;
    padding: 0 !important;
  }

  .preview-area.kl-hw-ws-preview .activity-sheets {
    transform: none !important;
  }
}
