/* Entity Manager IV (mobile/PWA) -- a unified, pinnable master-detail browser
   for Contacts and Vendors. Additive: reuses entity-detail.css for the shared
   modal + picker; this file styles only the EM IV shell (toggle, list, detail).
   Mobile-first single column; two columns side-by-side at >= 900px. */

body { background: #F2F2F4; }

.page-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ----- Controls row (type toggle + filter + new) ----- */
.emiv-controls {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #fff;
    border-bottom: 1px solid #e3e3e8;
    flex-wrap: wrap;
}

.emiv-toggle {
    display: inline-flex;
    border: 1px solid #4F46E5;
    border-radius: 8px;
    overflow: hidden;
}
.emiv-pill {
    background: #fff;
    color: #4F46E5;
    border: 0;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.emiv-pill.active {
    background: #4F46E5;
    color: #fff;
}

/* Sort toggle -- same look as the type toggle, slightly tighter. */
.emiv-sort {
    display: inline-flex;
    border: 1px solid #4F46E5;
    border-radius: 8px;
    overflow: hidden;
}
.emiv-sortpill {
    background: #fff;
    color: #4F46E5;
    border: 0;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.emiv-sortpill.active {
    background: #4F46E5;
    color: #fff;
}

.emiv-search {
    flex: 1 1 180px;
    min-width: 140px;
    padding: 9px 12px;
    font-size: 16px;            /* 16px keeps iOS from zooming on focus */
    border: 1px solid #c8c8d0;
    border-radius: 8px;
}

.emiv-new {
    flex: 0 0 auto;
    background: #4F46E5;
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

/* Filters show/hide toggle -- a small unlabeled funnel icon in the always-visible
   top controls row, so it costs almost no width and never wraps the +New button.
   It fills indigo when the filters row is open, outline when collapsed. */
.emiv-filterstoggle {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    padding: 0;
    background: #fff;
    color: #4F46E5;
    border: 1px solid #4F46E5;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.emiv-filterstoggle.open { background: #4F46E5; color: #fff; }
.emiv-ft-icon { display: block; }

/* ----- Filters row (type filter + sort + vendor filters + clear) ----- */
.emiv-filters {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: #fafafb;
    border-bottom: 1px solid #e3e3e8;
    flex-wrap: wrap;
}
.emiv-filters.collapsed { display: none; }

.emiv-filter-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.emiv-flabel {
    font-size: 13px;
    font-weight: 600;
    color: #4F46E5;
}
/* Keep the type-filter picker a sensible width inside the row. */
.emiv-typewrap {
    width: 220px;
    max-width: 56vw;
}

.emiv-vfilters {
    display: inline-flex;
    align-items: center;
    gap: 14px;
}
.emiv-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #333;
    cursor: pointer;
}
.emiv-check input { width: 16px; height: 16px; }

/* Clear rides on the Type-filter line -- never let it wrap onto a row of its
   own, which burned a full row of vertical space on the phone. */
.emiv-clear {
    flex: 0 0 auto;
    background: #fff;
    color: #4F46E5;
    border: 1px solid #4F46E5;
    border-radius: 8px;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

/* Story 5715: Search in -- a link on the filters row (All view only) that opens the
   window of kinds a search looks in. Bold when it narrows the search. */
.emiv-searchin-wrap { display: inline-flex; align-items: center; }
.emiv-searchin {
    background: none;
    border: 0;
    padding: 6px 2px;
    color: #4F46E5;
    font-size: 13px;
    text-decoration: underline;
    cursor: pointer;
}
.emiv-searchin.emiv-searchin-on { font-weight: 700; }

/* ----- Body: master + detail ----- */
.emiv-body {
    flex: 1 1 auto;
    display: flex;
    overflow: hidden;
}

.emiv-master {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.emiv-count {
    flex: 0 0 auto;
    padding: 6px 12px;
    font-size: 12px;
    color: #777;
    background: #fafafb;
    border-bottom: 1px solid #eee;
}

.emiv-list {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.emiv-row {
    display: block;
    width: 100%;
    text-align: left;
    background: #fff;
    border: 0;
    border-bottom: 1px solid #eee;
    padding: 12px 14px;
    cursor: pointer;
}
.emiv-row:hover { background: #f5f5fb; }
.emiv-row.selected { background: #eceaff; }
.emiv-row .name { font-size: 15px; color: #1a1a1a; }
.emiv-row .sub  { font-size: 12px; color: #888; margin-top: 2px; }

.emiv-loading, .emiv-empty {
    padding: 24px 14px;
    color: #999;
    text-align: center;
}

/* Detail: hidden on phones until a record is tapped (no empty gray pane). */
.emiv-detail {
    flex: 1 1 auto;
    overflow-y: auto;
    display: none;
    background: #fff;
}
body.emiv-show-detail .emiv-master { display: none; }
body.emiv-show-detail .emiv-detail { display: block; }

.emiv-detail-band {
    background: #4F46E5;
    color: #fff;
    padding: 12px 16px;
    font-size: 17px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
}
.emiv-back {
    background: rgba(255,255,255,0.18);
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
}

/* Story 3504: Needs attention | Details -- a strip that exists only while
   something needs attention. Amber tab = the signal; Details opens first. */
.emiv-dtabs { display: flex; gap: 0; border-bottom: 1px solid #E4E4EA; padding: 0 8px; }
.emiv-dtabs[hidden], [data-dpane][hidden] { display: none; }
.emiv-dtab {
    background: transparent;
    border: 0;
    border-bottom: 3px solid transparent;
    padding: 10px 14px;
    font-size: 14px;
    color: #555;
    cursor: pointer;
    white-space: nowrap;
}
.emiv-dtab.active { color: #1a1a1a; border-bottom-color: #4F46E5; font-weight: 600; }
.emiv-dtab.attn { color: #8A5A00; font-weight: 600; }
.emiv-dtab.attn.active { border-bottom-color: #E0A52B; }
.emiv-attention { padding: 12px 12px 4px; }
.emiv-attention .ed-attn { margin: 0; }

.emiv-fields { padding: 12px 16px; }
.emiv-field {
    display: flex;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}
.emiv-field .lbl { flex: 0 0 130px; color: #777; font-size: 13px; }
.emiv-field .val { flex: 1 1 auto; color: #1a1a1a; font-size: 14px; }

.emiv-detail-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding: 14px 16px;
}
.emiv-btn {
    background: #4F46E5;
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}
.emiv-btn.secondary {
    background: #fff;
    color: #4F46E5;
    border: 1px solid #4F46E5;
}
/* White text on the site-wide button:hover gray (picasso-base.css) washed out (Story 5645). */
.emiv-btn:hover, .emiv-btn:active, .emiv-new:hover, .emiv-new:active { background: #4338CA; }
.emiv-btn.secondary:hover, .emiv-btn.secondary:active { background: #EEF0FF; }

.emiv-detail-hint {
    padding: 40px 24px;
    color: #999;
    text-align: center;
    font-size: 14px;
}

/* Wide screens: master and detail side-by-side, both always visible. */
@media (min-width: 900px) {
    .emiv-master {
        flex: 0 0 360px;
        border-right: 1px solid #e0e0e6;
    }
    .emiv-detail { display: block; }
    body.emiv-show-detail .emiv-master { display: flex; }
    .emiv-back { display: none; }   /* no back button when both panes show */
}

/* Open matters on the selected record (Story 2464). Rendered only when there
   are some -- an empty "Open matters" heading is dead real estate. */

/* Icons-only type toggle (Story 2464 rework): five types no longer fit as
   words on a phone. The SVGs draw with currentColor, so the active pill's
   white-on-indigo flip needs no extra rules. */
.emiv-pill { padding: 8px 13px; line-height: 0; }
.emiv-pill svg { display: block; }

/* The type band stays one clean row. It never shrinks below its pills and
   never grows past the row; the pills that do not fit (a phone) are hidden
   by fitPills() in the JS and listed in the More menu instead. */
.emiv-toggle { flex-shrink: 0; max-width: 100%; }
.emiv-pill.emiv-overflowed { display: none; }
.emiv-morebtn {
    display: none;
    background: #fff;
    color: #4F46E5;
    border: 0;
    border-left: 1px solid #e3e3e8;
    padding: 8px 11px;
    line-height: 0;
    cursor: pointer;
}
.emiv-morebtn.shown { display: block; }
.emiv-morebtn[aria-expanded="true"] { background: #eeedfd; }
.emiv-morebtn svg { display: block; }

/* The More menu: fixed under the More button, placed by openMore(). */
.emiv-moremenu {
    display: none;
    position: fixed;
    z-index: 1000;
    min-width: 200px;
    background: #fff;
    border: 1px solid #d8d8e0;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
    padding: 4px 0;
}
.emiv-moremenu.open { display: block; }
.emiv-moreitem {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 11px 16px;
    background: none;
    border: 0;
    color: #333;
    font-size: 15px;
    text-align: left;
    cursor: pointer;
}
.emiv-moreitem svg { flex: 0 0 auto; color: #4F46E5; }
.emiv-moreitem:hover, .emiv-moreitem:active { background: #f3f2fd; }

/* Story 3476: the list is paged. This sits under the last loaded row and
   pulls the next page in; scrolling near the bottom does the same thing. */
.emiv-loadmore {
    display: block;
    width: 100%;
    padding: 12px 14px;
    background: #fafafb;
    border: 0;
    border-top: 1px solid #eee;
    color: #5a4fcf;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
}
.emiv-loadmore:hover { background: #f0eefc; }
.emiv-loadmore:disabled { color: #999; cursor: default; }
