/* モバイル用共通設定 */

html,
body {
    overflow-x: hidden;
}

@media (max-width: 768px) {
    /* -------------------------------- */
    /* 仕訳一覧（検索フォーム） */
    /* -------------------------------- */
    :is(#page-journals form.grid.gap-3.sm\:grid-cols-6, form.grid.gap-3.sm\:grid-cols-6)
        > .sm\:col-span-6.flex.flex-col {
        width: 100%;
    }

    :is(#page-journals form.grid.gap-3.sm\:grid-cols-6, form.grid.gap-3.sm\:grid-cols-6)
        > .sm\:col-span-6.flex.flex-col.gap-3 {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.85rem;
    }

    :is(#page-journals form.grid.gap-3.sm\:grid-cols-6, form.grid.gap-3.sm\:grid-cols-6)
        > .sm\:col-span-6.flex.flex-col.gap-3
        > div {
        margin: 0;
        min-width: 0;
    }

    /* キーワード欄（100%） */
    :is(#page-journals form.grid.gap-3.sm\:grid-cols-6, form.grid.gap-3.sm\:grid-cols-6)
        > .sm\:col-span-6.flex.flex-col.gap-3
        > div:nth-child(1) {
        grid-column: 1 / -1;
    }

    /* ラベル */
    :is(#page-journals form.grid.gap-3.sm\:grid-cols-6, form.grid.gap-3.sm\:grid-cols-6)
        > .sm\:col-span-6.flex.flex-col.gap-3
        label {
        font-size: 0.75rem;
        color: #64748b;
    }

    :is(#page-journals form.grid.gap-3.sm\:grid-cols-6, form.grid.gap-3.sm\:grid-cols-6)
        > .sm\:col-span-6.flex.flex-col.gap-3
        > div
        > input,
    :is(#page-journals form.grid.gap-3.sm\:grid-cols-6, form.grid.gap-3.sm\:grid-cols-6)
        > .sm\:col-span-6.flex.flex-col.gap-3
        > div
        > select {
        width: 100%;
        min-width: 0;
    }

    :is(#page-journals form.grid.gap-3.sm\:grid-cols-6, form.grid.gap-3.sm\:grid-cols-6)
        > .sm\:col-span-6.flex.flex-wrap.items-center.justify-end {
        display: flex;
        flex-wrap: nowrap !important;
        justify-content: flex-end;
        align-items: center;
        width: 100%;
        gap: 0.5rem;
        text-align: right;
    }

    :is(#page-journals form.grid.gap-3.sm\:grid-cols-6, form.grid.gap-3.sm\:grid-cols-6)
        > .sm\:col-span-6.flex.flex-wrap.items-center.justify-end
        > * {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* -------------------------------- */
    /* 仕訳入力フォーム */
    /* -------------------------------- */
    form[data-prevent-multiple-submit] .overflow-x-auto {
        overflow: visible;
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
        padding: 0;
    }

    form[data-prevent-multiple-submit] table {
        display: block;
        width: 100%;
        border-spacing: 0;
    }

    form[data-prevent-multiple-submit] table thead {
        display: none;
    }

    form[data-prevent-multiple-submit] #entry-rows {
        display: flex;
        flex-direction: column;
        gap: 1.5rem;
        width: 100%;
    }

    form[data-prevent-multiple-submit] #entry-rows tr {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        padding: 1.5rem;
        border: 1px solid rgba(15, 23, 42, 0.12);
        border-radius: 1.5rem;
        background: #fff;
        box-shadow: 0 16px 30px rgba(15, 23, 42, 0.08);
    }

    form[data-prevent-multiple-submit] #entry-rows td {
        display: flex;
        flex-direction: column;
        width: 100%;
        padding: 0 !important;
        gap: 0.35rem;
    }

    form[data-prevent-multiple-submit] #entry-rows td::before {
        font-size: 0.7rem;
        font-weight: 600;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: #475569;
        content: '';
    }

    form[data-prevent-multiple-submit] #entry-rows td:nth-child(1)::before {
        content: '日付';
    }

    form[data-prevent-multiple-submit] #entry-rows td:nth-child(2)::before {
        content: '借方勘定科目';
    }

    form[data-prevent-multiple-submit] #entry-rows td:nth-child(3)::before {
        content: '借方金額';
    }

    form[data-prevent-multiple-submit] #entry-rows td:nth-child(4)::before {
        content: '貸方勘定科目';
    }

    form[data-prevent-multiple-submit] #entry-rows td:nth-child(5)::before {
        content: '貸方金額';
    }

    form[data-prevent-multiple-submit] #entry-rows td:nth-child(6)::before {
        content: '取引先';
    }

    form[data-prevent-multiple-submit] #entry-rows td:nth-child(7)::before {
        content: '備考';
    }

    form[data-prevent-multiple-submit] #entry-rows td:nth-child(8)::before {
        content: '課税区分';
    }

    form[data-prevent-multiple-submit] #entry-rows td:nth-child(9)::before {
        content: '操作';
    }

    form[data-prevent-multiple-submit] #entry-rows input,
    form[data-prevent-multiple-submit] #entry-rows select {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100%;
    }

    form[data-prevent-multiple-submit] #entry-rows td:nth-child(3) input,
    form[data-prevent-multiple-submit] #entry-rows td:nth-child(5) input {
        text-align: right;
    }

    form[data-prevent-multiple-submit] #entry-rows td:nth-child(9) > .flex {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    form[data-prevent-multiple-submit] #entry-rows td:nth-child(9) button {
        width: auto;
    }

    form[data-prevent-multiple-submit] .mt-6.flex.justify-end.items-center.gap-3 {
        flex-direction: column;
        align-items: stretch;
        text-align: left;
        gap: 0.75rem;
    }

    form[data-prevent-multiple-submit] .mt-6.flex.justify-end.items-center.gap-3 select {
        width: 100% !important;
    }

    /* -------------------------------- */
    /* ログインページ */
    /* -------------------------------- */
    #page-login {
        padding: 1.5rem;
        border-radius: 1rem;
    }

    /* ログインページ見出し */
    #page-login h1 {
        font-size: 1.8rem !important;
        line-height: 1.25 !important;
        margin-bottom: 1.25rem;
    }

    /* -------------------------------- */
    /* ダッシュボード全体 */
    /* -------------------------------- */
    #page-dashboard {
        gap: 1.25rem;
    }

    /* ダッシュボードのグリッド */
    #page-dashboard .grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.85rem;
    }

    /* ダッシュボードカード */
    #page-dashboard .grid > * {
        min-width: 0;
    }

    /* カードの余白 */
    #page-dashboard .rounded-lg {
        padding: clamp(0.9rem, 4vw, 1.1rem);
        border-radius: 1rem;
    }

    /* ダッシュボード見出し（大） */
    #page-dashboard .text-2xl {
        font-size: 1.3rem;
    }

    /* ダッシュボード見出し（中） */
    #page-dashboard .text-lg {
        font-size: 1rem;
    }

    /* ダッシュボード内の表コンテナ */
    #page-dashboard .dashboard-table-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* ダッシュボード内の表 */
    #page-dashboard .dashboard-table-scroll table {
        min-width: 0;
    }

    /* P/L テーブル配置 */
    #page-dashboard
        .grid.gap-6
        .rounded-lg:first-child
        .dashboard-table-scroll
        table {
        white-space: normal;
    }

    /* P/L のコード列 */
    #page-dashboard
        .grid.gap-6
        .rounded-lg:first-child
        .dashboard-table-scroll
        table
        th:nth-child(2),
    #page-dashboard
        .grid.gap-6
        .rounded-lg:first-child
        .dashboard-table-scroll
        table
        td:nth-child(2) {
        white-space: nowrap;
    }

    /* P/L 右側テーブルのヘッダー非表示 */
    #page-dashboard
        .grid.gap-6
        .rounded-lg:first-child
        .dashboard-table-scroll:nth-of-type(2)
        thead {
        display: none;
    }

    /* P/L コード列非表示 */
    #page-dashboard
        .grid.gap-6
        .rounded-lg:first-child
        .dashboard-table-scroll
        table
        th:first-child,
    #page-dashboard
        .grid.gap-6
        .rounded-lg:first-child
        .dashboard-table-scroll
        table
        td:first-child {
        display: none;
    }

    /* P/L 金額列の横幅固定 */
    #page-dashboard
        .grid.gap-6
        .rounded-lg:first-child
        .dashboard-table-scroll
        table
        th:last-child,
    #page-dashboard
        .grid.gap-6
        .rounded-lg:first-child
        .dashboard-table-scroll
        table
        td:last-child {
        white-space: nowrap;
    }

    /* B/S カード */
    #page-dashboard .balance-columns {
        grid-template-columns: minmax(0, 1fr);
    }

    /* B/S 部分のスクロール */
    #page-dashboard .balance-column .dashboard-table-scroll {
        -webkit-overflow-scrolling: touch;
    }

    /* B/S カラム構造 */
    #page-dashboard .balance-column {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    /* B/S カラム内ブロック */
    #page-dashboard .balance-column .balance-column__group {
        flex: 1 1 auto;
    }

    /* B/S テーブル */
    #page-dashboard .balance-column table {
        min-width: 0;
        white-space: normal;
    }

    /* B/S コード列非表示 */
    #page-dashboard .balance-column table th:first-child,
    #page-dashboard .balance-column table td:first-child {
        display: none;
    }

    /* B/S 金額列維持 */
    #page-dashboard .balance-column table td:last-child,
    #page-dashboard .balance-column table th:last-child {
        white-space: nowrap;
    }

    /* B/S サマリカード */
    #page-dashboard .balance-column .rounded {
        width: 100%;
    }

    /* B/S 合計ボックス位置 */
    #page-dashboard .balance-column .balance-column__total {
        margin-top: auto;
    }

    /* B/S 負債カラム */
    #page-dashboard .balance-column.balance-column--liability {
        gap: 1.25rem;
    }

    /* B/S 負債カラム内スペーサーを非表示 */
    #page-dashboard .balance-column.balance-column--liability .h-4,
    #page-dashboard .balance-column.balance-column--liability .h-6,
    #page-dashboard .balance-column.balance-column--liability .h-5 {
        display: none;
    }

    /* -------------------------------- */
    /* ヘッダーナビゲーション */
    /* -------------------------------- */
    header nav {
        gap: 0.1rem;
    }

    /* ナビのリンク */
    header nav a {
        font-size: clamp(0.72rem, 2.8vw, 0.9rem);
        padding: 0.32rem 0.6rem;
        white-space: nowrap;
        letter-spacing: -0.02em;
        font-feature-settings: "palt";
        font-variant-east-asian: proportional-width;
    }

    /* -------------------------------- */
    /* 固定費・家事按分（未処理） */
    /* -------------------------------- */
    #fixed-cost-pending h2.text-2xl {
        font-size: 1.2rem;
        line-height: 1.3;
        text-align: center;
    }

    /* -------------------------------- */
    /* 仕訳一覧（テーブル） */
    /* -------------------------------- */
    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table thead,
    #fixed-cost-pending .overflow-x-auto > table thead {
        display: none;
    }

    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table,
    #fixed-cost-pending .overflow-x-auto > table {
        width: 100%;
        border-spacing: 0;
        display: block;
    }

    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody,
    #fixed-cost-pending .overflow-x-auto > table tbody {
        display: block;
    }

    /* 仕訳行 */
    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody tr,
    #fixed-cost-pending .overflow-x-auto > table tbody tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem 1.25rem;
        padding: 1rem 0.75rem;
        border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    }

    /* 仕訳セル */
    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td,
    #fixed-cost-pending .overflow-x-auto > table tbody td {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: flex-start;
        border: none;
        padding: 0;
        width: 100%;
        min-width: 0;
        gap: 0.25rem;
        font-size: 0.94rem;
        line-height: 1.4;
        color: #0f172a;
        word-break: break-word;
    }

    /* 仕訳セルラベル */
    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td::before,
    #fixed-cost-pending .overflow-x-auto > table tbody td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 0.1rem;
        font-size: 0.68rem;
        letter-spacing: 0.02em;
        text-transform: none;
        color: #94a3b8;
        background: none;
        padding: 0;
        border-radius: 0;
    }

    /* 日付＋管理番号 */
    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(1),
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(1) {
        grid-column: 1;
        grid-row: 1;
        font-size: 1.05rem;
        font-weight: 600;
    }

    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(2),
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(2) {
        grid-column: 2;
        grid-row: 1;
        align-items: flex-end;
        text-align: right;
        font-variant-numeric: tabular-nums;
    }

    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(2)::before,
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(2)::before {
        align-self: flex-end;
    }

    /* 借方ブロック */
    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(3),
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(3) {
        grid-column: 1;
        grid-row: 2;
        text-align: left;
        align-items: flex-start;
    }

    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(4),
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(4) {
        grid-column: 2;
        grid-row: 2;
        align-items: flex-end;
        text-align: right;
        font-weight: 600;
        font-variant-numeric: tabular-nums;
    }

    /* 貸方ブロック */
    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(5),
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(5) {
        grid-column: 1;
        grid-row: 3;
        text-align: left;
        align-items: flex-start;
    }

    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(6),
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(6) {
        grid-column: 2;
        grid-row: 3;
        align-items: flex-end;
        text-align: right;
        font-weight: 600;
        font-variant-numeric: tabular-nums;
    }

    /* 取引先 */
    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(7),
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(7) {
        grid-column: 1 / -1;
        grid-row: 4;
        padding-top: 0.5rem;
    }

    /* 備考／証憑／操作 */
    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(8),
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(8) {
        grid-column: 1 / -1;
        grid-row: 5;
        color: #475569;
        line-height: 1.5;
    }

    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(9),
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(9) {
        grid-column: 1 / -1;
        grid-row: 6;
        border-top: 1px dashed rgba(148, 163, 184, 0.6);
        padding-top: 0.65rem;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.35rem;
    }

    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(9)::before,
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(9)::before {
        margin-bottom: 0;
        margin-right: 0.5rem;
        width: auto;
    }

    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(9),
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(9)
        > :not([hidden])
        ~ :not([hidden]) {
        margin-left: 0.75rem;
    }

    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(10),
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(10) {
        grid-column: 1 / -1;
        grid-row: 7;
        border-top: 1px dashed rgba(148, 163, 184, 0.6);
        padding-top: 0.65rem;
        gap: 0.35rem;
        align-items: center;
        text-align: left;
        flex-direction: row;
        flex-wrap: wrap;
    }

    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(10)::before,
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(10)::before {
        margin-bottom: 0;
        margin-right: 0.5rem;
        width: auto;
    }

    form.grid.gap-3.sm\:grid-cols-6 + .overflow-x-auto > table tbody td:nth-child(10),
    #fixed-cost-pending .overflow-x-auto > table tbody td:nth-child(10)
        > :not([hidden])
        ~ :not([hidden]) {
        margin-left: 0.75rem;
    }

    #page-journals .border-t.border-slate-100.flex.flex-col.gap-2 {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.45rem 0.75rem;
        align-items: baseline;
        justify-content: flex-end;
        text-align: right;
    }

    #page-journals .border-t.border-slate-100.flex.flex-col.gap-2 > div {
        flex: 0 1 auto;
        white-space: nowrap;
        font-size: 0.82rem;
    }

    #page-journals .border-t.border-slate-100.flex.flex-col.gap-2 > div:first-child {
        flex: 1 1 auto;
        min-width: 45%;
        text-align: left;
        font-size: 0.75rem;
    }

    #page-journals .border-t.border-slate-100.flex.flex-col.gap-2 > div span {
        font-size: 0.92rem;
    }

    .overflow-x-auto + .flex.flex-col.gap-2 {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 0.45rem 1rem !important;
        align-items: baseline !important;
        justify-content: flex-end !important;
        text-align: right;
    }

    .overflow-x-auto + .flex.flex-col.gap-2 > div {
        flex: 0 1 auto;
        white-space: nowrap;
        font-size: 0.85rem;
    }

    .overflow-x-auto + .flex.flex-col.gap-2 > div span {
        font-size: 0.95rem;
    }
}

/* -------------------------------- */
/* レイアウトコンテナ（共通） */
/* -------------------------------- */
.layout-container .flex.flex-wrap.items-center.justify-end {
    justify-content: flex-start;
    text-align: left;
    flex-direction: column;
    align-items: flex-start;
}

/* レイアウト内の行 */
.layout-container
    .flex.flex-wrap.items-center.justify-end
    > .flex.items-center,
.layout-container .flex.flex-wrap.items-center.justify-end > form.flex {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    gap: 0.5rem;
}

/* レイアウト内のラベル */
.layout-container
    .flex.flex-wrap.items-center.justify-end
    span.font-semibold.text-slate-600 {
    min-width: 5rem;
}

/* レイアウト内フォーム */
.layout-container
    .flex.flex-wrap.items-center.justify-end
    > form:last-child {
    align-self: flex-end;
}

:is(#page-journals form.grid.gap-3.sm\:grid-cols-6, form.grid.gap-3.sm\:grid-cols-6)
    > .sm\:col-span-6.flex.flex-wrap.items-center.justify-end {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    justify-content: flex-end !important;
    align-items: center !important;
    width: 100% !important;
    gap: 0.5rem !important;
}

:is(#page-journals form.grid.gap-3.sm\:grid-cols-6, form.grid.gap-3.sm\:grid-cols-6)
    > .sm\:col-span-6.flex.flex-wrap.items-center.justify-end
    > * {
    white-space: nowrap;
    flex-shrink: 0;
}

@media (max-width: 392px) {
    /* ダッシュボード余白 */
    #page-dashboard {
        gap: 1rem;
    }

    /* ダッシュボードタイトル */
    #page-dashboard h1 {
        font-size: 1.5rem;
        line-height: 1.3;
    }

    /* ダッシュボードグリッド */
    #page-dashboard .grid {
        gap: 0.75rem;
    }

    /* カード余白 */
    #page-dashboard .rounded-lg {
        padding: 0.85rem;
    }

    /* 見出し縮小 */
    #page-dashboard .text-2xl {
        font-size: 1.2rem;
    }

    /* サブ見出し縮小 */
    #page-dashboard .text-lg {
        font-size: 0.95rem;
    }

    /* テーブルセル縮小 */
    #page-dashboard table th,
    #page-dashboard table td {
        padding: 0.35rem 0.5rem;
        font-size: 0.85rem;
    }
.overflow-x-auto + .flex.flex-col.gap-2 {
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 0.45rem 0.75rem;
        align-items: baseline;
        justify-content: flex-end;
        text-align: right;
    }

    .overflow-x-auto + .flex.flex-col.gap-2 > div {
        flex: 0 0 auto;
        white-space: nowrap;
        font-size: 0.8rem;
    }

    .overflow-x-auto + .flex.flex-col.gap-2 > div:first-child {
        flex: 1 0 auto;
        min-width: 40%;
        text-align: left;
        font-size: 0.75rem;
    }

    .overflow-x-auto + .flex.flex-col.gap-2 > div span {
        font-size: 0.92rem;
    }
