:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --danger-dark: #b91c1c;
    --bg: #f5f6f8;
    --card: #ffffff;
    --border: #e2e5ea;
    --text: #1f2733;
    --muted: #6b7280;
    --header-bg: #4d6fa6; /* 目に優しい落ち着いた青（ヘッダー） */
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont,
        "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden; /* スライドイン待機中の項目による右側のはみ出しを防ぐ */
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ヘッダー */
.site-header {
    background: var(--header-bg);
    border-bottom: 1px solid rgba(0, 0, 0, .08);
    /* 常に画面上部に固定（モバイルのドロップダウンもこの中に収まる） */
    position: sticky;
    top: 0;
    z-index: 50;
}
.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}
.brand {
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    text-decoration: none;
}
.site-nav a {
    margin-left: 16px;
    color: rgba(255, 255, 255, .85);
    text-decoration: none;
    font-size: 14px;
}
.site-nav a:hover { color: #fff; }
.nav-user { color: rgba(255, 255, 255, .75) !important; }
/* ログアウトは小さめに（PC・バーガー両方） */
.site-nav a.nav-logout { font-size: 12px; opacity: .85; }
@media (max-width: 768px) { .site-nav a.nav-logout { font-size: 13px; } }

/* ハンバーガーボタン（PC では非表示） */
.nav-toggle-label {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 26px;
    height: 20px;
    cursor: pointer;
}
.nav-toggle-label span {
    display: block;
    height: 3px;
    width: 100%;
    background: #fff;
    border-radius: 2px;
    transition: transform .25s ease, opacity .25s ease;
}

/* タブレット以下（768px 以下）でハンバーガーに切り替え */
@media (max-width: 768px) {
    .nav-toggle-label { display: flex; }

    /* ヘッダー下に上寄せで開くドロップダウン */
    .site-nav {
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        background: var(--header-bg);
        border-bottom: 1px solid rgba(0, 0, 0, .12);
        box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
        /* HTMLの並び順そのまま（TOP → … → ログアウト）で上から表示 */
        flex-direction: column;
        align-items: stretch;
        text-align: right;
        z-index: 30;
        display: flex;
        overflow: hidden;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity .2s ease, visibility .2s ease;
    }
    .site-nav a {
        margin: 0;
        padding: 16px 20px;
        border-top: 1px solid rgba(255, 255, 255, .15);
        font-size: 16px;
        text-align: right;
        /* 初期状態は右にずらして非表示。開くと右からスライドイン */
        transform: translateX(40px);
        opacity: 0;
        transition: transform .3s ease, opacity .3s ease;
    }
    /* メニューを開く */
    .nav-toggle:checked ~ .site-nav {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
    .nav-toggle:checked ~ .site-nav a {
        transform: translateX(0);
        opacity: 1;
    }
    /* スタッガー：上（TOP）から順に登場 */
    .nav-toggle:checked ~ .site-nav a:nth-child(1) { transition-delay: .05s; }
    .nav-toggle:checked ~ .site-nav a:nth-child(2) { transition-delay: .10s; }
    .nav-toggle:checked ~ .site-nav a:nth-child(3) { transition-delay: .15s; }
    .nav-toggle:checked ~ .site-nav a:nth-child(4) { transition-delay: .20s; }
    .nav-toggle:checked ~ .site-nav a:nth-child(5) { transition-delay: .25s; }
    .nav-toggle:checked ~ .site-nav a:nth-child(6) { transition-delay: .30s; }
    .nav-toggle:checked ~ .site-nav a:nth-child(7) { transition-delay: .35s; }

    /* ハンバーガー → × のアニメーション */
    .nav-toggle:checked ~ .nav-toggle-label span:nth-child(1) {
        transform: translateY(8px) rotate(45deg);
    }
    .nav-toggle:checked ~ .nav-toggle-label span:nth-child(2) {
        opacity: 0;
    }
    .nav-toggle:checked ~ .nav-toggle-label span:nth-child(3) {
        transform: translateY(-9px) rotate(-45deg);
    }
}

/* ページ見出し */
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 28px 0 16px;
}
.page-head h1 { font-size: 22px; margin: 0; }

/* ボタン */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
    line-height: 1.2;
}
.btn:hover { background: #f0f2f5; }
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}
.btn-danger:hover { background: var(--danger-dark); }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* テーブル */
.table-wrap {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow-x: auto;
}
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.table th, .table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}
.table thead th {
    background: #fafbfc;
    color: var(--muted);
    font-weight: 600;
}
.table tbody tr:hover { background: #fafbfc; }
.table .num { text-align: right; }
.table .actions { text-align: right; }
.table tfoot td {
    font-weight: 700;
    background: #fafbfc;
}

.inline { display: inline; margin: 0; }

/* フォーム */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
}
.form .field { margin-bottom: 18px; }
.form label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 600;
}
.form input,
.form textarea,
.form select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 15px;
    font-family: inherit;
    box-sizing: border-box;
    background: #fff;
}
.form textarea { resize: vertical; }
.form input:focus,
.form textarea:focus,
.form select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

/* 絞り込み表示バー */
.filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #eef4ff;
    border: 1px solid #cfe0ff;
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: 14px;
}

/* マイページ：集計カード */
.cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 18px;
}
.stat-label {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 8px;
}
.stat-value {
    font-size: 22px;
    font-weight: 700;
}
.section-title {
    font-size: 18px;
    margin: 24px 0 12px;
}
.more-link {
    margin-top: 12px;
    text-align: right;
}
.more-link a {
    color: var(--primary);
    text-decoration: none;
    font-size: 14px;
}
@media (max-width: 768px) {
    .cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
    .cards { grid-template-columns: 1fr; }
}

/* メッセージ */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}
.alert ul { margin: 0; padding-left: 20px; }
.alert-success {
    background: #e7f6ec;
    border: 1px solid #b6e3c4;
    color: #1a7f37;
}
.alert-error {
    background: #fdeaea;
    border: 1px solid #f3bcbc;
    color: #b42318;
}

.empty {
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: 8px;
    padding: 40px;
    text-align: center;
    color: var(--muted);
}

/* フッター */
.site-footer {
    margin-top: 40px;
    /* 右下に浮いている「? 使い方」ボタンと重ならないよう下に余白を確保 */
    padding: 20px 0 72px;
    color: var(--muted);
    text-align: center;
}

/* ===== 認証ページ（ログイン・登録） ===== */
.auth-body {
    background: var(--bg);
}
.auth-brand {
    text-align: center;
    padding: 28px 16px 8px;
}
.auth-brand a {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}
.auth-wrap {
    max-width: 420px;
    margin: 12px auto 48px;
    padding: 0 16px;
}
.auth-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 28px 24px;
    box-shadow: 0 2px 12px rgba(0,0,0,.05);
}
.auth-title {
    margin: 0 0 18px;
    font-size: 20px;
    text-align: center;
}
.auth-switch {
    margin: 18px 0 0;
    text-align: center;
    font-size: 14px;
    color: var(--muted);
}

/* ヘッダーのユーザー名表示 */
.nav-user {
    color: var(--muted);
    font-size: 14px;
}

/* 設定ページの印影プレビュー */
.hint {
    color: var(--muted);
    font-size: 14px;
    margin-top: 0;
}
.muted { color: var(--muted); }
.seal-preview {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}
.seal-preview img {
    width: 110px;
    height: 110px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: 8px;
    background:
        linear-gradient(45deg, #eee 25%, transparent 25%) 0 0/16px 16px,
        linear-gradient(-45deg, #eee 25%, transparent 25%) 0 8px/16px 16px,
        linear-gradient(45deg, transparent 75%, #eee 75%) 8px -8px/16px 16px,
        linear-gradient(-45deg, transparent 75%, #eee 75%) -8px 0/16px 16px,
        #fff;
}

/* ===== 明細入力テーブル ===== */
.li-table th, .li-table td { padding: 4px 5px; vertical-align: middle; }
.li-table input, .li-table select {
    width: 100%; padding: 6px 8px; font-size: 14px;
    border: 1px solid var(--border); border-radius: 5px; box-sizing: border-box;
    font-family: inherit;
}
.li-table .li-qty, .li-table .li-unit { text-align: right; }
.li-table .li-amount { white-space: nowrap; }
.li-table .li-del { padding: 4px 9px; line-height: 1; }
#li-add { margin-top: 8px; }

/* ===== TOP一覧タブ・発行バッジ ===== */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.tabs a {
    padding: 9px 18px;
    text-decoration: none;
    color: var(--muted);
    font-size: 14px;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    margin-bottom: -2px;
}
.tabs a.active {
    color: var(--header-bg);
    font-weight: 700;
    background: #fff;
    border-color: var(--border);
    border-bottom: 2px solid #fff;
}
.issue-badges { display: inline-flex; gap: 5px; }
.ibadge {
    display: inline-block;
    font-size: 12px;
    padding: 2px 7px;
    border-radius: 10px;
    background: #eef0f3;
    color: #9aa1ab;
    white-space: nowrap;
}
.ibadge.on-invoice { background: #eef4ff; color: #2563eb; }
.ibadge.on-quote   { background: #e9f7ef; color: #15803d; }
.ibadge.on-order   { background: #fff1e7; color: #ea580c; }

/* ===== 明細入力（1明細＝2行カード） ===== */
.li-items { margin-bottom: 8px; }
.li-row {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    background: #fff;
}
/* Grid + minmax(0,fr) で入力欄の最小幅に影響されず比率を正確に保つ */
.li-r1 { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,2fr); gap: 8px; }
.li-r2 {
    display: grid;
    grid-template-columns: minmax(0,2.5fr) minmax(0,5fr) minmax(0,2.5fr) minmax(0,5fr) auto;
    gap: 8px; margin-top: 8px; align-items: center;
}
.li-r2 .c-amount { text-align: right; white-space: nowrap; font-weight: 600; }
.li-row input, .li-row select {
    width: 100%; padding: 8px 9px; border: 1px solid var(--border);
    border-radius: 6px; font-size: 14px; box-sizing: border-box; font-family: inherit; background: #fff;
}
.li-totals {
    display: flex; gap: 20px; justify-content: flex-end;
    padding: 6px 2px; font-size: 14px; flex-wrap: wrap;
}
.li-totals strong { font-size: 16px; }

/* 無効化されたボタン（タブ未選択の発行ボタンなど）はグレーアウト */
.btn:disabled, .btn[disabled] { opacity: .4; cursor: not-allowed; }
.btn:disabled:hover, .btn[disabled]:hover { background: inherit; }

/* 取引先情報の入力グリッド */
.client-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 600px) { .client-grid { grid-template-columns: 1fr; } }
/* キー・バリュー表（取引先詳細） */
.kv { width: 100%; border-collapse: collapse; font-size: 14px; }
.kv th { text-align: left; width: 130px; color: var(--muted); font-weight: 600; padding: 6px 8px; vertical-align: top; white-space: nowrap; }
.kv td { padding: 6px 8px; }

/* パスワード表示トグル（目マーク） */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 44px; }
.pw-toggle {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; padding: 0;
    background: none; border: none; cursor: pointer; color: var(--muted);
}
.pw-toggle:hover { color: var(--text); }

/* 認証画面（ログイン等）の送信ボタンは中央寄せ */
.auth-card .form-actions { justify-content: center; }

/* 税区分などのラジオ行 */
.radio-row { display: flex; flex-wrap: wrap; gap: 16px; }
.radio-row label { font-weight: 400; display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.radio-row input[type="radio"] { width: auto; margin: 0; box-shadow: none; }

/* 期間絞り込みフォーム */
.date-filter { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; font-size: 14px; }
.date-filter label { font-weight: 600; }
.date-filter input[type="month"] { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; }

/* ===== ガイドツアー ===== */
.tour-overlay { position: fixed; inset: 0; z-index: 9997; background: transparent; cursor: pointer; }
.tour-spot {
    position: fixed; z-index: 9998; display: none; border-radius: 8px;
    border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(15, 23, 42, .55);
    pointer-events: none; transition: top .2s, left .2s, width .2s, height .2s;
}
.tour-tip {
    position: fixed; z-index: 9999; width: 300px; max-width: calc(100vw - 16px);
    background: #fff; border-radius: 10px; padding: 16px 16px 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
.tour-tip-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.tour-tip-text { font-size: 13px; line-height: 1.7; color: #333; }
.tour-tip-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.tour-count { font-size: 12px; color: var(--muted); }
.tour-btns { display: flex; gap: 8px; }
.tour-close {
    position: absolute; top: 6px; right: 8px; border: none; background: none;
    font-size: 20px; line-height: 1; color: #9aa1ab; cursor: pointer;
}
.tour-close:hover { color: var(--text); }
.tour-fab {
    position: fixed; right: 16px; bottom: 16px; z-index: 9990;
    padding: 9px 16px; border: none; border-radius: 999px; cursor: pointer;
    background: var(--header-bg); color: #fff; font-size: 13px; font-weight: 600;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .22);
}
.tour-fab:hover { background: var(--primary-dark); }
@media print { .tour-fab, .tour-overlay, .tour-spot, .tour-tip { display: none !important; } }

/* フッター：著作権とお問い合わせ先 */
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.footer-contact a { color: var(--primary); text-decoration: none; }
.footer-contact a:hover { text-decoration: underline; }
@media (max-width: 480px) { .footer-inner { justify-content: center; text-align: center; } }
/* 印刷時は「? 使い方」ぶんの余白は不要 */
@media print { .site-footer { padding-bottom: 20px; } }
