.protocol-page {
    color: #173d42;
    background: #f5f8f8;
}

.protocol-page::before {
    display: none;
}

.library-header {
    min-height: 100px;
    padding: 22px 4%;
    border-bottom: 1px solid #d3e2e1;
    background: #003a40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.library-header img {
    max-width: 40%;
    height: auto;
}

.protocol-page a {
    color: #176762;
    text-underline-offset: 3px;
}

.protocol-page .home-link {
    font-weight: 600;
    color: #fff;
}

.library-main {
    max-width: 1500px;
    margin: 0 auto;
    padding: 40px 4%;
}

.library-layout {
    display: grid;
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
    align-items: start;
    gap: clamp(28px, 4vw, 56px);
}

.library-content {
    min-width: 0;
}

.hierarchy-sidebar {
    position: sticky;
    top: 24px;
    padding: 12px 20px 24px 0;
    border-right: 1px solid #cadbd9;
}

.hierarchy-sidebar h2 {
    margin: 0 0 22px;
    color: #003a40;
    font-size: 1.05rem;
}

.hierarchy-tree,
.hierarchy-tree ol {
    margin: 0;
    padding: 0;
    list-style: none;
}

.hierarchy-tree li {
    position: relative;
}

.hierarchy-tree ol {
    margin: 8px 0 0 4px;
    padding-left: 9px;
    border-left: 1px solid #a8c4c1;
}

.hierarchy-tree ol > li {
    margin-bottom: 8px;
    padding-left: 7px;
}

.hierarchy-tree ol > li::before {
    position: absolute;
    top: 17px;
    left: -10px;
    width: 9px;
    border-top: 1px solid #a8c4c1;
    content: '';
}

.hierarchy-node {
    display: block;
    padding: 9px 10px;
    border: 1px solid #c7d9d7;
    border-radius: 4px;
    background: #fff;
    color: #24494b;
    font-size: 0.84rem;
    font-weight: 600;
    line-height: 1.35;
    overflow-wrap: normal;
    word-break: normal;
    hyphens: none;
}

.hierarchy-root {
    border-color: #003a40;
    background: #003a40;
    color: #fff;
}

.hierarchy-leaf {
    border-color: #b6d2c8;
    background: #e8f2ee;
}

.hierarchy-nowrap {
    white-space: nowrap;
}

.library-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 20px;
}

.library-heading h1 {
    font-size: 1.8rem;
    overflow-wrap: anywhere;
}

.folder-button {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    color: #fff;
    background: #003a40;
    border: 1px solid #003a40;
    border-radius: 5px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.folder-button:hover {
    background: #176762;
}

.create-button {
    background: #176762;
    border-color: #176762;
}

.create-button:hover {
    background: #0e514d;
}

.library-edit-button {
    min-height: 46px;
}

.create-symbol {
    position: relative;
    width: 18px;
    height: 18px;
    border: 2px solid currentColor;
    border-radius: 50%;
}

.create-symbol::before,
.create-symbol::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 10px;
    height: 2px;
    background: currentColor;
    transform: translate(-50%, -50%);
}

.create-symbol::after {
    transform: translate(-50%, -50%) rotate(90deg);
}

.protocol-dialog {
    width: min(940px, calc(100% - 32px));
    max-width: none;
    max-height: min(92vh, 1000px);
    padding: 0;
    color: #173d42;
    border: 1px solid #cadbd9;
    border-radius: 6px;
    background: #f8fbfa;
    box-shadow: 0 24px 70px rgb(0 35 38 / 28%);
}

.protocol-dialog::backdrop {
    background: rgb(0 30 33 / 62%);
}

.protocol-dialog form {
    padding: 28px clamp(18px, 4vw, 40px) 24px;
    overflow-y: auto;
    max-height: min(92vh, 1000px);
}

.dialog-heading,
.step-editor-heading,
.step-heading,
.parameter-heading,
.dialog-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.dialog-heading {
    padding-bottom: 20px;
    border-bottom: 1px solid #cadbd9;
}

.dialog-heading h2,
.step-editor-heading h3 {
    margin: 0;
}

.dialog-kicker {
    margin: 0 0 5px;
    color: #176762;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.protocol-mode-note {
    margin: 16px 0 0;
    padding: 10px 12px;
    border-left: 3px solid #176762;
    background: #e8f2f0;
    color: #35595a;
    font-size: 0.88rem;
    overflow-wrap: anywhere;
}

.icon-button {
    display: inline-grid;
    flex: 0 0 36px;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid #97b5b3;
    border-radius: 4px;
    background: #fff;
    color: #173d42;
    font: inherit;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

.icon-button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.metadata-fields {
    margin: 22px 0 0;
    padding: 0;
    border: 0;
}

.metadata-fields legend {
    margin-bottom: 14px;
    font-weight: 700;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.form-field,
.protocol-step > label,
.action-field {
    display: grid;
    gap: 7px;
    min-width: 0;
    font-size: 0.87rem;
    font-weight: 600;
}

.form-field[hidden] {
    display: none;
}

.form-field label span {
    color: #627779;
    font-size: 0.78rem;
    font-weight: 400;
}

.form-field input,
.form-field select,
.form-field textarea,
.protocol-step input,
.protocol-step textarea,
.parameter-row select,
.parameter-row input {
    width: 100%;
    min-width: 0;
    min-height: 42px;
    padding: 9px 10px;
    border: 1px solid #97b5b3;
    border-radius: 4px;
    background: #fff;
    color: #173d42;
    font: inherit;
    font-weight: 400;
}

.objective-field {
    grid-column: 1 / -1;
}

.protocol-step textarea {
    resize: vertical;
}

.protocol-text-editor {
    min-width: 0;
}

.format-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 5px;
    border: 1px solid #97b5b3;
    border-bottom: 0;
    border-radius: 4px 4px 0 0;
    background: #edf5f3;
}

.format-toolbar button,
.format-toolbar select {
    width: auto;
    min-width: 36px;
    min-height: 34px;
    padding: 4px 8px;
    border: 1px solid #97b5b3;
    border-radius: 3px;
    background: #fff;
    color: #173d42;
    font-size: 14px;
    cursor: pointer;
}

.format-toolbar .format-bold {
    font-weight: 700;
}

.format-toolbar .format-italic {
    font-style: italic;
}

.format-toolbar button[aria-pressed="true"] {
    background: #c8e5dd;
    border-color: #176762;
}

.protocol-rich-text {
    min-height: 100px;
    padding: 9px 10px;
    border: 1px solid #97b5b3;
    border-radius: 0 0 4px 4px;
    background: #fff;
    color: #173d42;
    font-size: 12pt;
    font-weight: 400;
    line-height: 1.5;
}

.protocol-rich-text:focus {
    outline: 2px solid #176762;
    outline-offset: -2px;
}

.protocol-rich-text[aria-invalid="true"] {
    border-color: #a12525;
}

.protocol-formatted-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.protocol-formatted-text font[size="1"] { font-size: 10pt; }
.protocol-formatted-text font[size="2"] { font-size: 11pt; }
.protocol-formatted-text font[size="3"] { font-size: 12pt; }
.protocol-formatted-text font[size="4"] { font-size: 14pt; }
.protocol-formatted-text font[size="5"] { font-size: 18pt; }
.protocol-formatted-text font[size="6"] { font-size: 24pt; }
.protocol-formatted-text font[size="7"] { font-size: 32pt; }

.step-images {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
    gap: 12px;
}

.step-images:empty,
.step-image-status[hidden] {
    display: none;
}

.step-image {
    position: relative;
    min-width: 0;
    margin: 0;
}

.step-image img {
    display: block;
    width: 100%;
    height: 180px;
    object-fit: contain;
    background: #f5f8f8;
}

.step-image figcaption {
    padding: 6px 0;
    font-size: 0.8rem;
    overflow-wrap: anywhere;
}

.step-image .icon-button {
    position: absolute;
    top: 4px;
    right: 4px;
}

.step-image-status {
    margin: 0;
    font-size: 0.85rem;
}

.step-editor {
    margin-top: 30px;
    padding-top: 22px;
    border-top: 1px solid #cadbd9;
}

.secondary-button,
.text-button {
    min-height: 40px;
    padding: 8px 13px;
    border: 1px solid #176762;
    border-radius: 4px;
    background: #fff;
    color: #176762;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.secondary-button:hover,
.text-button:hover {
    background: #e8f2f0;
}

.protocol-step {
    display: grid;
    gap: 14px;
    margin: 18px 0 0;
    padding: 18px;
    border: 1px solid #cadbd9;
    border-radius: 5px;
    background: #fff;
}

.step-heading h4,
.parameter-heading h5 {
    margin: 0;
}

.parameter-heading {
    padding-top: 4px;
}

.text-button {
    min-height: 34px;
    padding: 5px 10px;
    font-size: 0.85rem;
}

.step-parameters {
    display: grid;
    gap: 8px;
}

.parameter-row {
    display: grid;
    grid-template-columns: minmax(75px, 0.7fr) minmax(105px, 1fr) minmax(105px, 1fr) minmax(85px, 0.75fr) 36px;
    gap: 8px;
}

.parameter-row select,
.parameter-row input {
    min-height: 38px;
    padding: 7px 8px;
}

.dialog-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
    margin-top: 26px;
    padding-top: 18px;
    border-top: 1px solid #cadbd9;
}

.protocol-print-view {
    display: none;
}

@media print {
    @page {
        margin: 18mm;
    }

    body.protocol-page > *:not(#protocol-print-view) {
        display: none !important;
    }

    .protocol-print-view {
        display: block !important;
        color: #172f32;
        font: 10pt/1.5 Georgia, 'Times New Roman', serif;
    }

    .print-header {
        padding-bottom: 12px;
        border-bottom: 3px solid #176762;
    }

    .print-header h1 {
        margin: 0;
        color: #003a40;
        font: 700 24pt/1.2 Georgia, 'Times New Roman', serif;
        overflow-wrap: anywhere;
    }

    .print-header p {
        margin: 8px 0 0;
        color: #435b5d;
        font: 10pt/1.4 Arial, sans-serif;
        overflow-wrap: anywhere;
    }

    .print-metadata {
        display: grid;
        grid-template-columns: minmax(130px, 1fr) 2fr;
        margin: 18px 0 24px;
        font: 9.5pt/1.4 Arial, sans-serif;
    }

    .print-metadata dt,
    .print-metadata dd {
        margin: 0;
        padding: 6px 8px;
        border-bottom: 1px solid #ccd8d6;
        overflow-wrap: anywhere;
    }

    .print-metadata dt {
        font-weight: 700;
    }

    .protocol-print-view > h2 {
        margin: 0 0 12px;
        color: #003a40;
        font: 700 16pt/1.25 Georgia, 'Times New Roman', serif;
    }

    .print-step {
        margin: 0 0 18px;
        break-inside: avoid-page;
    }

    .print-step h3 {
        margin: 0 0 5px;
        font: 700 12pt/1.3 Arial, sans-serif;
    }

    .print-step > p {
        margin: 0 0 10px;
        white-space: pre-wrap;
        overflow-wrap: anywhere;
    }

    .print-step-image {
        margin: 0 0 12px;
        break-inside: avoid;
    }

    .print-step-image img {
        display: block;
        max-width: 100%;
        max-height: 180mm;
        object-fit: contain;
    }

    .print-parameters {
        width: 100%;
        border-collapse: collapse;
        font: 9pt/1.35 Arial, sans-serif;
    }

    .print-parameters th,
    .print-parameters td {
        padding: 6px 8px;
        border: 1px solid #b8c9c7;
        text-align: left;
        overflow-wrap: anywhere;
    }

    .print-parameters th {
        background: #e4efed !important;
        print-color-adjust: exact;
    }

    .print-summary {
        width: 100%;
        margin-top: 12px;
        border-collapse: collapse;
        table-layout: fixed;
        font: 9pt/1.35 Arial, sans-serif;
    }

    .print-summary thead {
        display: table-header-group;
    }

    .print-summary th,
    .print-summary td {
        width: 25%;
        padding: 6px 8px;
        border: 1px solid #b8c9c7;
        text-align: left;
        vertical-align: top;
        overflow-wrap: anywhere;
    }

    .print-summary th {
        background: #e4efed !important;
        print-color-adjust: exact;
    }

    .print-summary tbody tr {
        break-inside: avoid-page;
    }
}

.folder-symbol {
    position: relative;
    width: 20px;
    height: 15px;
    border: 2px solid currentColor;
    border-radius: 2px;
}

.folder-symbol::before {
    content: '';
    position: absolute;
    top: -6px;
    left: -2px;
    width: 9px;
    height: 4px;
    border: 2px solid currentColor;
    border-bottom: none;
    border-radius: 2px 2px 0 0;
}

.folder-status {
    margin-top: 16px;
    color: #52666a;
    overflow-wrap: anywhere;
}

.library-controls {
    display: grid;
    grid-template-columns: minmax(240px, 2fr) repeat(3, minmax(140px, 1fr));
    gap: 18px;
    margin-top: 30px;
    padding: 24px 0;
    border-top: 1px solid #cadbd9;
    border-bottom: 1px solid #cadbd9;
}

.library-controls > div {
    min-width: 0;
}

.library-controls label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.library-controls input,
.library-controls select {
    width: 100%;
    height: 44px;
    padding: 8px 10px;
    border: 1px solid #97b5b3;
    border-radius: 4px;
    background: #fff;
    color: #173d42;
    font: inherit;
}

.protocol-page :focus-visible {
    outline: 3px solid #287d77;
    outline-offset: 3px;
}

.results-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 24px 0 16px;
}

.results-heading h2 {
    font-size: 1.1rem;
}

.results-heading p,
.file-path {
    color: #52666a;
    font-size: 0.85rem;
}

.empty-state {
    text-align: center;
    padding: 75px 16px;
    border-top: 1px solid #d3e2e1;
    border-bottom: 1px solid #d3e2e1;
}

.empty-state h3 {
    font-size: 1.05rem;
    font-weight: 500;
}

.table-scroll {
    position: relative;
    overflow-x: auto;
}

.library-main table {
    width: 100%;
    min-width: 680px;
    border-collapse: collapse;
    table-layout: fixed;
    background: #fff;
}

.library-main th,
.library-main td {
    padding: 16px 14px;
    border-bottom: 1px solid #d3e2e1;
    text-align: left;
    vertical-align: top;
    overflow-wrap: anywhere;
}

.library-main th {
    background: #e4efed;
    font-size: 0.85rem;
}

.library-main th:first-child {
    width: 44%;
}

.library-main th:last-child {
    width: 58px;
}

.library-main tbody tr:hover {
    background: #f1f8f6;
}

.hierarchy-builders {
    margin-top: 34px;
    padding-top: 24px;
    border-top: 1px solid #cadbd9;
}

.builder-section-heading {
    margin-bottom: 18px;
}

.builder-section-heading h2 {
    margin: 0;
    color: #003a40;
    font-size: 1.2rem;
}

.builder-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border-bottom: 1px solid #a8c4c1;
}

.builder-tab {
    min-width: 0;
    padding: 12px 10px;
    border: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: #52666a;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    overflow-wrap: anywhere;
}

.builder-tab[aria-selected='true'] {
    border-bottom-color: #176762;
    color: #003a40;
}

.builder-panel {
    padding: 22px 0;
}

.builder-form {
    display: grid;
    grid-template-columns: minmax(180px, 0.7fr) minmax(0, 1.3fr);
    align-items: start;
    gap: 18px 22px;
}

.builder-name-field,
.builder-choice-field {
    display: grid;
    align-content: start;
    gap: 8px;
    min-width: 0;
}

.builder-name-field label,
.builder-choice-field > label,
.builder-choice-field h3 {
    margin: 0;
    font-size: 0.88rem;
    font-weight: 700;
}

.builder-name-field input,
.builder-choice-field > input {
    width: 100%;
    min-width: 0;
    height: 42px;
    padding: 8px 10px;
    border: 1px solid #97b5b3;
    border-radius: 4px;
    background: #fff;
    color: #173d42;
    font: inherit;
}

.builder-choice-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    max-height: 240px;
    overflow-y: auto;
}

.module-sequence-field {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.module-sequence-field h3 {
    margin: 0;
    font-size: 0.88rem;
}

.module-sequence-list {
    display: grid;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style-position: inside;
}

.module-sequence-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
    padding: 6px 8px;
    border: 1px solid #cadbd9;
    border-radius: 4px;
    background: #f5f8f8;
    color: #24494b;
    font-size: 0.83rem;
}

.module-sequence-list li > span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.module-sequence-controls {
    display: flex;
    flex: 0 0 auto;
    gap: 4px;
}

.module-sequence-controls .icon-button {
    width: 30px;
    height: 30px;
    flex-basis: 30px;
    font-size: 1rem;
}

#module-builder-version {
    background: #eef5f3;
    font-weight: 700;
}

.builder-choice {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    min-width: 0;
    padding: 9px 10px;
    border: 1px solid #cadbd9;
    border-radius: 4px;
    background: #fff;
    color: #24494b;
    font-size: 0.85rem;
    overflow-wrap: anywhere;
    cursor: pointer;
}

.builder-choice input {
    flex: 0 0 auto;
    margin: 2px 0 0;
    accent-color: #176762;
}

.builder-choice span {
    min-width: 0;
}

.builder-empty-choice {
    grid-column: 1 / -1;
    margin: 0;
    padding: 12px;
    border: 1px dashed #a8c4c1;
    color: #52666a;
    font-size: 0.85rem;
}

.builder-form > .folder-button {
    justify-self: start;
}

.builder-saved-section {
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid #e0e9e8;
}

.builder-saved-section h3 {
    margin: 0 0 10px;
    font-size: 0.9rem;
}

.builder-saved-list {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.builder-saved-list li {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    padding: 9px 10px;
    border-left: 3px solid #176762;
    background: #eef5f3;
    font-size: 0.84rem;
    overflow-wrap: anywhere;
}

.builder-saved-list li span {
    color: #52666a;
}

.builder-status {
    min-height: 1.4em;
    margin: 10px 0 0;
    color: #176762;
    font-size: 0.85rem;
    overflow-wrap: anywhere;
}

.file-path,
.filename-warning {
    display: block;
    margin-top: 6px;
    overflow-wrap: anywhere;
}

.filename-warning {
    font-size: 0.8rem;
    color: #865611;
}

.download-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid #97b5b3;
    border-radius: 4px;
    text-decoration: none;
    font-size: 1.4rem;
}

.library-message {
    margin: 18px 0;
    color: #865611;
    overflow-wrap: anywhere;
}

.guide-link {
    display: inline-block;
    margin-top: 16px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
}

@media (max-width: 900px) {
    .library-layout {
        grid-template-columns: minmax(0, 1fr);
        gap: 28px;
    }
    .hierarchy-sidebar {
        position: static;
        padding: 0 0 22px;
        border-right: 0;
        border-bottom: 1px solid #cadbd9;
    }
    .hierarchy-sidebar h2 {
        margin-bottom: 14px;
    }
    .library-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .search-control {
        grid-column: 1 / -1;
    }
    .builder-form {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 480px) {
    .library-heading h1 {
        font-size: 1.5rem;
    }
    .library-main {
        padding-top: 28px;
    }
    .hierarchy-tree ol {
        margin-left: 4px;
        padding-left: 9px;
    }
    .hierarchy-tree ol > li {
        padding-left: 7px;
    }
    .hierarchy-tree ol > li::before {
        left: -10px;
        width: 9px;
    }
    .library-controls {
        grid-template-columns: minmax(0, 1fr);
    }
    .library-heading .folder-button {
        flex: 1 1 100%;
        justify-content: center;
    }
    .form-grid,
    .parameter-row {
        grid-template-columns: minmax(0, 1fr);
    }
    .parameter-row .icon-button {
        justify-self: end;
    }
    .dialog-actions {
        align-items: stretch;
        flex-direction: column-reverse;
    }
    .builder-tabs,
    .builder-choice-list {
        grid-template-columns: minmax(0, 1fr);
    }
    .builder-tab {
        text-align: left;
    }
    .builder-form > .folder-button {
        justify-self: stretch;
        justify-content: center;
    }
    .dialog-actions button {
        justify-content: center;
    }
}