/* 画面専用。A4印刷・PDFのレイアウトは変更しない。
   Tailwind CDN が後から挿入するスタイルより優先するため、
   レイアウトを上書きする箇所はフック + ユーティリティの2クラスで指定する。 */
@media screen {
    .app-shell.h-screen { height: 100dvh; }
    .app-sidebar.h-screen { height: 100%; }
    .app-content { min-height: 0; }
    .mobile-header, .sidebar-close, .sidebar-backdrop, .sidebar-rail { display: none; }
    .app-sidebar { position: relative; }
    .sidebar-hide {
        position: absolute; top: .5rem; right: .5rem; z-index: 1;
        width: 2rem; height: 2rem; display: flex; align-items: center; justify-content: center;
        border-radius: .5rem; color: #94a3b8; font-size: .8rem;
    }
    .sidebar-hide:hover, .sidebar-hide:focus-visible { background: #1e293b; color: #fff; }
    .document-form, .document-preview.flex { min-width: 0; }
    .document-preview.flex { overflow-x: auto; }
    .a4-paper { flex-shrink: 0; }
    .responsive-grid > *, .customer-fields > *, .work-record-fields > *, .item-row > * { min-width: 0; }
    .overflow-x-auto { max-width: 100%; }
    /* タップ領域が高くなっても、タブのラベル・件数は上下中央に揃える。 */
    .tab-control.tab-control {
        display: inline-flex; align-items: center; justify-content: center;
        text-align: center;
    }
    /* 一覧の操作リンクも、ボタンと同じくタップ領域の上下中央に配置する。 */
    .table-actions > a, .table-actions > button {
        display: inline-flex; align-items: center; justify-content: center;
        text-align: center;
    }
    .tab-btn.tab-control { padding-top: .375rem; padding-bottom: .375rem; }
    .kanban-board.grid { grid-template-columns: repeat(5, minmax(16rem, 1fr)); }
}
/* PC でサイドバーを隠したとき（docs/18 の21章）。スマホ・タブレットは今までどおり「メニュー」で開く */
@media screen and (min-width: 1024px) {
    .sidebar-hidden .app-sidebar.h-screen { display: none; }
    /* 隠して広くなった分、案件パイプラインの取引先を長く出す（docs/18 の21章） */
    .sidebar-hidden [data-deal-customer-cell] { max-width: 14rem; }
    .sidebar-hidden .sidebar-rail {
        display: flex; flex-direction: column; align-items: center; flex-shrink: 0;
        width: 2.75rem; height: 100%; padding-top: .5rem; background: #0f172a;
    }
    .sidebar-rail button {
        width: 2rem; height: 2rem; display: flex; align-items: center; justify-content: center;
        border-radius: .5rem; color: #cbd5e1;
    }
    .sidebar-rail button:hover, .sidebar-rail button:focus-visible { background: #1e293b; color: #fff; }
}
@media screen and (max-width: 1023px) {
    .sidebar-hide { display: none; }
    .app-sidebar.h-screen {
        position: fixed; inset: 0 auto 0 0; z-index: 80;
        width: min(18rem, calc(100vw - 3rem)); height: 100dvh;
        visibility: hidden; transform: translateX(-100%);
    }
    .app-sidebar.is-open { visibility: visible; transform: translateX(0); }
    .sidebar-close {
        display: flex; align-items: center; justify-content: center;
        align-self: flex-end; min-width: 44px; min-height: 44px;
        color: white;
    }
    .sidebar-backdrop:not([hidden]) {
        display: block; position: fixed; inset: 0; z-index: 70;
        background: rgb(15 23 42 / 60%);
    }
    .mobile-header {
        display: flex; align-items: center; justify-content: space-between;
        flex-shrink: 0; padding: .5rem 1rem; gap: 1rem;
        background: #0f172a; color: white;
    }
    .mobile-header button {
        display: flex; align-items: center; gap: .5rem;
        min-height: 44px; padding: .5rem; font-size: .875rem;
    }
    .document-editor.flex { display: block; height: auto; overflow: visible; }
    .document-editor .document-form { width: 100%; overflow: visible; padding: 1rem; }
    .document-editor .document-preview.flex {
        width: 100%; padding: 1rem; justify-content: flex-start;
    }
    .document-detail.flex {
        flex-direction: column; padding: 1rem; gap: 1rem;
        overflow-x: auto; align-items: stretch;
    }
    .document-detail > .a4-paper { align-self: flex-start; }
    .document-detail > .no-print { width: 100%; min-width: 0; }
    .responsive-modal.fixed { overflow-y: auto; padding: .75rem; }
    .responsive-modal.fixed > div {
        max-height: calc(100dvh - 1.5rem); overflow-y: auto;
        min-width: 0; margin-top: auto; margin-bottom: auto;
    }
    /* 案件編集モーダル：中身が短くても、保存ボタンの欄はモーダルの一番下に置く */
    .deal-edit-modal form[data-deal-edit-form] { flex-grow: 1; }
    .deal-edit-modal .deal-edit-footer { margin-top: auto; }
    /* iPhone の日付・年月の入力欄は、標準の見た目だと中央寄せで幅・高さが他の欄とそろわない */
    input[type="date"], input[type="month"] {
        -webkit-appearance: none; appearance: none; min-width: 0; background-color: #fff;
    }
    input[type="date"]::-webkit-date-and-time-value, input[type="month"]::-webkit-date-and-time-value {
        text-align: left;
    }
    .customer-fields > .col-span-6 { grid-column: span 12 / span 12; border-right: 0; padding-right: 0; }
    .responsive-row { flex-wrap: wrap; gap: .75rem; }
    .responsive-row > .flex { flex-wrap: wrap; max-width: 100%; }
    .responsive-filter, .responsive-filter > .flex { flex-wrap: wrap; }
    .responsive-filter > * { min-width: 0; max-width: 100%; }
    .responsive-tabs { overflow-x: auto; max-width: 100%; }
    .responsive-tabs > .flex { flex-wrap: wrap; }
    .responsive-tabs > button { flex-shrink: 0; }
    .responsive-row.flex-col { flex-wrap: nowrap; }
    /* Document contents stay fixed-size; only their outer viewport scrolls. */
    .a4-paper .responsive-row, .a4-paper .responsive-row > .flex { flex-wrap: nowrap; gap: 0; }
}
@media screen and (max-width: 639px) {
    .responsive-grid.grid { grid-template-columns: minmax(0, 1fr); }
    .responsive-grid > [class*="col-span-"] { grid-column: auto; }
    main .p-6, main .p-8 { padding: 1rem; }
    main .px-6, main .px-8 { padding-left: 1rem; padding-right: 1rem; }
    main .overflow-x-auto > table { min-width: 40rem; }
    main .overflow-x-auto { -webkit-overflow-scrolling: touch; }
    .customer-fields.grid { row-gap: .5rem; }
    .customer-fields > :not(.col-span-6) { grid-column: span 12 / span 12; }
    .work-record-fields.grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .work-record-fields > * { grid-column: span 1 / span 1; }
    .work-record-fields > .row-content { grid-column: span 2 / span 2; }
    .custom-schedule-row.grid { grid-template-columns: minmax(0, 1fr); }
    .item-row { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .item-row > * { grid-column: span 1 / span 1 !important; }
    .item-row > .item-name { grid-column: span 2 / span 2 !important; }
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select, textarea, .ts-control, .ts-control input {
        font-size: 16px !important;
    }
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select { min-height: 44px; max-width: 100%; }
    button, a[class*="bg-"], .app-sidebar nav a { min-height: 44px; }
    /* サイドバーの開け閉めする見出し（帳票管理・承認）も押しやすい高さにする（docs/21 の6章） */
    .app-sidebar nav summary { min-height: 44px; }
    /* 予実管理の表のセル（仮の金額のボタン）は行の高さを詰めるため低めにする。幅はセルいっぱいなので押しやすさは保つ */
    .budget-cell-btn.budget-cell-btn { min-height: 1.5rem; }
    .tab-control.tab-control { min-height: 44px; padding-top: .5rem; padding-bottom: .5rem; }
    .ts-wrapper, .ts-control { min-width: 0; max-width: 100%; }
    /* 文字を入れて探す選択（TomSelect）も、入力欄と同じく押しやすい高さにする（2026-11-27。どの画面でも 36px だった） */
    .ts-wrapper .ts-control { min-height: 44px; align-items: center; }
    main form > [class*="min-w-"] { min-width: 0; width: 100%; }
    .document-preview.flex { justify-content: flex-start; padding: .75rem; }
    .document-detail > .no-print { flex-shrink: 0; }
    .no-print.responsive-row { position: relative; }
    .no-print { overflow-wrap: anywhere; }
    .responsive-filter > .flex-1 { flex-basis: 100%; }
    .responsive-date-range.flex { display: grid; grid-template-columns: minmax(0, 1fr); width: 100%; }
    .responsive-date-range input { width: 100%; min-width: 0; }
    .responsive-date-range > span:first-child { grid-column: 1 / -1; }
    /* 案件編集モーダルは画面いっぱいに出し、保存・キャンセルを画面の一番下に固定する */
    .responsive-modal.deal-edit-modal.fixed { padding: 0; }
    .responsive-modal.deal-edit-modal.fixed > div {
        width: 100%; height: 100dvh; max-height: 100dvh;
        border-radius: 0; border: 0; margin: 0;
    }
    .deal-edit-modal .deal-edit-footer {
        padding-bottom: calc(.75rem + env(safe-area-inset-bottom));
        box-shadow: 0 -4px 12px rgb(15 23 42 / 8%);
    }
    /* Avoid changing controls embedded in the fixed-size paper. */
    .a4-paper input, .a4-paper select, .a4-paper textarea { font-size: inherit !important; }
}
