/* ============================================================
   CPN 車両販売管理システム - スタイルシート
   Version: 0.3.0
   ============================================================ */

/* ---------- CSS変数 ---------- */
:root {
    --font-main: 'Noto Sans JP', sans-serif;

    --color-primary:    #1d4ed8;
    --color-primary-dk: #1e40af;
    --color-danger:     #dc2626;
    --color-warning:    #d97706;
    --color-success:    #059669;
    --color-info:       #0891b2;

    --color-bg:         #f1f5f9;
    --color-surface:    #ffffff;
    --color-border:     #e2e8f0;
    --color-text:       #0f172a;
    --color-text-sub:   #64748b;
    --color-text-mute:  #94a3b8;

    --sidebar-bg:     #0f172a;
    --sidebar-text:   #94a3b8;
    --sidebar-hover:  rgba(255,255,255,.05);
    --sidebar-active-bg:  rgba(29,78,216,.15);
    --sidebar-active-txt: #60a5fa;
    --sidebar-width:  256px;

    --header-h:  58px;
    --radius:    6px;
    --radius-lg: 10px;
    --shadow:    0 1px 3px rgba(0,0,0,.08);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07);
    --shadow-lg: 0 10px 15px rgba(0,0,0,.1);
}

/* ---------- リセット ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: var(--font-main);
    font-size: 14px;
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.6;
}
a { color: var(--color-primary); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }
.hidden { display: none !important; }

/* ---------- ログイン画面 ---------- */
.page { min-height: 100vh; }
#page-shop-login,
#page-user-login {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}
.login-wrap { width: 100%; max-width: 420px; padding: 24px; }
.login-logo {
    display: flex;
    align-items: center;
    gap: 14px;
    justify-content: center;
    margin-bottom: 36px;
    color: #fff;
    font-size: 20px;
    font-weight: 700;
}
.login-logo i { font-size: 32px; color: #60a5fa; }
.login-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-lg);
}
.login-card h2 {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.login-version {
    text-align: center;
    margin-top: 16px;
    color: rgba(255,255,255,.35);
    font-size: 12px;
}
.shop-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #eff6ff;
    color: #1d4ed8;
    padding: 5px 12px;
    border-radius: 9999px;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 20px;
}

/* ---------- レイアウト ---------- */
#page-main {
    display: flex;
    min-height: 100vh;
}

/* ---------- サイドバー ---------- */
#sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
    transition: transform .25s ease;
}
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
}
.sidebar-header i { font-size: 22px; color: #60a5fa; flex-shrink: 0; }
.sidebar-title { overflow: hidden; }
.sidebar-app  { display: block; color: #fff; font-size: 14px; font-weight: 700; }
.sidebar-shop {
    display: block;
    color: #60a5fa;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-nav {
    flex: 1;
    padding: 8px 0;
}
.nav-section {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #475569;
    padding: 12px 18px 4px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 18px;
    color: var(--sidebar-text);
    font-size: 13.5px;
    border-left: 3px solid transparent;
    text-decoration: none;
    transition: background .15s, color .15s;
}
.nav-item:hover  { background: var(--sidebar-hover); color: #e2e8f0; text-decoration: none; }
.nav-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-txt);
    border-left-color: #3b82f6;
}
.nav-item i { width: 17px; text-align: center; font-size: 13px; }
.sidebar-footer {
    padding: 14px 18px;
    border-top: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
}
.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    color: #e2e8f0;
    font-size: 13px;
}
.user-info i { font-size: 22px; color: #60a5fa; }
.role-badge {
    font-size: 11px;
    color: var(--sidebar-text);
    background: rgba(255,255,255,.08);
    padding: 1px 7px;
    border-radius: 9999px;
    display: inline-block;
}

/* ---------- メイン ---------- */
#main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.main-header {
    height: var(--header-h);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 24px;
    position: sticky; top: 0; z-index: 50;
    box-shadow: var(--shadow);
}
.main-header h1 { font-size: 16px; font-weight: 700; flex: 1; }
.header-right { display: flex; align-items: center; gap: 10px; }
.header-alert { margin-bottom: 0; font-size: 12px; }
#page-container { flex: 1; padding: 20px 24px; }

/* ---------- カード ---------- */
.card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--color-border);
}
.card-header h3 {
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-body { padding: 20px; }

/* ---------- フォーム ---------- */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 5px;
}
.form-control {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
.form-control.is-invalid { border-color: var(--color-danger); }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; }
.form-row .form-group { flex: 1; min-width: 160px; }
.form-hint  { font-size: 12px; color: var(--color-text-sub); margin-top: 3px; }
.form-error { font-size: 12px; color: var(--color-danger); margin-top: 3px; }

/* ---------- ボタン ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: var(--radius);
    font-size: 13.5px; font-weight: 500; border: none;
    transition: background .15s, opacity .15s; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-dk); }
.btn-danger  { background: var(--color-danger); color: #fff; }
.btn-danger:hover:not(:disabled)  { background: #b91c1c; }
.btn-success { background: var(--color-success); color: #fff; }
.btn-ghost   { background: transparent; color: var(--color-text-sub); border: 1px solid var(--color-border); }
.btn-ghost:hover:not(:disabled)   { background: #f8fafc; color: var(--color-text); }
.btn-icon    { background: transparent; color: var(--color-text-sub); padding: 7px; border: none; border-radius: var(--radius); }
.btn-icon:hover { background: #f1f5f9; }
.btn-sm   { padding: 5px 10px; font-size: 12.5px; }
.btn-full { width: 100%; justify-content: center; padding: 10px; }

/* ---------- テーブル ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
    background: #f8fafc;
    font-size: 11.5px; font-weight: 700;
    letter-spacing: .04em; color: var(--color-text-sub);
    padding: 9px 14px; text-align: left;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--color-border); }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 11px 14px; font-size: 13.5px; }
tbody tr:last-child { border-bottom: none; }

/* ---------- バッジ ---------- */
.badge {
    display: inline-flex; align-items: center;
    padding: 2px 8px; border-radius: 9999px;
    font-size: 11px; font-weight: 600;
}
.badge-blue    { background: #eff6ff; color: #1d4ed8; }
.badge-green   { background: #f0fdf4; color: #15803d; }
.badge-yellow  { background: #fffbeb; color: #92400e; }
.badge-red     { background: #fef2f2; color: #b91c1c; }
.badge-gray    { background: #f1f5f9; color: #475569; }
.badge-orange  { background: #fff7ed; color: #c2410c; }

/* ---------- アラート ---------- */
.alert {
    padding: 10px 14px; border-radius: var(--radius);
    margin-bottom: 16px; font-size: 13px;
    display: flex; align-items: center; gap: 8px;
}
.alert-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ---------- ツールバー ---------- */
.toolbar {
    display: flex; align-items: center;
    justify-content: space-between; gap: 12px;
    margin-bottom: 16px; flex-wrap: wrap;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; }
.search-box {
    display: flex; align-items: center;
    border: 1px solid var(--color-border);
    border-radius: var(--radius); overflow: hidden;
    background: var(--color-surface);
}
.search-box i { padding: 0 10px; color: var(--color-text-mute); font-size: 13px; }
.search-box input { border: none; padding: 7px 8px 7px 0; outline: none; width: 200px; }

/* ---------- モーダル ---------- */
.modal {
    position: fixed; inset: 0; z-index: 200;
    display: flex; align-items: center; justify-content: center;
}
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.modal-box {
    position: relative; background: var(--color-surface);
    border-radius: var(--radius-lg); padding: 24px;
    width: 420px; max-width: 92vw; box-shadow: var(--shadow-lg);
}
.modal-header {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 10px; font-weight: 700; font-size: 16px;
    color: var(--color-warning);
}
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.modal-form-box {
    position: relative; background: var(--color-surface);
    border-radius: var(--radius-lg);
    width: 96vw; max-width: 1040px; max-height: 92vh;
    overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-form-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 24px; border-bottom: 1px solid var(--color-border);
    font-weight: 700; font-size: 15px;
    position: sticky; top: 0; background: var(--color-surface); z-index: 1;
}
.modal-form-body { padding: 24px; }
.modal-form-footer {
    padding: 14px 24px; border-top: 1px solid var(--color-border);
    display: flex; gap: 10px; justify-content: flex-end;
    position: sticky; bottom: 0; background: var(--color-surface);
}

/* ---------- Toast ---------- */
#toast-container {
    position: fixed; bottom: 20px; right: 20px; z-index: 300;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    padding: 11px 16px; border-radius: var(--radius);
    color: #fff; font-size: 13.5px;
    display: flex; align-items: center; gap: 10px;
    box-shadow: var(--shadow-lg); min-width: 250px;
    animation: toast-in .25s ease;
}
.toast.out { animation: toast-out .25s ease forwards; }
.toast-success { background: var(--color-success); }
.toast-error   { background: var(--color-danger); }
.toast-warning { background: var(--color-warning); }
.toast-info    { background: var(--color-primary); }
@keyframes toast-in  { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:translateY(0); } }
@keyframes toast-out { from { opacity:1; transform:translateY(0); } to { opacity:0; transform:translateY(12px); } }

/* ---------- ローディング ---------- */
.loading-spinner {
    display: flex; align-items: center; justify-content: center;
    height: 200px; color: var(--color-text-mute); font-size: 30px;
}

/* ---------- ダッシュボード ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px; margin-bottom: 20px;
}
.stat-card {
    background: var(--color-surface); border-radius: var(--radius-lg);
    border: 1px solid var(--color-border); padding: 18px;
    box-shadow: var(--shadow); display: flex; align-items: center; gap: 14px;
}
.stat-icon {
    width: 44px; height: 44px; border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; flex-shrink: 0;
}
.stat-icon.blue   { background: #eff6ff; color: var(--color-primary); }
.stat-icon.green  { background: #f0fdf4; color: var(--color-success); }
.stat-icon.orange { background: #fff7ed; color: #ea580c; }
.stat-icon.red    { background: #fef2f2; color: var(--color-danger); }
.stat-value { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--color-text-sub); }

/* ---------- レスポンシブ ---------- */
@media (max-width: 768px) {
    #sidebar { transform: translateX(-100%); }
    #sidebar.open { transform: translateX(0); }
    #main-content { margin-left: 0; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr; }
}

/* ---------- ヘッダー ユーザー情報 ---------- */
.header-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px;
    min-width: 0;
}
.header-user-shop {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--color-text-sub);
    border-right: 1px solid var(--color-border);
    padding-right: 10px;
    margin-right: 2px;
    white-space: nowrap;
}
.header-user-shop i { color: var(--color-primary); }
.header-user-avatar {
    font-size: 22px;
    color: var(--color-primary);
    line-height: 1;
}
.header-user-detail {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.header-user-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}
.header-user-role {
    font-size: 10px;
    align-self: flex-start;
    line-height: 1.4;
}

/* ---------- ヘッダー ユーザードロップダウン ---------- */
.header-user-info { position: relative; }

.header-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 500;
    overflow: hidden;
    animation: dropdown-in .12s ease;
}
.header-dropdown.open { display: block; }

@keyframes dropdown-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.header-dropdown-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 11px 16px;
    background: none;
    border: none;
    font-size: 13px;
    font-family: var(--font-main);
    color: var(--color-text);
    cursor: pointer;
    text-align: left;
    transition: background .1s;
}
.header-dropdown-item:hover { background: #f1f5f9; }
.header-dropdown-item i { width: 16px; text-align: center; color: var(--color-text-sub); }

.header-dropdown-item--danger { color: var(--color-danger); }
.header-dropdown-item--danger i { color: var(--color-danger); }
.header-dropdown-item--danger:hover { background: #fff1f2; }

.header-dropdown-divider {
    height: 1px;
    background: var(--color-border);
    margin: 4px 0;
}


/* ---------- ページネーション ---------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 20px;
    border-top: 1px solid var(--color-border);
}
.page-btn {
    min-width: 40px; height: 40px;
    padding: 0 12px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, border-color .15s, color .15s;
}
.page-btn:hover { background: #f1f5f9; border-color: var(--color-primary); color: var(--color-primary); }
.page-btn.active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
    font-weight: 700;
    box-shadow: 0 1px 4px rgba(29,78,216,.25);
}
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
/* 前後ナビボタン（10ページ超で表示） */
.page-btn.page-nav {
    min-width: 36px;
    font-size: 18px;
    font-weight: 700;
    color: var(--color-primary);
    border-color: var(--color-primary);
}
.page-btn.page-nav:hover { background: var(--color-primary); color: #fff; }
.page-btn.page-nav.disabled { opacity: .3; cursor: not-allowed; pointer-events: none; }
/* 省略記号 */
.page-ellipsis {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    color: var(--color-text-mute);
    font-size: 14px;
    letter-spacing: 2px;
    pointer-events: none;
    user-select: none;
}

/* ---------- 車検証レイアウト ---------- */
.shakensho-block {
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 4px;
    font-size: 13px;
}
/* 4列グリッド: 左ラベル(200px固定) | 入力(伸縮) | 右ラベル(140px固定) | 入力(伸縮) */
.shakensho-row {
    display: grid;
    grid-template-columns: 200px 1fr 140px 1fr;
    border-bottom: 1px solid var(--color-border);
    min-height: 40px;
}
.shakensho-row:last-child { border-bottom: none; }
/* 登録番号行など独自レイアウトはflexのまま */
.shakensho-row.no-grid {
    display: flex;
}
/* 2列だけ使う行（軸重など） */
.shakensho-row.col2 {
    grid-template-columns: 200px 1fr;
}
.shakensho-cell {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    border-right: 1px solid var(--color-border);
    min-width: 0;
    overflow: hidden;
}
.shakensho-cell:last-child { border-right: none; }
.shakensho-label {
    background: #f1f5f9;
    color: var(--color-text-sub);
    font-size: 11px;
    font-weight: 600;
    white-space: normal;
    line-height: 1.4;
    word-break: keep-all;
}
/* flex行（自動車登録番号など）のラベルは200px固定 */
.shakensho-row.no-grid .shakensho-label {
    min-width: 200px;
    flex-shrink: 0;
}
.shakensho-input {
    font-size: 13px !important;
    height: 30px !important;
    padding: 2px 6px !important;
}
.shakensho-unit {
    font-size: 12px;
    color: var(--color-text-sub);
    white-space: nowrap;
}

/* ---------- 得意先サジェスト ---------- */
.suggest-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    max-height: 220px;
    overflow-y: auto;
    margin-top: 2px;
}
.suggest-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid var(--color-border);
    transition: background .1s;
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover { background: #f1f5f9; }
.suggest-code {
    font-size: 11px;
    font-weight: 700;
    color: var(--color-primary);
    min-width: 52px;
    font-family: monospace;
}
.suggest-name { font-weight: 600; flex: 1; }
.suggest-kana { font-size: 11px; color: var(--color-text-sub); min-width: 80px; }
.suggest-tel  { font-size: 11px; color: var(--color-text-mute); white-space: nowrap; }
