/* ==========================================================================
   UI refresh - pipeline toolbar "more" menu,
   tablet board grid, stage accents, Brief "Needs you today".
   Controls stay flat (no shadow / transform / gradient). Cards may sit on --shadow-sm.
   Loaded after style_essence.css and dark-mode.css; behaviour lives in js/ui_refresh.js.
   ========================================================================== */

/* ---------- Pipeline toolbar ---------- */
#view-pipeline .macos-toolbar-group > button:not(.pl-more-btn),
#view-pipeline #btn-pipeline-avail-mobile,
#view-pipeline button[title="Insights"],
#view-pipeline button[title="Archive Completed"] { display: none !important; }
.pl-more-btn { position: relative; }
.pl-more-btn .pl-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--secondary-color, #E88D78);
    border: 2px solid var(--bg-card, #fff);
}
.pl-more-btn .pl-dot[hidden] { display: none; }
#view-pipeline .macos-segmented-control button { display: inline-flex; align-items: center; gap: 6px; }
#view-pipeline .macos-segmented-control .seg-lbl { font-size: 0.75rem; font-weight: 600; }
@media (max-width: 1279px) { #view-pipeline .macos-segmented-control .seg-lbl { display: none; } }

/* ---------- Popover menu (pipeline "more", quick add on phones) ---------- */
.ui-menu {
    position: fixed;
    z-index: 1200;
    min-width: 220px;
    max-width: calc(100vw - 24px);
    padding: 6px;
    border-radius: 14px;
    border: 1px solid var(--border-strong, #e2e8f0);
    background: var(--bg-card, #fff);
    box-shadow: var(--shadow-md, 0 8px 24px rgba(15, 23, 42, .12));
}
.ui-menu button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    min-height: 44px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-primary, #1f2937);
    font-size: 0.85rem;
    font-weight: 500;
    text-align: left;
    transition: background-color .15s ease;
}
.ui-menu button:hover, .ui-menu button:focus-visible { background: var(--primary-light, #f0f7ec); outline: none; }
.ui-menu button .ui-menu-badge {
    margin-left: auto;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    background: var(--secondary-color, #E88D78);
}

/* ---------- Board: stage accents, late chips, tablet grid ---------- */
#colhead-Inquiry { border-top: 3px solid var(--ocean, #8FB8CA); }
#colhead-Scheduled { border-top: 3px solid var(--sun, #ECD489); }
#colhead-InProgress { border-top: 3px solid var(--clay, #EBA07E); }
#colhead-Completed { border-top: 3px solid var(--primary-color, #97B881); }
.pl-late-chip {
    flex-shrink: 0;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 0.625rem;
    font-weight: 700;
    white-space: nowrap;
    color: var(--secondary-dark, #d67560);
    background: var(--secondary-light, #fdf2f0);
    border: 1px solid var(--secondary-color, #E88D78);
}
html.dark .pl-late-chip { background: rgba(232, 141, 120, .15); color: #f2b3a5; }

/* tablets / small laptops: 2 x 2 grid instead of a sideways strip */
@media (min-width: 768px) and (max-width: 1279px) {
    #view-pipeline:not(.plm-phone) #pipeline-board {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-auto-rows: minmax(300px, 1fr);
        overflow-x: hidden !important;
        overflow-y: auto;
        scroll-snap-type: none !important;
        gap: 12px;
        padding-bottom: 16px;
    }
    #view-pipeline:not(.plm-phone) #pipeline-board .pipeline-col {
        min-width: 0 !important;
        max-width: none !important;
        width: auto !important;
        height: auto !important;
        max-height: 520px;
    }
    #view-pipeline:not(.plm-phone) #pipeline-prev,
    #view-pipeline:not(.plm-phone) #pipeline-next { display: none !important; }
}

/* ---------- Brief: Needs you today ---------- */
#brief-needs-today { margin: 8px 0 24px; }
.nyt-card {
    padding: 16px 20px;
    border-radius: 20px;
    border: 1px solid var(--border-strong, #e2e8f0);
    background: var(--bg-card, #fff);
    box-shadow: var(--shadow-sm, 0 1px 3px rgba(15, 23, 42, .06));
}
.nyt-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.nyt-head h2 { margin: 0; font-family: var(--font-heading, 'Quicksand', sans-serif); font-size: 1.05rem; font-weight: 700; color: var(--text-primary, #1f2937); }
.nyt-head .nyt-sub { font-size: 0.75rem; color: var(--text-muted, #9ca3af); }
.nyt-list { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.nyt-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    min-height: 52px;
    border-radius: 14px;
    border: 1px solid var(--border-color, #f1f5f9);
    background: var(--primary-50, #f7f9f5);
    text-align: left;
    color: var(--text-primary, #1f2937);
    transition: background-color .15s ease, border-color .15s ease;
}
.nyt-row:hover { border-color: var(--primary-color, #97B881); background: var(--primary-light, #f0f7ec); }
.nyt-tag { flex-shrink: 0; min-width: 34px; padding: 0 8px; height: 34px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; font-size: .7rem; font-weight: 700; }
.nyt-tag.today { background: var(--primary-light, #f0f7ec); color: var(--primary-dark, #7da066); }
.nyt-tag.late { background: var(--secondary-light, #fdf2f0); color: var(--secondary-dark, #d67560); }
.nyt-tag.money { background: var(--sun-light, #FBF7E6); color: var(--sun-dark, #C5AF6B); }
.nyt-tag.req { background: var(--ocean-light, #E8F3F8); color: var(--ocean-dark, #6D94A6); }
.nyt-main { min-width: 0; flex: 1; }
.nyt-main b { display: block; font-size: .85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nyt-main span { display: block; font-size: .72rem; color: var(--text-muted, #9ca3af); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nyt-clear { padding: 4px 0; font-size: .85rem; color: var(--text-secondary, #4b5563); }

/* ---------- Dark mode ---------- */
html.dark .ui-menu, html.dark .nyt-card { background: var(--dark-card, #1e293b); border-color: var(--dark-border, #334155); }
html.dark .ui-menu button, html.dark .nyt-row, html.dark .nyt-head h2 { color: #f1f5f9; }
html.dark .ui-menu button:hover { background: rgba(151, 184, 129, .15); }
html.dark .nyt-row { background: rgba(255, 255, 255, .03); border-color: var(--dark-border, #334155); }
html.dark .nyt-row:hover { background: rgba(151, 184, 129, .12); }
html.dark .pl-more-btn .pl-dot { border-color: var(--dark-card, #1e293b); }

@media (max-width: 767px) {
    .nyt-card { padding: 14px; border-radius: 16px; }
}
@media (prefers-reduced-motion: reduce) {
    .ui-menu, .nyt-row { transition: none; }
}

/* ==========================================================================
   Pipeline header (option A): actions inline with the title on phones, and the
   search field morphs over that row instead of stacking under an icon bar.
   Controls stay flat: no shadow / gradient / transform on buttons.
   ========================================================================== */

/* --- clear button (desktop + phone) --- */
#view-pipeline .pl-search-clear {
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: rgba(100, 116, 139, .13);
    color: #64748b;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}
#view-pipeline .pl-search-clear svg { width: 13px; height: 13px; }
/* 44px tap target without enlarging the 24px dot */
#view-pipeline .pl-search-clear::after {
    content: "";
    position: absolute;
    inset: -10px;
    border-radius: 999px;
}
#view-pipeline .pl-search-input:not(:placeholder-shown) ~ .pl-search-clear { display: inline-flex; }
#view-pipeline .pl-search-clear:hover { background: rgba(100, 116, 139, .22); color: #334155; }

/* --- the field itself --- */
/* The app's global input skin (border + gradient + inset shadow) must not draw a
   second box inside the search pill; the pill is the field. */
#view-pipeline .pl-search-input,
#view-pipeline .pl-search-input:focus {
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    outline: none !important;
}
/* keep the text clear of the magnifier and the clear button at every width
   (the global responsive input padding overrides pl-10 / pr-9) */
#view-pipeline #pipelineSearch {
    padding: 0 2.25rem 0 2.75rem !important;
}
#view-pipeline #pipelineSearch::placeholder {
    font-size: .85rem;
}
/* no clear button while empty: give the placeholder the space back */
#view-pipeline #pipelineSearch:placeholder-shown {
    padding-right: .75rem !important;
}

/* --- Cancel: phone only, next to the field, 44px tall --- */
#view-pipeline .pl-search-cancel {
    display: none;
    flex: 0 0 auto;
    min-width: 0;
    min-height: 0;
    height: 44px;
    padding: 0 2px 0 10px;
    border: 0;
    background: transparent;
    color: var(--primary-dark, #7da066);
    font-family: inherit;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    transition: color .15s ease;
}
#view-pipeline .pl-search-cancel:hover { color: var(--primary-color, #97B881); }

@media (max-width: 767px) {
    /* the header is the morph surface: the toolbar wrapper keeps zero height */
    #view-pipeline .section-page-header,
    #view-pipeline.plm-phone .section-page-header { gap: 0; }

    /* the decorative proxy badge costs 41px of the one row; the title is the content */
    #view-pipeline.plm-phone .section-page-header .macos-proxy-badge,
    #view-pipeline .section-page-header .macos-proxy-badge { display: none !important; }

    #view-pipeline .section-page-header > .pl-actions {
        position: static;
        width: 0;
        height: 0;
        min-height: 0;
        padding: 0;
        margin: 0;
    }

    #view-pipeline .pl-title-wrap { flex: 1 1 auto; min-width: 0; }
    #view-pipeline .pl-title-row { gap: 4px; min-width: 0; transition: opacity .16s ease, transform .22s ease; }
    #view-pipeline .pl-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #view-pipeline.plm-phone .pl-title-row h2,
    #view-pipeline .pl-title-row h2 { font-size: 1rem; }

    #view-pipeline .pl-hd-actions {
        display: flex;
        align-items: center;
        gap: 4px;
        margin-left: auto;
        flex: 0 0 auto;
    }

    #view-pipeline .pl-hd-btn {
        position: relative;
        width: 40px;
        height: 44px;
        min-width: 40px;
        min-height: 44px;
        padding: 0;
        border: 1px solid transparent;
        border-radius: 11px;
        background: transparent;
        color: #64748b;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        box-shadow: none;
        transition: background-color .15s ease, border-color .15s ease, color .15s ease;
    }
    #view-pipeline .pl-hd-btn svg { width: 18px; height: 18px; }
    #view-pipeline .pl-hd-btn:hover,
    #view-pipeline .pl-hd-btn[aria-expanded="true"] {
        background: var(--primary-light, #f0f7ec);
        border-color: var(--primary-color, #97B881);
        color: var(--primary-dark, #7da066);
    }
    #view-pipeline .pl-hd-add,
    #view-pipeline .pl-hd-btn.pl-hd-add {
        background: var(--primary-color, #97B881);
        border-color: var(--primary-dark, #7da066);
        color: #fff;
    }
    #view-pipeline .pl-hd-add:hover,
    #view-pipeline .pl-hd-btn.pl-hd-add:hover {
        background: var(--primary-dark, #7da066);
        border-color: var(--primary-dark, #7da066);
        color: #fff;
    }
    #view-pipeline .pl-hd-dot {
        position: absolute;
        top: 7px;
        right: 7px;
        width: 8px;
        height: 8px;
        border-radius: 999px;
        background: var(--secondary-color, #E88D78);
        border: 2px solid var(--bg-card, #fff);
    }
    #view-pipeline .pl-hd-dot[hidden] { display: none; }

    /* one button, three view icons: only the current view shows */
    #view-pipeline #pl-mobile-view svg { display: none; }
    #view-pipeline #pl-mobile-view[data-view="board"] svg[data-v="board"],
    #view-pipeline #pl-mobile-view[data-view="calendar"] svg[data-v="calendar"],
    #view-pipeline #pl-mobile-view[data-view="today"] svg[data-v="today"] { display: block; }

    /* title row fades out, search takes its place (no reflow either way) */
    #view-pipeline .section-page-header.pl-searching .pl-title-row {
        opacity: 0;
        transform: translateX(-10px);
        pointer-events: none;
    }

    #view-pipeline #pipeline-search-container {
        position: absolute;
        left: .75rem;
        right: .75rem;
        top: 50%;
        transform: translateY(-50%);
        width: auto;
        min-width: 0;
        max-width: none !important;
        margin: 0;
        padding: 0;
        display: none;
        opacity: 0;
        z-index: 6;
        align-items: center;
        gap: 0;
        transition: opacity .16s ease;
    }
    #view-pipeline .section-page-header.pl-searching #pipeline-search-container {
        display: flex;
        opacity: 1;
    }
    #view-pipeline .pl-search-shell { width: auto; flex: 1 1 auto; min-width: 0; }
    #view-pipeline #pipelineSearch {
        height: 38px;
        min-height: 0;
        padding-top: 0;
        padding-bottom: 0;
        font-size: 16px !important; /* below 16px iOS zooms the page on focus */
    }
    #view-pipeline .pl-search-cancel { display: inline-flex; align-items: center; }
}

/* --- dark --- */
html.dark #view-pipeline .pl-hd-btn {
    background: transparent !important;
    border-color: transparent !important;
    color: var(--dark-text-secondary) !important;
}
html.dark #view-pipeline .pl-hd-btn:hover,
html.dark #view-pipeline .pl-hd-btn[aria-expanded="true"] {
    background: rgba(168, 204, 143, .16) !important;
    border-color: rgba(168, 204, 143, .38) !important;
    color: var(--dark-primary) !important;
}
html.dark #view-pipeline .pl-hd-add {
    background: var(--dark-primary) !important;
    border-color: var(--dark-primary) !important;
    color: #10150d !important;
}
html.dark #view-pipeline .pl-hd-add:hover {
    background: #b9dda1 !important;
    border-color: #b9dda1 !important;
    color: #10150d !important;
}
html.dark #view-pipeline .pl-hd-dot { border-color: var(--dark-card, #20252a); }
html.dark #view-pipeline .pl-search-clear {
    background: rgba(255, 255, 255, .12) !important;
    border-color: transparent !important;
    color: var(--dark-text-secondary) !important;
}
html.dark #view-pipeline .pl-search-cancel {
    background: transparent !important;
    border-color: transparent !important;
    color: var(--dark-primary) !important;
}

/* ==========================================================================
   MOBILE POLISH (<=768px)
   Lives here, not in style_essence.css: that file is at its size budget, and
   this sheet loads after it, so these rules win over the five legacy
   `.tab-content` / `input` overrides without a specificity war.
   ========================================================================== */
@media (max-width: 768px) {
    /* 1. Clearance for the floating bottom dock. Several views still carried the
          legacy 1rem bottom padding, so their last row scrolled under the nav.
          Two class-level parts so it outranks `.tab-content.p-4` (the legacy
          retail-theme rule that re-sets padding to 1rem with !important). */
    .app-shell-main > .tab-content {
        padding-bottom: calc(5.75rem + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* 2. Icon-prefixed inputs. The global touch normaliser in style_essence.css
          forces `padding: 12px 16px`, so an absolutely-positioned search icon sat
          on top of the placeholder (Client Records sticky search was unreadable).
          Restore the padding the markup asked for via its own utility class. */
    input.pl-8 { padding-left: 2rem !important; }
    input.pl-9 { padding-left: 2.25rem !important; }
    input.pl-10 { padding-left: 2.5rem !important; }
    input.pr-8 { padding-right: 2rem !important; }
    input.pr-9 { padding-right: 2.25rem !important; }
    input.pr-10 { padding-right: 2.5rem !important; }

    /* 3. Console action deck: "Calculate Numerology" never fits beside Reset in
          a 390px deck and clipped mid-word. Mobile shows "Calculate". */
    #calculatorForm .crm-calc-btn span + span { display: none !important; }

    /* 4. Lo-Shu tab strip wraps to two rows; the lone third tab now fills its
          row instead of sitting orphaned in the middle. */
    #view-loshu .macos-segmented-control > button { flex: 1 1 auto; }
}

/* 5. Narrow phones. At 360px the logo + 5 header actions were 2px wider than
      the screen (avatar clipped); at 320px (iPhone SE 1st gen, iOS Display
      Zoom) the account avatar sat 42px outside the viewport, unreachable. */
@media (max-width: 400px) {
    .app-shell-mobile-header {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
}

@media (max-width: 359px) {
    .app-shell-mobile-header {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }

    #navbarLogoMobile {
        max-width: 96px;
    }

    #mobile-btn-load,
    #mobile-notification-bell,
    #mobile-dark-mode-toggle,
    .app-shell-mobile-header button[aria-label="Search"] {
        min-width: 38px !important;
        min-height: 38px !important;
        padding: 0.25rem !important;
    }
}

/* ==========================================================================
   SYNC CENTER ENTRY (Account Center)
   The mobile top bar dropped its sync button; the Account Center header now
   carries it, and the "N pending" dot moved to the header icon plus the avatar
   that opens the sheet (js/sync_center.js updateBadge sets both).
   ========================================================================== */
.acx-sync-btn {
    position: relative;
}

.acx-dot {
    position: absolute;
    top: 0.375rem;
    right: 0.375rem;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #f59e0b;
    box-shadow: 0 0 0 2px var(--acx-surface, #fff);
    pointer-events: none;
}

#mobile-user-status {
    position: relative;
}

#mobile-user-status.has-sync-pending::after {
    content: '';
    position: absolute;
    top: -1px;
    right: -1px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #f59e0b;
    border: 1.5px solid #fff;
    pointer-events: none;
}

html.dark #mobile-user-status.has-sync-pending::after {
    border-color: var(--dark-surface, #1b1f23);
}

/* ==========================================================================
   CLIENT RECORDS — mobile card list
   The phone list read uneven: cards with an alert chip (birthday / new /
   follow-up) grew a row taller than the rest, the five actions sat in a
   ragged row with ~18px holes between them, and the list was inset 24px per
   side while the search bar above it ran edge to edge. Everything below
   applies to the card view only (table view keeps its own layout).
   ========================================================================== */
@media (max-width: 767px) {
    /* one gutter: record cards line up with the filter bar above them */
    #historyContainer.history-view-cards,
    #historyContainer.history-view-cards #historyCards {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    #historyCards {
        gap: 0.5rem !important;
        padding-top: 0 !important;
    }

    #historyCards .hc-card {
        padding: 0.6rem 0.7rem;
        /* cards are a fixed 120px tall on a phone; keep the scrollbar estimate
           in step so long lists don't jump as rows come into view */
        contain-intrinsic-size: auto 120px;
    }

    /* name + B/L/D on one line, always: long names ellipsis instead of
       pushing the chips onto a second row */
    #historyCards .hc-l1 {
        flex-wrap: nowrap;
        gap: 0.35rem;
    }

    #historyCards .hc-name {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* meta + alert chips share the second line, chips pinned right */
    #historyCards .hc-l2 {
        flex-wrap: nowrap;
        overflow: hidden;
        gap: 0.3rem;
        margin-top: 0.15rem;
        min-height: 1.0625rem;
    }

    /* one chip height for every card, so a birthday/follow-up badge can no
       longer make its card a few pixels taller than the rest */
    #historyCards .hc-chip {
        height: 1.0625rem;
        padding: 0 0.3rem;
    }

    #historyCards .hc-meta {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #historyCards .hc-chips {
        margin-left: auto;
        flex-shrink: 0;
    }

    /* actions: five equal cells instead of a ragged auto-width row */
    #historyCards .hc-card-foot {
        margin-top: 0.45rem;
        padding-top: 0.45rem;
    }

    #historyCards .hc-card-actions {
        display: grid;
        grid-template-columns: repeat(5, 2.75rem);
        justify-content: space-between;
        gap: 0.375rem;
        width: 100%;
        margin-left: 0;
    }

    #historyCards .history-action-btn {
        width: 2.75rem;
        min-width: 2.75rem;
        height: 2.75rem;
    }
}

/* ==========================================================================
   ACCOUNT CENTER FIELDS
   Same metrics as the CRM's canonical `.ess-input` (Console, Records, modals):
   the Account Center fields carried their own 44px/10px-padding recipe, which
   read 4px taller than every other field on desktop and 6px taller on mobile.
   Dark colours stay in css/dark-mode.css (also covers html.dark .acx-field).
   ========================================================================== */
.acx-field input,
.acx-field select,
.acx-field textarea {
    width: 100%;
    min-height: 2.5rem;          /* 40px, like .ess-input */
    padding: 0.55rem 0.75rem;
    font-size: 0.85rem;
    line-height: 1.35;
    border-radius: 0.625rem;     /* 10px, like .ess-input */
}

/* The read-only metadata rows (username / role / DOB / member since) carry no
   value until an account is loaded (local mode, or the first second after open),
   which left four label-only rows and a stray divider inside the card. */
.acx-dl > div:has(> dd:empty) { display: none; }
.acx-dl:not(:has(dd:not(:empty))) { display: none; }

@media (max-width: 768px) {
    /* Account Center fields are sized by css/form_density.css (44px touch
       height, 16px font). Only the row layout is app-specific. */

    /* The sheet's own row rule stretched every trailing control to the full
       width, turning the on/off switch into a 300px bar and each row action
       into its own line. Keep the controls at their natural size, as on
       desktop; the row still wraps when the text needs the space. */
    .acx-row .acx-act {
        width: auto;
    }

    .acx-row .acx-act .acx-btn {
        flex: 0 1 auto;
    }

    /* The switch label also carries .acx-act, so the rule above collapsed it to
       0px; give it back its own 40x22 size (it used to stretch to full width). */
    .acx-row .acx-act.ac-toggle {
        width: 40px;
        flex: 0 0 40px;
    }
}
