/* ==================== 顧客管理ページ (customers.html) ==================== */
/* v2.0: Excel風のデータ表表示（1顧客=1行・展開で履歴・列幅ドラッグ調整） */

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

body {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 14px;
    color: #1E293B;
    background: #F1F5F9;
    min-height: 100vh;
}

body.cp-resizing { cursor: col-resize; user-select: none; }

code { background: #E2E8F0; border-radius: 4px; padding: 1px 5px; font-size: 12px; }

/* ヘッダー */
.cp-header {
    background: #1E3A5F;
    color: #FFFFFF;
    padding: 12px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.cp-header-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.cp-header-title > i { font-size: 22px; color: #F5A014; }
.cp-header-title h1 { font-size: 17px; font-weight: 800; }
.cp-header-sub { font-size: 11.5px; opacity: 0.8; }

.cp-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.cp-org-tag {
    font-size: 11px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 999px;
    padding: 3px 10px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cp-user-name { font-size: 13px; font-weight: 700; }

/* ボタン */
.cp-btn {
    appearance: none;
    border: none;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.cp-btn--primary { background: #2563EB; color: #FFFFFF; }
.cp-btn--primary:hover { background: #1D4ED8; }
.cp-btn--ghost { background: rgba(148, 163, 184, 0.15); color: inherit; }
.cp-header .cp-btn--ghost { color: #FFFFFF; background: rgba(255, 255, 255, 0.14); }
.cp-btn--ghost:hover { background: rgba(148, 163, 184, 0.3); }
.cp-btn--open { background: #EFF6FF; color: #1D4ED8; border: 1px solid #BFDBFE; }
.cp-btn--open:hover { background: #DBEAFE; }
.cp-btn--danger { background: transparent; color: #94A3B8; }
.cp-btn--danger:hover { color: #DC2626; background: #FEF2F2; }
.cp-btn--sm { padding: 4px 9px; font-size: 12px; }

/* 表を広く使うため、管理ビューは画面幅いっぱいに表示する */
.cp-main { max-width: none; margin: 0 auto; padding: 22px 22px 80px; }

/* ===== ログインビュー ===== */
.cp-login-card {
    max-width: 420px;
    margin: 7vh auto 0;
    background: #FFFFFF;
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    padding: 34px 30px 28px;
    text-align: center;
}

.cp-login-logo {
    width: 58px;
    height: 58px;
    margin: 0 auto 14px;
    border-radius: 16px;
    background: linear-gradient(135deg, #F5A014, #F97316);
    color: #FFFFFF;
    font-size: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cp-login-card h2 { font-size: 20px; font-weight: 800; color: #1E3A5F; }

.cp-login-lead {
    font-size: 12.5px;
    color: #64748B;
    line-height: 1.7;
    margin: 10px 0 20px;
}

.cp-field { text-align: left; margin-bottom: 14px; }
.cp-field label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: #475569;
    margin-bottom: 5px;
}
.cp-field input {
    width: 100%;
    padding: 11px 12px;
    border: 1.5px solid #CBD5E1;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
}
.cp-field input:focus { outline: none; border-color: #2563EB; }

.cp-login-error { min-height: 20px; font-size: 12.5px; color: #DC2626; margin-bottom: 8px; }
.cp-login-submit { width: 100%; justify-content: center; padding: 12px; font-size: 14px; }

.cp-login-back {
    display: inline-block;
    margin-top: 18px;
    font-size: 12.5px;
    color: #64748B;
    text-decoration: none;
}
.cp-login-back:hover { color: #2563EB; }

/* ===== ツールバー ===== */
.cp-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.cp-search {
    flex: 1 1 220px;
    max-width: 460px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #FFFFFF;
    border: 1.5px solid #CBD5E1;
    border-radius: 8px;
    padding: 8px 12px;
}
.cp-search i { color: #94A3B8; font-size: 13px; }
.cp-search input {
    border: none;
    outline: none;
    width: 100%;
    font-size: 13.5px;
    font-family: inherit;
    background: transparent;
}

.cp-select {
    padding: 8px 10px;
    border: 1.5px solid #CBD5E1;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    background: #FFFFFF;
    color: #334155;
}

.cp-meta-note {
    background: #FFFBEB;
    border: 1px solid #FDE68A;
    color: #92400E;
    border-radius: 8px;
    padding: 9px 13px;
    font-size: 12.5px;
    margin-bottom: 12px;
}

.cp-summary-bar { font-size: 12.5px; color: #64748B; margin-bottom: 8px; min-height: 18px; }

.cp-empty, .cp-error {
    background: #FFFFFF;
    border-radius: 10px;
    padding: 34px 20px;
    text-align: center;
    color: #64748B;
    font-size: 13.5px;
    line-height: 1.8;
}
.cp-error { color: #DC2626; }

/* ===== Excel風テーブル ===== */
.cp-table-wrap {
    background: #FFFFFF;
    border: 1px solid #CBD5E1;
    border-radius: 8px;
    overflow: auto;
    max-height: calc(100vh - 210px);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.cp-table {
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    font-size: 12.5px;
}

.cp-table th,
.cp-table td {
    border-right: 1px solid #E2E8F0;
    border-bottom: 1px solid #E2E8F0;
    padding: 7px 9px;
    text-align: left;
    vertical-align: middle;
    overflow: hidden;
}

.cp-table th:last-child,
.cp-table td:last-child { border-right: none; }

/* ヘッダー（固定・Excel風グレー） */
.cp-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #F1F5F9;
    color: #334155;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    border-bottom: 2px solid #CBD5E1;
    user-select: none;
}

.cp-th-sortable { cursor: pointer; }
.cp-th-sortable:hover { background: #E2E8F0; }
.cp-th-active { color: #1D4ED8; }
.cp-th-label i { font-size: 11px; }

/* 列の入れ替え（ヘッダーD&D） */
.cp-table thead th[draggable="true"] { cursor: grab; }
.cp-table thead th.cp-th-sortable[draggable="true"] { cursor: pointer; }
.cp-th-dragging { opacity: 0.45; background: #DBEAFE !important; }
.cp-th-drop-before { box-shadow: inset 3px 0 0 #2563EB; }
.cp-th-drop-after { box-shadow: inset -3px 0 0 #2563EB; }

/* 列幅ドラッグハンドル */
.cp-table thead th { position: sticky; }
.cp-col-resizer {
    position: absolute;
    top: 0;
    right: -4px;
    width: 9px;
    height: 100%;
    cursor: col-resize;
    z-index: 3;
}
.cp-col-resizer:hover { background: rgba(37, 99, 235, 0.25); }

/* 行 */
.cp-row { cursor: pointer; }
.cp-row:nth-child(4n+1) td { background: #FFFFFF; }
.cp-row:hover td { background: #F0F7FF; }
.cp-row--open td { background: #EFF6FF; }
.cp-row-chevron { color: #94A3B8; font-size: 11px; }

.cp-table tbody td { white-space: nowrap; }

.cp-td-center { text-align: center; }
.cp-td-num { text-align: right; font-variant-numeric: tabular-nums; }
.cp-td-name strong { font-size: 13px; color: #0F172A; }
.cp-td-ellipsis, .cp-td-name {
    text-overflow: ellipsis;
    overflow: hidden;
}
.cp-plus { color: #059669; font-weight: 700; }

.cp-org-mini {
    font-size: 10px;
    color: #6D28D9;
    background: #F3E8FF;
    border-radius: 999px;
    padding: 1px 7px;
    margin-left: 6px;
    vertical-align: 1px;
}

/* ステータス */
.cp-status-select {
    appearance: none;
    border: none;
    border-radius: 999px;
    padding: 3px 20px 3px 10px;
    font-size: 11.5px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    max-width: 100%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='6'%3E%3Cpath d='M0 0l4 6 4-6z' fill='%2364748B'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 7px center;
}

.cp-status-badge {
    display: inline-block;
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 11.5px;
    font-weight: 700;
}

/* 機器チップ */
.cp-td-equip { white-space: normal; }
.cp-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10.5px;
    font-weight: 700;
    border-radius: 999px;
    padding: 1px 8px;
    margin: 1px 2px 1px 0;
    white-space: nowrap;
}
.cp-chip--pv { color: #B45309; background: #FEF3C7; }
.cp-chip--bt { color: #1D4ED8; background: #DBEAFE; }
.cp-chip--eq { color: #6D28D9; background: #F3E8FF; }
.cp-chip--ih { color: #BE185D; background: #FCE7F3; }
.cp-chip--v2h { color: #047857; background: #D1FAE5; }
.cp-chip--none { color: #94A3B8; background: #F1F5F9; }

/* メモセル */
.cp-td-memo { white-space: normal; }
.cp-memo-cell {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 12px;
    color: #92400E;
    cursor: pointer;
    max-height: 54px;
    overflow: hidden;
    line-height: 1.5;
}
.cp-memo-cell i { color: #F59E0B; margin-top: 2px; font-size: 11px; }
.cp-memo-cell--empty { color: #94A3B8; }
.cp-memo-cell--empty i { color: #CBD5E1; }

.cp-memo-edit { padding: 2px 0; }
.cp-memo-textarea {
    width: 100%;
    border: 1.5px solid #F5A014;
    border-radius: 7px;
    padding: 7px 9px;
    font-size: 12.5px;
    font-family: inherit;
    resize: vertical;
}
.cp-memo-edit-actions { display: flex; gap: 6px; margin-top: 5px; }

.cp-td-actions { white-space: nowrap; }
.cp-td-actions .cp-btn + .cp-btn { margin-left: 4px; }

/* サブ表（シミュレーション履歴） */
.cp-subrow > td {
    background: #F8FAFC;
    padding: 10px 14px 14px 40px;
}

.cp-subtable {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    background: #FFFFFF;
    border: 1px solid #E2E8F0;
    border-radius: 6px;
}

.cp-subtable th,
.cp-subtable td {
    border-bottom: 1px solid #EDF2F7;
    border-right: 1px solid #F1F5F9;
    padding: 6px 9px;
    text-align: left;
    white-space: nowrap;
}

.cp-subtable th {
    background: #F8FAFC;
    color: #64748B;
    font-size: 11px;
    font-weight: 700;
}

.cp-subtable tbody tr:hover td { background: #F0F7FF; }
/* 未計算（保存のみ）の行は金額列が空なので少し控えめに */
.cp-subrow-uncalc td { color: #64748B; }
.cp-subtable .cp-td-ellipsis { max-width: 200px; }
.cp-subtable .cp-td-equip { white-space: normal; min-width: 200px; }

/* スマホ: 横スクロールで表をそのまま使う */
@media (max-width: 680px) {
    .cp-main { padding: 14px 10px 60px; }
    .cp-table-wrap { max-height: none; }
    .cp-subrow > td { padding-left: 14px; }
}
.cp-chip--fdock { color: #6D28D9; background: #EDE9FE; }
