:root {
    --triangle-color: #3b3b3b;
    /* Button tokens: every button in the app uses these, so the look stays the same on every page. */
    --btn-bg: #ffffff;
    --btn-bg-hover: #f3f4f6;
    --btn-line: #d1d5db;
    --btn-line-hover: #9ca3af;
    --btn-ink: #374151;
    --btn-ink-strong: #111827;
    --btn-primary-bg: #111827;
    --btn-primary-bg-hover: #374151;
}

/* Base */
body {
    font-family: 'Inter', system-ui, Helvetica, Arial, sans-serif;
    padding: 1em;
    /* scrollbar-gutter: stable; */
}

a:hover {
    color: #007cc4;
}

button {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25;
    white-space: nowrap;   /* a label never breaks over two lines */
    cursor: pointer;
    background-color: var(--btn-bg);
    border: 1px solid var(--btn-line);
    color: var(--btn-ink);
    transition: all 0.15s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

button:hover:not(:disabled) {
    background-color: var(--btn-bg-hover);
    border-color: var(--btn-line-hover);
}

button:focus-visible,
a[class*="-btn"]:focus-visible {
    outline: 2px solid #111827;
    outline-offset: 2px;
}

/* Bold labels inside buttons (<b>EDIT</b>) read as small caps, not shouting. */
button b,
a[class*="-btn"] b {
    font-weight: 600;
    letter-spacing: 0.03em;
}

button:disabled {
    background-color: #f3f4f6;
    color: #9ca3af;
    border-color: #e5e7eb;
    cursor: not-allowed;
    box-shadow: none;
}

/* Robust layout: any zoom level or screen width scrolls inside the element that is too wide,
   never the whole page. */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    overflow-wrap: break-word;   /* a long word or URL breaks only when it cannot fit its line */
}

img,
video,
canvas,
iframe {
    max-width: 100%;
}

select,
input,
button,
textarea {
    max-width: 100%;
}

pre {
    max-width: 100%;
    overflow-x: auto;
}

/* Every wide table scrolls sideways in its own box. */
.table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Action buttons in a table cell sit on one line, small and evenly spaced. If the row is too narrow,
   the table scrolls sideways in its .table-wrap instead of the buttons wrapping. */
td:has(> :is(button, a[class*="-btn"])) {
    white-space: nowrap;
}

td > :is(button, a[class*="-btn"]) {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    margin: 0 0.35rem 0 0 !important;
    float: none !important;
}

/* Navigation */
nav {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;   /* a narrow window or a long project name wraps the bar instead of widening the page */
    align-items: center;
    gap: 0.5em;
    padding: 0.75rem 1.5rem;
    background-color: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    margin-bottom: 1.5rem;
    border-radius: 8px;
    border: 1px solid #eaeaea;
}

nav div {
    display: flex;
}

nav a {
    padding: 0.5em 0.8em;
    color: #4a4a4a;
    text-decoration: none;
    font-weight: 500;
    border-radius: 6px;
    transition: all 0.2s ease;
}

nav a:hover {
    background-color: #f5f5f5;
    color: #111111;
}

.resource-list-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.list-filter-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.nav-right-group {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1em;
    min-width: 0;
    max-width: 100%;
}

.nav-selected-project {
    display: flex;
    align-items: center;
    color: #666;
    font-size: 0.9em;
    font-weight: 500;
    white-space: nowrap;
    min-width: 0;
    max-width: 100%;
    padding: 0.4em 0.8em;
    background-color: #f9f9f9;
    border-radius: 6px;
    border: 1px solid #eaeaea;
}

.nav-selected-project a {
    margin-left: 0.4em;
    padding: 0;
    color: #007cc4;
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;   /* long project names are shortened, the full name stays in the tooltip */
}

.nav-selected-project a:hover {
    background-color: transparent;
    text-decoration: underline;
}

/* Generic components */
table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.9rem;
    border: 1px solid #e5e7eb;
}

th,
td {
    padding: 12px 16px;
    text-align: left;
    border: 1px solid #e5e7eb;
}

th {
    background: #f9fafb;
    color: #4b5563;
    font-weight: 600;
}

tr:nth-child(even) {
    background-color: #fcfcfc;
}

tr:hover {
    background-color: #f1f5f9;
}

.card {
    padding: 1.5rem;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
}

.card:hover {
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
}

input[type="text"],
input[type="number"],
select,
textarea {
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    color: #1f2937;
    background-color: #ffffff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.accordionTemplate {
    margin-bottom: 1rem;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.accordionTemplateSummary {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    cursor: pointer;
    background: #f9fafb;
    font-weight: 600;
    color: #1f2937;
    list-style: none;
    border-bottom: 1px solid transparent;
    transition: background 0.15s ease;
}

.accordionTemplate[open] .accordionTemplateSummary {
    border-bottom-color: #e5e7eb;
}

.accordionTemplateSummary::-webkit-details-marker {
    display: none;
}

.accordionTemplateSummary::before {
    content: "";
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 7px solid var(--triangle-color);
    transform: rotate(90deg);
    transition: transform 0.12s ease;
}

.accordionTemplate[open] .accordionTemplateSummary::before {
    transform: rotate(180deg);
}

.accordionTemplateContent {
    padding: 0.75em;
    background: #fff;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
}

.accordionTemplate[open] .accordionTemplateContent {
    max-height: 600px;
    opacity: 1;
}

/* Content that must show in full (no inner scrolling), e.g. the beam data tables. */
.accordionTemplate[open] .accordionTemplateContent.flow {
    max-height: none;
    overflow: visible;
}

/* Sortable table headers */
th.sortable {
    padding: 0;
    user-select: none;
    white-space: nowrap;
    background: #f9fafb;
    color: #4b5563;
}

th.sortable.active-sort {
    background: #f3f4f6;
    color: #111827;
}

th.sortable:focus-within {
    outline: 2px solid #4b5563;
    outline-offset: -2px;
}

.sort-button {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
    padding: 8px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 600;
    text-align: left;
}

th.sortable .sort-button:hover {
    background: #e3edf5;
}

th.sortable.active-sort .sort-button {
    background: #d1dfeb;
}

.sort-indicator {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    opacity: 0.82;
}

th.sortable:hover .sort-indicator,
th.sortable:focus-within .sort-indicator,
th.sortable.active-sort .sort-indicator {
    opacity: 1;
}

th.sortable .sort-triangle {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    opacity: 0.35;
    transition: opacity 0.12s ease, transform 0.12s ease;
}

th.sortable .sort-triangle.up {
    border-bottom: 6px solid var(--triangle-color);
}

th.sortable .sort-triangle.down {
    border-top: 6px solid var(--triangle-color);
}

th.sortable .sort-triangle.active {
    opacity: 1;
    transform: scale(1.08);
}

/* Button variants: one neutral look for every action. Colour is not used to tell actions apart;
   the label does that. Only the danger action turns red, and only on hover. */
.create-btn,
.delete-btn,
.duplicate-btn,
.edit-btn,
.export-btn,
.trimble-btn,
.label-btn,
.crops-btn,
.inspect-btn,
.window-btn,
.shopDrawingTypeButton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35em;
    white-space: nowrap;
    background-color: var(--btn-bg);
    color: var(--btn-ink);
    border: 1px solid var(--btn-line);
}

/* Link-style buttons: <a> does not get the base button box */
a.create-btn,
a.crops-btn,
a.inspect-btn,
a.label-btn,
a.window-btn {
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: all 0.15s ease;
}

:is(.delete-btn, .duplicate-btn, .edit-btn, .export-btn, .trimble-btn, .label-btn, .crops-btn,
    .inspect-btn, .window-btn, .shopDrawingTypeButton):hover:not(:disabled) {
    background-color: var(--btn-bg-hover);
    border-color: var(--btn-line-hover);
    color: var(--btn-ink-strong);
}

/* The one primary action on a page (create) is dark, not coloured. */
.create-btn {
    background-color: var(--btn-primary-bg);
    border-color: var(--btn-primary-bg);
    color: #ffffff;
}

.create-btn:hover:not(:disabled) {
    background-color: var(--btn-primary-bg-hover);
    border-color: var(--btn-primary-bg-hover);
}

.delete-btn:hover:not(:disabled) {
    color: #b91c1c;
    border-color: #fca5a5;
    background-color: #fef2f2;
}

.delete-btn.float-right,
.duplicate-btn.float-right {
    float: right;
}

.crops-btn+.inspect-btn,
.crops-btn+.window-btn,
.crops-btn+.trimble-btn,
.crops-btn+.edit-btn,
.inspect-btn+.window-btn,
.inspect-btn+.trimble-btn,
.inspect-btn+.edit-btn,
.window-btn+.trimble-btn,
.window-btn+.edit-btn,
.trimble-btn+.edit-btn,
.trimble-btn+.duplicate-btn,
.trimble-btn+.delete-btn,
.create-btn+.delete-btn,
.edit-btn+.delete-btn,
.edit-btn+.duplicate-btn,
.duplicate-btn+.delete-btn {
    margin-left: 0.5em;
}

/* Process page */
.processSelectedShopDrawing {
    margin-bottom: 0.5rem;
    padding: 0.75rem;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #f9fafb;
}

.process-toolbar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.process-toolbar-top {
    flex-wrap: wrap;
}

.process-toolbar button {
    display: inline-flex;
    align-items: center;
}

.process-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(22rem, 100%), 1fr));
    gap: 1rem;
    align-items: flex-start;
}

.process-card {
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
}

.process-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.process-card-toggle {
    flex: 1;
}

.process-card-header .delete-btn {
    margin-right: 0.75rem;
}

.process-card .process-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
}

.process-card .process-form-col {
    position: static;
}

.process-accordion {
    border: 1px solid #e5e7eb;
    background: #ffffff;
    border-radius: 8px;
    margin-bottom: 1rem;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.accordion-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border: 0;
    cursor: pointer;
    background: #f9fafb;
    border-radius: 0;
    transition: background 0.15s ease;
}

.accordion-header:hover {
    background: #f3f4f6;
}

.accordion-triangle {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 7px solid var(--triangle-color);
    transition: transform 0.12s ease;
}

.accordion-triangle.open {
    transform: rotate(180deg);
}

.accordion-triangle.closed {
    transform: rotate(90deg);
}

.accordion-body {
    padding: 0.75rem 1rem 1rem;
}

.accordion-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.5rem;
}

.process-grid {
    display: grid;
    grid-template-columns: minmax(280px, 320px) repeat(3, minmax(0, 1fr));
    gap: 2em;
    align-items: start;
}

.process-form-col {
    position: sticky;
    top: 1rem;
}

.process-history-actions {
    margin-bottom: 1rem;
}

.process-related-result-card {
    margin-top: 0.75rem;
    padding: 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #ffffff;
    display: grid;
    gap: 0.5rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.process-history-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 1000;
}

.process-history-modal {
    width: min(1100px, 100%);
    max-height: 85vh;
    overflow: auto;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 1.5rem;
    box-sizing: border-box;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.process-history-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.process-history-modal-note,
.process-history-modal-empty {
    margin: 0.4rem 0 0;
    color: #555;
}

.process-shop-actions-col {
    width: 1%;
    white-space: nowrap;
}

/* Tables and forms */
.shopDrawingDetailTable {
    margin-bottom: 2rem;
}

.shopDrawingDetailTable th,
.shopDrawingDetailTable td {
    border: 1px solid #e5e7eb;
}

.shopDrawingPdfFrame {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
}

.table-scroll {
    max-height: 67vh;
    overflow: auto;
}

.inputBox1 {
    width: min(400px, 100%);
    height: 20px;
}

/* Utilities */
.flexContainer {
    display: flex;
    gap: 1rem;
}

.errorText,
.fail {
    color: #c40000;
}

.text-danger {
    color: #c40000;
}

.text-muted {
    color: #666;
}

.text-success {
    color: green;
}

.text-success-dark {
    color: #1b5e20;
}

.not-applicable {
    color: #444;
}

.pass {
    color: green;
}

.result-status {
    font: inherit;
}

.result-status.processing {
    color: #e26600;
}

.uncertain {
    color: #ac9a00;
}

.list-compact {
    margin: 0;
    padding-left: 1rem;
}

.preformatted-inline,
.preformatted-block {
    white-space: pre-wrap;
    font-family: monospace;
    margin: 0;
}

.preformatted-inline {
    display: inline-block;
}

.bordered-frame {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
}

/* Responsive */
@media (max-width: 1280px) {
    .process-grid {
        grid-template-columns: minmax(280px, 320px) repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 960px) {
    .process-grid {
        grid-template-columns: 1fr;
    }

    .process-form-col {
        position: static;
    }

    .process-card {
        min-width: 0;
    }
}

@media (max-width: 768px) {
    body {
        padding: 0.75em;
    }

    .nav-right-group {
        margin-left: 0;
        flex-wrap: wrap;
    }

    .process-toolbar {
        flex-wrap: wrap;
    }

    .process-toolbar button {
        width: 100%;
        justify-content: center;
    }

    .process-accordion>div:first-child {
        flex-wrap: wrap;
        align-items: stretch !important;
    }

    .accordion-header {
        min-width: 0;
        padding: 0.75rem;
    }

    .accordion-header>span:first-child {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .process-grid {
        gap: 1rem;
    }

    .process-grid>.process-table-col {
        grid-column: auto !important;
        min-width: 0;
    }

    .process-history-modal {
        padding: 0.75rem;
    }

    .process-history-modal-header {
        flex-direction: column;
        align-items: stretch;
    }

    .table-scroll {
        max-width: 100%;
        -webkit-overflow-scrolling: touch;
    }

    .inputBox1 {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        height: auto;
    }

    select,
    input,
    button,
    textarea {
        max-width: 100%;
    }
}

@media (max-width: 600px) {
    nav {
        flex-direction: column;
        gap: 0.5em;
        padding: 0.5em;
    }

    nav a {
        display: block;
        width: 100%;
        box-sizing: border-box;
        padding: 0.7em 1em;
        font-size: 1.1em;
        border-bottom: 1px solid #eaeaea;
    }

    nav a:last-child {
        border-bottom: none;
    }
}



/* EXTENSION TRIMBLE WORKSPACE API */
.extensionPage {
    max-width: 100%;
}

.extensionActions {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.extensionActions button {
    width: 100%;
}

.extensionProjectSelector {
    display: grid;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.extensionProjectSelector select {
    width: 100%;
}

.extensionAccordionContent {
    max-height: none;
    opacity: 1;
}

.extensionAccordion {
    overflow: visible;
}

.extensionAccordion[open] .extensionAccordionContent {
    max-height: none;
    overflow: visible;
}

.extensionModelItem {
    padding: 0.75rem 0;
    border-bottom: 1px solid #e5e7eb;
    overflow-wrap: anywhere;
}

.extensionModelHeader {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.35rem;
}

.extensionModelActions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.5rem;
}

.extensionModelHeader button {
    min-width: 5.5rem;
}

.extensionSecondaryButton {
    background: #f3f4f6;
}

.extensionModelHeader button.is-unloaded {
    background: #e8f4ea;
}

.extensionModelItem:first-child {
    padding-top: 0;
}

.extensionModelItem:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.extensionCode {
    word-break: break-word;
    font-family: monospace;
}

.extensionReferenceList {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.extensionReferenceLink {
    color: #005bb5;
    text-decoration: underline;
}

.extensionReferenceMissing {
    color: #c40000;
}

.extensionSelectedObjectBlock {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed #e5e7eb;
}

.extensionPropertyBlock {
    margin-top: 0.35rem;
    padding: 0.5rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
}

.drawingTypeSelect label {
    /* margin-right: 0.5rem; */
    font-weight: 600;
}

/* Shop drawing data (step 2): review status chips and value sources */
.data-check {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 4px;
    border: 1px solid #cbd5e1;
    background: #f1f5f9;
    color: #334155;
    white-space: nowrap;
}
.data-check.auto_accepted { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.data-check.needs_review { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.data-check.reviewed { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.source-tag {
    display: inline-block;
    font-size: 0.68rem;
    padding: 1px 6px;
    border-radius: 999px;
    border: 1px solid #d1d5db;
    color: #4b5563;
    background: #ffffff;
    white-space: nowrap;
}

/* Demo mode (guest): anything only members can use is hidden. Add class="member-only" to such buttons and columns. */
body.guest-mode .member-only { display: none !important; }
