/* ==========================================
   受注発注システム スタイルシート
   ========================================== */

* { box-sizing: border-box; }

body {
    font-family: "Yu Gothic", "游ゴシック", "YuGothic", "Meiryo", "メイリオ", sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f5f5f5;
    color: #333;
    font-size: 14px;
    /* v0.9.1: ページ自体も縦スクロール可 (テーブルとの 2 段スクロール構成) */
    min-height: 100vh;
}

/* ---------- ヘッダー ---------- */
.header {
    background-color: #1f4e79;
    color: white;
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 500;
}

.header nav {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header nav a {
    color: white;
    text-decoration: none;
    font-size: 14px;
    padding: 6px 14px;
    border-radius: 4px;
    transition: background-color 0.15s, color 0.15s;
}

.header nav a:hover { background-color: rgba(255, 255, 255, 0.15); }

/* 現在のページ: 白背景 + 紺文字でハッキリ表示 */
.header nav a.active {
    background-color: #ffffff;
    color: #1f4e79;
    font-weight: 600;
}
.header nav a.active:hover { background-color: #ffffff; }

/* v0.11: ホームアイコンボタン (ヘッダー左端の小さい家アイコン) */
.header nav a.nav-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    padding: 0;
    color: #fff;
    border-radius: 6px;
    transition: background 0.15s;
}
.header nav a.nav-icon-btn:hover { background-color: rgba(255, 255, 255, 0.18); }
.header nav a.nav-icon-btn.active {
    background-color: #ffffff;
    color: #1f4e79;
}
.header nav a.nav-icon-btn.active:hover { background-color: #ffffff; }
.header nav a.nav-icon-btn svg { display: block; }

.user-info {
    color: #cfe2f3;
    font-size: 13px;
    margin-right: 8px;
}

/* ---------- コンテナ ---------- */
.container {
    padding: 20px;
    max-width: 100%;
}

/* ---------- ツールバー ---------- */
.toolbar {
    background: white;
    padding: 12px 16px;
    border-radius: 4px;
    margin-bottom: 12px;
    display: flex;
    gap: 10px;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.btn {
    padding: 8px 18px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    transition: background-color 0.15s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary   { background-color: #1f4e79; color: white; }
.btn-primary:hover:not(:disabled)   { background-color: #163a5a; }

.btn-secondary { background-color: #6c757d; color: white; }
.btn-secondary:hover:not(:disabled) { background-color: #565e64; }

.btn-success   { background-color: #2e7d32; color: white; }
.btn-success:hover:not(:disabled)   { background-color: #1b5e20; }

.btn-danger    { background-color: #c62828; color: white; }
.btn-danger:hover:not(:disabled)    { background-color: #8e1e1e; }

.btn-block { width: 100%; padding: 10px; font-size: 15px; }

.info-text {
    margin-left: auto;
    color: #666;
    font-size: 13px;
}

/* ---------- テーブル ---------- */
/* v0.9.1: テーブル上部のミラー横スクロールバー */
.table-scroll-top {
    overflow-x: auto;
    overflow-y: hidden;
    height: 14px;
    background: #fff;
    border-radius: 4px 4px 0 0;
    box-shadow: 0 -1px 0 rgba(0,0,0,0.04) inset;
    margin-bottom: 0;
}
.table-scroll-top > div {
    height: 1px;  /* スクロールが発生するためのダミー要素 */
}

.table-wrapper {
    background: white;
    border-radius: 0 0 4px 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    /* v0.9.1: 自身の縦スクロール (これが「テーブル用」の上下スクロールバー)
       max-height はビューポート高 - ヘッダ/検索/ツールバー/フッタ概算 */
    max-height: calc(100vh - 320px);
    min-height: 240px;
    overflow: auto;
}
/* table-scroll-top と隣接する場合は table-wrapper の上角を直角に */
.table-scroll-top + .table-wrapper {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

table.data-table {
    /* 内容に合わせて自動幅 + 最小は親幅 (横スクロール許可) */
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
}

table.data-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

table.data-table th {
    background-color: #e7eef5;
    color: #1f4e79;
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #1f4e79;
    border-right: 1px solid #d0d7de;
    /* v0.10: 列幅は内容に合わせて自動調整 (min-width 既定値は撤去、必要列は inline style で個別指定) */
}

table.data-table td {
    padding: 6px 10px;
    border-bottom: 1px solid #eaecef;
    border-right: 1px solid #eaecef;
}

/* ----- v0.10: 凍結列 (sticky-left) ----- */
/* 適用: th と td 両方に .sticky-col を付与し、left:Npx を inline style で個別指定する */
table.data-table th.sticky-col,
table.data-table td.sticky-col {
    position: sticky;
    z-index: 4;
}
table.data-table tbody td.sticky-col { background: #ffffff; }
table.data-table tbody tr:nth-child(even) td.sticky-col { background: #fafbfc; }
table.data-table tbody tr:hover td.sticky-col { background: #f6f8fa; }
table.data-table tbody tr.dirty td.sticky-col { background: #fffde7; }
table.data-table thead th.sticky-col {
    background: #e7eef5;
    z-index: 12;  /* thead(z:10) + 横方向 sticky の重ねる為 */
}
/* 凍結列の右端: 視覚的な区切り */
table.data-table .sticky-col.sticky-edge {
    border-right: 2px solid #90a4ae;
    box-shadow: 2px 0 4px -1px rgba(0, 0, 0, 0.10);
}
/* cell-warn (異常値) は sticky 列でも背景色が優先されるよう保証 */
table.data-table td.sticky-col.cell-warn { background: #ffcdd2 !important; }

/* ----- v0.11: 共通 編集セル スタイル (orders / products 両方で利用)
   列ヘッダで指定した width を尊重するため、input の intrinsic min-width は 0 まで縮める ----- */
.data-table td input.edit-cell {
    width: 100%; min-width: 0;
    border: 1px solid transparent; padding: 3px 5px;
    font-size: 12px; font-family: inherit; background: transparent;
    box-sizing: border-box;
}
.data-table td input.edit-cell[type=number] { min-width: 0; }
.data-table td input.edit-cell[type=date]   { min-width: 95px; }
.data-table td input.edit-cell:focus {
    border-color: #1f4e79; background: #fff8e1; outline: none;
}
.data-table td input.edit-cell[readonly] {
    background: #f5f5f5; color: #555;
}
.data-table tr.dirty td { background: #fffde7 !important; }
.data-table td.cell-warn { background: #ffcdd2 !important; }
.data-table td.cell-warn input { background: transparent; color: #c62828; font-weight: 600; }
.btn-row-save { padding: 3px 10px; font-size: 11px; }
.calc-cell { background: #f0f4f8; color: #333; font-style: italic; }
/* 自動管理セル (旧値・更新日 など、画面で編集不可) */
.readonly-cell { background: #f5f5f5; color: #555; }


table.data-table tbody tr:hover    { background-color: #f6f8fa; }
table.data-table tbody tr:nth-child(even) { background-color: #fafbfc; }

.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- フラッシュメッセージ ---------- */
#flash-container {
    padding: 0 20px;
    margin-top: 12px;
}

.flash {
    padding: 12px 16px;
    border-radius: 4px;
    margin-bottom: 8px;
    border-left: 4px solid;
}
.flash-success { background: #e8f5e9; border-color: #2e7d32; color: #1b5e20; }
.flash-error   { background: #ffebee; border-color: #c62828; color: #8e1e1e; }
.flash-info    { background: #e3f2fd; border-color: #1f4e79; color: #0d3a66; }
.flash-warning { background: #fff3cd; border-color: #ff9800; color: #7d5a00; }

/* ---------- モーダル ---------- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 100;
}
.modal-overlay.show { display: flex; }

.modal {
    background: white;
    padding: 24px;
    border-radius: 6px;
    min-width: 420px;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.modal h2 {
    margin: 0 0 12px;
    font-size: 18px;
    color: #1f4e79;
}

.modal p { margin: 0 0 16px; line-height: 1.6; }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.conflict-list {
    max-height: 200px;
    overflow-y: auto;
    background: #f6f8fa;
    padding: 10px;
    border-radius: 4px;
    margin: 12px 0;
    font-family: "Consolas", "メイリオ", monospace;
    font-size: 12px;
    line-height: 1.5;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}
.empty-state h3 { color: #666; }

.footer {
    text-align: center;
    padding: 16px;
    color: #999;
    font-size: 12px;
}

/* ---------- ログイン画面 ---------- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1f4e79 0%, #2d6ca3 100%);
    padding: 20px;
}

.login-card {
    background: white;
    padding: 32px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
}

.login-card h1 {
    margin: 0 0 8px;
    color: #1f4e79;
    font-size: 22px;
    text-align: center;
}

.login-card .subtitle {
    text-align: center;
    color: #666;
    margin: 0 0 24px;
    font-size: 13px;
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: #333;
    font-weight: 500;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #1f4e79;
    box-shadow: 0 0 0 2px rgba(31, 78, 121, 0.15);
}

/* ---------- 進捗バー ---------- */
.progress-bar {
    width: 100%;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 12px;
}

.progress-bar-fill {
    height: 100%;
    background: #1f4e79;
    transition: width 0.2s;
    width: 0%;
}
