/* Warm Study Desk — shared Japanese/Korean stationery theme */

@media screen {
  :root {
    --font-ui: "Noto Sans Thai", "Leelawadee UI", "Segoe UI", Tahoma, sans-serif;
    --bg-app: #fff8f1;
    --bg-sidebar: #fffdfb;
    --bg-card: #ffffff;
    --bg-input: #fffaf7;
    --border-color: #f1d8c7;
    --border-focus: #c2410c;
    --text-main: #4a2a22;
    --text-muted: #755449;
    --primary: #c2410c;
    --primary-hover: #9a3412;
    --success: #16805b;
    --success-hover: #0f6849;
    --shadow-sm: 0 2px 8px rgba(132, 66, 35, 0.06);
    --shadow-md: 0 10px 26px rgba(132, 66, 35, 0.1);
    --shadow-xl: 0 20px 40px rgba(94, 45, 25, 0.16);
  }

  html,
  body {
    font-family: var(--font-ui);
    color: var(--text-main);
  }

  /* Buttons and form fields do not inherit the page font by default (they showed Arial). */
  button,
  input,
  select,
  textarea {
    font-family: inherit;
  }

  body {
    background:
      radial-gradient(circle at 8% 0%, rgba(255, 185, 124, 0.18), transparent 24rem),
      #fff8f1;
  }

  ::selection {
    color: #ffffff;
    background: #c2410c;
  }

  :focus-visible {
    outline: 3px solid rgba(194, 65, 12, 0.24);
    outline-offset: 2px;
  }

  body::-webkit-scrollbar,
  body *::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }

  body::-webkit-scrollbar-track,
  body *::-webkit-scrollbar-track {
    background: #fff1e8;
  }

  body::-webkit-scrollbar-thumb,
  body *::-webkit-scrollbar-thumb {
    background: #edb18b;
    border: 3px solid #fff1e8;
    border-radius: 999px;
  }

  .navbar {
    position: sticky;
    top: 0;
    z-index: 1200;
    isolation: isolate;
    height: auto;
    min-height: 76px;
    max-height: none;
    padding: 14px clamp(16px, 3vw, 38px);
    gap: 12px 20px;
    align-items: center;
    flex-wrap: nowrap;
    background: rgba(255, 253, 251, 0.97);
    border-bottom: 1px solid #f1d8c7;
    box-shadow: 0 4px 16px rgba(132, 66, 35, 0.05);
  }

  /* Keep dialogs above the persistent navbar layer. */
  .modal-overlay {
    z-index: 1300;
  }

  .nav-brand {
    flex: 0 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
    gap: 8px 11px;
  }

  /* College logo (Thai-Austrian) in place of the old magnifier mark. */
  .brand-icon {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: 12px;
    background: #ffffff url("/assets/logo.png") center / 30px auto no-repeat;
    border: 1px solid #f1d8c7;
    color: transparent;
    font-size: 0;
    box-shadow: 0 4px 10px rgba(132, 66, 35, 0.08);
  }

  .brand-title {
    color: #4a2a22;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
  }

  .brand-subtitle {
    color: #7a5a4e;
    font-size: 12px;
  }

  .template-switcher {
    order: 0;
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    gap: 6px;
    padding: 3px 0 1px;
    overflow: visible;
    flex-wrap: nowrap;
    scrollbar-width: thin;
    background: transparent;
    border: 0;
    margin-left: 0;
  }

  .template-switch-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #6f4a3f;
    background: #fffaf7;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 10px;
    white-space: nowrap;
    transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
  }

  .ui-icon {
    display: inline-block;
    width: 1em;
    height: 1em;
    flex: 0 0 auto;
    margin-right: 4px;
    vertical-align: -0.14em;
  }

  .nav-icon {
    width: 15px;
    height: 15px;
    stroke-width: 1.9;
    margin-right: 0;
  }

  .icon-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.05em;
    height: 1.05em;
    flex: 0 0 1.05em;
    margin-right: 4px;
    vertical-align: -0.16em;
  }

  .icon-slot .ui-icon {
    width: 100%;
    height: 100%;
  }

  .template-switch-btn:hover {
    color: #9a3412;
    background: #fff1e8;
    border-color: #f8c7a6;
  }

  .template-switch-btn.active {
    color: #ffffff;
    background: #c2410c;
    border-color: #c2410c;
    box-shadow: 0 4px 10px rgba(194, 65, 12, 0.16);
  }

  .nav-dropdown,
  .nav-user-menu {
    position: relative;
  }

  .nav-user-menu > summary {
    list-style: none;
    cursor: pointer;
  }

  .nav-user-menu > summary::-webkit-details-marker {
    display: none;
  }

  .nav-dropdown-trigger {
    border: 1px solid transparent;
    font-family: inherit;
    cursor: pointer;
    user-select: none;
  }

  .nav-caret {
    width: 14px;
    height: 14px;
    margin-right: 0;
    transition: transform 160ms ease;
  }

  .nav-dropdown.open .nav-caret,
  .nav-user-menu[open] .nav-caret,
  .page-tools-dropdown[open] .page-tools-chevron {
    transform: rotate(180deg);
  }

  .nav-dropdown-menu {
    position: absolute;
    top: calc(100% + 7px);
    left: 0;
    z-index: 120;
    display: none;
    gap: 4px;
    min-width: 286px;
    padding: 7px;
    background: #fffdfb;
    border: 1px solid #edcfbb;
    border-radius: 14px;
    box-shadow: 0 14px 30px rgba(94, 45, 25, 0.16);
  }

  .nav-dropdown.open .nav-dropdown-menu {
    display: grid;
  }

  .nav-dropdown.open .nav-dropdown-trigger:not(.active) {
    color: #9a3412;
    background: #fff1e8;
    border-color: #f8c7a6;
  }

  .nav-menu-item {
    width: 100%;
    justify-content: flex-start;
    border-color: transparent;
    background: transparent;
  }

  .nav-menu-item.active {
    color: #ffffff;
    background: #c2410c;
  }

  .nav-user-menu {
    align-self: center;
    flex: 0 0 auto;
    margin-left: 0;
  }

  .nav-user-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 5px 9px 5px 6px;
    color: #6f4a3f;
    background: #fff7f1;
    border: 1px solid #edcfbb;
    border-radius: 12px;
  }

  .nav-user-trigger:hover {
    color: #9a3412;
    background: #fff1e8;
    border-color: #f6c09a;
  }

  .nav-user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    color: #ffffff;
    background: #f97316;
    border-radius: 9px;
  }

  .nav-user-avatar .ui-icon {
    width: 17px;
    height: 17px;
    margin-right: 0;
  }

  .nav-user-copy {
    display: grid;
    gap: 1px;
    text-align: left;
    line-height: 1.15;
  }

  .nav-user-copy strong {
    font-size: 12px;
    font-weight: 700;
  }

  .nav-user-copy small {
    color: #8b6b61;
    font-size: 10px;
    white-space: nowrap;
  }

  .nav-user-popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 120;
    display: grid;
    gap: 4px;
    width: 242px;
    padding: 13px 14px;
    color: #6f4a3f;
    background: #fffdfb;
    border: 1px solid #edcfbb;
    border-radius: 14px;
    box-shadow: 0 14px 30px rgba(94, 45, 25, 0.16);
  }

  .nav-user-popover strong {
    color: #6f2f20;
    font-size: 13px;
  }

  .nav-user-popover span {
    color: #8b6b61;
    font-size: 12px;
    line-height: 1.45;
  }

  /* Profile menu sections: who is signed in (filled by cloud.js), then where to report problems */
  .nav-user-info {
    display: grid;
    gap: 4px;
  }

  .nav-contact {
    display: grid;
    gap: 4px;
    margin-top: 8px;
    padding-top: 10px;
    border-top: 1px solid #f1d8c7;
  }

  .nav-user-popover .nav-contact-hint {
    color: #755449;
  }

  .nav-contact-email {
    color: #c2410c;
    font-size: 13px;
    font-weight: 700;
    overflow-wrap: anywhere;
  }

  .nav-contact-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 4px;
  }

  .nav-contact-actions .btn {
    justify-content: center;
    min-height: 32px;
    padding: 5px 6px;
    font-size: 12px;
    white-space: nowrap;
  }

  .nav-user-popover .nav-contact-actions span {
    color: inherit;
    font-size: inherit;
    line-height: inherit;
  }

  /* Profile menu settings: switches remembered in this browser */
  .nav-settings {
    display: grid;
    gap: 6px;
    margin-top: 8px;
    padding-top: 10px;
    border-top: 1px solid #f1d8c7;
  }

  .nav-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    cursor: pointer;
  }

  .nav-toggle input {
    appearance: none;
    position: relative;
    flex: none;
    width: 34px;
    height: 20px;
    margin: 0;
    background: #e7d3c7;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s ease;
  }

  .nav-toggle input::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    background: #ffffff;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(94, 45, 25, 0.25);
    transition: transform 0.15s ease;
  }

  .nav-toggle input:checked {
    background: #f97316;
  }

  .nav-toggle input:checked::after {
    transform: translateX(14px);
  }

  .nav-toggle input:focus-visible {
    outline: 2px solid #c2410c;
    outline-offset: 2px;
  }

  .server-status-pill {
    color: #16805b;
    background: #effaf4;
    border: 1px solid #bfe8d2;
    margin-left: 0;
  }

  .server-status-pill.offline {
    color: #9a3412;
    background: #fff7ed;
    border-color: #fed7aa;
  }

  .server-status-pill.online .status-indicator-dot {
    background: #22a06b;
    box-shadow: 0 0 0 3px rgba(34, 160, 107, 0.12);
    animation: none;
  }

  .nav-actions {
    flex: 0 1 auto;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .btn {
    min-height: 38px;
    padding: 8px 12px;
    border-radius: 11px;
    border: 1px solid #f1d8c7;
    font-size: 13px;
    font-weight: 700;
    box-shadow: none;
  }

  .btn-primary {
    background: #c2410c;
    border-color: #c2410c;
    color: #ffffff;
  }

  .btn-primary:hover {
    background: #9a3412;
    border-color: #9a3412;
    transform: translateY(-1px);
  }

  .btn-success {
    background: #effaf4;
    border-color: #bfe8d2;
    color: #157347;
  }

  .btn-success:hover {
    background: #dff5e8;
    border-color: #8fd2ac;
    color: #0f6849;
  }

  .btn-secondary {
    background: #ffffff;
    color: #6f4a3f;
    border-color: #f1d8c7;
  }

  .btn-secondary:hover,
  .btn-icon:hover {
    background: #fff1e8;
    border-color: #edb18b;
    color: #9a3412;
  }

  .btn-sm {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 12px;
  }

  /* Small outline actions beside a field label: remove (red) and add back / add (orange) */
  .btn-outline-danger,
  .btn-outline-primary {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 28px;
    padding: 4px 11px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    border: 1px solid;
    border-radius: 999px;
    cursor: pointer;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
  }

  .btn-outline-danger .ui-icon,
  .btn-outline-primary .ui-icon {
    width: 14px;
    height: 14px;
    margin-right: 0;
  }

  .btn-outline-danger {
    color: #b91c1c;
    background: #fef2f2;
    border-color: #fca5a5;
  }

  .btn-outline-danger:hover {
    color: #ffffff;
    background: #dc2626;
    border-color: #dc2626;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.28);
    transform: translateY(-1px);
  }

  .btn-outline-primary {
    color: #c2410c;
    background: #fff7ed;
    border-color: #fdba74;
  }

  .btn-outline-primary:hover {
    color: #ffffff;
    background: #ea580c;
    border-color: #ea580c;
    box-shadow: 0 4px 12px rgba(234, 88, 12, 0.26);
    transform: translateY(-1px);
  }

  .btn-outline-danger:active,
  .btn-outline-primary:active {
    box-shadow: none;
    transform: translateY(0) scale(0.97);
  }

  .btn-outline-danger:focus-visible,
  .btn-outline-primary:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
  }

  .btn-icon {
    min-width: 34px;
    min-height: 34px;
    padding: 6px;
    border-radius: 10px;
    background: #ffffff;
    border-color: #f1d8c7;
    color: #755449;
  }

  .app-container {
    flex: 1 1 0;
    min-height: 0;
    height: auto;
    max-height: none;
    background: #fff8f1;
  }

  .page-action-bar {
    width: 100%;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 13px 16px;
    margin: 0 0 2px;
    background: #fffdfb;
    border: 1px solid #f1d8c7;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
  }

  .sidebar-panel > .page-action-bar {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 10px;
    width: 100%;
    margin: 0;
    padding: 13px 12px;
    border: 0;
    border-bottom: 1px solid #f1d8c7;
    border-radius: 0;
    box-shadow: none;
    background: #fffaf7;
  }

  .sidebar-panel > .page-action-bar .page-action-copy {
    min-width: 0;
  }

  .sidebar-panel > .page-action-bar .page-action-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    justify-content: stretch;
  }

  .sidebar-panel > .page-action-bar .page-action-buttons .btn {
    width: 100%;
    min-width: 0;
    justify-content: center;
  }

  .page-tools-sidebar {
    align-self: start;
  }

  .preview-workspace > .page-action-bar {
    width: min(100%, 1180px);
    margin-bottom: 18px;
  }

  .page-action-bar-evaluation {
    margin-bottom: 0;
  }

  .page-tools-dropdown {
    display: block;
    padding: 0;
    overflow: visible;
  }

  .page-tools-dropdown > summary {
    list-style: none;
    cursor: pointer;
  }

  .page-tools-dropdown > summary::-webkit-details-marker {
    display: none;
  }

  .page-tools-trigger {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 58px;
    padding: 13px 14px;
    color: #6f4a3f;
    background: #fffaf7;
    border-radius: 15px;
    visibility: visible;
    opacity: 1;
  }

  .sidebar-panel > .page-tools-dropdown .page-tools-trigger {
    border-radius: 0;
  }

  .page-tools-trigger:hover {
    background: #fff1e8;
  }

  .page-tools-trigger-main {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    gap: 9px;
  }

  .page-tools-trigger-main > .ui-icon {
    width: 18px;
    height: 18px;
    margin-right: 0;
    color: #c2410c;
  }

  .page-tools-trigger-main > span {
    display: grid;
    gap: 2px;
    min-width: 0;
  }

  .page-tools-trigger strong {
    color: #6f2f20;
    font-size: 13px;
  }

  .page-tools-trigger small {
    color: #8b6b61;
    font-size: 11px;
    line-height: 1.35;
  }

  .page-tools-chevron {
    width: 17px;
    height: 17px;
    margin-right: 0;
    color: #9a3412;
    transition: transform 160ms ease;
  }

  .page-tools-dropdown .page-action-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px 14px 14px;
  }

  .page-tools-dropdown .page-action-buttons .btn {
    width: 100%;
    min-width: 0;
    justify-content: center;
    line-height: 1.25;
  }

  /* Drive gets its own full row under the two export buttons. */
  .page-action-buttons .btn-drive {
    grid-column: 1 / -1;
    color: #1a56b8;
    border-color: #cfdcf3;
    background: #f5f8fe;
  }

  .page-action-buttons .btn-drive:hover {
    background: #e8f0fd;
    border-color: #a9c1ea;
    color: #174ea6;
  }

  .page-action-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 180px;
  }

  .page-action-copy strong {
    color: #6f2f20;
    font-size: 14px;
    font-weight: 700;
  }

  .page-action-copy span {
    color: #755449;
    font-size: 12px;
    line-height: 1.4;
  }

  /* stretch + equal grid rows: every button keeps the same height even when a label wraps. */
  .page-action-buttons {
    display: flex;
    align-items: stretch;
    grid-auto-rows: 1fr;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 7px;
  }

  .sidebar-panel {
    width: 420px;
    min-width: 340px;
    max-width: 460px;
    background: #fffdfb;
    border-right: 1px solid #f1d8c7;
  }

  .sidebar-tabs {
    gap: 6px;
    padding: 10px 12px;
    background: #fff1e8;
    border-bottom: 1px solid #f1d8c7;
  }

  .tab-btn {
    gap: 5px;
    min-height: 48px;
    padding: 7px 4px;
    color: #755449;
    border-radius: 11px;
    font-size: 12px;
    font-weight: 600;
  }

  .tab-btn:hover {
    color: #9a3412;
    background: #ffffff;
  }

  .tab-btn.active {
    color: #9a3412;
    background: #ffffff;
    border-color: #f6c09a;
    box-shadow: 0 3px 10px rgba(132, 66, 35, 0.08);
  }

  .sidebar-tab-panels {
    padding: 16px;
  }

  .panel-section {
    background: #ffffff;
    border: 1px solid #f1d8c7;
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--shadow-sm);
  }

  .section-header {
    margin-bottom: 14px;
  }

  .section-title {
    color: #9a3412;
    font-size: 14px;
    font-weight: 700;
  }

  .section-badge {
    color: #a34b1b;
    background: #fff1e8;
    border-color: #f6c09a;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 11px;
  }

  .form-group {
    margin-bottom: 14px;
  }

  .form-label {
    color: #755449;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
  }

  .form-input,
  .form-textarea,
  .form-select {
    min-height: 40px;
    padding: 9px 11px;
    border: 1px solid #edcfbb;
    border-radius: 11px;
    background: #fffaf7;
    color: #4a2a22;
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.45;
  }

  .form-textarea {
    min-height: 76px;
  }

  .form-input::placeholder,
  .form-textarea::placeholder {
    color: #9a7568;
    opacity: 1;
  }

  .form-input:focus,
  .form-textarea:focus,
  .form-select:focus {
    border-color: #c2410c;
    box-shadow: 0 0 0 3px rgba(194, 65, 12, 0.13);
  }

  .form-tip {
    color: #755449;
    background: #fff7f1;
    border: 1px solid #edcfbb;
    border-radius: 12px;
    padding: 11px 12px;
    font-size: 12px;
    line-height: 1.55;
  }

  .members-list {
    gap: 8px;
  }

  .member-item {
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid #edcfbb;
    border-radius: 11px;
    background: #fffaf7;
  }

  .member-input {
    color: #4a2a22;
    font-size: 14px;
  }

  .range-input {
    accent-color: #c2410c;
  }

  .range-val {
    color: #9a3412;
    font-size: 13px;
  }

  .preview-workspace {
    background: #fff8f1;
    background-image: none;
    padding: 36px 30px 100px;
  }

  body.unit2-mode .preview-workspace,
  body.unit3-mode .preview-workspace {
    background: #fff8f1;
    background-image: none;
  }

  .preview-toolbar {
    top: 14px;
    margin-bottom: 20px;
  }

  .zoom-controls {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 253, 251, 0.97);
    border: 1px solid #edcfbb;
    border-radius: 14px;
    padding: 5px 8px;
    box-shadow: 0 10px 24px rgba(132, 66, 35, 0.12);
  }

  .zoom-btn {
    color: #755449;
  }

  .zoom-btn .ui-icon,
  .zoom-quick-btn .ui-icon {
    width: 15px;
    height: 15px;
    margin-right: 0;
  }

  .zoom-quick-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
  }

  .zoom-level {
    min-width: 52px;
    color: #9a3412;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }

  .zoom-controls .zoom-quick-btn {
    min-width: 48px;
    min-height: 34px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 700;
  }

  .zoom-btn:hover {
    color: #9a3412;
    background: #fff1e8;
  }

  .zoom-divider {
    background: #edcfbb;
  }

  .zoom-level-badge,
  .zoom-text {
    color: #9a3412;
  }

  .zoom-slider::-webkit-slider-thumb,
  .zoom-slider::-moz-range-thumb {
    background: #c2410c;
  }

  .zoom-preset-menu {
    background: #fffdfb;
    border-color: #edcfbb;
    box-shadow: 0 14px 30px rgba(94, 45, 25, 0.16);
  }

  .zoom-preset-item {
    color: #6f4a3f;
  }

  .zoom-preset-item:hover {
    background: #fff1e8;
    color: #9a3412;
  }

  .zoom-menu-divider {
    background: #f1d8c7;
  }

  .zoom-quick-btn {
    color: #6f4a3f;
    background: #fff7f1;
    border-color: #edcfbb;
  }

  .zoom-quick-btn:hover {
    color: #9a3412;
    background: #fff1e8;
    border-color: #f6c09a;
  }

  .page-wrapper {
    box-shadow: 0 16px 34px rgba(94, 45, 25, 0.14);
  }

  [contenteditable="true"]:hover {
    background-color: rgba(249, 115, 22, 0.08);
    outline-color: rgba(194, 65, 12, 0.42);
  }

  [contenteditable="true"]:focus {
    background-color: rgba(249, 115, 22, 0.12);
    outline-color: #c2410c;
  }

  .toast-msg {
    color: #4a2a22;
    background: #fffdfb;
    border: 1px solid #edcfbb;
    border-radius: 14px;
    box-shadow: var(--shadow-xl);
  }

  .sidebar-panel small {
    color: #755449 !important;
    font-size: 13px !important;
    line-height: 1.5 !important;
  }

  #field-deleted-msg {
    color: #b42318 !important;
    background: #fff0ef !important;
    border-color: #f4b8b3 !important;
  }

  .modal-overlay {
    background: rgba(74, 42, 34, 0.42);
    backdrop-filter: blur(4px);
  }

  .modal-card {
    background: #fffaf5;
    border-color: #edcfbb;
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(94, 45, 25, 0.22);
  }

  .modal-header,
  .modal-footer {
    border-color: #f1d8c7;
  }

  .modal-title {
    color: #9a3412;
    font-size: 19px;
  }

  .modal-body {
    color: #755449;
    font-size: 14px;
    line-height: 1.7;
  }

  .btn-content-helper,
  .btn-add-table,
  .btn-table-action {
    color: #9a3412;
    background: #fff7f1;
    border-color: #edcfbb;
    border-radius: 10px;
  }

  .btn-content-helper:hover,
  .btn-add-table:hover,
  .btn-table-action:hover {
    color: #ffffff;
    background: #c2410c;
    border-color: #c2410c;
  }

  /* Consistent add-action language across all editor surfaces */
  .sidebar-action-bar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px;
    background: #fffaf7;
    border-bottom: 1px solid #f1d8c7;
  }

  .sidebar-action-bar .btn-action {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    padding: 8px 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid #edcfbb;
    border-radius: 11px;
    color: #9a3412;
    background: #fff7f1;
    font-family: var(--font-ui);
    font-size: 12.5px;
    font-weight: 700;
    line-height: 1.35;
    text-align: center;
    text-decoration: none;
    box-shadow: 0 2px 7px rgba(132, 66, 35, 0.06);
    transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
  }

  .sidebar-action-bar .btn-action:hover {
    color: #ffffff;
    background: #c2410c;
    border-color: #c2410c;
    transform: translateY(-1px);
  }

  .sidebar-action-bar .btn-action-primary,
  .sidebar-action-bar .btn-action-primary:hover {
    color: #ffffff;
    background: #c2410c;
    border-color: #c2410c;
  }

  .sidebar-action-bar .btn-action-primary:hover {
    background: #9a3412;
    border-color: #9a3412;
  }

  .sidebar-action-bar > a.btn-action {
    color: #9a3412 !important;
    background: #fff7f1 !important;
    border-color: #edcfbb !important;
  }

  .sidebar-action-bar > a.btn-action:hover {
    color: #ffffff !important;
    background: #c2410c !important;
    border-color: #c2410c !important;
  }

  body.unit3-mode .sidebar-action-bar > a.btn-action {
    grid-column: 1 / -1;
  }

  .sidebar-action-bar .btn-action:disabled,
  .sidebar-tabs .tab-btn-add:disabled,
  .content-helper-buttons .btn-content-helper:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    transform: none;
  }

  .sidebar-tabs .tab-btn-add,
  body.unit2-mode .sidebar-tabs .tab-btn-add,
  body.unit3-mode .sidebar-tabs .tab-btn-add,
  body.chapter-mode .sidebar-tabs .tab-btn-add {
    flex: 0 0 34px !important;
    width: 34px !important;
    min-width: 34px !important;
    max-width: 34px !important;
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    margin: 0 2px !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: 1px solid #f6c09a !important;
    border-radius: 10px !important;
    color: #9a3412 !important;
    background: #fff7f1 !important;
    font-family: var(--font-ui) !important;
    font-size: 20px !important;
    font-weight: 700 !important;
    line-height: 1 !important;
    box-shadow: 0 2px 7px rgba(132, 66, 35, 0.07);
  }

  .sidebar-tabs .tab-btn-add:hover,
  body.unit2-mode .sidebar-tabs .tab-btn-add:hover,
  body.unit3-mode .sidebar-tabs .tab-btn-add:hover,
  body.chapter-mode .sidebar-tabs .tab-btn-add:hover {
    color: #ffffff !important;
    background: #c2410c !important;
    border-color: #c2410c !important;
    transform: translateY(-1px);
  }

  .content-helper-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 10px;
  }

  .btn-content-helper,
  .btn-add-figure,
  .btn-add-table {
    min-width: 0;
    min-height: 36px;
    padding: 8px 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid #edcfbb;
    border-radius: 10px;
    color: #9a3412;
    background: #fff7f1;
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.35;
    text-align: center;
    transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
  }

  .btn-content-helper:hover,
  .btn-add-figure:hover,
  .btn-add-table:hover {
    color: #ffffff;
    background: #c2410c;
    border-color: #c2410c;
    transform: translateY(-1px);
  }

  #btn-add-member,
  #btn-add-author {
    min-height: 36px;
    padding: 8px 12px;
    flex: 0 0 auto;
    border: 1px solid #c2410c;
    border-radius: 10px;
    color: #ffffff;
    background: #c2410c;
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.35;
    box-shadow: 0 3px 9px rgba(194, 65, 12, 0.16);
  }

  #btn-add-member:hover,
  #btn-add-author:hover {
    color: #ffffff;
    background: #9a3412;
    border-color: #9a3412;
    transform: translateY(-1px);
  }

  .eval-body .eval-layout {
    display: grid;
    grid-template-columns: minmax(220px, 260px) minmax(0, 1fr);
    /* A trailing 1fr row absorbs the sticky sidebar's height so the first row (metrics)
       is not stretched and no gap appears above the toolbar. */
    grid-template-rows: repeat(5, auto) 1fr;
    align-items: start;
    gap: 18px;
    min-width: 0;
  }

  .eval-body .eval-layout > * {
    min-width: 0;
  }

  .eval-body .eval-metrics-grid,
  .eval-body .eval-toolbar,
  .eval-body .eval-sheet-card {
    min-width: 0;
  }

  .eval-body .eval-layout > .page-tools-sidebar {
    grid-column: 1;
    grid-row: 1 / -1;
    position: sticky;
    top: 16px;
    width: 100%;
    min-width: 0;
    margin: 0;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 12px;
    padding: 14px;
    border-radius: 16px;
  }

  .eval-body .eval-layout > :not(.page-tools-sidebar) {
    grid-column: 2;
  }

  .eval-body .page-tools-sidebar .page-action-copy {
    min-width: 0;
  }

  .eval-body .page-tools-sidebar .page-action-buttons {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .eval-body .page-tools-sidebar .page-action-buttons .btn {
    width: 100%;
    justify-content: center;
  }

  @media (max-width: 1600px) {
    .brand-subtitle {
      display: none;
    }

    .template-switcher {
      gap: 4px;
    }

    .template-switch-btn {
      padding: 7px 9px;
    }
  }

  @media (min-width: 1101px) and (max-width: 1520px) {
    /* Logo, avatar and save status stay; the brand and user names hide (the user menu still shows the name). */
    .nav-brand > div:not(.brand-icon),
    .nav-brand .brand-text,
    .nav-user-copy strong {
      display: none;
    }

    .nav-user-trigger {
      padding-right: 6px;
    }
  }

  @media (min-width: 1101px) and (max-width: 1320px) {
    .template-switch-btn {
      padding: 7px 7px;
      font-size: 12.5px;
    }

    .template-switcher > .template-switch-btn > .nav-icon,
    .nav-dropdown-trigger > .nav-icon {
      display: none;
    }
  }

  @media (max-width: 1100px) {
    .navbar {
      align-items: center;
      flex-wrap: wrap;
    }

    .nav-brand {
      flex-basis: auto;
      flex-wrap: nowrap;
    }

    .nav-actions {
      flex: 1 1 100%;
      justify-content: flex-start;
    }

    .nav-user-menu {
      margin-left: 0;
    }

    /* The links get their own row here; let them wrap instead of running past the window edge. */
    .template-switcher {
      flex-wrap: wrap;
    }
  }

  @media (max-width: 760px) {
    html,
    body {
      height: auto;
      min-height: 100%;
      max-height: none;
      overflow-x: hidden;
      overflow-y: auto;
    }

    .navbar {
      padding: 12px 13px;
    }

    .template-switcher {
      order: 3;
      flex: 1 0 100%;
      width: 100%;
      flex-wrap: wrap;
      position: relative;
    }

    /* The chapter menu opens full width under the links instead of running off the screen. */
    .nav-dropdown {
      position: static;
    }

    .nav-dropdown-menu {
      left: 0;
      right: 0;
      min-width: 0;
    }

    .nav-user-menu {
      width: 100%;
    }

    .nav-user-trigger {
      width: 100%;
      justify-content: flex-start;
    }

    .nav-user-trigger > .nav-caret {
      margin-left: auto;
    }

    .nav-user-popover {
      left: 0;
      right: auto;
      width: min(242px, calc(100vw - 26px));
    }

    .brand-title {
      font-size: 15px;
    }

    .brand-subtitle {
      max-width: 250px;
    }

    .nav-actions {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .nav-actions .btn {
      width: 100%;
      justify-content: center;
    }

    .app-container {
      flex: 0 0 auto;   /* stacked layout: grow with the content so the page scrolls to the end */
      height: auto;
      max-height: none;
      min-height: calc(100vh - 76px);
      flex-direction: column;
      overflow: visible;
    }

    .sidebar-panel {
      width: 100%;
      min-width: 0;
      max-width: none;
      max-height: none;
      height: auto;
      overflow: visible;
      border-right: 0;
      border-bottom: 1px solid #f1d8c7;
    }

    .sidebar-tabs {
      display: flex;
      overflow-x: auto;
      padding: 8px 10px;
    }

    .tab-btn {
      flex: 0 0 auto;
      min-width: 104px;
    }

    .sidebar-tab-panels {
      max-height: 56vh;
      padding: 12px;
    }

    .preview-workspace {
      min-height: 76vh;
      padding: 22px 12px 70px;
      align-items: flex-start;
    }

    .page-action-bar,
    .preview-workspace > .page-action-bar {
      align-items: stretch;
      flex-direction: column;
      gap: 11px;
      width: 100%;
      margin-bottom: 14px;
      padding: 13px;
    }

    .page-action-buttons {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      width: 100%;
    }

    .page-action-buttons .btn {
      width: 100%;
      justify-content: center;
    }

    .eval-body .eval-layout {
      grid-template-columns: minmax(190px, 220px) minmax(0, 1fr);
      gap: 14px;
    }

    .preview-toolbar {
      justify-content: flex-start;
      overflow-x: auto;
    }

    .sidebar-action-bar,
    .content-helper-buttons {
      grid-template-columns: 1fr;
    }

    .sidebar-action-bar .btn-action,
    .content-helper-buttons .btn-content-helper,
    .btn-add-figure,
    .btn-add-table {
      width: 100%;
    }

    .eval-body .eval-layout {
      display: flex;
      flex-direction: column;
    }

    .eval-body .eval-layout > .page-tools-sidebar {
      position: static;
      width: 100%;
      order: -1;
    }

    .eval-body .page-tools-sidebar .page-action-buttons {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .eval-body .page-tools-sidebar .page-action-buttons .btn {
      min-width: 0;
      white-space: normal;
    }
  }

  @media print {
    .page-action-bar {
      display: none !important;
    }
  }
}

@media print {
  .page-action-bar {
    display: none !important;
  }
}

/* Pictures dragged onto the paper (chapter-engine.js): the section that will receive the picture is outlined */
@media screen {
  .preview-workspace.paper-drop-active .page-a4 {
    box-shadow: 0 0 0 2px rgba(194, 65, 12, 0.35), var(--shadow-md);
  }

  .paper-drop-target {
    background: rgba(194, 65, 12, 0.07);
    box-shadow: -10px 0 0 rgba(194, 65, 12, 0.07), 10px 0 0 rgba(194, 65, 12, 0.07);
  }

  .paper-drop-hint {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%);
    z-index: 2000;
    max-width: calc(100vw - 32px);
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--primary);
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    box-shadow: var(--shadow-xl);
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .paper-drop-hint[hidden] {
    display: none;
  }

  .chapter-figure-block.figure-just-added {
    outline: 3px solid rgba(194, 65, 12, 0.45);
    outline-offset: 6px;
    transition: outline-color 0.4s ease;
  }
}

/* Section content editor: sub-headings and their text in separate blocks */
.cb-hidden {
  display: none !important;
}

@media screen {
  .cb-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px 10px;
    margin-bottom: 8px;
  }

  .cb-legend {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    color: #755449;
  }

  .cb-swatch {
    width: 10px;
    height: 10px;
    margin-left: 4px;
    border-radius: 3px;
  }

  .cb-swatch:first-child {
    margin-left: 0;
  }

  .cb-swatch.is-heading {
    background: #c2410c;
  }

  .cb-swatch.is-text {
    border: 1px solid #d9b8a5;
    background: #ffffff;
  }

  .cb-mode-btn {
    padding: 4px 11px;
    border: 1px solid #edcfbb;
    border-radius: 999px;
    background: #ffffff;
    color: #9a3412;
    font-family: var(--font-ui);
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
  }

  .cb-mode-btn:hover {
    border-color: #c2410c;
    background: #fff1e6;
  }

  .cb-mode-btn:focus-visible,
  .cb-act:focus-visible {
    outline: 2px solid #c2410c;
    outline-offset: 2px;
  }

  .cb-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .cb-empty {
    margin: 0;
    padding: 14px 12px;
    border: 1px dashed #edcfbb;
    border-radius: 11px;
    color: #9a7568;
    font-size: 12.5px;
    text-align: center;
  }

  .cb-block {
    padding: 7px 9px 9px;
    border: 1px solid #edcfbb;
    border-radius: 11px;
    background: #fffaf7;
  }

  .cb-block.cb-heading {
    border-color: #f3b98f;
    border-left: 4px solid #c2410c;
    background: #fff1e6;
  }

  .cb-block.cb-text.is-nested {
    margin-left: 16px;
  }

  .cb-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 5px;
  }

  .cb-kind {
    font-size: 11px;
    font-weight: 700;
    color: #755449;
  }

  .cb-heading .cb-kind {
    color: #9a3412;
  }

  .cb-actions {
    display: flex;
    gap: 2px;
  }

  .cb-act {
    display: inline-grid;
    place-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: #9a7568;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .cb-act svg {
    width: 15px;
    height: 15px;
  }

  .cb-act:hover:not(:disabled) {
    background: #ffe4d1;
    color: #9a3412;
  }

  .cb-act-remove:hover:not(:disabled) {
    background: #fee2e2;
    color: #b91c1c;
  }

  .cb-act:disabled {
    opacity: 0.3;
    cursor: default;
  }

  .cb-heading-fields {
    display: grid;
    grid-template-columns: 70px minmax(0, 1fr);
    gap: 6px;
  }

  .cb-num,
  .cb-title,
  .cb-textarea {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding: 7px 10px;
    border: 1px solid #edcfbb;
    border-radius: 9px;
    background: #ffffff;
    color: #4a2a22;
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
  }

  .cb-num {
    text-align: center;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #9a3412;
  }

  .cb-title {
    font-weight: 700;
    color: #7c2d12;
  }

  .cb-textarea {
    display: block;
    min-height: 60px;
    resize: none;
    overflow: hidden;
  }

  .cb-num:focus,
  .cb-title:focus,
  .cb-textarea:focus {
    border-color: #c2410c;
    box-shadow: 0 0 0 3px rgba(194, 65, 12, 0.13);
  }

  .cb-title::placeholder,
  .cb-textarea::placeholder {
    color: #9a7568;
    font-weight: 400;
    opacity: 1;
  }
}

/* Chapter tables pulled in from the ตารางประเมิน page */
@media screen {
  .eval-import {
    margin-top: 8px;
  }

  .btn-import-eval {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 36px;
    padding: 8px 12px;
    border: 1px solid #e8b48f;
    border-radius: 10px;
    background: #fff7f1;
    color: #9a3412;
    font-family: var(--font-ui);
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  }

  .btn-import-eval:hover,
  .btn-import-eval[aria-expanded="true"] {
    border-color: #c2410c;
    background: #c2410c;
    color: #ffffff;
  }

  .btn-import-eval:focus-visible,
  .eval-import-option:focus-visible,
  .btn-table-refresh:focus-visible {
    outline: 2px solid #c2410c;
    outline-offset: 2px;
  }

  .eval-import-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
    padding: 10px;
    border: 1px solid #edcfbb;
    border-radius: 12px;
    background: #fffaf7;
  }

  .eval-import-panel[hidden] {
    display: none;
  }

  .eval-import-status {
    margin: 0;
    font-size: 12px;
    line-height: 1.5;
    color: #755449;
  }

  .eval-import-status.is-empty {
    color: #b91c1c;
    font-weight: 700;
  }

  .eval-import-status a {
    color: #c2410c;
  }

  .eval-import-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .eval-import-option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #edcfbb;
    border-radius: 10px;
    background: #ffffff;
    font-family: var(--font-ui);
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
  }

  .eval-import-option:hover:not(:disabled) {
    border-color: #c2410c;
    background: #fff1e6;
  }

  .eval-import-option:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .eval-import-option-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
    color: #4a2a22;
  }

  .eval-import-option-detail {
    font-size: 11.5px;
    line-height: 1.45;
    color: #755449;
  }

  .eval-import-badge {
    padding: 1px 7px;
    border-radius: 999px;
    background: #c2410c;
    color: #ffffff;
    font-size: 10.5px;
    font-style: normal;
    font-weight: 700;
  }

  .eval-import-missing {
    font-size: 11px;
    color: #b45309;
  }

  .eval-import-note {
    margin: 0;
    font-size: 11px;
    line-height: 1.5;
    color: #9a7568;
  }

  .table-source-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px 8px;
    margin-bottom: 6px;
    padding: 5px 8px;
    border-radius: 8px;
    background: #fff1e6;
    color: #9a3412;
    font-size: 11.5px;
  }

  .btn-table-refresh {
    padding: 4px 8px;
    border: 1px solid #c2410c;
    border-radius: 7px;
    background: #ffffff;
    color: #9a3412;
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
  }

  .btn-table-refresh:hover {
    background: #c2410c;
    color: #ffffff;
  }
}

/* Page-number settings (page-numbering.js) */
@media screen {
  .pn-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .pn-mode {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    padding: 4px;
    border: 1px solid #edcfbb;
    border-radius: 10px;
    background: #fffaf7;
  }

  .pn-mode label {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 32px;
    border-radius: 7px;
    color: #755449;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
  }

  .pn-mode input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
  }

  .pn-mode label:has(input:checked) {
    background: #c2410c;
    color: #ffffff;
  }

  .pn-mode label:has(input:focus-visible) {
    outline: 2px solid #c2410c;
    outline-offset: 2px;
  }

  .pn-panel .form-group {
    margin-bottom: 0;
  }

  .pn-start.is-auto {
    background: #fff1e6;
    color: #9a3412;
    font-weight: 700;
  }

  .pn-hint,
  .pn-note,
  .pn-map-note {
    margin: 4px 0 0;
    color: #755449;
    font-size: 11.5px;
    line-height: 1.5;
  }

  .pn-check {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #4a2a22;
    font-size: 12.5px;
    cursor: pointer;
  }

  .pn-check input {
    accent-color: #c2410c;
  }

  .pn-warning {
    margin: 0;
    padding: 8px 10px;
    border: 1px solid #f5c992;
    border-radius: 10px;
    background: #fff7e6;
    color: #92400e;
    font-size: 12px;
    line-height: 1.55;
  }

  .pn-warning[hidden] {
    display: none;
  }

  .pn-warning a,
  .pn-map a {
    color: #c2410c;
  }

  .pn-map {
    border: 1px solid #edcfbb;
    border-radius: 10px;
    background: #ffffff;
  }

  .pn-map summary {
    padding: 8px 10px;
    color: #9a3412;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
  }

  .pn-map-list {
    margin: 0;
    padding: 0 10px 8px;
    list-style: none;
  }

  .pn-map-list li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0 8px;
    padding: 4px 0;
    border-top: 1px solid #f6e8de;
    font-size: 12px;
  }

  .pn-map-list li small {
    grid-column: 1 / -1;
    color: #9a7568;
    font-size: 11px;
  }

  .pn-map-list li.is-current a {
    font-weight: 700;
  }

  .pn-map-list li.is-unknown .pn-map-range {
    color: #b45309;
  }

  .pn-map-range {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: #4a2a22;
  }

  .pn-map-note {
    padding: 0 10px 10px;
  }
}
