/* Trace Excel add-in — aligns with apps/trace-web/styles/isb-base.scss tokens */

:root {
    /*
     * Task panes are very narrow (~300px+); keep type a notch below full app sizes.
     * (px at default 16px root.)
     */
    --tp-fs-body: 1rem; /* 16px */
    --tp-fs-input: 0.875rem; /* 14px */
    /** Form / filter captions — below body so controls feel primary. */
    --tp-fs-label: 0.8125rem; /* 13px */
    --tp-fs-title: 1.125rem; /* 18px */
    --tp-fs-subtitle: 0.875rem; /* 14px */
    --tp-fs-code: 0.75rem; /* 12px — compact copy / desktop API debug panel */

    --color-primary: rgb(38, 57, 81);
    --color-interaction-outline: #2196f3;
    --color-accent: rgb(109, 146, 138);

    --color-background-start: rgb(234, 244, 250);
    --color-background-end: rgb(247, 247, 247);

    --color-neutral-0: #ffffff;
    --color-neutral-1: rgb(249, 250, 251);
    --color-neutral-2: rgb(240, 242, 244);
    --color-neutral-3: rgb(234, 237, 240);
    --color-neutral-4: rgb(223, 227, 231);
    --color-neutral-5: rgb(206, 212, 218);
    --color-neutral-6: rgb(173, 181, 189);
    --color-neutral-7: rgb(106, 113, 120);
    --color-neutral-8: rgb(79, 87, 94);

    --color-success: rgb(146, 187, 127);
    --color-error: rgb(187, 127, 127);

    --font-family: "Mulish", system-ui, -apple-system, sans-serif;
    --font-weight-normal: 400;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    --border-radius-soft: 0.25rem;
    --space-xxs: 0.125rem; /* 2px — label to control */
    --space-xs: 0.25rem;
    --space-s: 0.5rem;
    --space-base: 1rem;
    --space-m: 1.5rem;
    --space-l: 2rem;

    --box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.25);
    --box-shadow-md: 0 2px 10px rgba(38, 57, 81, 0.12);
}

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

html {
    height: 100%;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    font-size: var(--tp-fs-body);
    font-weight: var(--font-weight-normal);
    color: var(--color-primary);
    line-height: 1.5;
    background: linear-gradient(
        117deg,
        var(--color-background-start) 0%,
        var(--color-background-end) 100%
    );
    -webkit-font-smoothing: antialiased;
}

.taskpane-shell {
    display: flex;
    flex-direction: column;
    /* Task pane hosts often don’t give html/body a definite % height; vh matches the visible pane. */
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--space-base) var(--space-s);
    padding-bottom: var(--space-s);
    max-width: 100%;
    box-sizing: border-box;
}

.taskpane-shell > .trace-card + .trace-card {
    margin-top: var(--space-s);
}

.trace-card {
    background: var(--color-neutral-0);
    border: 1px solid var(--color-neutral-3);
    border-radius: var(--border-radius-soft);
    padding: var(--space-base) var(--space-s);
    box-shadow: var(--box-shadow-md);
}

/* Title stays one line; when the row is too narrow, auth wraps beneath. */
.trace-card__header {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 1rem;
    margin-bottom: var(--space-s);
}

.trace-card__title {
    margin: 0;
    font-size: var(--tp-fs-title);
    font-weight: var(--font-weight-bold);
    color: var(--color-primary);
    letter-spacing: -0.02em;
    line-height: 1.2;
    flex: 1 1 auto;
    min-width: max-content;
    white-space: nowrap;
}

.trace-card__auth {
    display: flex;
    align-items: center;
    gap: var(--space-s);
    min-width: fit-content;
    flex-shrink: 0;
}

.trace-card__auth-copy {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    min-width: 0;
}

.trace-card__status-detail {
    margin: 0;
    max-width: 100%;
    font-size: var(--tp-fs-code);
    font-weight: var(--font-weight-semibold);
    line-height: 1.4;
    color: var(--color-error);
    text-align: right;
    word-break: break-word;
}

.trace-card__status-dot {
    width: 0.5625rem;
    height: 0.5625rem;
    border-radius: 50%;
    background-color: var(--color-success);
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgb(from var(--color-success) r g b / 0.35);
    transform: scale(1);
    transform-origin: center;
}

@keyframes trace-connected-pulse {
    0%,
    100% {
        opacity: 1;
        transform: scale(1);
        box-shadow: 0 0 0 2px rgb(from var(--color-success) r g b / 0.35);
    }

    50% {
        opacity: 0.88;
        transform: scale(1.14);
        box-shadow: 0 0 0 4px rgb(from var(--color-success) r g b / 0.2);
    }
}

.trace-card__status-dot:not(.hidden) {
    animation: trace-connected-pulse 2.2s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
    .trace-card__status-dot:not(.hidden) {
        animation: none;
        opacity: 1;
        transform: none;
        box-shadow: 0 0 0 2px rgb(from var(--color-success) r g b / 0.35);
    }
}

.trace-card__status {
    margin: 0;
    text-align: right;
    min-width: 0;
    line-height: 1.35;
    white-space: nowrap;
}

.trace-card__subtitle {
    margin: 0 0 var(--space-base);
    color: var(--color-neutral-7);
    font-size: var(--tp-fs-subtitle);
    font-weight: var(--font-weight-normal);
    line-height: 1.55;
}

.stack-sm {
    display: flex;
    flex-direction: column;
    gap: var(--space-s);
}

.login-section__actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-s);
    width: 100%;
}

.taskpane-shell__footer {
    margin-top: auto;
    padding-top: var(--space-m);
}

.taskpane-shell__version {
    margin: 0 0 var(--space-xxs);
    text-align: center;
    font-size: var(--tp-fs-subtitle);
    font-weight: var(--font-weight-normal);
    line-height: 1.35;
    color: var(--color-neutral-6);
}

.taskpane-footer-legal {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    column-gap: var(--space-base);
    row-gap: var(--space-xxs);
    padding-top: var(--space-s);
    border-top: 1px solid var(--color-neutral-4);
    font-size: var(--tp-fs-subtitle);
}

.taskpane-footer-legal__sep {
    color: var(--color-neutral-6);
    font-weight: var(--font-weight-normal);
    user-select: none;
}

.taskpane-footer-legal__link {
    font-size: inherit;
    font-weight: var(--font-weight-bold);
    color: var(--color-accent);
    text-decoration: none;
    cursor: pointer;
}

.taskpane-footer-legal__link:hover {
    text-decoration: underline;
}

.taskpane-footer-legal__link:focus-visible {
    outline: 2px solid var(--color-interaction-outline);
    outline-offset: 2px;
    border-radius: 2px;
}

.trace-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 2.375rem;
    padding: 0.45rem var(--space-base);
    font-family: var(--font-family);
    font-size: var(--tp-fs-body);
    font-weight: var(--font-weight-semibold);
    line-height: 1.25;
    border: none;
    border-radius: var(--border-radius-soft);
    cursor: pointer;
    box-shadow: var(--box-shadow);
    transition:
        background-color 0.15s ease,
        color 0.15s ease,
        box-shadow 0.15s ease,
        transform 0.05s ease;
}

.trace-btn:active:not(:disabled) {
    transform: translateY(1px);
}

.trace-btn:focus-visible {
    outline: 2px solid var(--color-interaction-outline);
    outline-offset: 2px;
}

.trace-btn--primary {
    background-color: var(--color-primary);
    color: var(--color-neutral-0);
}

.trace-btn--primary:hover:not(:disabled) {
    filter: brightness(1.08);
}

.trace-btn--secondary {
    background-color: var(--color-neutral-0);
    color: var(--color-primary);
    border: 1px solid var(--color-neutral-4);
}

.trace-btn--secondary:hover:not(:disabled) {
    background-color: var(--color-neutral-1);
}

.trace-btn:disabled {
    background-color: var(--color-neutral-4);
    color: var(--color-neutral-7);
    cursor: not-allowed;
    box-shadow: none;
    border-color: var(--color-neutral-4);
}

.filters-grid {
    margin-top: var(--space-base);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.report-filters-panel__divider {
    margin: var(--space-base) 0;
    border: none;
    border-top: 1px solid var(--color-neutral-3);
}

/* Tighter gap under the divider above the filter block (first filter label sits closer). */
#report-filters-panel > .report-filters-panel__divider:first-of-type {
    margin-bottom: var(--space-s);
}

/* When common filters are empty, pull target filters closer to the divider. */
.report-filters-panel__filter-body > .filters-grid--primary:empty + #report-target-filters {
    margin-top: var(--space-xs);
}

/* Inset filters + primary action under reporting target for visual hierarchy */
.report-filters-panel__filter-body {
    padding-inline: var(--space-base);
}

/* First filter inside the inset block (depends on reporting target). */
.report-filters-panel__record-count-row:not(.hidden),
.report-filters-panel__record-type-row:not(.hidden) {
    margin-bottom: var(--space-s);
}

.filters-grid--primary {
    margin-top: 0;
}

.filters-grid__row--split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-s);
    min-width: 0;
}

.filters-grid__field {
    display: flex;
    flex-direction: column;
    gap: var(--space-xxs);
    min-width: 0;
}

.filters-grid__field .field-label {
    margin-bottom: 0;
}

.field-label {
    display: block;
    font-size: var(--tp-fs-label);
    font-weight: var(--font-weight-bold);
    color: var(--color-neutral-8);
    margin-bottom: var(--space-xs);
    padding-inline: var(--space-xs);
}

.field-label__optional {
    font-weight: var(--font-weight-normal);
    font-size: var(--tp-fs-code);
    color: var(--color-neutral-7);
}

/* One line of error copy (matches .org-code-field__error line-height); keeps layout stable when text appears. */
.org-code-field__error-slot {
    min-height: calc(var(--tp-fs-code) * 1.35);
    margin-top: var(--space-xxs);
    padding-inline: var(--space-xs);
}

.org-code-field__error {
    margin: 0;
    font-size: var(--tp-fs-code);
    font-weight: var(--font-weight-normal);
    color: var(--color-error);
    line-height: 1.35;
}

.field-input {
    width: 100%;
    min-height: 2.25rem;
    border: 1px solid var(--color-neutral-4);
    border-radius: var(--border-radius-soft);
    padding: 0.375rem 0.625rem;
    font-family: var(--font-family);
    font-size: var(--tp-fs-input);
    font-weight: var(--font-weight-semibold);
    color: var(--color-primary);
    background: var(--color-neutral-0);
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.field-input::placeholder {
    color: rgba(38, 57, 81, 0.55);
    font-weight: var(--font-weight-normal);
}

/* `type="date"` empty state — same tone as `.field-input::placeholder` (class toggled in TS). */
input[type='date'].field-input.field-input--date-unfilled {
    color: rgba(38, 57, 81, 0.55);
    font-weight: var(--font-weight-normal);
}

input[type='date'].field-input.field-input--date-unfilled::-webkit-datetime-edit,
input[type='date'].field-input.field-input--date-unfilled::-webkit-datetime-edit-fields-wrapper {
    color: rgba(38, 57, 81, 0.55);
}

.field-input:hover:not(:disabled) {
    border-color: var(--color-neutral-5);
}

.field-input:focus {
    outline: none;
    border-color: var(--color-interaction-outline);
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.2);
}

.field-input.field-input--error {
    border-color: var(--color-error);
}

.field-input.field-input--error:hover:not(:disabled) {
    border-color: var(--color-error);
}

.field-input.field-input--error:focus {
    border-color: var(--color-error);
    box-shadow: 0 0 0 2px rgb(from var(--color-error) r g b / 0.35);
}

select.field-input {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 12 12'%3E%3Cpath fill='%23263951' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 14px 14px;
    padding-right: 2.25rem;
}

/* Checkbox multiselect (Material-like: trigger + panel) */
.report-multiselect {
    position: relative;
    width: 100%;
    min-width: 0;
}

button.report-multiselect__trigger.field-input {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-s);
    width: 100%;
    text-align: left;
    font-family: inherit;
    cursor: pointer;
    box-sizing: border-box;
}

.report-multiselect__value {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--tp-fs-input);
    font-weight: var(--font-weight-semibold);
    color: var(--color-primary);
}

.report-multiselect__value--placeholder {
    color: rgba(38, 57, 81, 0.55);
    font-weight: var(--font-weight-normal);
}

.report-multiselect__chevron {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 12 12'%3E%3Cpath fill='%23263951' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 14px 14px;
}

.report-multiselect__panel {
    position: absolute;
    top: 100%;
    bottom: auto;
    left: 0;
    right: 0;
    z-index: 100;
    margin-top: 2px;
    margin-bottom: 0;
    padding: var(--space-xs) 0;
    border: 1px solid var(--color-neutral-4);
    border-radius: var(--border-radius-soft);
    background: var(--color-neutral-0);
    box-shadow: var(--box-shadow-md);
}

.report-multiselect__panel.report-multiselect__panel--drop-up {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: 2px;
}

.report-multiselect__list {
    overflow-y: auto;
}

.report-multiselect__option {
    display: flex;
    align-items: center;
    gap: var(--space-s);
    margin: 0;
    padding: 0.5rem var(--space-base);
    cursor: pointer;
    font-size: var(--tp-fs-input);
    color: var(--color-primary);
}

.report-multiselect__option:hover {
    background: var(--color-neutral-1);
}

.report-multiselect__option input[type='checkbox'] {
    flex-shrink: 0;
    width: 1rem;
    height: 1rem;
    margin: 0;
    accent-color: var(--color-primary);
    cursor: pointer;
}

.report-multiselect__option-label {
    flex: 1;
    min-width: 0;
    font-weight: var(--font-weight-semibold);
    line-height: 1.35;
}

.report-multiselect__helper {
    margin: var(--space-xs) 0 0;
    padding-inline: var(--space-xs);
}

.row-actions {
    margin-top: var(--space-base);
    display: flex;
    flex-direction: column;
    gap: var(--space-s);
}

.report-filters-panel__divider + .row-actions {
    margin-top: 0;
}

#data-section #fetch-summary:not(.hidden) {
    margin-top: var(--space-base);
}

#fetch-summary.fetch-summary--prominent {
    margin-bottom: var(--space-base);
    padding: var(--space-s) var(--space-base);
    border-radius: var(--border-radius-soft);
    background: rgb(from var(--color-success) r g b / 0.12);
    border: 1px solid rgb(from var(--color-success) r g b / 0.32);
    font-size: var(--tp-fs-body);
    line-height: 1.45;
}

#fetch-summary.fetch-summary--prominent-error {
    margin-bottom: var(--space-base);
    padding: var(--space-s) var(--space-base);
    border-radius: var(--border-radius-soft);
    background: rgb(from var(--color-error) r g b / 0.1);
    border: 1px solid rgb(from var(--color-error) r g b / 0.35);
    font-size: var(--tp-fs-body);
    line-height: 1.45;
}

#fetch-summary.fetch-summary--prominent-error .fetch-summary__line {
    color: var(--color-error);
    font-weight: var(--font-weight-semibold);
}

.fetch-summary {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.fetch-summary__line {
    margin: 0;
    font-size: var(--tp-fs-body);
    line-height: 1.45;
}

.hint {
    margin: 0;
    font-size: var(--tp-fs-body);
    color: var(--color-neutral-7);
    line-height: 1.5;
}

.hint--success {
    color: var(--color-success);
    font-weight: var(--font-weight-semibold);
}

.hint--error {
    color: var(--color-error);
    font-weight: var(--font-weight-semibold);
}

/* Native confirm/alert are blocked in some Office hosts; use this instead */
.overwrite-confirm {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-base);
    box-sizing: border-box;
}

.overwrite-confirm.hidden {
    display: none !important;
}

.overwrite-confirm__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(38, 57, 81, 0.5);
}

.overwrite-confirm__panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 22rem;
    padding: var(--space-m);
    border-radius: var(--border-radius-soft);
    background: var(--color-neutral-0);
    box-shadow: var(--box-shadow-md);
}

.overwrite-confirm__title {
    margin: 0 0 var(--space-s);
    font-size: var(--tp-fs-title);
    font-weight: var(--font-weight-bold);
    color: var(--color-primary);
    line-height: 1.3;
}

.overwrite-confirm__message {
    margin: 0 0 var(--space-base);
    font-size: var(--tp-fs-input);
    color: var(--color-neutral-8);
    line-height: 1.5;
    white-space: pre-line;
}

.overwrite-confirm__options {
    display: flex;
    align-items: flex-start;
    gap: var(--space-s);
    margin: 0 0 var(--space-base);
}

.overwrite-confirm__checkbox {
    margin-top: 0.2rem;
    flex-shrink: 0;
}

.overwrite-confirm__checkbox-label {
    font-size: var(--tp-fs-input);
    color: var(--color-neutral-8);
    line-height: 1.45;
    cursor: pointer;
}

.overwrite-confirm__actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-s);
}

.overwrite-confirm__actions .trace-btn {
    width: 100%;
}

.loading-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-s);
    margin-top: var(--space-s);
    font-size: var(--tp-fs-body);
    font-weight: var(--font-weight-semibold);
    color: var(--color-primary);
}

.spinner {
    width: 1.125rem;
    height: 1.125rem;
    flex-shrink: 0;
    border: 2px solid var(--color-neutral-3);
    border-top-color: var(--color-interaction-outline);
    border-radius: 50%;
    animation: trace-spin 0.75s linear infinite;
}

@keyframes trace-spin {
    to {
        transform: rotate(360deg);
    }
}

.hidden {
    display: none !important;
}
