/*
 * 入力欄の説明を「タイトルにカーソルを合わせると出る」形にする見た目（2026-10-16 ボブ氏指示：製品編集のページを詰める）。
 * - 説明は入力欄の下に書かず、タイトルの横の「？」に入れる（Filament の hintIcon の tooltip）
 * - 「？」は右端ではなくタイトルのすぐ横に置き、薄い色・小さめにする
 * - タイトルにカーソルを合わせても説明が出る（/js/costa-form-tips.js）
 */
.fi-fo-field-label-ctn > .fi-sc.fi-align-end:has(svg[x-tooltip]) {
    flex-grow: 0;
    justify-content: flex-start;
    margin-inline-start: calc(var(--spacing) * -1.5);
}

.fi-fo-field-label-ctn > .fi-sc.fi-align-end svg.fi-sc-icon[x-tooltip] {
    width: 1rem;
    height: 1rem;
    color: var(--gray-400);
    cursor: help;
}

.fi-fo-field-label-ctn:has(svg[x-tooltip]) .fi-fo-field-label-content {
    cursor: help;
    text-decoration: underline dotted var(--gray-400);
    text-underline-offset: 3px;
}

/*
 * 製品仕様のまとまり（パッケージ・インナー・アウター・デートコード・取説など）の枠を詰める（2026-10-16 ボブ氏指示）。
 * 見出しは枠の名前1回だけにし、余白を小さくしてページが伸びないようにする。
 */
.fi-fieldset.costa-spec-group:not(.fi-fieldset-not-contained) {
    padding: calc(var(--spacing) * 2) calc(var(--spacing) * 3) calc(var(--spacing) * 3);
}

.fi-fieldset.costa-spec-group > legend {
    font-weight: var(--font-weight-semibold, 600);
    color: var(--primary-600);
}

.fi-fieldset.costa-spec-group .fi-sc-has-gap {
    gap: calc(var(--spacing) * 3);
}

/*
 * チェックシート（製品の「チェック」タブ。2026-10-17 ボブ氏指示）
 * - 見出し（実施日・担当・参加者・チェック数・型）を項目として見やすく並べる
 * - チェックの列：型卸の金型単体項目は「P01 □ P02 □」と横に並べ、他の区分に余計な列を作らない
 */
.costa-ck-head {
    display: flex;
    flex-wrap: wrap;
    gap: calc(var(--spacing) * 2) calc(var(--spacing) * 6);
    margin-top: calc(var(--spacing) * 2);
}

.costa-ck-head-cell {
    min-width: 7rem;
}

.costa-ck-head-label {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.costa-ck-head-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--gray-950);
}

.dark .costa-ck-head-value {
    color: var(--gray-100);
}

.costa-ck-head-value.is-muted {
    color: var(--danger-600);
    font-weight: 500;
}

.costa-ck-head-foot {
    margin-top: calc(var(--spacing) * 2);
    font-size: 0.8rem;
    color: var(--gray-500);
}

.costa-ck-checks {
    display: flex;
    flex-wrap: wrap;
    gap: calc(var(--spacing) * 1) calc(var(--spacing) * 3);
    align-items: center;
}

.costa-ck-mold {
    display: inline-flex;
    align-items: center;
    gap: calc(var(--spacing) * 1);
    font-size: 0.8rem;
    color: var(--gray-600);
    cursor: pointer;
}

.costa-ck-none {
    font-size: 0.75rem;
    color: var(--gray-400);
}

/* チェックシートの見出し：1段目＝シート名・型・チェック数、2段目＝実施日・担当・参加者を横に並べる（2026-10-17） */
.costa-ck-line {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: calc(var(--spacing) * 1) calc(var(--spacing) * 6);
}

.costa-ck-title {
    font-size: 1rem;
    font-weight: 700;
}

.costa-ck-pair {
    display: inline-flex;
    align-items: baseline;
    gap: calc(var(--spacing) * 2);
    white-space: nowrap;
}

/* 型ごとのチェック（P01 □ P02 □ …）は横に並べる。型が多いときは表を横に送る */
.costa-ck-checks {
    flex-wrap: nowrap;
    white-space: nowrap;
}

/* チェックシートの見出し：情報とボタンを1つの枠に（1段目の右にボタン、2段目の右に［入力］）（2026-10-17） */
.costa-ck-header {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 2);
    padding: calc(var(--spacing) * 3) calc(var(--spacing) * 6);
}

.costa-ck-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: calc(var(--spacing) * 2) calc(var(--spacing) * 6);
}

.costa-ck-actions {
    display: inline-flex;
    gap: calc(var(--spacing) * 2);
    margin-inline-start: auto;
}

.costa-ck-actions.is-inline {
    margin-inline-start: 0;
}

/* 型ごとのチェック：□ を同じ幅で並べ、上に型の名前（いちばん上の行だけ） */
.costa-ck-mold {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    width: 2.25rem;
    gap: 2px;
}

.costa-ck-mold-label {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.costa-ck-checks {
    gap: 0;
}

/* 型の名前（P01 P02 …）を「金型単体項目」の区分の行に、□ の真上に置く（2026-10-17 ボブ氏指示） */
.costa-ck-mold-heads {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.costa-ck-mold-heads span {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-500);
}

.costa-ck-mold-heads span.is-left {
    transform: translate(0, -50%);
}

/* チェックシートの表は列の見出しの行（項目／チェック／メモ）を出さない。列の名前は区分ごとの行に出す（2026-10-17 ボブ氏指示） */
.fi-ta:has(.costa-ck-header) .fi-ta-table > thead {
    display: none;
}

/* 区分の行の「チェック」の文字が □ の列からはみ出してメモの名前と重ならないよう、チェックの列に幅を取り、□ を真ん中に置く */
.costa-ck-checks {
    min-width: 4rem;
    justify-content: center;
}

/* 見積もり・請求の一覧（2026-10-17 ボブ氏指示）：1段目に客先・プロジェクト名・TT番号、2段目から明細（名目・金額・状態） */
.costa-est {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    min-width: 28rem;
}

.costa-est-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: calc(var(--spacing) * 3);
    margin-bottom: 2px;
}

.costa-est-customer {
    font-weight: 700;
}

.costa-est-project {
    font-weight: 600;
}

.costa-est-tt {
    font-size: 0.8rem;
    color: var(--gray-500);
}

.costa-est-line {
    display: grid;
    /* どの見積書の行でも、名目・金額・状態の位置をそろえる */
    grid-template-columns: 2rem minmax(0, 1fr) 7rem 10.5rem;
    align-items: center;
    gap: calc(var(--spacing) * 3);
    font-size: 0.875rem;
    padding: 1px 0;
    border-top: 1px dashed var(--gray-200);
}

.dark .costa-est-line {
    border-top-color: var(--gray-700);
}

.costa-est-line.is-cancelled .costa-est-category,
.costa-est-line.is-cancelled .costa-est-amount {
    text-decoration: line-through;
    color: var(--gray-400);
}

.costa-est-branch {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.costa-est-amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.costa-est-meta {
    white-space: nowrap;
    font-size: 0.875rem;
}

.costa-est-meta-sub {
    color: var(--gray-500);
}

/* 名目が長いときは折り返す（金額に重ならないように） */
.costa-est-category {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
}

.costa-est-head span {
    white-space: normal;
}

/* 見積書の編集：明細の表は幅を決め打ち（名目に残りの幅を全部回す） */
.costa-est-lines table {
    table-layout: fixed;
    width: 100%;
}

.costa-est-lines thead th:last-child {
    width: 9.5rem;
}

.costa-est-progress {
    font-size: 0.8125rem;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

/* 見積書の編集：進み具合・作業の詳細は、ボタンではなく文字・行のクリックで開く（2026-10-18） */
.costa-est-hidden-action {
    display: none !important;
}

.costa-est-progress-link {
    text-align: left;
    color: var(--primary-600);
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.dark .costa-est-progress-link {
    color: var(--primary-400);
}

.costa-work-add {
    align-self: flex-start;
    margin-top: 4px;
    font-size: 0.8125rem;
    color: var(--primary-600);
    cursor: pointer;
}

.dark .costa-work-add {
    color: var(--primary-400);
}

/* 明細の下の作業の一覧：作業内容・担当・完了予定日・状態（2026-10-18） */
.costa-works {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.costa-work {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 9rem 7rem 10rem;
    column-gap: 12px;
    align-items: baseline;
    width: 100%;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.875rem;
    text-align: left;
    background: var(--gray-50);
}

button.costa-work {
    cursor: pointer;
}

.dark .costa-work {
    background: rgba(255, 255, 255, 0.04);
}

button.costa-work:hover {
    background: var(--primary-50);
}

.dark button.costa-work:hover {
    background: rgba(255, 255, 255, 0.08);
}

.costa-work-head {
    background: transparent;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-500);
    padding-top: 0;
    padding-bottom: 0;
}

.dark .costa-work-head {
    background: transparent;
}

.costa-work-title {
    min-width: 0;
    overflow-wrap: anywhere;
}

.costa-work-who {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.costa-work-due {
    color: var(--gray-600);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.costa-work-status {
    font-size: 0.8125rem;
    color: var(--gray-600);
}

.costa-work.is-doing .costa-work-status {
    color: var(--info-600);
}

.costa-work.is-done {
    opacity: 0.6;
}

.costa-work.is-done .costa-work-title {
    text-decoration: line-through;
}

.costa-work.is-alert .costa-work-status,
.costa-work.is-alert .costa-work-due {
    color: var(--danger-600);
    font-weight: 600;
}

/* スマホなど狭い画面：作業内容を1段目、担当・完了予定日・状態を2段目に */
@media (max-width: 640px) {
    .costa-work {
        grid-template-columns: 1fr 1fr 1fr;
    }

    .costa-work-title,
    .costa-work-head span:first-child {
        grid-column: 1 / -1;
    }
}

/* 見積もり・請求の一覧：名目の下の作業のまとめ */
.costa-est-works {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-500);
}

.costa-est-works.is-alert {
    color: var(--danger-600);
    font-weight: 600;
}

/* 見積書の編集：明細のカードの見出し＝名目の入力欄（2026-10-18）。右上の 入金・取りやめ・削除 と同じ高さに置く */
.costa-est-lines .fi-fo-repeater-item {
    position: relative;
}

.costa-est-lines .fi-fo-repeater-item-header {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 1;
    padding: 0;
    border: 0;
    background: transparent;
}

/* 右上のボタン（取りやめ・削除）の下に、名目・詳細の行が来るよう、上に少し空ける（2026-11-15。名目と詳細は2つで1行） */
.costa-est-lines .fi-fo-repeater-item-content {
    padding-top: 2.25rem;
}

/* 見出しの行（「見積書」＋フォーマット、「明細」＋通貨・消費税）：画面の幅や窓の大きさに関係なく、いつも左に見出し・右に選択欄の1段にする（2026-11-16 ボブ氏）。
   選択欄は項目名が上・ドロップボックスが下。狭いスマホ幅だけ折り返す */
.costa-est-linehead {
    flex-direction: row !important;
    align-items: flex-end !important;
    gap: 0.75rem;
}

.costa-est-linehead > .fi-growable {
    min-width: 0;
    padding-bottom: 0.5rem;
}

@media (max-width: 560px) {
    .costa-est-linehead {
        flex-wrap: wrap;
    }
}

.costa-est-title input {
    font-size: 1rem;
    font-weight: 700;
}

/* 見積書の製品（TT番号）の候補：TT番号と製品名を並べ、選んだあとの表示は TT番号だけ（2026-10-20） */
.costa-opt-name {
    margin-left: 0.75em;
    color: var(--gray-500);
}

.fi-select-input-value-label .costa-opt-name {
    display: none;
}

/* 説明文を見出しの「？」にまとめる（2026-10-21。仕組みは public/js/costa-help-tips.js）。仕組みが動いたときだけ元の説明を隠す */
.costa-help-on .fi-fo-field:has(> .fi-fo-field-label-col .fi-fo-field-label-ctn) > .fi-fo-field-content-col > .fi-sc:has(.fi-sc-text) {
    display: none;
}

/* 表示専用の欄（見積番号・状態など）の説明も同じ */
.costa-help-on .fi-in-entry:has(> .fi-in-entry-label-col .fi-in-entry-label-ctn) > .fi-in-entry-content-col > .fi-sc:has(.fi-sc-text) {
    display: none;
}

/* 枠・タブの先頭の長い説明（processNotes）も、「？」に移したら隠す */
.costa-help-on .costa-help-moved {
    display: none;
}

.costa-help-on .fi-section-header-description.costa-help-moved,
.costa-help-on .fi-header-subheading.costa-help-moved {
    display: none;
}

.costa-help {
    display: inline-flex;
    vertical-align: middle;
    margin-left: 4px;
    width: 1.1rem;
    height: 1.1rem;
    color: var(--gray-400);
    cursor: help;
    border-radius: 9999px;
}

.costa-help svg {
    width: 100%;
    height: 100%;
}

.costa-help:hover,
.costa-help:focus-visible {
    color: var(--primary-600);
    outline: none;
}

.costa-help-pop {
    display: none;
    position: fixed;
    z-index: 100;
    max-width: min(360px, calc(100vw - 16px));
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--gray-900);
    color: #fff;
    font-size: 0.8125rem;
    line-height: 1.5;
    white-space: pre-line;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

.dark .costa-help-pop {
    background: var(--gray-700);
}

/* 支払の合計（通貨ごと。2026-10-21） */
.costa-pay-totals {
    width: 100%;
    max-width: 44rem;
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
}

.costa-pay-totals th,
.costa-pay-totals td {
    padding: 4px 8px;
    text-align: right;
    border-bottom: 1px solid var(--gray-200);
}

.costa-pay-totals th:first-child,
.costa-pay-totals td:first-child {
    text-align: left;
}

.dark .costa-pay-totals th,
.dark .costa-pay-totals td {
    border-bottom-color: var(--gray-700);
}

/* 表のリンクのファイルの取り込みの状態（2026-10-21） */
.costa-linked-state {
    margin-top: 8px;
    font-size: 0.8125rem;
    color: var(--gray-600);
}

.costa-linked-state a {
    color: var(--primary-600);
    text-decoration: underline;
}

/* リンクのファイルを写している間の進み具合（2026-10-21） */
.costa-linked-progress {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    background: var(--primary-50);
    color: var(--primary-700);
    font-size: 0.875rem;
}

.dark .costa-linked-progress {
    background: rgba(255, 255, 255, 0.05);
    color: var(--primary-300);
}

/* 支払の請求項目（2026-10-22）：狭い画面（タブレット）でも名目の幅を残し、足りなければ表を横に動かす */
.costa-pay-lines {
    overflow-x: auto;
    /* overflow を指定すると縦方向も切られ、表の枠の端・入力欄の枠・「請求項目を足す」ボタンの下が欠けるため、余白で逃がす（2026-11-17） */
    padding: 0.25rem 0.25rem 0.75rem;
    margin: -0.25rem;
}
/* 表の形（幅 36rem 以上）のとき、表の幅の下限を決めて名目に 12rem 以上を残す（他の列は幅が決まっている） */
@container (min-width: 36rem) {
    .costa-pay-lines > table {
        min-width: 43rem;
    }
    .costa-pay-lines.costa-pay-lines-tt > table {
        min-width: 51rem;
    }
}
/* 消費税の欄：左に種類（幅固定）、右に額（¥ 付き）。免税・不課税は額が無いので種類だけ */
.costa-pay-lines .costa-pay-tax > .fi-sc.fi-grid:has(input) {
    --cols-default: 7rem minmax(0, 1fr) !important;
}
/* 額の数字は右そろえ（桁がそろって読みやすい） */
.costa-pay-lines input[type="number"] {
    text-align: right;
}
