/* ---------------------------------------------------------------------------
   Invoicing / fulfilment console.
   A thin layer over the bundled Bootstrap 5 - no CDN, because the production
   server serves this behind Apache with no outbound asset fetching.
   --------------------------------------------------------------------------- */

:root {
    --brand:            #1f3a5f;
    --brand-dark:       #16293f;
    --brand-accent:     #2f7fd1;
    --sidebar-width:    16rem;
    --surface:          #f5f7fa;
    --border:           #dfe3e8;
    --text-muted:       #6b7683;
}

html, body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
    background: var(--surface);
    color: #212a35;
}

h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }

a { color: var(--brand-accent); }
a:hover { color: var(--brand); }

/* ----- shell ------------------------------------------------------------- */

.app {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--brand);
    color: #dce4ee;
    display: flex;
    flex-direction: column;

    /* Stays put while the content scrolls. align-self is required: without it the
       flex item stretches to the full container height and has no room to stick in. */
    align-self: flex-start;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Only visible if the navigation itself outgrows the viewport. */
.app-sidebar::-webkit-scrollbar { width: 8px; }
.app-sidebar::-webkit-scrollbar-track { background: transparent; }
.app-sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.16);
    border-radius: 4px;
}
.app-sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.26); }
.app-sidebar { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.2) transparent; }

.app-brand {
    padding: 1.15rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.app-brand a {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.app-brand .brand-mark {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.3));
}

/* min-width:0 lets the text truncate instead of pushing the mark out of the bar. */
.app-brand .brand-text { min-width: 0; }

.app-brand .name {
    font-size: 1.05rem;
    font-weight: 600;
    color: #fff;
    line-height: 1.2;
    display: block;
}

.app-brand .sub {
    font-size: 0.75rem;
    color: #9fb3cd;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-nav { padding: 0.75rem 0; flex: 1 1 auto; }

.app-nav .nav-link {
    color: #c6d3e4;
    padding: 0.55rem 1.25rem;
    border-left: 3px solid transparent;
    font-size: 0.94rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-nav .nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.app-nav .nav-link.active {
    background: rgba(255, 255, 255, 0.10);
    border-left-color: var(--brand-accent);
    color: #fff;
    font-weight: 600;
}

.app-nav .nav-section {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #7f95b3;
    padding: 1rem 1.25rem 0.35rem;
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* Header block - warning bar plus top bar - stays visible while content scrolls,
   so the environment indicator and sign-out are always reachable. */
.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 1px 3px rgba(20, 40, 70, 0.06);
}

.app-topbar {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 0.55rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.app-content { padding: 1.5rem; flex: 1 1 auto; }

/* The active page caption lives in the header bar rather than on the page, so the
   content area starts with the content itself. */
.page-caption { min-width: 0; }

/* FocusOnNavigate moves focus to the page heading after each render so screen readers
   announce the new page. The heading now lives in the header bar, so that focus was
   drawing a visible rectangle around the caption on every form post.

   FocusOnNavigate gives the heading tabindex="-1", which makes it focusable by script
   but NOT reachable by tabbing. There is therefore no keyboard-focus case to preserve,
   and both :focus and :focus-visible are suppressed - browsers do match :focus-visible
   on programmatic focus, so leaving that rule in place simply drew a different
   rectangle instead of removing it. */
.page-caption h1:focus,
.page-caption h1:focus-visible { outline: none; box-shadow: none; }

.page-caption h1 {
    font-size: 1.15rem;
    font-weight: 650;
    letter-spacing: -0.01em;
    margin: 0;
    color: #16293f;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.page-caption p {
    margin: 0.1rem 0 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* The subtitle is the first thing to go when the bar gets tight. */
@media (max-width: 1100px) {
    .page-caption p { display: none; }
}

/* ----- environment banner ------------------------------------------------ */

/* The single most important piece of chrome here: this application can spend
   real money, so which environment it points at must never be ambiguous. */
.env-pill {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
}

.env-sandbox    { background: #e7f3ff; color: #14507f; border: 1px solid #b9d9f5; }
.env-production { background: #fdecea; color: #8c1d13; border: 1px solid #f5c2bd; }

.env-warning-bar {
    background: #8c1d13;
    color: #fff;
    font-size: 0.85rem;
    padding: 0.45rem 1.5rem;
    text-align: center;
}

/* ----- stat tiles -------------------------------------------------------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr));
    gap: 0.85rem;
}

.stat-tile {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.9rem 1rem;
    text-decoration: none;
    color: inherit;
    display: block;
    border-left: 4px solid var(--border);
    transition: box-shadow 0.12s ease, transform 0.12s ease;
}

.stat-tile:hover {
    box-shadow: 0 2px 10px rgba(20, 40, 70, 0.09);
    transform: translateY(-1px);
    color: inherit;
}

.stat-tile.is-active { border-color: var(--brand-accent); }

.stat-tile .value { font-size: 1.6rem; font-weight: 650; line-height: 1.1; }
.stat-tile .label { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.15rem; }

.stat-tile.tone-attention { border-left-color: #d9880a; }
.stat-tile.tone-danger    { border-left-color: #c0392b; }
.stat-tile.tone-ready     { border-left-color: var(--brand-accent); }
.stat-tile.tone-done      { border-left-color: #2e8b57; }
.stat-tile.tone-muted     { border-left-color: #b6bdc7; }

/* ----- cards and tables -------------------------------------------------- */

.panel {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    margin-bottom: 1.25rem;
}

.panel-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.panel-header h2 { margin: 0; font-size: 1rem; }
.panel-body { padding: 1rem; }
.panel-body.flush { padding: 0; }

.table > :not(caption) > * > * { padding: 0.55rem 0.75rem; }
.table thead th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom-width: 1px;
    white-space: nowrap;
}

.table td { font-size: 0.88rem; vertical-align: middle; }
.mono { font-family: Consolas, 'Courier New', monospace; font-size: 0.82rem; }

/* ----- state badges ------------------------------------------------------ */

.state {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.2rem 0.55rem;
    border-radius: 0.25rem;
    white-space: nowrap;
    border: 1px solid transparent;
}

.state-review   { background: #fff4e0; color: #8a5a00; border-color: #f2d9a8; }
.state-ready    { background: #e8f1fc; color: #14507f; border-color: #bcd6f2; }
.state-sent     { background: #eef1f5; color: #3c4a5a; border-color: #d3dae3; }
.state-paid     { background: #e9f6ee; color: #1d6b3f; border-color: #bfe3cd; }
.state-shipped  { background: #e3f4ea; color: #14663a; border-color: #b3ddc4; }
.state-done     { background: #2e8b57; color: #fff; border-color: #2e8b57; }
.state-error    { background: #fdecea; color: #8c1d13; border-color: #f5c2bd; }
.state-inactive { background: #f2f4f7; color: #6b7683; border-color: #dfe3e8; }

/* ----- misc -------------------------------------------------------------- */

.empty-state {
    padding: 2.5rem 1rem;
    text-align: center;
    color: var(--text-muted);
}

.field-issue {
    border-left: 3px solid #d9880a;
    background: #fffaf0;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 0.25rem;
}

.field-issue.blocking { border-left-color: #c0392b; background: #fdf3f2; }
.field-issue .field { font-weight: 600; font-size: 0.82rem; }
.field-issue .detail { font-size: 0.85rem; color: #4a5563; }

.kv { display: grid; grid-template-columns: 11rem 1fr; gap: 0.35rem 1rem; font-size: 0.9rem; }
.kv dt { color: var(--text-muted); font-weight: 500; }
.kv dd { margin: 0; }

@media (max-width: 900px) {
    .app { flex-direction: column; }
    .app-sidebar {
        width: 100%;
        flex-basis: auto;
        position: static;
        height: auto;
        align-self: auto;
        overflow-y: visible;
    }
    /* On a phone a pinned header costs too much of a short screen. */
    .app-header { position: static; }
    .kv { grid-template-columns: 1fr; }
}

/* ----- marketplace selector --------------------------------------------- */

.marketplace-selector { margin: 0; }

.marketplace-selector select {
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--brand-accent);
    padding: 0.28rem 1.7rem 0.28rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 0.35rem;
    background-color: #fff;
    background-image:
        linear-gradient(45deg, transparent 50%, #6b7683 50%),
        linear-gradient(135deg, #6b7683 50%, transparent 50%);
    background-position: right 0.72rem center, right 0.45rem center;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    appearance: none;
    cursor: pointer;
}

.marketplace-selector option { color: var(--brand-accent); }

.marketplace-selector select:hover { border-color: #b9c4d1; }

.marketplace-selector select:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(47, 127, 209, 0.16);
}

.marketplace-single {
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--brand-accent);
}

.marketplace-none { font-size: 0.82rem; color: #8c1d13; }

.topbar-divider {
    width: 1px;
    height: 1.35rem;
    background: var(--border);
}

/* ----- sync progress ----------------------------------------------------- */

.sync-panel {
    background: #fff;
    border: 1px solid var(--border);
    border-left: 4px solid var(--brand-accent);
    border-radius: 0.5rem;
    padding: 0.9rem 1rem;
    margin-bottom: 1.25rem;
}

.sync-panel-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    margin-bottom: 0.55rem;
}

.sync-panel-head .label { font-size: 0.9rem; font-weight: 600; color: #16293f; }
.sync-panel-head .detail { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; }

.sync-progress {
    height: 1.15rem;
    background: #eef1f5;
    border-radius: 0.35rem;
    overflow: hidden;
}

.sync-progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(180deg, #2f7fd1 0%, #2569b0 100%);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.15rem;
    text-align: center;
    transition: width 0.25s ease;
}

/* No total yet, so show motion rather than a percentage we would be inventing. */
.sync-progress-bar.is-indeterminate {
    background: repeating-linear-gradient(
        45deg, #2f7fd1 0 12px, #2569b0 12px 24px);
    background-size: 34px 34px;
    animation: sync-stripes 0.9s linear infinite;
}

@keyframes sync-stripes {
    from { background-position: 0 0; }
    to   { background-position: 34px 0; }
}

@media (prefers-reduced-motion: reduce) {
    .sync-progress-bar.is-indeterminate { animation: none; }
    .sync-progress-bar { transition: none; }
}

/* ----- pagination -------------------------------------------------------- */

.pager {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
}

/* At the top of a table the divider belongs on the other edge. */
.pager.is-top {
    border-top: none;
    border-bottom: 1px solid var(--border);
}

.pager-summary { color: var(--text-muted); }

.pager-links { display: flex; align-items: center; gap: 0.25rem; }

.pager-links a,
.pager-links span {
    display: inline-block;
    min-width: 2rem;
    padding: 0.25rem 0.5rem;
    text-align: center;
    border-radius: 0.3rem;
    text-decoration: none;
}

.pager-links a {
    color: var(--brand-accent);
    border: 1px solid var(--border);
    background: #fff;
}

.pager-links a:hover { border-color: var(--brand-accent); background: #f2f7fd; }

.pager-links .current {
    background: var(--brand-accent);
    border: 1px solid var(--brand-accent);
    color: #fff;
    font-weight: 600;
}

.pager-links .disabled { color: #b6bdc7; border: 1px solid transparent; }
.pager-links .gap { min-width: 1rem; color: var(--text-muted); border: none; }

.pager-controls { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

.pager-size { display: flex; align-items: center; gap: 0.4rem; margin: 0; }
.pager-size label { color: var(--text-muted); font-size: 0.82rem; }

.pager-size select {
    font-size: 0.82rem;
    padding: 0.2rem 1.5rem 0.2rem 0.5rem;
    color: var(--brand-accent);
    background-color: #fff;
    border: 1px solid var(--border);
    border-radius: 0.3rem;
    background-image:
        linear-gradient(45deg, transparent 50%, #6b7683 50%),
        linear-gradient(135deg, #6b7683 50%, transparent 50%);
    background-position: right 0.62rem center, right 0.38rem center;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    appearance: none;
    cursor: pointer;
}

.pager-size select:hover { border-color: #b9c4d1; }
.pager-size select:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(47, 127, 209, 0.16);
}

/* ----- record navigation ------------------------------------------------- */

.record-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}

.record-nav-back { font-size: 0.9rem; }

.record-nav-controls { display: flex; align-items: center; gap: 0.4rem; }

.record-nav-position {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-right: 0.3rem;
}

.record-nav-controls a,
.record-nav-controls span.disabled {
    font-size: 0.85rem;
    min-width: 2rem;
    text-align: center;
    padding: 0.28rem 0.7rem;
    border-radius: 0.3rem;
    text-decoration: none;
    border: 1px solid var(--border);
    background: #fff;
}

.record-nav-controls a { color: var(--brand-accent); }
.record-nav-controls a:hover { border-color: var(--brand-accent); background: #f2f7fd; }
.record-nav-controls span.disabled { color: #b6bdc7; border-color: transparent; background: transparent; }

/* Purchase-invoice export form: a short row of controls, wrapping on narrow screens. */
.pi-form {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
}

.pi-field { display: flex; flex-direction: column; gap: 0.25rem; }

.pi-field label { font-size: 0.82rem; color: var(--text-muted); }

.pi-field input[type="date"] {
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.3rem;
    background: #fff;
    font: inherit;
}

.pi-field-check {
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
    padding-bottom: 0.4rem;
}

.pi-field-check label { font-size: 0.9rem; color: inherit; }

/* Correction panel: a compact two-column grid of short text fields. */
.fix-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem 1rem;
}

.fix-grid label {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.fix-grid input {
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.3rem;
    font: inherit;
    font-size: 0.9rem;
    color: var(--text);
    background: #fff;
}

.fix-grid input::placeholder { color: #aab2bd; }

.fix-grid .fix-wide { grid-column: 1 / -1; }

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

/* One row per DropXL account: country, credentials, save. */
.account-row {
    display: grid;
    grid-template-columns: 8rem minmax(0, 1.2fr) minmax(0, 1.2fr) minmax(0, 1fr) auto;
    gap: 0.5rem;
    align-items: center;
}

.account-label { font-size: 0.85rem; line-height: 1.2; }

@media (max-width: 900px) {
    .account-row { grid-template-columns: 1fr; }
}
