:root {
    --bg: #f5f6f8;
    --fg: #1f2933;
    --muted: #6b7280;
    --border: #e2e5ea;
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --ok: #16a34a;
    --warn: #d97706;
    --err: #dc2626;
    --dcix: #ef8903;      /* DCIx logo orange */
    --dcix-dark: #d67a03;
}

* { box-sizing: border-box; }
/* Keep the hidden attribute working even on elements we give an explicit display. */
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- top bar ---- */
.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0 1.5rem;
    height: 56px;
    background: #fff;
    border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; color: var(--fg); display: inline-flex; align-items: center; gap: .4rem; }

/* Brand service icons (Depoto / DCIx) shown next to their names; scale with text. */
.brand-icon { width: 1.3em; height: 1.3em; border-radius: 5px; vertical-align: middle; }
.topbar .mainnav { display: flex; gap: 1rem; flex: 1; border-left: 1px solid var(--border); padding-left: 1.5rem; }
.topbar .mainnav .nav-group { display: flex; gap: 1rem; }
.topbar .mainnav .nav-group + .nav-group { border-left: 1px solid var(--border); padding-left: 1rem; }
.topbar .mainnav a { color: var(--fg); padding: .2rem 0; border-bottom: 2px solid transparent; }
.topbar .mainnav a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.topbar .user { display: flex; align-items: center; gap: .75rem; color: var(--muted); }
.topbar .user .user-link { display: inline-flex; align-items: center; gap: .35rem; }
.topbar .user .user-link.active { color: var(--accent); font-weight: 600; }
.topbar .user .user-icon { width: 1.1em; height: 1.1em; }
.topbar .user .logout-btn { display: inline-flex; align-items: center; justify-content: center; padding: .35rem; border: 1px solid var(--border); border-radius: 6px; color: var(--muted); }
.topbar .user .logout-btn:hover { color: var(--accent); border-color: var(--accent); }
.topbar .user .logout-btn svg { width: 1.1em; height: 1.1em; }
.topbar .conn-info { display: flex; gap: .5rem; margin-right: 1rem; font-size: .75rem; color: var(--muted); }
.conn-item { background: #f3f4f6; border: 1px solid var(--border); border-radius: 999px; padding: .15rem .6rem; white-space: nowrap; }
.conn-label { font-weight: 600; color: var(--fg); }

.content { max-width: 1400px; margin: 1.5rem auto; padding: 0 1.5rem; }

h1 { font-size: 1.4rem; }
.muted { color: var(--muted); }

/* ---- flashes ---- */
.flash { padding: .6rem .9rem; border-radius: 6px; margin: .5rem 0; border: 1px solid transparent; }
.flash-success { background: #ecfdf3; color: #166534; border-color: #bbf7d0; }
.flash-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.flash-danger  { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.flash-info    { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

/* ---- cards ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin: 1rem 0 2rem; }
.card { display: block; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 1rem 1.2rem; color: var(--fg); }
.card:hover { border-color: var(--accent); text-decoration: none; }
.card h2 { margin: 0 0 .3rem; font-size: 1.1rem; }
.card p { margin: 0; color: var(--muted); }

/* ---- tables ---- */
.table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.table th, .table td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--border); }
.table thead th { background: #fafbfc; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f0f4fc; }
.table tbody tr[data-action] { cursor: pointer; }
.table .col-check { width: 2.5rem; text-align: center; }
.table .col-num { text-align: right; }
/* Long DCIx error reasons (nvarchar(max)) must wrap inside the modal. */
.table .col-reason { max-width: 40rem; overflow-wrap: anywhere; }
/* Horizontal scroll instead of clipping; keep full identifiers readable. */
.table-scroll { width: 100%; overflow-x: auto; }
/* Payload-style headers (packageCode, messageId, …) — keep camelCase, not UPPERCASE. */
.table.table-payload-fields thead th,
.table.table-nowrap thead th {
    text-transform: none;
    letter-spacing: normal;
    font-variant-numeric: normal;
}
/* Do not wrap table rows / cells; wide content scrolls via .table-scroll or modal wrap. */
.table.table-nowrap th,
.table.table-nowrap td {
    white-space: nowrap;
    vertical-align: middle;
}
/*
 * Key identifiers (packageCode, messageId, orderId, …): always show in full.
 * Truncation here was CSS text-overflow:ellipsis + max-width — NOT Symfony u.truncate.
 * That ellipsis chops mid-string to fit a box width (often looks like “N chars cut + …”),
 * which is wrong for scan codes and Pub/Sub ids. Prefer horizontal scroll.
 */
.table .col-id {
    white-space: nowrap;
    max-width: none;
    overflow: visible;
    text-overflow: clip;
    font-variant-numeric: tabular-nums;
}

/* ---- icon buttons / modal ---- */
.btn-icon { background: transparent; color: var(--accent); padding: .15rem .35rem; line-height: 1; vertical-align: middle; }
.btn-icon:hover { background: #eef2fb; color: var(--accent-dark); }
.modal { border: 1px solid var(--border); border-radius: 10px; padding: 1.25rem 1.5rem; min-width: 1100px; max-width: 1500px; }
.modal::backdrop { background: rgba(15, 23, 42, .45); }
.modal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.modal-head h2 { margin: 0 0 .75rem; font-size: 1.05rem; }
.modal-toolbar {
    display: flex;
    justify-content: flex-end;
    margin: 0 0 .75rem;
}
.modal-toolbar form { margin: 0; }
.modal-toolbar .btn-danger {
    padding: .4rem .9rem;
    white-space: nowrap;
}
/* Compact JSON preview on /packages (sorter API) */
.modal.modal-json {
    min-width: min(720px, 92vw);
    max-width: min(900px, 96vw);
    width: 100%;
}
/* Wider table modal (Pub/Sub records on /packages) */
.modal.modal-wide {
    min-width: min(960px, 94vw);
    max-width: min(1200px, 96vw);
    width: 100%;
}
.ss-content {
    z-index: 100000 !important;
}
.pubsub-modal-table-wrap {
    max-height: min(70vh, 32rem);
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.pubsub-modal-table-wrap .table {
    margin: 0;
    border: none;
    border-radius: 0;
    overflow: visible; /* don't clip full messageId / packageCode */
}
.table-compact th,
.table-compact td {
    padding: .4rem .55rem;
    font-size: .85rem;
}
.badge-as-button {
    border: none;
    cursor: pointer;
    font: inherit;
    padding: .15rem .55rem;
}
.badge-as-button:hover { filter: brightness(0.95); }
.sorter-api-status-actions {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
}
.demo-toggle {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .85rem;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.demo-toggle input { margin: 0; cursor: pointer; }
.package-status-card {
    background: var(--bg-card, #fff);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 8px;
    padding: 1.1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: .65rem;
    min-height: 9.5rem;
}
.package-status-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    flex-wrap: wrap;
}
.package-status-card-title {
    margin: 0;
    font-size: 1.05rem;
    display: inline-flex;
    align-items: center;
    gap: .45rem;
}
.package-status-card-body {
    font-size: .9rem;
    line-height: 1.5;
    flex: 1;
}
.package-status-card-body .break-all { word-break: break-all; }
.sorter-api-settings-panel {
    display: flex;
    flex-direction: column;
    gap: .85rem;
    margin-bottom: 1.25rem;
    padding: 1rem;
    background: var(--bg-subtle, #f7fafc);
    border-radius: 6px;
}
.sorter-api-settings-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}
.sorter-api-settings-row-border {
    padding-top: .85rem;
    border-top: 1px solid var(--border-color, #e2e8f0);
}
.btn-split-menu-divider {
    height: 1px;
    margin: .3rem 0;
    background: var(--border);
}
.btn-split-menu-action {
    display: block;
    width: 100%;
    text-align: left;
    background: #fff !important;
    color: var(--fg) !important;
    border: none !important;
    border-radius: 0 !important;
    padding: .45rem .75rem;
    font-size: .85rem;
    cursor: pointer;
}
.btn-split-menu-action:hover {
    background: #f0f4fc !important;
}
.btn-split-menu-action .muted {
    display: block;
    font-size: .75rem;
    margin-top: .1rem;
}
/* 3× hover-like flash when jumping between pubsub modal and log row */
@keyframes row-flash-pulse {
    0%, 100% { background-color: transparent; }
    8%, 18% { background-color: #dbeafe; }
    28% { background-color: transparent; }
    38%, 48% { background-color: #dbeafe; }
    58% { background-color: transparent; }
    68%, 78% { background-color: #dbeafe; }
    88% { background-color: transparent; }
}
tr.row-flash > td {
    animation: row-flash-pulse 1.65s ease-in-out 1;
}
tr.pubsub-row-sent:hover > td {
    background: #f0f4fc;
}
.sorter-api-json {
    margin: 0;
    max-height: min(70vh, 32rem);
    overflow: auto;
    background: #1f2933;
    color: #e5e7eb;
    border-radius: 8px;
    padding: .85rem 1rem;
    font-size: .8rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---- forms / buttons ---- */
.searchbar { display: flex; gap: .5rem; margin: 1rem 0; align-items: flex-end; }
input[type="search"], input[type="text"], input[type="email"], input[type="password"], input[type="date"], select {
    padding: .5rem .7rem; border: 1px solid var(--border); border-radius: 6px; font: inherit;
    background: #fff;
}
.searchbar input[type="search"] { flex: 1; min-width: 0; }
.searchbar input, .searchbar select, .searchbar button { height: 2.5rem; box-sizing: border-box; }
/* Equal width for the wide lookup selects regardless of their option lengths. The company
   select is wider — on the orders list it holds the combined "Company – Depot" labels. */
.searchbar select[name="carrier"], .searchbar select[name="depot"] { width: 12rem; }
.searchbar select[name="company"] { width: 16rem; }
.searchbar-field { display: flex; flex-direction: column; gap: .2rem; }
.searchbar-field > span { font-size: .8rem; color: var(--muted); }
button {
    padding: .5rem .9rem; border: none; border-radius: 6px; background: var(--accent); color: #fff;
    font: inherit; cursor: pointer;
}
button:hover { background: var(--accent-dark); }
button:disabled { opacity: .55; cursor: not-allowed; }
button:disabled:hover { background: var(--accent); }
/* DCIx-branded action (push to DCIx) */
.btn-dcix { background: var(--dcix); }
.btn-dcix:hover { background: var(--dcix-dark); }
.btn-dcix:disabled:hover { background: var(--dcix); }
/* Destructive action (delete in DCIx) */
.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-danger:disabled:hover { background: #dc2626; }
/* Groups the push + delete buttons so they pin to the right edge together. */
.btn-group { display: inline-flex; gap: .75rem; }

/* Split button + dropdown (packages resend → force arm).
   Menu is position:fixed via dropdown_controller (not clipped by .table overflow). */
.btn-split {
    display: inline-flex;
    position: relative;
    vertical-align: middle;
    border-radius: 6px;
    overflow: hidden; /* clean join between primary + toggle */
}
.btn-split form { display: inline; margin: 0; }
.btn-split > form > button,
.btn-split > .btn-split-toggle {
    padding: .25rem .55rem;
    font-size: .8rem;
    line-height: 1.2;
    border-radius: 0 !important;
}
.btn-split-toggle {
    border-left: 1px solid rgba(255, 255, 255, .35);
    min-width: 1.75rem;
}
.btn-split-menu {
    /* top/right set by JS (fixed); keep base chrome here */
    z-index: 1000;
    min-width: 12rem;
    max-height: min(70vh, 20rem);
    overflow-x: hidden;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
    padding: .25rem 0;
    box-sizing: border-box;
}
.btn-split-menu form { display: block; width: 100%; margin: 0; }
.btn-split-menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: #fff !important;
    color: var(--fg) !important;
    border: none !important;
    border-radius: 0 !important;
    padding: .45rem .75rem;
    font-size: .85rem;
    box-shadow: none !important;
}
.btn-split-menu button:hover {
    background: #f0f4fc !important;
    color: var(--fg) !important;
}
.btn-split-menu .muted {
    display: block;
    font-size: .75rem;
    margin-top: .1rem;
}
.actions { margin: 1rem 0; }
/* Stretch makes the banner and the submit button the same height. */
.actions-row { display: flex; align-items: stretch; gap: .75rem; flex-wrap: wrap; }
.actions-row .flash { margin: 0; padding: 0 .9rem; display: inline-flex; align-items: center; gap: .5rem; box-sizing: border-box; }
.actions-row .flash > span { display: inline-flex; align-items: center; gap: .5rem; }
.actions-row .flash button { padding: .15rem .6rem; font-size: .85em; }
/* Pins the element to the right edge even when the banner before it is hidden. */
.actions-row-end { margin-left: auto; }

/* ---- badges ---- */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; }
.badge-success, .badge-pushed_ok, .badge-forwarded, .badge-confirmed { background: #ecfdf3; color: #166534; }
.badge-error, .badge-push_failed, .badge-forward_failed, .badge-invalid { background: #fef2f2; color: #991b1b; }
.badge-pending, .badge-received, .badge-validated { background: #eff6ff; color: #1e40af; }
.badge-skipped { background: #f5f5f4; color: #57534e; }
/* Amber/orange warning — used e.g. for sorter API demo mode (not the blue pending/info look). */
.badge-warning, .badge-demo {
    background: #fff7ed;
    color: #c2410c;
    border: 1px solid #fdba74;
}

/* ---- pagination ---- */
.pagination { display: flex; align-items: center; gap: 1rem; margin: 1rem 0; }
/* Load-more variant: page info on the left, the button truly centered in the row. */
.pagination-load-more { display: grid; grid-template-columns: 1fr auto 1fr; }
.pagination-load-more > span { justify-self: start; }
.pagination-load-more > button { grid-column: 2; }

/* ---- subnav (logs) ---- */
.subnav { display: flex; gap: 1rem; margin: 1rem 0; border-bottom: 1px solid var(--border); }
.subnav a { padding: .4rem .2rem; color: var(--muted); border-bottom: 2px solid transparent; }
.subnav a.active { color: var(--fg); border-bottom-color: var(--accent); }
.subnav form { display: inline; }

/* ---- docs ---- */
.docs { max-width: 800px; }
.docs h2 { margin-top: 2rem; font-size: 1.15rem; }
.docs h3 { margin-top: 1.2rem; font-size: .95rem; }
.docs code {
    background: #eef0f3; border: 1px solid var(--border); border-radius: 4px;
    padding: .05rem .3rem; font-size: .85em;
}
.docs pre {
    background: #1f2933; color: #e5e7eb; border-radius: 8px;
    padding: 1rem 1.2rem; overflow-x: auto; font-size: .85rem; line-height: 1.5;
}
.docs pre code { background: none; border: none; padding: 0; font-size: inherit; }
.docs .method {
    display: inline-block; padding: .1rem .45rem; border-radius: 5px; margin-right: .4rem;
    background: var(--accent); color: #fff; font-size: .75em; vertical-align: middle;
}
.btn-inline { padding: .15rem .6rem; font-size: .8rem; vertical-align: baseline; }
.webhook-test textarea {
    width: 100%; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: 8px;
    font: .85rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; resize: vertical;
}
.docs pre.test-result { background: #fff; color: var(--fg); border: 1px solid var(--border); }

/* ---- sync log detail ---- */
.btn-caret {
    background: none; border: none; cursor: pointer; padding: .1rem .3rem;
    font-size: .9rem; color: var(--muted); line-height: 1;
}
.btn-caret:hover { color: var(--fg); }
.detail-row td { background: #fafbfc; padding: .3rem .7rem 1rem; }
.log-detail h4 {
    margin: .8rem 0 .3rem; font-size: .8rem; text-transform: uppercase;
    letter-spacing: .03em; color: var(--muted);
}
.log-detail .stmt { margin-bottom: .6rem; }
.log-detail .phase {
    display: inline-block; padding: .05rem .4rem; border-radius: 5px; margin-bottom: .3rem;
    background: var(--accent); color: #fff; font-size: .72rem;
    text-transform: uppercase; letter-spacing: .03em;
}
.log-detail pre {
    background: #1f2933; color: #e5e7eb; border-radius: 8px; margin: .2rem 0;
    padding: .7rem 1rem; overflow-x: auto; font-size: .78rem; line-height: 1.5;
    white-space: pre-wrap; word-break: break-word;
}
.log-detail pre.error { background: #fef2f2; color: #991b1b; }

/* ---- login ---- */
.login-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 2rem; width: 320px; display: flex; flex-direction: column; gap: .5rem; }
.login-card h1 { margin: 0 0 1rem; font-size: 1.2rem; text-align: center; }
.login-card label { font-size: .85rem; color: var(--muted); margin-top: .4rem; }
.login-card button { margin-top: 1rem; }
.login-card-wide { width: 420px; }
.login-alt { margin: .8rem 0 0; text-align: center; font-size: .85rem; }
.form-hint { margin: .2rem 0 0; font-size: .8rem; color: var(--muted); }

/* ---- 2FA setup ---- */
.totp-steps { margin: 0 0 .5rem; padding-left: 1.2rem; font-size: .9rem; line-height: 1.6; }
.totp-qr { margin: .5rem 0; text-align: center; }
.totp-qr img { border: 1px solid var(--border); border-radius: 8px; }
.totp-secret-wrap { margin: 0 0 .5rem; text-align: center; font-size: .85rem; color: var(--muted); }
.totp-secret { background: #eef0f3; border: 1px solid var(--border); border-radius: 4px; padding: .1rem .4rem; font-size: .9em; word-break: break-all; }

/* ---- user management ---- */
.btn {
    display: inline-block; padding: .5rem .9rem; border-radius: 6px;
    background: var(--accent); color: #fff; text-decoration: none;
}
.btn:hover { background: var(--accent-dark); }
.btn.btn-inline { padding: .15rem .6rem; font-size: .8rem; }
.user-actions { display: flex; gap: .4rem; align-items: center; }
.user-actions form { margin: 0; }

/* ---- user form ---- */
.form-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 1.5rem 2rem; max-width: 480px; }
.form-card label { display: block; font-size: .85rem; color: var(--muted); margin: .8rem 0 .2rem; }
.form-card input[type=text], .form-card input[type=password] { width: 100%; }
.form-card .checkbox-row label { display: inline; margin: 0 0 0 .4rem; color: var(--fg); }
.form-card ul { margin: .2rem 0 0; padding-left: 1.2rem; color: #991b1b; font-size: .85rem; }
.form-card button { margin-top: 1.2rem; }
.form-card .checkbox-row { margin-top: .8rem; }
.form-card .btn-link { margin-left: .8rem; font-size: .9rem; }
