/* Shared styling for the admin pages (Admin → Therefore, Fields, Shortcuts). */

/* Tabs: a clear bar under the tab headers. */
.admin-tabs .mud-tabs-tabbar {
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

/* The table scrolls, not the page: its height follows the window. Each page sets
   --admin-table-offset to the space above and below the table (app bar, page margin,
   tabs, toolbar, panel padding). */
.admin-table-wrap {
    overflow: auto;
    max-height: calc(100vh - var(--admin-table-offset, 170px));
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 8px;
}

.admin-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.875rem;
}

.admin-table th,
.admin-table td {
    padding: 6px 12px;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

/* Header rows stay in view while scrolling; opaque so rows don't show through. */
.admin-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

.admin-table thead th {
    background-color: var(--mud-palette-surface);
}

.admin-table .label-col {
    text-align: left;
    min-width: 220px;
}

.admin-table thead th.label-col,
.admin-table thead th.text-head {
    text-align: left;
    vertical-align: bottom;
    font-weight: 600;
    color: var(--mud-palette-text-secondary);
}

/* Stage headers (Pre-registration / Approval): tinted with the app colour, divider between stages. */
.admin-table .stage-head {
    text-align: center;
    font-weight: 600;
    /* Tint layered over the surface colour, so the sticky header stays opaque. */
    background: linear-gradient(rgba(47, 179, 131, 0.10), rgba(47, 179, 131, 0.10)), var(--mud-palette-surface);
    color: var(--mud-palette-primary);
    white-space: nowrap;
}

.admin-table .stage-head .mud-icon-root {
    vertical-align: middle;
}

.admin-table .stage-start {
    border-left: 2px solid var(--mud-palette-lines-default);
}

.admin-table .setting-head {
    text-align: center;
    width: 104px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
}

.admin-table .setting-head span {
    margin-left: 4px;
    vertical-align: middle;
}

.admin-table .setting-head .mud-icon-root {
    vertical-align: middle;
    opacity: 0.8;
}

/* Group rows, e.g. Invoice fields / Accounting / Supplier information. */
.admin-table .group-row td {
    background-color: var(--mud-palette-background-gray);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--mud-palette-text-secondary);
    padding-top: 8px;
    padding-bottom: 8px;
}

.admin-table .data-row:hover td {
    background-color: var(--mud-palette-action-default-hover);
}

.admin-table tbody tr:last-child td {
    border-bottom: none;
}

/* A row's label, with its technical name (setting, field or action) underneath. */
.admin-table .row-label {
    font-weight: 500;
}

.admin-table .tech-name {
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
}

/* A row's short explanation, in plain text (Admin → Settings). */
.admin-table .row-help {
    font-size: 0.8125rem;
    color: var(--mud-palette-text-secondary);
}

/* Admin → Settings: the control column (switches; process number and delete for the workflows). */
.settings-table .control-col {
    width: 200px;
}

.settings-table .label-col .mud-input-control {
    margin: 0;
    max-width: 480px;
}

/* Controls line up on the right edge: the switches, and the workflows' process number (a soft box like the
   index panel's fields) with its delete button. */
.admin-table.settings-table .setting-cell {
    text-align: right;
    padding-right: 12px;
}

.settings-table .setting-cell .mud-input-control {
    width: 110px;
}

/* A process number is an identifier, not an amount: left-aligned in its box. */
.settings-table .setting-cell input.mud-input-root {
    text-align: left;
}

/* Workflow rows: the index panel's soft boxes (.index-fields), without the room for a caption. */
.settings-table .workflow-row td {
    padding-top: 6px;
    padding-bottom: 6px;
}

.settings-table .index-fields .mud-input.mud-input-text {
    margin-top: 0 !important;
}

.admin-table .setting-cell {
    text-align: center;
    padding-top: 0;
    padding-bottom: 0;
}

.admin-table .setting-cell .mud-input-control,
.admin-table .setting-cell .mud-checkbox {
    display: inline-flex;
    margin: 0;
}

/* "Not applicable" mark. */
.admin-table .na {
    color: var(--mud-palette-text-disabled);
    cursor: help;
}

/* Shortcuts: a field that shows the combination as key caps; click it and press the keys to change it.
   Soft box like the index panel's fields, primary ring while recording, red when there's a problem. */
.shortcut-field {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}

.shortcut-box {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 150px;
    height: 34px;
    padding: 0 10px;
    border-radius: 6px;
    background-color: var(--index-field-bg);
    cursor: pointer;
    outline: none;
    transition: background-color 150ms, box-shadow 150ms;
}

.shortcut-box:hover {
    background-color: var(--index-field-bg-hover);
}

.shortcut-box.recording {
    background-color: var(--mud-palette-surface);
    box-shadow: inset 0 0 0 2px var(--mud-palette-primary);
}

.shortcut-box.error {
    box-shadow: inset 0 0 0 1px var(--mud-palette-error);
}

.shortcut-box kbd {
    display: inline-block;
    min-width: 22px;
    padding: 1px 7px;
    border: 1px solid var(--mud-palette-lines-inputs);
    border-bottom-width: 2px;
    border-radius: 5px;
    background-color: var(--mud-palette-surface);
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 20px;
    text-align: center;
    color: var(--mud-palette-text-primary);
}

.shortcut-plus {
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
}

.shortcut-placeholder {
    font-size: 0.8125rem;
    color: var(--mud-palette-text-secondary);
}

.shortcut-box.recording .shortcut-placeholder {
    color: var(--mud-palette-primary);
}

/* Switch off / back to default: fixed width so the fields line up whether or not the buttons show. */
.shortcut-buttons {
    display: inline-flex;
    width: 64px;
}

.shortcut-problem {
    padding-bottom: 4px;
    font-size: 0.75rem;
    color: var(--mud-palette-error);
}

/* Custom fields → Layout: the index panel in miniature (380px, same sections). Its own fields are grey
   blocks; custom fields are cards in a two-column grid per section, full-width cards spanning both columns,
   so the rows come out as in the panel (at most two fields side by side). */
/* The designer scrolls, not the page: like .admin-table-wrap its height follows the window, with the same
   --admin-table-offset for the space above and below it. */
.layout-designer {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    max-height: calc(100vh - var(--admin-table-offset, 270px));
    overflow-y: auto;
    padding: 16px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 8px;
    background-color: var(--mud-palette-background-gray);
}

.layout-panel {
    width: 380px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 8px;
    background-color: var(--mud-palette-surface);
    overflow: hidden;
}

.layout-section + .layout-section {
    border-top: 1px solid var(--mud-palette-lines-default);
}

.layout-section-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background-color: var(--index-section-head-bg);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--mud-palette-text-secondary);
}

.layout-section-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 0 14px 10px;
}

.layout-row {
    display: flex;
    gap: 10px;
}

.layout-builtin {
    flex: 1 1 0;
    min-width: 0;
    height: 30px;
    display: flex;
    align-items: center;
    padding: 0 8px;
    border-radius: 6px;
    background-color: var(--index-field-bg);
    font-size: 0.75rem;
    color: var(--mud-palette-text-disabled);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layout-builtin.empty {
    visibility: hidden;
}

.layout-zone {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
    border-radius: 6px;
}

/* End strip of a section: drop here to put a card last. Invisible until a drag starts, except in an empty
   section, where it's the "drag fields here" spot. */
.layout-drop-end {
    grid-column: 1 / -1;
    height: 0;
    border-radius: 6px;
    transition: height 120ms;
}

.layout-drop-end.empty,
.layout-panel.dragging .layout-drop-end {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    border: 1px dashed var(--mud-palette-lines-inputs);
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
}

.layout-drop-end.active {
    border-color: var(--mud-palette-primary);
    background-color: var(--index-selected-bg);
}

.layout-item.full {
    grid-column: 1 / -1;
}

/* The empty half of a row (a half-width field alone): keeps its space, and while dragging it's a drop spot. */
.layout-slot {
    height: 34px;
    border-radius: 6px;
}

.layout-panel.dragging .layout-slot {
    border: 1px dashed var(--mud-palette-lines-inputs);
}

.layout-slot.active {
    border-color: var(--mud-palette-primary) !important;
    background-color: var(--index-selected-bg);
}

.layout-item.dragged {
    opacity: 0.4;
}

/* Where a dragged card would land: in front of this one. */
.layout-item.drop-before {
    box-shadow: inset 4px 0 0 var(--mud-palette-primary), inset 0 0 0 1px var(--mud-palette-primary);
}

.layout-item {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 34px;
    padding: 0 2px 0 2px;
    border-radius: 6px;
    background-color: var(--index-selected-bg);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--mud-palette-primary) 35%, transparent);
    font-size: 0.8125rem;
    color: var(--mud-palette-text-primary);
    cursor: grab;
}

.layout-item .layout-grip {
    font-size: 1.1rem;
    color: var(--mud-palette-text-secondary);
}

.layout-item .layout-type {
    font-size: 1rem;
    color: var(--mud-palette-primary);
}

.layout-label {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Group headers: title, then rename / move / delete, which show on hover (or keyboard focus). */
.layout-section-title {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layout-group-actions {
    display: inline-flex;
    margin: -4px -8px -4px 0;
    opacity: 0;
    transition: opacity 120ms;
}

.layout-section-head:hover .layout-group-actions,
.layout-group-actions:focus-within {
    opacity: 1;
}

.layout-rename {
    flex: 1;
    min-width: 0;
    height: 26px;
    padding: 0 6px;
    border: none;
    border-radius: 4px;
    outline: none;
    background-color: var(--mud-palette-surface);
    box-shadow: inset 0 0 0 1px var(--mud-palette-primary);
    font: inherit;
    font-size: 0.8125rem;
    text-transform: none;
    letter-spacing: normal;
    color: var(--mud-palette-text-primary);
}

.layout-add-group {
    display: flex;
    justify-content: center;
    padding: 6px;
    border-top: 1px solid var(--mud-palette-lines-default);
}

/* Admin → Therefore: installation settings as rows, a wider control column with the index panel's soft boxes. */
.install-table .label-col {
    width: 45%;
}

.install-table .install-control .mud-input.mud-input-text {
    margin-top: 0 !important;
}

/* The Therefore server and tenant and the callback URL share one width; numbers are narrow. */
.install-table .install-control .field-url {
    max-width: 420px;
}

/* A document number is an identifier, not an amount: left-aligned. */
.install-table .install-control .field-docno input {
    text-align: left;
}

.install-table .install-control .narrow-number {
    max-width: 160px;
}

.install-table .install-control .mud-switch {
    margin-left: -12px;
}

.install-table .install-row td {
    padding-top: 6px;
    padding-bottom: 6px;
}

.license-key textarea {
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
    font-size: 0.75rem !important;
    word-break: break-all;
}

/* Setup wizard: a card over the login background with numbered steps. */
.setup-wizard {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
    width: min(620px, calc(100% - 32px));
    max-height: calc(100% - 96px);
    display: flex;
}

.setup-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    border-radius: 12px !important;
    overflow: hidden;
}

.setup-head {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 24px 28px 8px;
}

.setup-steps {
    display: flex;
    gap: 6px;
    list-style: none;
    margin: 12px 28px 4px;
    padding: 0;
}

.setup-step {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--mud-palette-lines-default);
    font-size: 0.8125rem;
    color: var(--mud-palette-text-secondary);
}

.setup-step.current {
    border-bottom-color: var(--mud-palette-primary);
    color: var(--mud-palette-text-primary);
    font-weight: 500;
}

.setup-step.done {
    border-bottom-color: color-mix(in srgb, var(--mud-palette-primary) 45%, transparent);
    cursor: pointer;
}

.setup-step-dot {
    flex: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    background-color: var(--mud-palette-action-default-hover);
}

.setup-step.current .setup-step-dot,
.setup-step.done .setup-step-dot {
    background-color: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
}

.setup-step-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.setup-body {
    padding: 20px 28px 8px;
    overflow-y: auto;
    min-height: 260px;
}

.setup-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px 20px;
}

.install-field {
    margin-bottom: 16px;
}

.install-help {
    margin: 4px 2px 0;
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
}

.install-readonly-label {
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
}

.install-readonly-value {
    font-size: 0.875rem;
    word-break: break-all;
}

@media (max-width: 560px) {
    .setup-step-label {
        display: none;
    }
}

/* Layout editor: the box of fields that aren't in the index panel, next to it. Stays in view while the panel
   scrolls, so a card can always be dragged in or out. */
.layout-unplaced {
    position: sticky;
    top: 0;
    width: 380px; /* as wide as the panel */
    margin-left: 16px;
    border: 1px dashed var(--mud-palette-lines-inputs);
    border-radius: 8px;
    background-color: var(--mud-palette-surface);
    overflow: hidden;
}

.layout-unplaced .layout-section-head {
    background-color: transparent;
}

.layout-unplaced-count {
    min-width: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background-color: var(--index-field-bg);
    font-size: 0.7rem;
    text-align: center;
    letter-spacing: 0;
}

.layout-unplaced-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 0 14px 12px;
}

.layout-unplaced .layout-item {
    grid-column: auto;
}

.layout-unplaced.dragging .layout-drop-end {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    border: 1px dashed var(--mud-palette-lines-inputs);
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
}

.layout-unplaced .layout-drop-end.empty {
    height: auto;
    min-height: 64px;
    padding: 8px;
    text-align: center;
}

/* Admin → Features: a switch that depends on another one that is off. */
.settings-table .data-row.unavailable .row-label,
.settings-table .data-row.unavailable .row-help {
    color: var(--mud-palette-text-disabled);
}

/* Admin → Automations: a card per automation (icon, name, description, on/off), its settings below. */
/* One card per row, all as tall as the tallest. */
.automation-list {
    display: grid;
    grid-auto-rows: 1fr;
    gap: 12px;
}

.automation-card {
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 10px;
    padding: 14px 16px 12px;
    background-color: var(--mud-palette-surface);
    transition: border-color 150ms, box-shadow 150ms;
}

.automation-card.enabled {
    border-color: color-mix(in srgb, var(--mud-palette-primary) 45%, transparent);
    box-shadow: inset 3px 0 0 var(--mud-palette-primary);
}

.automation-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.automation-icon {
    flex: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--index-selected-bg);
    color: var(--mud-palette-primary);
}

.automation-title {
    flex: 1;
    min-width: 0;
}

.automation-name {
    font-weight: 600;
}

.automation-description {
    font-size: 0.8125rem;
    color: var(--mud-palette-text-secondary);
}

.automation-note {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--index-warning-text);
}

.automation-note .mud-icon-root {
    font-size: 0.95rem;
}

.automation-settings {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    max-width: 720px; /* the cards are full width; the dropdowns needn't be */
    margin: 10px 0 0 48px;
}

.automation-settings .mud-input-control {
    margin: 0;
}

.automation-formula {
    margin: 10px 0 0 48px;
    font-size: 0.75rem;
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
    color: var(--mud-palette-text-secondary);
}

/* Admin → Features: a dropdown in place of a switch, right-aligned like the switches. */
.settings-table .setting-cell .setting-choice {
    display: inline-block;
    width: 190px;
    text-align: left;
}

.settings-table .setting-cell .setting-choice .mud-input-control {
    width: 100%;
}

/* Admin -> Automations -> vendor accounting: what's remembered, per vendor and document type. */
.automation-settings-block {
    margin: 10px 0 0 48px;
}

.automation-subtitle {
    display: flex;
    align-items: center;
    font-size: 0.8125rem;
    color: var(--mud-palette-text-secondary);
}

.vendor-accounting-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.vendor-accounting-table th {
    text-align: left;
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
    padding: 4px 8px;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.vendor-accounting-table td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    vertical-align: middle;
}

.vendor-accounting-table .sub {
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
}

.vendor-accounting-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.vendor-accounting-table .actions {
    width: 40px;
    text-align: right;
}

/* A long list scrolls inside the dialog, under its fixed header row. */
.vendor-accounting-scroll {
    max-height: 60vh;
    overflow-y: auto;
}

.vendor-accounting-scroll .vendor-accounting-table th {
    position: sticky;
    top: 0;
    background-color: var(--mud-palette-surface);
}

/* An extra option of an automation (e.g. "also remember on approval"), level with the card's text. */
.automation-option {
    margin-left: -8px; /* the checkbox's own padding, so its box lines up with the text above */
    margin-bottom: 2px;
}

.automation-option .mud-typography {
    font-size: 0.8125rem;
}

.automation-option .automation-note {
    margin: -4px 0 4px 8px;
}

/* Setup wizard with P2PWEB_SETUP: the existing configuration, to keep or change. */
.setup-existing {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 6px 16px;
    padding: 12px 14px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 8px;
    font-size: 0.875rem;
}

.setup-existing-title {
    grid-column: 1 / -1;
    font-weight: 600;
    margin-bottom: 2px;
}

.setup-existing .label {
    color: var(--mud-palette-text-secondary);
}

.setup-existing .value {
    overflow-wrap: anywhere;
}

/* Setup wizard, Therefore step: the optional sign-in test. */
.setup-signin-test {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--mud-palette-lines-default);
}

.setup-signin-title {
    font-weight: 600;
    font-size: 0.875rem;
}

.setup-signin-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.setup-signin-fields .mud-input-control {
    margin: 0;
}

/* Admin -> List columns: a row per column (position, move up/down, name and what it shows, shown or not). */
.list-columns-preview {
    margin-bottom: 16px;
    padding: 10px 12px 6px;
    border-radius: 8px;
    background-color: var(--mud-palette-background-gray);
}

.list-columns-preview-label {
    margin-bottom: 6px;
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
}

/* The sample list: like the real lists, on a white card. */
.list-columns-preview-table {
    border-radius: 6px;
    overflow: hidden;
}

.list-columns {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 760px;
}

.list-column-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 10px;
    background-color: var(--mud-palette-surface);
}

.list-column-row.hidden-column .list-column-text {
    opacity: 0.55;
}

.list-column-position {
    flex: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--mud-palette-primary);
    background-color: var(--index-selected-bg);
}

.list-column-row {
    position: relative;
    cursor: grab;
}

.list-column-grip {
    flex: none;
    color: var(--mud-palette-text-secondary);
}

/* While dragging: the row being moved fades, and a line shows where it will land. */
.list-column-row.dragging {
    opacity: 0.4;
}

.list-column-row.drop-before::before,
.list-column-row.drop-after::after {
    content: "";
    position: absolute;
    left: 8px;
    right: 8px;
    height: 3px;
    border-radius: 2px;
    background-color: var(--mud-palette-primary);
}

.list-column-row.drop-before::before {
    top: -6px;
}

.list-column-row.drop-after::after {
    bottom: -6px;
}

.list-column-text {
    flex: 1;
    min-width: 0;
}

.list-column-name {
    font-weight: 600;
}

.list-column-help {
    font-size: 0.8125rem;
    color: var(--mud-palette-text-secondary);
}
