/* ============================================================
   Tactizen shared components
   ------------------------------------------------------------
   Loaded after tokens.css, before page styles.

   The section card was the app's most-copied pattern: nine pages
   used `.section-card` and all nine defined their own version of
   the CSS, which had drifted (three different radii, two border
   alphas, two background treatments). This is the one definition.

   A page declares which of Tactizen's domains a card belongs to:

       <div class="section-card" data-domain="war"> ...

   and the title, icon tile, header wash, border and hover sweep
   all follow. Omitting data-domain gives economy green.
   ============================================================ */

/* ---- Domain selection -------------------------------------
   Set on ANY element and everything inside inherits, because the
   tokens cascade. Put it on the page container to colour a whole
   screen, or on a single card to colour just that one. A card can
   override the page it sits on. */
[data-domain="economy"]    { --tz-domain: var(--tz-domain-economy);    --tz-domain-rgb: var(--tz-domain-economy-rgb); }
[data-domain="war"]        { --tz-domain: var(--tz-domain-war);        --tz-domain-rgb: var(--tz-domain-war-rgb); }
[data-domain="government"] { --tz-domain: var(--tz-domain-government); --tz-domain-rgb: var(--tz-domain-government-rgb); }
[data-domain="market"]     { --tz-domain: var(--tz-domain-market);     --tz-domain-rgb: var(--tz-domain-market-rgb); }
[data-domain="community"]  { --tz-domain: var(--tz-domain-community);  --tz-domain-rgb: var(--tz-domain-community-rgb); }

/* ---- Card -------------------------------------------------- */
.section-card {
    background: rgba(var(--tz-slate-900-rgb), 0.88);
    border: 1px solid rgba(var(--tz-domain-rgb), 0.2);
    border-radius: var(--tz-radius-xl);
    overflow: hidden;
    position: relative;
}

.section-header {
    background: linear-gradient(90deg, rgba(var(--tz-domain-rgb), 0.16), rgba(var(--tz-domain-rgb), 0.05), transparent);
    border-bottom: 1px solid rgba(var(--tz-domain-rgb), 0.3);
    padding: 0.875rem 1rem;
}

@media (min-width: 768px) {
    .section-header {
        padding: 1rem 1.25rem;
    }
}

/* ---- Heading ----------------------------------------------
   Replaces the inline recipe (Orbitron 900 uppercase, pasted per
   site at five different sizes) that this pattern accumulated. */
.section-title {
    font-family: var(--tz-font-display);
    font-size: var(--tz-text-xl);
    font-weight: var(--tz-weight-black);
    letter-spacing: var(--tz-tracking-hud);
    text-transform: uppercase;
    color: var(--tz-domain);
    line-height: 1.2;
    margin: 0;
}

.section-eyebrow {
    font-size: var(--tz-text-sm);
    font-weight: var(--tz-weight-bold);
    letter-spacing: var(--tz-tracking-hud);
    text-transform: uppercase;
    color: var(--tz-text-dim);
    margin: 0;
}

.section-icon {
    width: 48px;
    height: 48px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--tz-radius-md);
    background: linear-gradient(135deg, var(--tz-domain), rgba(var(--tz-domain-rgb), 0.5));
    color: var(--tz-white);
    font-size: var(--tz-text-xl);
}

.section-icon--sm {
    width: 40px;
    height: 40px;
    font-size: var(--tz-text-lg);
}

/* ============================================================
   Daily Orders
   ------------------------------------------------------------
   The dashboard's answer to "what should I do right now?".
   Reads as a standing-orders briefing rather than a stat panel:
   a checklist that empties as the day is played out, with the
   next outstanding item promoted so following the highlight is
   the same as playing the game correctly.
   ============================================================ */
.daily-orders {
    background:
        linear-gradient(180deg, rgba(var(--tz-domain-rgb), 0.07) 0%, transparent 70%),
        rgba(var(--tz-slate-900-rgb), 0.9);
    border: 1px solid rgba(var(--tz-domain-rgb), 0.28);
    border-radius: var(--tz-radius-xl);
    padding: 1rem 1.15rem 1.15rem;
    margin-bottom: 1.5rem;
}

.daily-orders__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.daily-orders__title {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-family: var(--tz-font-display);
    font-size: var(--tz-text-lg);
    font-weight: var(--tz-weight-black);
    letter-spacing: var(--tz-tracking-hud);
    text-transform: uppercase;
    color: var(--tz-domain);
}

.daily-orders__meta {
    display: flex;
    align-items: baseline;
    gap: 1.1rem;
    font-size: var(--tz-text-sm);
    color: var(--tz-text-dim);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-weight: var(--tz-weight-bold);
}

.daily-orders__count {
    color: var(--tz-text);
    font-family: var(--tz-font-mono);
}
.daily-orders__count span { color: var(--tz-text-dim); }

.daily-orders__reset { cursor: help; }
.daily-orders__reset b {
    color: var(--tz-text-muted);
    font-family: var(--tz-font-mono);
}

/* Progress across the whole day, not per item. */
.daily-orders__meter {
    height: 3px;
    margin: 0.75rem 0 0.9rem;
    border-radius: var(--tz-radius-pill);
    background: rgba(var(--tz-white-rgb), 0.07);
    overflow: hidden;
}
.daily-orders__meter span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, rgba(var(--tz-domain-rgb), 0.5), var(--tz-domain));
    transition: width var(--tz-dur-slow) var(--tz-ease-out);
}

.daily-orders__list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
    gap: 0.6rem;
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: none;
}

.order {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    height: 100%;
    padding: 0.7rem 0.8rem;
    border-radius: var(--tz-radius-md);
    border: 1px solid rgba(var(--tz-white-rgb), 0.07);
    background: rgba(var(--tz-white-rgb), 0.02);
    text-decoration: none;
    transition: border-color var(--tz-dur-base) var(--tz-ease),
                background var(--tz-dur-base) var(--tz-ease),
                transform var(--tz-dur-base) var(--tz-ease);
}

.order:hover {
    transform: translateY(-2px);
    border-color: rgba(var(--tz-domain-rgb), 0.5);
    background: rgba(var(--tz-domain-rgb), 0.08);
}

.order__mark {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 30px;
    height: 30px;
    border-radius: var(--tz-radius-sm);
    background: rgba(var(--tz-white-rgb), 0.05);
    color: var(--tz-text-muted);
    font-size: var(--tz-text-base);
}

.order__body { display: flex; flex-direction: column; min-width: 0; }

.order__label {
    font-family: var(--tz-font-display);
    font-size: var(--tz-text-base);
    font-weight: var(--tz-weight-bold);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--tz-text);
    line-height: 1.25;
}

.order__state {
    font-size: var(--tz-text-xs);
    color: var(--tz-text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Finished: still legible, but it stops asking for attention. */
.order.is-done { opacity: 0.45; }
.order.is-done .order__mark {
    background: rgba(var(--tz-green-500-rgb), 0.14);
    color: var(--tz-green-400);
}
.order.is-done:hover { opacity: 0.75; }

/* The one thing to do next. This is the only loud element on the strip. */
.order.is-next {
    border-color: rgba(var(--tz-domain-rgb), 0.65);
    background: rgba(var(--tz-domain-rgb), 0.12);
}
.order.is-next .order__mark {
    background: linear-gradient(135deg, var(--tz-domain), rgba(var(--tz-domain-rgb), 0.55));
    color: var(--tz-surface-base);
}
.order.is-next .order__state { color: var(--tz-domain); }

.order__next {
    position: absolute;
    top: -7px;
    right: 8px;
    padding: 0.05rem 0.4rem;
    border-radius: var(--tz-radius-pill);
    background: var(--tz-domain);
    color: var(--tz-surface-base);
    font-size: var(--tz-text-2xs);
    font-weight: var(--tz-weight-black);
    letter-spacing: 0.09em;
    text-transform: uppercase;
}


@media (max-width: 600px) {
    .daily-orders { padding: 0.85rem 0.9rem 1rem; }
    .daily-orders__meta { width: 100%; justify-content: space-between; }
}

/* ============================================================
   Joint company finances
   ------------------------------------------------------------
   One pot per currency rather than a single blended number.
   Gold is universal so it gets one figure; every other currency
   is listed separately, because a company earns its home
   currency and its export-licence currencies into different
   places and they are not interchangeable.
   ============================================================ */
.joint-finances {
    background: rgba(var(--tz-slate-900-rgb), 0.85);
    border: 1px solid rgba(var(--tz-domain-rgb), 0.25);
    border-radius: var(--tz-radius-lg);
    padding: 0.85rem 1rem 1rem;
    margin-bottom: 1.25rem;
}

.joint-finances__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.joint-finances__title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--tz-font-display);
    font-size: var(--tz-text-base);
    font-weight: var(--tz-weight-black);
    letter-spacing: var(--tz-tracking-hud);
    text-transform: uppercase;
    color: var(--tz-domain);
}

.joint-finances__note {
    font-size: var(--tz-text-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--tz-text-dim);
}

.joint-finances__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr));
    gap: 0.6rem;
}

.jf-pot {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--tz-radius-md);
    border: 1px solid rgba(var(--tz-white-rgb), 0.07);
    background: rgba(var(--tz-white-rgb), 0.02);
}

.jf-pot__label {
    font-size: var(--tz-text-2xs);
    font-weight: var(--tz-weight-bold);
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--tz-text-dim);
}

.jf-pot__value {
    font-family: var(--tz-font-mono);
    font-size: var(--tz-text-lg);
    font-weight: var(--tz-weight-bold);
    color: var(--tz-text);
    line-height: 1.15;
}

/* The same currency can sit in two places; say so rather than hide it. */
.jf-pot__split {
    font-size: var(--tz-text-2xs);
    color: var(--tz-text-dim);
}

.jf-pot--gold {
    border-color: rgba(var(--tz-gold-rgb), 0.35);
    background: rgba(var(--tz-gold-rgb), 0.07);
}
.jf-pot--gold .jf-pot__value { color: var(--tz-gold); }

.jf-pot--empty .jf-pot__value { color: var(--tz-text-dim); }

/* On a company card: what this company can draw on, beyond its own
   balance. Quiet, because the company's own figure is still the headline. */
.company-stat-pool {
    margin-top: 0.1rem;
    font-size: var(--tz-text-2xs);
    letter-spacing: 0.04em;
    color: var(--tz-text-dim);
    cursor: help;
}

/* ---- Empty-state action -------------------------------------
   An empty panel is the best place in the app to tell someone what
   to do next. Most of them said "No X yet" and stopped there - a few
   even said "Be the first to..." without offering a way to be first.
   This is the button that goes under that sentence. */
.empty-state-action {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding: 0.55rem 1.1rem;
    border-radius: var(--tz-radius-md);
    border: 1px solid rgba(var(--tz-domain-rgb), 0.45);
    background: rgba(var(--tz-domain-rgb), 0.12);
    color: var(--tz-domain);
    font-size: var(--tz-text-base);
    font-weight: var(--tz-weight-semi);
    text-decoration: none;
    transition: background var(--tz-dur-base) var(--tz-ease),
                border-color var(--tz-dur-base) var(--tz-ease);
}

.empty-state-action:hover {
    background: rgba(var(--tz-domain-rgb), 0.2);
    border-color: rgba(var(--tz-domain-rgb), 0.7);
    color: var(--tz-domain);
}

@media (max-width: 767px) {
    .section-header .section-title,
    .section-header h3,
    .section-header h2 {
        font-size: var(--tz-text-lg);
    }

    .section-icon {
        width: 40px;
        height: 40px;
        font-size: var(--tz-text-lg);
    }

    .section-icon--sm {
        width: 32px;
        height: 32px;
        font-size: var(--tz-text-base);
    }
}

/* ============================================================
   Collapsible cards
   ------------------------------------------------------------
   Opt in per card with `data-collapsible="<key>"`; the toggle
   button is injected into the header and the open/closed state
   is remembered per key in localStorage.

   Collapsing hides every child of the card except the header
   (and the decorative scan line), so cards whose tabs sit
   outside `.section-body` fold away as one piece.
   ============================================================ */
.section-header--collapsible {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Keep the existing header content full width so adding the
   button does not shift anything already in the header. */
.section-header--collapsible > :first-child {
    flex: 1 1 auto;
    min-width: 0;
}

.section-collapse-btn {
    width: 32px;
    height: 32px;
    flex: none;
    padding: 0;
    border-radius: var(--tz-radius-md);
    background: rgba(var(--tz-domain-rgb), 0.15);
    border: 1px solid rgba(var(--tz-domain-rgb), 0.35);
    color: var(--tz-domain);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: var(--tz-text-base);
    transition: background var(--tz-dur-base) var(--tz-ease),
                border-color var(--tz-dur-base) var(--tz-ease);
}

@media (min-width: 768px) {
    .section-collapse-btn {
        width: 36px;
        height: 36px;
    }
}

.section-collapse-btn:hover {
    background: rgba(var(--tz-domain-rgb), 0.25);
    border-color: rgba(var(--tz-domain-rgb), 0.6);
}

.section-collapse-btn i {
    transition: transform var(--tz-dur-base) var(--tz-ease);
}

.section-card.is-collapsed .section-collapse-btn i {
    transform: rotate(180deg);
}

.section-card.is-collapsed > *:not(.section-header):not(.scan-line) {
    /* !important because several card bodies carry an inline display. */
    display: none !important;
}

/* Header keeps its border box (no shift) but reads as a closed lid. */
.section-card.is-collapsed > .section-header {
    border-bottom-color: transparent;
}

/* Stretch grids would otherwise blow a collapsed card back up to
   the height of its neighbour. */
.section-card.is-collapsed {
    align-self: start;
}
