/* ---------------------------------------------------------------------
 * FMS theme — warm off-white + soft mustard + deep slate anchor.
 * Edit values here, all components inherit via custom properties.
 * --------------------------------------------------------------------- */

:root {
    --bg:           #FAFAF7;
    --surface:      #FFFFFF;
    --surface-alt:  #F5F4EE;
    --border:       #ECE9DD;
    --border-soft:  #F1EFE6;

    --accent:       #F2C744;
    --accent-soft:  #FFD166;
    --accent-ink:   #4A3A00;

    --anchor:       #1F2A44;
    --anchor-soft:  #334066;

    --text:         #1C1F26;
    --muted:        #6B7280;

    --success:      #2E8B57;
    --warning:      #E1A93A;
    --danger:       #C0392B;
    --info:         #4A6B8A;

    --radius:       8px;
    --radius-lg:    14px;
    --shadow-sm:    0 1px 2px rgba(28, 31, 38, 0.04);
    --shadow-md:    0 4px 12px rgba(28, 31, 38, 0.06);
    --shadow-lg:    0 12px 32px rgba(28, 31, 38, 0.08);

    --font-body:    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono:    "SF Mono", "Cascadia Code", "Consolas", monospace;

    --sidebar-w:    260px;
    --topbar-h:     60px;
}

/* --- Base ------------------------------------------------------------ */
html, body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;     /* prevents accidental horizontal scroll from any wide flex child */
}

body { min-height: 100vh; margin: 0; }
*, *::before, *::after { box-sizing: border-box; }

a { color: var(--anchor); text-decoration: none; }
a:hover { color: var(--accent-ink); text-decoration: underline; }

/* --- Bootstrap overrides --------------------------------------------- */
.btn { border-radius: var(--radius); font-weight: 500; }

.btn-primary {
    background-color: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}
.btn-primary:hover, .btn-primary:focus {
    background-color: var(--accent-soft);
    border-color: var(--accent-soft);
    color: var(--accent-ink);
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-soft);
    padding: 0.85rem 1.25rem;
    font-weight: 600;
    color: var(--anchor);
}
.card-body { padding: 1.25rem; }

.form-control, .form-select {
    border-radius: var(--radius);
    border-color: var(--border);
    background: var(--surface);
}
.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 0.15rem rgba(242, 199, 68, 0.25);
}

.table { --bs-table-bg: var(--surface); --bs-table-border-color: var(--border-soft); }
.table > thead { background: var(--surface-alt); }
.table > thead th {
    color: var(--anchor); font-weight: 600;
    border-bottom: 1px solid var(--border);
}

.badge.bg-anchor { background: var(--anchor) !important; color: #fff; }
.badge.bg-accent { background: var(--accent) !important; color: var(--accent-ink); }
.badge.bg-muted  { background: var(--surface-alt) !important; color: var(--muted); }

.text-muted   { color: var(--muted) !important; }
.text-anchor  { color: var(--anchor) !important; }

.alert-soft-danger {
    background: #FBE9E7; color: #8E2A1A;
    border: 1px solid #F2C8C0; border-radius: var(--radius);
}
.alert-soft-warning {
    background: #FFF4D6; color: #6B4A00;
    border: 1px solid #F4DD9B; border-radius: var(--radius);
}
.alert-soft-success {
    background: #E9F5EE; color: #1F6A41;
    border: 1px solid #C3E2CD; border-radius: var(--radius);
}

/* --- App shell layout ------------------------------------------------ */
body.app-shell {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    height: 100vh;       /* lock to viewport so .app-main can own the scroll */
    overflow: hidden;    /* body itself doesn't scroll — app-main does */
}

.app-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--anchor);
    color: #C8CEDC;
    display: flex;
    flex-direction: column;
    z-index: 1030;
    transition: transform 220ms ease;
}
.app-sidebar .sidebar-brand {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.app-sidebar .brand-link img {
    max-height: 38px;
    filter: brightness(0) invert(1);  /* keeps white on dark */
}
.sidebar-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.2rem;
    padding: 0.25rem 0.5rem;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0.5rem 1.5rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.18) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.16); border-radius: 3px; }

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.75rem;
    color: #C8CEDC;
    border-radius: var(--radius);
    font-size: 0.92rem;
    transition: background 120ms ease, color 120ms ease;
}
.sidebar-nav .nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    text-decoration: none;
}
.sidebar-nav .nav-link i {
    width: 18px; text-align: center; font-size: 0.95rem;
    color: rgba(255,255,255,0.6);
}
.sidebar-nav .nav-item.active > .nav-link,
.sidebar-nav .nav-link:not(.collapsed)[data-bs-toggle="collapse"] {
    background: rgba(242, 199, 68, 0.12);
    color: #FFE69A;
}
.sidebar-nav .nav-item.active > .nav-link i,
.sidebar-nav .nav-link:not(.collapsed)[data-bs-toggle="collapse"] i {
    color: var(--accent);
}
.sidebar-nav .nav-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-nav .nav-caret {
    font-size: 0.75rem;
    transition: transform 180ms ease;
}
.sidebar-nav .nav-link:not(.collapsed) .nav-caret {
    transform: rotate(180deg);
}

.sidebar-nav .nav-children {
    padding: 0.25rem 0 0.5rem 1.6rem;
    list-style: none;
    border-left: 1px dashed rgba(255,255,255,0.10);
    margin-left: 1rem;
    /* Force vertical stack — Bootstrap's `.nav` defaults to flex-row, which
       was causing submenu items to wrap onto the same line at narrow widths. */
    display: flex;
    flex-direction: column;
    width: 100%;
}
.sidebar-nav .nav-children .nav-item {
    width: 100%;
}
.sidebar-nav .nav-children .nav-link {
    padding: 0.4rem 0.65rem;
    font-size: 0.86rem;
    color: #A6ADBE;
    width: 100%;
}
.sidebar-nav .nav-children .nav-link:hover { color: #fff; background: rgba(255,255,255,0.05); }
.sidebar-nav .nav-children .nav-link .dot {
    width: 5px; height: 5px;
    border-radius: 50%;
    background: rgba(255,255,255,0.25);
    flex-shrink: 0;
}

.sidebar-empty {
    color: rgba(255,255,255,0.5);
    font-size: 0.85rem;
    padding: 1rem 0.75rem;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1029;
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
}
body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-width: 0;       /* allow flex children to shrink instead of overflowing */
    max-width: 100%;
    height: 100vh;      /* fixed height so this container can scroll */
    overflow-y: auto;   /* the topbar's `position: sticky` sticks to the top of THIS scroll */
    overflow-x: hidden;
    transition: margin-left 220ms ease;
}

/* --- Topbar ---------------------------------------------------------- */
.app-topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    /* small inline padding only — vertical centering handled by align-items.
       No padding-top: a sticky topbar at the scroll container's top has
       zero margin to bleed into. */
    padding: 0 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.topbar-toggle {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--anchor);
    height: 38px; width: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.topbar-toggle:hover { background: var(--surface-alt); }

.topbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    color: var(--anchor);
    letter-spacing: 0.02em;
}
.topbar-brand .dot {
    display: inline-block;
    width: 9px; height: 9px;
    background: var(--accent);
    border-radius: 50%;
}

.topbar-spacer { flex: 1; }

.topbar-company .company-trigger {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.35rem 0.65rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--anchor);
    font-weight: 500;
    font-size: 0.9rem;
}
.topbar-company .company-trigger:hover { background: var(--bg); }
.topbar-company .company-trigger img {
    width: 22px; height: 22px;
    border-radius: 50%;
    object-fit: cover;
}
.topbar-company .company-name {
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dropdown-item .company-logo-mini {
    width: 18px; height: 18px;
    border-radius: 50%;
    margin-right: 0.5rem;
    object-fit: cover;
}
.dropdown-item.active {
    background: var(--accent);
    color: var(--accent-ink);
}

.topbar-plan {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.35rem 0.65rem;
    font-size: 0.82rem;
    color: var(--muted);
}
.topbar-plan.is-urgent { color: #8B5A00; background: #FFF4D6; border-color: #F4DD9B; }
.topbar-plan.is-expired { color: #8E2A1A; background: #FBE9E7; border-color: #F2C8C0; }

.topbar-icon-btn {
    position: relative;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 38px; height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--anchor);
}
.topbar-icon-btn:hover {
    background: var(--surface-alt);
    color: var(--anchor);
    text-decoration: none;
}
.topbar-badge {
    position: absolute;
    /* Sit just inside the button's top-right corner — no overhang.
       The previous -6px offsets got clipped now that the topbar is
       sticky to the top edge of the scrolling .app-main. */
    top: -2px; right: -2px;
    background: var(--danger);
    color: #fff;
    font-size: 0.65rem;
    line-height: 1;
    padding: 3px 5px;
    border-radius: 10px;
    border: 2px solid var(--surface);  /* tiny halo so it pops against the icon button */
    min-width: 18px;
    text-align: center;
}

.topbar-user .user-trigger {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.25rem 0.6rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--anchor);
}
.topbar-user .user-trigger:hover { background: var(--surface-alt); }
.topbar-user .avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}
.topbar-user .user-meta {
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.1;
}
.topbar-user .user-name { font-weight: 600; font-size: 0.9rem; }
.topbar-user .user-sub  { color: var(--muted); font-size: 0.75rem; }

.app-flash {
    margin: 0.85rem 1.25rem 0;
    padding: 0.55rem 0.85rem;
    font-size: 0.9rem;
}

/* --- Content & footer ------------------------------------------------ */
.app-content {
    padding: 1.5rem;
    flex: 1;
    max-width: 1320px;
    width: 100%;
    margin: 0 auto;
}

.app-footer {
    text-align: center;
    color: var(--muted);
    padding: 1rem;
    font-size: 0.8rem;
    border-top: 1px solid var(--border-soft);
    background: var(--surface);
}

/* --- Dashboard ------------------------------------------------------- */
.dashboard-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}
.dashboard-greeting {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--anchor);
    margin: 0 0 0.25rem;
}
.dashboard-sub {
    color: var(--muted);
    margin: 0;
}

.stat-card .card-body {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.stat-card .stat-icon {
    width: 38px; height: 38px;
    border-radius: var(--radius);
    background: var(--surface-alt);
    color: var(--anchor);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    margin-bottom: 0.4rem;
}
.stat-card .stat-label {
    color: var(--muted);
    font-size: 0.85rem;
}
.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--anchor);
    line-height: 1;
}
.stat-card .stat-value-text {
    font-size: 1rem;
    font-weight: 600;
}

.changelog {
    list-style: none;
    padding: 0;
    margin: 0;
}
.changelog li {
    display: flex;
    gap: 0.75rem;
    padding: 0.65rem 0;
    border-bottom: 1px dashed var(--border-soft);
    align-items: flex-start;
}
.changelog li:last-child { border-bottom: none; }
.cl-pill {
    flex-shrink: 0;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 999px;
}
.cl-success { background: #E9F5EE; color: #1F6A41; border: 1px solid #C3E2CD; }
.cl-current { background: var(--accent); color: var(--accent-ink); }
.cl-pending { background: var(--surface-alt); color: var(--muted); border: 1px solid var(--border); }
.changelog code {
    background: var(--surface-alt);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.85em;
}

/* --- Page sections (used by module list/edit screens) --------------- */
.page-section { display: flex; flex-direction: column; gap: 1rem; }
.page-section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.page-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--anchor);
    margin: 0 0 0.25rem;
}
.page-sub { font-size: 0.9rem; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.btn-anchor {
    background: var(--anchor);
    border-color: var(--anchor);
    color: #fff;
}
.btn-anchor:hover, .btn-anchor:focus {
    background: var(--anchor-soft);
    border-color: var(--anchor-soft);
    color: #fff;
}

/* Row icon-action buttons in list tables */
.row-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px; height: 30px;
    border-radius: var(--radius);
    color: var(--anchor);
    background: transparent;
    border: 1px solid transparent;
    margin-left: 0.15rem;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.row-action:hover {
    background: var(--surface-alt);
    border-color: var(--border);
    text-decoration: none;
}
.row-action.row-action-danger:hover {
    background: #FBE9E7;
    border-color: #F2C8C0;
    color: var(--danger);
}
.row-action.row-action-success:hover {
    background: #E9F5EE;
    border-color: #C3E2CD;
    color: var(--success);
}

/* --- Voucher types: small color dot in the list table --------------- */
.vt-color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid var(--border);
    vertical-align: middle;
}

/* --- Service-unit row action icons (legacy parity X / $ / terminal) - */
.su-icons {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}
.su-icon {
    cursor: pointer;
    color: var(--muted);
    font-size: 0.95rem;
    padding: 0.2rem;
    border-radius: 4px;
    transition: color 100ms ease, background 100ms ease;
    user-select: none;
}
.su-icon:hover { background: var(--surface-alt); }
.su-icon.su-remove        { color: var(--danger); }
.su-icon.su-remove:hover  { background: #FBE9E7; }
.su-icon.su-loadprices       { color: var(--success); }
.su-icon.su-loadprices:hover { background: #E9F5EE; }
.su-icon.su-posdefault            { color: var(--muted); }
.su-icon.su-posdefault.is-active  { color: var(--danger); background: #FBE9E7; }

/* --- Companies list: small logo cell -------------------------------- */
.cmp-list-logo {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    object-fit: cover;
    border: 1px solid var(--border-soft);
    background: var(--surface-alt);
    display: inline-block;
    vertical-align: middle;
}
.cmp-list-logo-empty {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
}

/* --- Pill-style checkbox group (used for multi-select link tables) -- */
.pill-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.25rem 0;
}
.pill-checkbox {
    margin: 0;
    cursor: pointer;
    user-select: none;
}
.pill-checkbox input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.pill-checkbox span {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    background: var(--surface);
    color: var(--anchor);
    border: 1px solid var(--border);
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.pill-checkbox:hover span {
    border-color: var(--accent-soft);
    background: var(--surface-alt);
}
.pill-checkbox input:checked + span {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
}
.pill-checkbox input:focus-visible + span {
    box-shadow: 0 0 0 0.15rem rgba(242, 199, 68, 0.35);
}
/* For long pill lists (e.g. dozens of ledgers), keep the form compact */
.pill-checkboxes-scroll {
    max-height: 200px;
    overflow-y: auto;
    padding: 0.5rem;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    background: var(--surface-alt);
}

/* --- FMS MultiPick — custom searchable multi-select with separate
       Available + Selected panels. Backed by a hidden <select multiple>
       so form submit and validation behave natively.

       Note: the underlying <select> is hidden by JS once init succeeds
       (see app.js, sets `.fms-multipick-hidden`). If JS fails to load,
       the browser falls back to the native multi-select control instead
       of leaving a void in the form. ----------------------------- */
.fms-multipick-hidden { display: none; }
.fms-multipick-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
}
.fms-multipick-wrap.is-disabled { opacity: 0.6; pointer-events: none; }

/* Search row */
.fms-multipick-search {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-soft);
    background: var(--surface-alt);
}
.fms-multipick-search input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.35rem 0.65rem;
    font-size: 0.92rem;
    background: var(--surface);
    color: var(--text);
}
.fms-multipick-search input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 0.15rem rgba(242, 199, 68, 0.25);
}
.fms-multipick-counter {
    color: var(--muted);
    font-size: 0.8rem;
    white-space: nowrap;
}

/* Available list */
.fms-multipick-available {
    max-height: 240px;
    overflow-y: auto;
    padding: 0.25rem 0;
}
.fms-multipick-available::-webkit-scrollbar { width: 8px; }
.fms-multipick-available::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.fms-multipick-available .fms-multipick-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.85rem;
    cursor: pointer;
    color: var(--text);
    font-size: 0.9rem;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    transition: background 100ms ease;
}
.fms-multipick-available .fms-multipick-row:hover,
.fms-multipick-available .fms-multipick-row:focus {
    background: rgba(242, 199, 68, 0.18);
    color: var(--anchor);
    outline: none;
}
.fms-multipick-available .fms-multipick-row .plus {
    color: var(--accent-ink);
    background: var(--accent);
    width: 18px; height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}
.fms-multipick-empty {
    padding: 1rem 0.85rem;
    color: var(--muted);
    font-size: 0.85rem;
    font-style: italic;
}

/* Selected panel */
.fms-multipick-selected {
    border-top: 1px solid var(--border-soft);
    background: var(--surface-alt);
    padding: 0.6rem 0.75rem;
}
.fms-multipick-selected-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--anchor);
}
.fms-multipick-selected-head .fms-multipick-clear {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    color: var(--muted);
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
}
.fms-multipick-selected-head .fms-multipick-clear:hover { color: var(--danger); text-decoration: underline; }
.fms-multipick-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    min-height: 28px;
}
.fms-multipick-chip {
    display: inline-flex;
    align-items: center;
    background: var(--accent);
    color: var(--accent-ink);
    border-radius: 999px;
    padding: 2px 0.4rem 2px 0.7rem;
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 1.4;
}
.fms-multipick-chip button {
    background: transparent;
    border: none;
    color: var(--accent-ink);
    margin-left: 0.25rem;
    padding: 0 0.25rem;
    border-radius: 50%;
    cursor: pointer;
    line-height: 1;
    opacity: 0.65;
    font-size: 1rem;
}
.fms-multipick-chip button:hover { opacity: 1; }
.fms-multipick-empty-selected {
    color: var(--muted);
    font-size: 0.85rem;
    font-style: italic;
}

/* --- FMS ImagePicker — drag-and-drop image upload widget ----------- */
.fms-imagepicker { width: 100%; max-width: 360px; }
.fms-imagepicker-zone {
    position: relative;
    border: 2px dashed var(--border);
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 120ms ease, background 120ms ease;
    min-height: 160px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.fms-imagepicker-zone:hover,
.fms-imagepicker-zone:focus-visible {
    border-color: var(--accent);
    background: rgba(242, 199, 68, 0.06);
    outline: none;
}
.fms-imagepicker-zone.is-dragover {
    border-color: var(--accent);
    border-style: solid;
    background: rgba(242, 199, 68, 0.12);
}
.fms-imagepicker-zone.is-busy { opacity: 0.7; cursor: progress; }

.fms-imagepicker-empty i.fa {
    font-size: 1.8rem;
    color: var(--muted);
    margin-bottom: 0.5rem;
    display: block;
}
.fms-imagepicker-hint  { color: var(--anchor); font-size: 0.95rem; }
.fms-imagepicker-hint strong { font-weight: 600; }
.fms-imagepicker-meta  { color: var(--muted); font-size: 0.78rem; margin-top: 0.35rem; }

.fms-imagepicker-preview {
    position: relative;
    display: inline-block;
}
.fms-imagepicker-preview img {
    max-width: 100%;
    max-height: 220px;
    border-radius: var(--radius);
    background: var(--surface-alt);
    border: 1px solid var(--border-soft);
}
.fms-imagepicker-remove {
    position: absolute;
    top: -10px; right: -10px;
    width: 26px; height: 26px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--danger);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    box-shadow: var(--shadow-sm);
    transition: background 120ms ease;
}
.fms-imagepicker-remove:hover { background: #FBE9E7; }

.fms-imagepicker-busy {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.7);
    border-radius: var(--radius-lg);
    color: var(--anchor);
    font-weight: 500;
}

/* --- Error pages ----------------------------------------------------- */
.error-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.error-card { max-width: 540px; width: 100%; }
.error-code {
    font-size: 4rem;
    font-weight: 700;
    color: var(--anchor);
    line-height: 1;
}
.error-code .accent { color: var(--accent); }

/* --- Responsive ------------------------------------------------------ */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
    }
    body.sidebar-open .app-sidebar {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }
    .app-main { margin-left: 0; }
}

/* Desktop: hamburger collapses the sidebar so the user can free up
   horizontal space. Same toggle button as mobile, JS picks the right
   class based on viewport. */
@media (min-width: 992px) {
    body.sidebar-collapsed .app-sidebar {
        transform: translateX(-100%);
    }
    body.sidebar-collapsed .app-main {
        margin-left: 0;
    }
}

@media (max-width: 767.98px) {
    .topbar-company .company-name { display: none; }
    .topbar-user .user-meta       { display: none !important; }
    .topbar-plan                   { font-size: 0.75rem; padding: 0.25rem 0.5rem; }
}

@media (max-width: 575.98px) {
    .app-content { padding: 1rem; }
    .app-topbar  { gap: 0.4rem; padding: 0 0.6rem; }
    .topbar-plan { display: none; }
    .topbar-brand span:not(.dot) { display: none; }
    .topbar-icon-btn,
    .topbar-toggle { width: 36px; height: 36px; }
}

/* --- Voucher truck-details table ------------------------------------ */
/* Many narrow columns (Truck | Trip | Route | Ledger | Rate | Qty | Ccy |
   ROE | Ccy amount | del). Give the table a floor width so its
   .table-responsive wrapper scrolls horizontally instead of squeezing
   every cell when the sidebar is open and the viewport is narrow. */
.voucher-td-table {
    min-width: 62rem;
}

/* --- FMS.LedgerPicker (AJAX typeahead) ------------------------------- */
.fms-ledger-picker {
    position: relative;
}
.fms-ledger-picker-wrap {
    position: relative;
}
.fms-ledger-picker-panel {
    /* `fixed` so the panel escapes ancestor `overflow: hidden/auto`
       (e.g. Bootstrap's .table-responsive). Coordinates are computed
       in JS from the input's getBoundingClientRect(). */
    position: fixed;
    z-index: 1050;
    max-height: 240px;
    overflow-y: auto;
    background: #FFF;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 0.25rem;
}
.fms-ledger-picker-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.4rem 0.6rem;
    background: transparent;
    border: 0;
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    font-size: 0.875rem;
}
.fms-ledger-picker-item:hover,
.fms-ledger-picker-item:focus {
    background: var(--surface-alt);
    outline: none;
}
.fms-ledger-picker-loading,
.fms-ledger-picker-empty {
    padding: 0.6rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-align: center;
}

/* --- Trailer-doc upload dropzone (Trailers sub-phase 2) -------------- */
.trailer-doc-dropzone {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface-alt);
    padding: 1.25rem 1rem;
    text-align: center;
    transition: border-color 120ms ease, background 120ms ease;
    cursor: pointer;
    min-height: 96px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.trailer-doc-dropzone:hover,
.trailer-doc-dropzone.is-drag {
    border-color: var(--accent);
    background: #FFF;
}
.trailer-doc-dropzone.has-file {
    border-style: solid;
    background: #FFF;
}
.trailer-doc-fileinput {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}
.trailer-doc-dropzone-empty {
    pointer-events: none;
    color: var(--text-muted);
}
.trailer-doc-dropzone-icon {
    font-size: 1.6rem;
    color: var(--accent);
    margin-bottom: 0.25rem;
    display: block;
}
.trailer-doc-dropzone-link {
    color: var(--anchor);
    text-decoration: underline;
}
.trailer-doc-dropzone-filled {
    z-index: 1;
    color: var(--text);
    font-weight: 500;
}
.trailer-doc-fname {
    word-break: break-all;
}
.trailer-doc-clear {
    margin-left: 0.5rem;
    text-decoration: none;
}

/* ------------------------------------------------------------------
   Print — strip the app chrome so pages like the ledger statement
   print as a clean document instead of the on-screen app (sidebar,
   topbar, scrollbars). Mark any page control you don't want on paper
   with Bootstrap's `d-print-none`. `.table-responsive` is un-clipped
   so long tables print in full, not just the scrolled-into-view slice.
   ------------------------------------------------------------------ */
@media print {
    .app-sidebar,
    .app-topbar,
    .app-footer,
    .app-flash { display: none !important; }

    body.app-shell { background: #fff !important; }

    /* Content occupies the full page once the sidebar is gone. */
    .app-main    { margin-left: 0 !important; }
    .app-content { padding: 0 !important; max-width: none !important; }

    /* Don't clip inside scroll containers — print the whole table. */
    .table-responsive { overflow: visible !important; }

    /* Avoid splitting rows / cards across page breaks. */
    thead      { display: table-header-group; }
    tr, .card  { page-break-inside: avoid; }
    .card      { border: 1px solid #ddd; box-shadow: none !important; }
}
