/* ==========================================================================
   char-summary.css - Production character summary (LAB 14 direction)
   Replaces old .cs-hero / .cs-meta-* / .cs-munition-* rules in sidebar.css
   ========================================================================== */

/* ── Container ─────────────────────────────────────────────────────────── */
#char-summary {
    flex-shrink: 0;
    min-height: 180px;
    padding: var(--space-lg);
    border-bottom: 1px solid rgba(197, 160, 89, 0.18);
    position: relative;
    isolation: isolate;
}

#char-summary::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url(/assets/parchment-BIko6U1V.avif);
    background-size: cover;
    background-position: center;
    opacity: 0.25;
    z-index: -1;
    pointer-events: none;
}

/* ── Identity hero block (portrait + info + bars) ─────────────────────── */
.cs14-hero {
    display: grid;
    grid-template-columns: 6rem 1fr;
    column-gap: var(--space-sm);
    row-gap: var(--space-xs);
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(197, 160, 89, 0.1);
}
.cs14-portrait {
    grid-row: 1 / 3;
    overflow: visible;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cs14-portrait img {
    width: 7.5rem;
    height: 7.5rem;
    object-fit: contain;
    transform: rotate(90deg);
}
.cs14-info {
    min-width: 0;
}
.cs14-name {
    font-family: var(--font-heading);
    font-size: var(--font-size-xl);
    color: #d4ba80;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cs14-context {
    font-size: var(--font-size-xs);
    color: rgba(255, 255, 255, 0.2);
    font-style: italic;
    margin: 2px 0 0;
}

/* ── Ship class + tier line ───────────────────────────────────────────── */
.cs14-ship-line {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    margin: 0px 0px 6px 0px;
    font-size: var(--font-size-xs);
    letter-spacing: 0.08em;
    color: rgba(197, 160, 89, 0.55);
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
}
.cs14-meta-label,
.cs14-ship-class,
.cs14-tier-badge,
.cs14-ship-location {
    font-family: var(--font-body);
    color: var(--text-tertiary);
    letter-spacing: 1px;
    font-size: var(--font-size-sm);
}
.cs14-dot {
    color: rgba(255, 255, 255, 0.2);
    font-style: normal;
}

/* ── Inline stat chips ────────────────────────────────────────────────── */
.cs14-chips {
    display: flex;
    gap: var(--space-xs);
    flex-wrap: wrap;
    margin-top: var(--space-xs);
    margin-bottom: var(--space-xs);
    transition:
        opacity 0.3s ease,
        max-height 0.3s ease;
    max-height: 60px;
    overflow: hidden;
}
.cs14-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: var(--font-size-sm);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    background: rgba(197, 160, 89, 0.04);
    border: 1px solid rgba(197, 160, 89, 0.1);
    border-radius: 2px;
    padding: 3px 6px;
}
.cs14-chip b {
    color: var(--gold);
    font-weight: 700;
}
.cs14-chip--protected {
    color: #7ecfb3;
    border-color: rgba(126, 207, 179, 0.3);
    background: rgba(126, 207, 179, 0.06);
    padding: 2px 6px;
    font-size: 0.7rem;
    margin-left: 1rem;
}

/* ── Crew / Hull bars ─────────────────────────────────────────────────── */
.cs14-bars {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    gap: var(--space-2xs);
}
.cs14-bar-row {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}
.cs14-bar-label {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--font-size-xs);
    letter-spacing: 0.1em;
    color: rgba(197, 160, 89, 0.45);
    width: 6rem;
    flex-shrink: 0;
    text-transform: uppercase;
}
.cs14-bar-track {
    flex: 1;
    height: 6px;
    background: rgb(26 31 35);
    border-radius: 3px;
    overflow: hidden;
}
.cs14-bar-num {
    font-size: var(--font-size-xs);
    color: rgba(197, 160, 89, 0.55);
    white-space: nowrap;
    min-width: 3.5rem;
    text-align: right;
    flex-shrink: 0;
}

/* Bar fill colours (shared with ship panel via sp-health-- states) */
.cs-bar-fill {
    height: 100%;
    border-radius: 3px;
    min-width: 2px;
}
.cs-bar-fill--crew {
    background: #ac1e23;
    width: 70%;
}
.cs-bar-fill--hull {
    background: #366477;
}
.cs-bar-fill--rigging {
    background: #aa803e;
}
.cs-bar-fill--crew.sp-health--crit {
    background: linear-gradient(90deg, #a02020, #cc3030);
    animation: sp-pulse 1.2s ease-in-out infinite;
}
.cs-bar-fill--hull.sp-health--crit {
    background: linear-gradient(90deg, #aa2020, #cc3030);
    animation: sp-pulse 1.2s ease-in-out infinite;
}
.cs-bar-fill--rigging.sp-health--crit {
    background: linear-gradient(90deg, #8b5e1a, #b07820);
    animation: sp-pulse 1.2s ease-in-out infinite;
}

/* ── Section divider (horizontal rule with centred text) ──────────────── */
.cs14-divider {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    font-size: var(--font-size-sm);
    letter-spacing: 0.12em;
    color: rgb(142 128 97 / 45%);
    text-transform: uppercase;
    margin: 18px 0;
}
.cs14-divider::before,
.cs14-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgb(39 33 29);
}

/* ── Collapsible sections ─────────────────────────────────────────────── */
.cs14-section {
    transition:
        opacity 0.3s ease,
        max-height 0.4s ease;
    overflow: hidden;
}
.cs14-section--skills {
    max-height: 800px;
    opacity: 1;
}

/* ── Skills grid (overrides for pp-skill-card in sidebar context) ──── */
.cs14-skills-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

/* Card: 2-col grid - icon column (left) + content column (right) */
.cs14-skills-grid .pp-skill-card {
    display: grid;
    grid-template-columns: 3rem 1fr;
    grid-template-rows: auto auto auto;
    gap: var(--space-2xs) var(--space-xs);
    padding: 6px 10px 6px 14px;
    align-items: center;
    background: rgba(197, 160, 89, 0.02);
    border: 1px solid rgb(197 160 89 / 20%);
    border-radius: var(--radius-sm);
    min-width: 0; /* prevent grid blowout so both columns stay equal width */
}
.cs14-skills-grid .pp-skill-card--training {
    border-color: rgb(197 160 89 / 39%);
}

/* Unwrap pp-skill-top so icon + name become direct grid children */
.cs14-skills-grid .pp-skill-top {
    display: contents;
}

/* Icon: col 1, spans all 3 rows */
.cs14-skills-grid .pp-skill-icon {
    grid-column: 1;
    grid-row: 1 / 4;
    align-self: center;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    background: rgba(197, 160, 89, 0.06);
}
.cs14-skills-grid .pp-skill-icon img {
    width: 2rem;
    height: 2rem;
    border-radius: 3px;
    object-fit: contain;
}

/* Badge hidden - level shown via pp-skill-lv in the bottom row */
.cs14-skills-grid .pp-skill-badge {
    display: none;
}

/* Name: col 2, row 1 */
.cs14-skills-grid .pp-skill-name {
    grid-column: 2;
    grid-row: 1;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* Lv + XP row: col 2, row 2 */
.cs14-skills-grid .pp-skill-bottom {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    align-items: baseline;
    gap: 3px;
    min-width: 0;
}
.cs14-skills-grid .pp-skill-lv {
    font-size: var(--font-size-xs);
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
}
.cs14-skills-grid .pp-skill-xp {
    font-size: var(--font-size-xs);
    color: rgba(197, 160, 89, 0.3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    text-align: right;
}
.cs14-skills-grid .pp-skill-pct {
    display: none;
}

/* Bar: col 2, row 3 */
.cs14-skills-grid .pp-skill-bar {
    grid-column: 2;
    grid-row: 3;
    height: 2px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 1px;
    overflow: hidden;
}
.cs14-skills-grid .pp-skill-bar-fill {
    background: linear-gradient(90deg, #5a3a10, var(--gold));
}

/* ── Inspector panels - replace char-summary space when active ────── */
.cs14-inspector-view {
    flex: 0 0 auto;
    overflow-y: auto;
    padding: var(--space-lg);
    min-height: 217px;
    border-bottom: 1px solid rgba(197, 160, 89, 0.18);
    position: relative;
    isolation: isolate;
}

.cs14-inspector-view .cs14-hero {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.cs14-inspector-view .cs14-portrait {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.cs14-inspector-view .cs14-portrait img {
    transform: none;
    width: auto;
    height: 8rem;
    max-width: 100%;
    object-fit: contain;
    margin-bottom: -45px;
}

.cs14-inspector-view .cs14-bars {
    grid-column: unset;
}

.ship-inspector-btns {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-sm);
}

#tile-context-actions {
}

#tile-ship-img {
    height: 160px;
}

/* ── Hex reference links in onboarding descriptions ───────────────── */
.ob-hex-link {
    color: var(--gold);
    border-bottom: 1px solid rgba(197, 160, 89, 0.4);
    cursor: pointer;
    font-family: var(--font-body);
}
.ob-hex-link:hover {
    border-bottom-color: var(--gold);
}

/* ── game-sidebar tinted backgrounds per tile type ─────────────────── */
#game-sidebar[data-tile-type='ship'],
#game-sidebar[data-tile-type='npc-ship'] {
    background: linear-gradient(180deg, rgb(31 15 18) 0%, rgb(7 7 13 / 90%) 100%);
}

.cs14-inspector-view::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url(/assets/parchment-BIko6U1V.avif);
    background-size: cover;
    background-position: center;
    opacity: 0.25;
    z-index: -1;
    pointer-events: none;
}

/* ── Hidden helper IDs (gold/sovereign) ───────────────────────────────── */
.cs14-hidden {
    display: none;
}

/* ── Activity panel: #char-summary context overrides ─────────────────── */

/* Card wrapper: full border, rounded, clips bar corners */
#char-summary #active-task-panel {
    margin: 10px 0 0 0;
    border: 1px dashed rgba(197, 160, 89, 0.1);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition:
        background 0.4s,
        border-color 0.4s;
}

#char-summary #active-task-panel[data-state='running'][data-skill='smelting'],
#char-summary #active-task-panel[data-state='running'][data-skill='cooking'] {
    background: none;
}
#char-summary #active-task-panel[data-state='running'][data-skill='shipwright'] {
    border-top-color: rgba(120, 70, 160, 0.45);
}

/* context-bar-inner: positioned ancestor for the bar, and flex header row */
#char-summary .context-bar-inner {
    position: relative;
    padding: 12px 12px 24px;
    gap: var(--space-sm);
    align-items: flex-start;
}
#char-summary .task-bar--idle .context-bar-inner {
    padding: 18px 14px;
}

/* Progress bar: absolute against context-bar-inner, full-width at bottom.
   Removed from flex flow; left:0/right:0 span the element's full padding-box width. */
#char-summary .context-progress-wrap {
    position: absolute;
    bottom: 10px;
    left: 12px;
    right: 0;
    height: 3px;
    border-radius: 0;
    max-width: calc(100% - 24px);
    padding: 0;
}

/* Icon: framed box matching the LAB 14 csl-act-icon style */
#char-summary .context-icon {
    font-size: var(--font-size-lg);
    flex-shrink: 0;
    /* Size comes from content (img) or falls back to the emoji glyph box */
    width: fit-content;
    height: fit-content;
}
#char-summary .context-icon-img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    border-radius: 4px;
    background: rgba(197, 160, 89, 0.06);
    border: 1px solid rgba(197, 160, 89, 0.15);
    padding: 2px;
    box-sizing: border-box;
    display: block;
}

/* Buttons: 24px */
#char-summary .context-x-btn {
    width: 28px;
    height: 28px;
}

#char-summary .context-x-btn:disabled {
    cursor: default;
    opacity: 0.35;
    border-color: rgba(197, 160, 89, 0.15);
}

#char-summary .context-x-btn:disabled:hover {
    border-color: rgba(197, 160, 89, 0.15);
    color: rgba(255, 255, 255, 0.4);
}

#char-summary .context-x-btn:disabled:hover .context-btn-icon {
    opacity: 0.7;
}

/* Compact text sizing for narrow sidebar */
#char-summary .context-title {
    font-size: var(--font-size-base);
}
#char-summary .task-bar--running .context-info {
    flex: 1 1 auto;
    min-width: 0;
}
#char-summary .context-sub {
    font-size: var(--font-size-sm);
}

#char-summary .context-trailing {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-left: auto;
    align-self: center;
}

#char-summary .context-timer-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex-shrink: 0;
    gap: 2px;
    line-height: 1.25;
}

#char-summary .context-timer-stack .context-cycles-left,
#char-summary .context-timer-stack .context-end-timer {
    font-size: var(--font-size-sm);
    font-family: inherit;
    font-weight: 400;
    color: var(--text-muted);
    letter-spacing: normal;
    white-space: nowrap;
}

#char-summary .context-timer-stack .context-cycles-left .tf-timer,
#char-summary .context-timer-stack .context-end-timer .tf-timer {
    color: inherit;
}

/* ── Workshop strips (refit + ship build) ─────────────────────────────── */

#char-summary .cs-workshop-panel {
    margin: 6px 0 0;
    border: 1px dashed rgba(197, 160, 89, 0.1);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition:
        background 0.4s,
        border-color 0.4s;
}

#char-summary .cs-workshop-panel[data-state='idle'] {
    display: none;
}

#char-summary .cs-workshop-panel .task-bar--workshop-running,
#char-summary .cs-workshop-panel .task-bar--workshop-complete {
    display: none;
}

#char-summary .cs-workshop-panel[data-state='running'] .task-bar--workshop-running,
#char-summary .cs-workshop-panel[data-state='complete'] .task-bar--workshop-complete {
    display: block;
}

#char-summary .context-icon--ship {
    width: 34px;
    height: auto;
    margin-right: -6px;
}

#char-summary .context-icon-ship-img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    display: block;
}

#char-summary .context-icon-ship-img--portrait {
    transform: rotate(90deg);
}

#char-summary .task-bar--workshop-complete .context-icon-ship-img {
    transform: none;
}

#char-summary .context-progress-fill--complete {
    transform: scaleX(1);
}

#char-summary .cs-workshop-panel .context-bar-inner {
    flex-wrap: nowrap;
    align-items: center;
}

#char-summary .cs-workshop-panel .context-info {
    flex: 1 1 auto;
    min-width: 0;
}

#char-summary .cs-workshop-trailing {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-left: auto;
}

#char-summary .cs-workshop-panel .context-end-timer {
    display: block;
    white-space: nowrap;
}

#char-summary .cs-workshop-btn-group {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

#char-summary .cs-workshop-panel .context-view-btn {
    height: 28px;
    padding: 0 10px;
    font-size: var(--font-size-sm);
    flex-shrink: 0;
}

#char-summary .cs-workshop-btn-group [hidden] {
    display: none;
}

/* ── Skills section (hidden in char-summary; skills live in profile / act pill) ── */
#char-summary .cs14-section--skills {
    max-height: 0;
    opacity: 0;
    margin: 0;
    pointer-events: none;
}

/* ── Shorter screens (≤1080px tall): cap skills at 4 to leave room for chat ── */
@media (max-height: 1080px) {
    .cs14-skills-grid .pp-skill-card:nth-child(n + 5) {
        display: none;
    }
}
