/* Google Fonts のインポート */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Noto+Sans+JP:wght@400;500;700&display=swap');

*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --primary-color: #2c3e50;
    /* 濃いネイビー */
    --accent-color: #3498db;
    /* 明るいブルー */
    --success-color: #27ae60;
    /* グリーン */
    --warning-color: #e67e22;
    /* オレンジ */
    --danger-color: #c0392b;
    /* レッド */
    --background-color: #f4f6f7;
    /* 薄いグレー背景 */
    --card-bg: #ffffff;
    --text-color: #333333;
    --text-muted: #7f8c8d;
    --border-color: #e0e0e0;
}

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* ヘッダー */
header {
    background-color: var(--card-bg);
    padding: 0;
    height: 64px;
    display: flex;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
}

.header-inner.is-guest {
    justify-content: center;
}

header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 400;
}

header h1 a {
    color: var(--primary-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 20px;
}

.user-name-badge {
    font-size: 0.9em;
    background: #f0f0f0;
    padding: 5px 12px;
    border-radius: 20px;
    font-weight: 500;
}

nav a {
    color: var(--text-muted);
    text-decoration: none;
    margin-left: 20px;
    font-weight: 500;
    font-size: 0.95rem;
    transition: color 0.2s;
}

nav a:hover {
    color: var(--accent-color);
}

.logout-btn {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    font-size: 1em;
    padding: 0;
    margin-left: 15px;
    font-family: inherit;
    font-weight: 500;
}

/* コンテンツエリア */
.container {
    max-width: 1000px;
    margin: 40px auto;
    padding: 0 20px;
}

h2 {
    color: var(--primary-color);
    font-size: 1.5rem;
    font-weight: 400;
    margin-bottom: 24px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

/* カードスタイル */
.card,
article.case-detail,
.card-form {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    padding: 32px;
    margin-bottom: 24px;
}

/* テーブルスタイル */
.table-container {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    margin-bottom: 24px;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

th {
    background: #f8f9fa;
    color: var(--text-muted);
    font-weight: 400;
    text-transform: uppercase;
    font-size: 0.85rem;
    padding: 16px;
    text-align: center;
    border-bottom: 2px solid var(--border-color);
}

td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

/* 申請件名（左寄せ）のパディング調整 */
.text-left {
    text-align: left;
    padding-left: 30px !important;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: #fcfcfc;
}

/* リンク */
a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

a:hover {
    color: var(--accent-color);
    text-decoration: underline;
}

/* リンク定義は上記で集約済み */

/* ユーティリティ */
/* .text-left 定義は上記で集約済み */

.text-center {
    text-align: center !important;
}

/* ステータスバッジ */
.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 50px;
    font-size: 0.8rem;
    font-weight: 600;
    text-align: center;
    min-width: 80px;
}

.status-draft {
    background: #ecf0f1;
    color: #7f8c8d;
}

.status-submitted {
    background: #e3f2fd;
    color: #3498db;
}

.status-approved {
    background: #e8f8f5;
    color: #27ae60;
}

.status-remanded {
    background: #fdedec;
    color: #c0392b;
}

/* ボタン */
button {
    font-family: inherit;
    cursor: pointer;
    /* 手のひらマークを基本設定へ */
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 42px;
    padding: 0 24px;
    background-color: var(--accent-color);
    color: white !important;
    border-radius: 6px;
    font-weight: 500;
    font-size: 1rem;
    min-width: 120px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none !important;
    line-height: 1;
    box-sizing: border-box;
}

.button:hover {
    background-color: #2980b9;
    transform: translateY(-1px);
}

.button-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 42px;
    padding: 0 24px;
    background-color: #95a5a6;
    color: white !important;
    border-radius: 6px;
    font-weight: 500;
    font-size: 1rem;
    min-width: 120px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none !important;
    line-height: 1;
    box-sizing: border-box;
}

.button-success {
    background-color: var(--success-color) !important;
}

.button-danger {
    background-color: var(--danger-color) !important;
}

/* AI自動作成・領収書から自動入力ボタン */
.button-ai {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background-color: #6f42c1;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    /* 他のボタンと同じサイズに合わせる */
}

/* フォーム要素 */
input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="password"],
select,
textarea,
input[type="file"] {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: inherit;
    font-size: 1rem;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
    background-color: #fff;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.form-row {
    display: flex;
    gap: 20px;
    margin-bottom: 24px;
}

.form-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

@media screen and (max-width: 600px) {
    .form-row {
        flex-direction: column;
        gap: 24px;
    }
}

.large-input {
    font-size: 1.2rem !important;
    font-weight: 400 !important;
    padding: 14px 20px !important;
    color: var(--primary-color);
}

.form-group {
    margin-bottom: 24px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    /* 太字にして階層を明確化 */
    font-size: 0.95rem;
    /* サイズを少し調整 */
    color: var(--primary-color);
    /* 色を濃くして視認性向上 */
}

/* 詳細画面 */
.meta {
    background: #f8f9fa;
    padding: 16px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 20px;
    font-size: 0.95rem;
}

.case-body {
    margin-top: 20px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 4px;
    font-size: 1.05rem;
    line-height: 1.8;
}

/* 履歴タイムライン */
.history ul {
    padding-left: 20px;
}

.history li {
    padding-left: 24px;
    margin-bottom: 24px;
    border-left: 2px solid var(--border-color);
    position: relative;
    list-style: none;
}

.history li::before {
    content: '';
    position: absolute;
    left: -7px;
    top: 0;
    width: 12px;
    height: 12px;
    background: white;
    border: 2px solid var(--accent-color);
    border-radius: 50%;
}

/* アップロード */
.upload-drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 30px;
    text-align: center;
    cursor: pointer;
}

.hidden-file-input {
    display: none !important;
}

/* --- レスポンシブ対応 (モバイル向け) --- */
@media screen and (max-width: 768px) {
    html {
        font-size: 110%;
        /* 全体のベースを大きくする */
    }

    header {
        height: auto;
        padding: 15px 0;
    }

    .header-inner {
        flex-direction: column;
        gap: 15px;
        /* 少し広げる */
        text-align: center;
        padding: 0 15px;
    }

    header h1 {
        font-size: 1.35rem;
        /* 1.15remから引き上げ */
    }

    .user-info {
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }

    .user-name-badge {
        font-size: 0.95rem;
        /* 0.85remから引き上げ */
        padding: 6px 12px;
    }

    nav {
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 15px;
        flex-wrap: nowrap;
    }

    nav>form {
        display: contents;
        /* フォームの箱を消して、ボタンを直接 nav の子として扱う */
    }

    nav a,
    .logout-btn {
        margin: 0;
        padding: 5px 0;
        /* タップ領域の確保 */
        font-size: 1.1rem;
        /* 0.95remから引き上げ */
        font-weight: 500;
        text-decoration: none;
        background: none;
        border: none;
        cursor: pointer;
        display: inline-block;
        line-height: 1.5;
    }

    .logout-btn {
        color: #dc3545;
        font-family: inherit;
    }

    .container {
        margin: 20px auto;
        padding: 0 12px;
        /* 20pxから12pxに減らす */
    }

    .card,
    article.case-detail,
    .card-form {
        padding: 20px;
    }

    /* テーブル表示の最適化 */
    .table-container {
        background: transparent;
        box-shadow: none;
    }

    @media screen and (max-width: 600px) {

        table,
        thead,
        tbody,
        th,
        td,
        tr {
            display: block;
            width: 100%;
        }

        thead {
            display: none;
            /* ヘッダーを隠す */
        }

        tr {
            background: var(--card-bg);
            margin-bottom: 16px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
            padding: 12px;
            border: 1px solid var(--border-color);
            width: 100%;
        }

        td {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            padding: 10px 0;
            border-bottom: 1px solid #f2f2f2;
            font-size: 0.95rem !important;
            gap: 8px;
            width: 100%;
        }

        td:last-child {
            border-bottom: none;
        }

        td::before {
            content: attr(data-label);
            font-weight: 600;
            color: var(--text-muted);
            font-size: 0.75rem;
            text-align: left;
            flex-shrink: 0;
            width: 75px;
            padding-top: 3px;
        }

        /* tdの中身（右側）のスタイル */
        td>a,
        td>strong,
        td>span,
        td>small {
            flex: 1;
            min-width: 0;
            text-align: right;
            overflow-wrap: break-word;
            word-break: break-all;
            display: block;
        }

        .text-left {
            padding-left: 0 !important;
        }

        /* 金額を強調 */
        td[data-label="金額"] strong {
            font-size: 1.2rem;
            color: var(--primary-color);
        }
    }

    /* 600px以上のタブレット等では横スクロールを維持 */
    @media screen and (min-width: 601px) and (max-width: 768px) {
        .table-container {
            overflow-x: auto;
            background: var(--card-bg);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
        }

        table {
            min-width: 700px;
            /* 600から700に増やして余裕を持たせる */
        }

        th,
        td {
            white-space: nowrap;
        }
    }

    /* 詳細画面メタ情報 */
    .meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        font-size: 0.9rem;
        padding: 12px;
        background: #f8f9fa;
        border-radius: 8px;
    }

    /* 金額・カテゴリー等の情報グリッド */
    .expense-info {
        flex-direction: row !important;
        /* 横並びを維持しつつ */
        flex-wrap: wrap !important;
        /* 折り返しを許可 */
        gap: 15px !important;
        /* 隙間を詰める */
        padding: 15px !important;
    }

    .expense-info>div {
        flex: 1 1 120px;
        /* 120pxをベースに伸縮、足りなければ折り返す */
        min-width: 0;
        /* 文字溢れ防止 */
    }

    .expense-info>div:first-child {
        flex: 1 1 100%;
        /* 金額は一番上に大きく表示 */
        border-bottom: 2px solid #eee;
        padding-bottom: 10px;
        margin-bottom: 5px;
    }

    /* ボタン */
    .button,
    .button-secondary,
    .actions form {
        display: flex;
        /* blockからflexに戻して中央揃えを有効化 */
        align-items: center;
        justify-content: center;
        width: 100%;
        margin-left: 0 !important;
        margin-bottom: 12px;
        box-sizing: border-box;
    }

    .actions,
    .attachment-list,
    form>div[style*="display: flex"] {
        flex-direction: column !important;
        width: 100%;
    }

    .attachment-item {
        width: 100% !important;
    }

    /* モバイルでのフォーム入力欄の文字サイズを16pxに強制 (iOS拡大防止 & 可読性) */
    input[type="text"],
    input[type="number"],
    input[type="date"],
    input[type="email"],
    input[type="password"],
    select,
    textarea {
        font-size: 18px !important;
        /* 16pxから引き上げ */
        padding: 14px 16px;
        /* パディングも増やす */
    }

    /* ラベルとの余白調整 */
    .form-group {
        margin-bottom: 20px;
    }

    /* AIボタンの文字サイズ調整 */
    .button-ai {
        font-size: 18px !important;
        /* 16pxから引き上げ */
        padding: 12px 16px;
        /* パディング増やす */
        width: 100%;
        justify-content: center;
        margin-bottom: 8px;
    }
}

/* AI生成中のアニメーション（点滅） */
@keyframes pulse-animation {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }

    100% {
        opacity: 1;
    }
}

.is-processing {
    animation: pulse-animation 1.5s infinite ease-in-out !important;
    pointer-events: none !important;
    opacity: 0.7;
}

.processing-text::after {
    content: " 生成中...";
    font-size: 1.0em;
}

/* OCR結果入力時のハイライト効果 */
@keyframes highlight-fade {
    0% {
        background-color: rgba(46, 204, 113, 0.2);
        border-color: #2ecc71;
        box-shadow: 0 0 10px rgba(46, 204, 113, 0.3);
    }

    100% {
        background-color: #fff;
        border-color: var(--border-color);
        box-shadow: none;
    }
}

.ocr-fill-highlight {
    animation: highlight-fade 2s ease-out;
}

/* スマホ/PC表示の切り替え */
@media screen and (max-width: 768px) {
    .pc-only {
        display: none !important;
    }

    .mobile-only {
        display: block !important;
    }

    .mobile-camera-area {
        display: block !important;
    }

    .upload-drop-zone {
        padding: 20px 10px !important;
        border-style: solid !important;
        /* モバイルでは点線より実線の方がタップ領域として認識しやすい */
        background-color: #fcfcfc;
    }
}

/* 検索フォーム */
.search-card {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    padding: 24px;
    margin-bottom: 24px;
}

.search-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* 2 columns for tablet/smaller screens */
    gap: 20px;
    align-items: flex-end;
}

@media screen and (min-width: 1024px) {
    .search-form-grid {
        grid-template-columns: 1.2fr 1.8fr 1fr 1fr;
        /* 4 columns for desktop */
    }
}

.search-input {
    width: 100%;
}

.date-range-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-range-container input {
    flex: 1;
    min-width: 0;
    /* Important for flex items to shrink below content size */
}

.search-form-grid label {
    white-space: nowrap;
    font-size: 0.85rem;
    margin-bottom: 5px;
}

.search-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

@media screen and (max-width: 768px) {
    .search-form-grid {
        grid-template-columns: 1fr;
    }

    .search-actions {
        flex-direction: column;
    }

    .search-actions .button {
        width: 100%;
    }
}