/**
 * src/css/pages/index.css — Projects hub (project selection), premium pass.
 * Owns: index.html only. Consumes tokens from design-system.css.
 * Loaded LAST (after inline <style> and dobo2 links) so it wins equal/low
 * specificity ties. Purely additive classes (.pc-*) + high-specificity card
 * override; nothing JS references is renamed or removed.
 */

/* ── Page header refinement ─────────────────────────────────────────────── */
#projectGrid {
    /* give the grid a touch more air on desktop */
    gap: var(--sp-6);
    /* Responsive 3/2/1 grid (card min 320px). Mirrors the existing Tailwind
       breakpoints already on the element (grid-cols-1 sm:grid-cols-2
       lg:grid-cols-3) but adds a minmax(320px,…) floor per column so a
       column never gets squeezed thinner than 320px — falls back to fewer
       columns instead via the media queries below rather than an unbounded
       auto-fill (which would add a 4th+ column on very wide monitors,
       beyond the requested 3/2/1 cap). */
    display: grid;
    grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 640px) {
    #projectGrid { grid-template-columns: repeat(2, minmax(320px, 1fr)); }
}
@media (min-width: 1024px) {
    #projectGrid { grid-template-columns: repeat(3, minmax(320px, 1fr)); }
}

/* ── Empty state (no projects / no search results) ──────────────────────── */
.pc-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: var(--sp-16) var(--sp-4);
    color: var(--text-3);
    text-align: center;
}
.pc-empty .material-symbols-outlined {
    font-size: 40px;
    color: var(--text-4);
    margin-bottom: var(--sp-1);
}
.pc-empty p:first-of-type {
    font-size: var(--fs-16);
    font-weight: 600;
    color: var(--text-2);
}
.pc-empty p:last-of-type {
    font-size: var(--fs-13);
    color: var(--text-3);
}

/* ── Project card — the hero element ────────────────────────────────────── */
@keyframes pc-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

#projectGrid > div.project-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    padding: var(--sp-4);                    /* consistent 16px padding */
    min-height: 172px;                       /* uniform card height */
    background: var(--bg-card);
    border: 1px solid var(--surface-200);
    border-radius: var(--r-xl);              /* 16px */
    box-shadow: var(--sh-sm);
    cursor: pointer;
    /* NOTE: intentionally NOT overflow:hidden — the ⋮ dropdown (a descendant
       of the footer's .pc-menu-wrap) must be able to render outside the
       card bounds. The hover accent bar below fakes the clipped-corner look
       via its own border-radius instead of relying on card overflow. */
    animation: pc-in var(--dur-3) var(--ease-out) both;
    transition: box-shadow var(--dur-2) var(--ease-std),
                transform var(--dur-2) var(--ease-std),
                border-color var(--dur-2) var(--ease-std);
}
/* Staggered entrance */
#projectGrid > div.project-card:nth-child(1) { animation-delay: 0ms; }
#projectGrid > div.project-card:nth-child(2) { animation-delay: 45ms; }
#projectGrid > div.project-card:nth-child(3) { animation-delay: 90ms; }
#projectGrid > div.project-card:nth-child(4) { animation-delay: 135ms; }
#projectGrid > div.project-card:nth-child(5) { animation-delay: 180ms; }
#projectGrid > div.project-card:nth-child(6) { animation-delay: 225ms; }

/* Amber accent edge that slides in on hover (left) */
#projectGrid > div.project-card::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    border-radius: var(--r-xl) 0 0 var(--r-xl); /* fakes the clipped-corner
        look now that the card itself isn't overflow:hidden (see note above
        the card rule) */
    background: linear-gradient(180deg, var(--amber-400), var(--amber-600));
    transform: scaleY(0);
    transform-origin: top;
    transition: transform var(--dur-2) var(--ease-out);
}
#projectGrid > div.project-card:hover {
    box-shadow: 0 4px 6px rgba(15,23,42,0.07), 0 24px 50px rgba(2,36,72,0.16);
    transform: translateY(-4px);
    border-color: var(--navy-200);
}
#projectGrid > div.project-card:hover::before { transform: scaleY(1); }
#projectGrid > div.project-card:active { transform: translateY(-1px) scale(0.99); }
#projectGrid > div.project-card:focus-visible {
    outline: 2px solid var(--amber-500);
    outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
    #projectGrid > div.project-card { animation: none; }
}

/* ── Card top row: avatar left · name (single-line ellipsis) ───────────── */
.pc-top {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    min-width: 0; /* allow child ellipsis to work inside flex */
}
.pc-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--navy-500), var(--navy-400));
    color: #ffffff;
    font-size: var(--fs-18);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: var(--sh-sm);
    transition: transform var(--dur-2) var(--ease-std);
}
#projectGrid > div.project-card:hover .pc-icon { transform: scale(1.05); }

/* ── Project name — larger, single-line ellipsis (never wraps/collides) ── */
.pc-name {
    margin: 0;
    min-width: 0;
    flex: 1;
    font-size: var(--fs-20);
    font-weight: 700;
    letter-spacing: var(--tracking-tight);
    line-height: var(--lh-20);
    color: var(--text-1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Location row ───────────────────────────────────────────────────────── */
.pc-loc {
    margin-top: 0;
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: var(--fs-13);
    font-weight: 500;
    color: var(--text-3);
    min-width: 0;
}
.pc-loc > svg { width: 15px; height: 15px; flex-shrink: 0; color: var(--text-4); }
.pc-loc .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
/* Integrated hover arrow: slides in at the end of the meta row, on-brand navy */
.pc-loc .pc-arrow {
    width: 17px; height: 17px;
    flex-shrink: 0;
    color: var(--navy-500);
    opacity: 0;
    transform: translateX(-5px);
    transition: opacity var(--dur-2) var(--ease-std), transform var(--dur-2) var(--ease-std);
}
#projectGrid > div.project-card:hover .pc-arrow { opacity: 1; transform: translateX(0); }

/* ── Footer row: status pill LEFT · ⋮ menu RIGHT — never stacked ───────── */
.pc-footer {
    margin-top: auto;
    padding-top: var(--sp-2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-2);
    min-width: 0;
}

.pc-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border-radius: var(--r-full);
    font-size: var(--fs-11);
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1;
    white-space: nowrap;
    border: 1px solid transparent;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.pc-status .status-dot { width: 6px; height: 6px; flex-shrink: 0; }
/* Status pill colors per design system: Done=green, Pending=grey,
   Waiting=blue, Error=red (variant names kept from existing 4-status model:
   to-start≈Pending, active≈Waiting, payment≈Error-accent-adjacent kept
   amber per existing product semantics, completed≈Done). */
.pc-status.is-tostart  { background: var(--surface-100); color: var(--surface-600); border-color: var(--surface-200); }
.pc-status.is-active   { background: #dbeafe; color: #1d4ed8; border-color: #bfdbfe; }
.pc-status.is-payment  { background: #fef3c7; color: #b45309; border-color: #fde68a; }
.pc-status.is-completed{ background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.pc-status.is-error    { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }

/* ── Card menu (⋮) — own 40x40 hit area, footer-right, above pill z-order.
   No longer absolutely positioned over the header; lives in the footer row
   next to (never overlapping) the status pill. Keep JS structure/handlers
   unchanged — only the container class + position moved. ────────────────── */
.pc-menu-wrap {
    position: relative;
    z-index: 20;
    flex-shrink: 0;
    line-height: 0;
}
.pc-menu-btn {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-4);
    border-radius: var(--r-md);
    transition: background var(--dur-1) var(--ease-std), color var(--dur-1) var(--ease-std);
}
.pc-menu-btn:hover,
.pc-menu-btn:focus-visible {
    background: var(--surface-100);
    color: var(--text-1);
}
.pc-menu-btn:focus-visible { outline: 2px solid var(--amber-500); outline-offset: -2px; }

/* ── Dropdown direction flip ────────────────────────────────────────────
   Default (markup) is downward: top-full + mt-2 (set in dashboard.js).
   toggleMenu() measures available viewport space at open time and adds
   .drop-up when there isn't enough room below the trigger — this override
   switches it to open upward (bottom-full + mb-2) instead. Prevents the
   menu from rendering off-viewport/unclickable on top-row cards. ──────── */
.project-menu-dropdown.drop-up {
    top: auto !important;
    bottom: 100% !important;
    margin-top: 0 !important;
    margin-bottom: 0.5rem !important;
}
/* Downward-opening menus can visually extend past the card's own box into
   the row below. Cards are position:relative with z-index:auto (no own
   stacking context), so a later sibling card in DOM order would otherwise
   paint over an earlier card's open dropdown despite its z-index:50 (that
   z-index only applies within .pc-menu-wrap's local stacking context).
   Raise the open card above sibling cards so its dropdown stays visible
   and clickable regardless of grid position. */
#projectGrid > div.project-card:has(> .pc-footer > .pc-menu-wrap > .project-menu-dropdown:not(.hidden)) {
    z-index: 30;
}

/* ── "New Project" primary CTA — make it the amber brand button ─────────── */
/* Targets the existing button by its onclick → no markup/JS change. */
button[onclick*="new-project.html"] {
    background: var(--amber-500) !important;
    color: var(--on-amber) !important;
    box-shadow: var(--sh-sm) !important;
}
button[onclick*="new-project.html"]:hover {
    background: var(--amber-400) !important;
}

/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
    #projectGrid { gap: var(--sp-4); }
    #projectGrid > div.project-card { padding: var(--sp-4); min-height: 160px; }
    .pc-icon { width: 42px; height: 42px; }
    .pc-name { font-size: var(--fs-18); line-height: var(--lh-18); }
}
