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