: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; }

/* ---- 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; }

/* ---- 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; }
.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 { 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; }

/* ---- 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; }
