:root {
    --ink: #1c2733;
    --muted: #64748b;
    --line: #d9e0e8;
    --bg: #f3f5f8;
    --panel: #ffffff;
    --nav: #17324d;
    --nav-ink: #e6edf5;
    --accent: #0b6bcb;
    --danger: #c0392b;
    --ok-bg: #e5f6ec;
    --ok-ink: #17663a;
    --err-bg: #fdeceb;
    --warn-bg: #fff4d6;
}
* { box-sizing: border-box; }
html { font-size: 17px; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.6;
}
a { color: var(--accent); }

/* 全体の配置（タブレット横向き：左にメニュー） */
.shell { display: flex; min-height: 100vh; }
.nav {
    width: 210px; flex: none; background: var(--nav); color: var(--nav-ink);
    display: flex; flex-direction: column; padding: 16px 12px;
}
.nav .brand { font-weight: 700; font-size: 1.1rem; padding: 4px 10px 16px; }
.nav a, .nav button {
    display: block; width: 100%; text-align: left; color: var(--nav-ink); text-decoration: none;
    padding: 13px 12px; border-radius: 8px; font-size: 1rem; background: none; border: 0;
    font-family: inherit; cursor: pointer;
}
.nav a.is-current { background: rgba(255, 255, 255, .16); font-weight: 700; }
.nav .group { font-size: .75rem; opacity: .65; padding: 14px 12px 4px; }
.nav .who { margin-top: auto; font-size: .85rem; opacity: .85; padding: 12px; }
.main { flex: 1; min-width: 0; padding: 24px 28px 48px; }

/* 縦向き・幅が狭いとき：メニューを上に */
@media (max-width: 820px) {
    .shell { flex-direction: column; }
    .nav { width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px; }
    .nav .brand { padding: 4px 10px; }
    .nav a, .nav button { width: auto; padding: 10px 12px; }
    .nav .group { display: none; }
    .nav .who { margin: 0 0 0 auto; padding: 4px 10px; }
    .main { padding: 16px; }
}

.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.panel + .panel { margin-top: 18px; }
.muted { color: var(--muted); }

/* ボタン（指で押しやすい大きさ） */
.btn {
    display: inline-block; min-height: 46px; padding: 10px 20px; border-radius: 8px;
    border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 1rem;
    font-family: inherit; text-decoration: none; cursor: pointer; line-height: 1.5;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn-danger { color: var(--danger); border-color: #e7b9b4; }
.btn-small { min-height: 40px; padding: 7px 14px; font-size: .9rem; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }

/* 一覧表 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.right, th.right { text-align: right; }
.empty { padding: 28px 10px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; background: #e8edf3; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge-warn { background: var(--warn-bg); color: #7a5a00; }
.badge-danger { background: var(--err-bg); color: var(--danger); }

/* 入力フォーム */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form-grid .wide { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; }
.req { color: var(--danger); font-size: .75rem; margin-left: 6px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number],
input[type=date], input[type=time], input[type=search], select, textarea {
    width: 100%; min-height: 46px; padding: 9px 12px; font-size: 1rem; font-family: inherit;
    color: var(--ink); background: #fff; border: 1px solid #b9c4d0; border-radius: 8px;
}
textarea { min-height: 110px; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(11, 107, 203, .3); border-color: var(--accent); }
.is-invalid { border-color: var(--danger) !important; }
.error { color: var(--danger); font-size: .85rem; margin-top: 4px; }
.hint { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.form-foot { display: flex; gap: 10px; margin-top: 22px; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.flash-ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash-error { background: var(--err-bg); color: var(--danger); }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.stat .num { font-size: 2rem; font-weight: 700; line-height: 1.2; }
.search { display: flex; gap: 8px; margin-bottom: 16px; }
.search input { max-width: 360px; }
.pager { margin-top: 16px; display: flex; gap: 10px; align-items: center; }

.login { max-width: 420px; margin: 9vh auto; padding: 0 16px; }
.login h1 { text-align: center; margin-bottom: 20px; }
.login .field + .field { margin-top: 14px; }
.stats .panel { margin-top: 0; }

.checks { display: flex; flex-wrap: wrap; gap: 8px 12px; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 46px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.check input { width: 22px; height: 22px; }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tab { display: inline-block; min-height: 46px; padding: 10px 20px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none; }
.tab.is-current { background: var(--nav); border-color: var(--nav); color: #fff; font-weight: 700; }
td input[type=number] { min-width: 120px; text-align: right; }

/* 予約表（ガントチャート） */
.gantt-tools { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.gantt-tools .actions { margin-bottom: 16px; }
.gantt-tools input[type=date] { width: auto; }
.gantt { padding: 0; overflow: hidden; }
.gantt-row { display: flex; border-bottom: 1px solid var(--line); }
.gantt-row:last-child { border-bottom: 0; }
.gantt-label { width: 190px; flex: none; padding: 8px 12px; font-size: .85rem; line-height: 1.4; border-right: 1px solid var(--line); }
.gantt-track { position: relative; flex: 1; min-width: 0; display: flex; min-height: 58px; }
.gantt-track.is-selectable { touch-action: pan-y; cursor: cell; user-select: none; -webkit-user-select: none; }
.gantt-cell { flex: 1; min-width: 0; border-right: 1px solid #edf0f4; position: relative; }
.gantt-cell:last-child { border-right: 0; }
.gantt-cell.is-closed { background: #eceff3; }
.gantt-cell.is-today { background: #eaf3fd; }
.gantt-head { background: #f8fafc; }
.gantt-head .gantt-label { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--muted); }
.gantt-head .gantt-label strong { color: var(--ink); }
.gantt-head .gantt-track { min-height: 0; }
.gantt-head .gantt-cell { text-align: center; font-size: .8rem; line-height: 1.3; padding: 6px 0; }
.gantt-head .gantt-cell a { color: inherit; text-decoration: none; display: block; }
.gantt-head .gantt-cell.is-red { color: var(--danger); }
.gantt-head .gantt-cell.is-blue { color: var(--accent); }
.gantt-mark { display: block; color: var(--muted); }
.gantt-mark.is-high { color: #a15c00; }
.gantt-inspection { position: absolute; left: 2px; bottom: 2px; z-index: 1; font-size: .65rem; line-height: 1.2; padding: 1px 4px; border-radius: 4px; background: var(--err-bg); color: var(--danger); white-space: nowrap; pointer-events: none; }
.gantt-bar {
    position: absolute; top: 8px; height: 36px; min-width: 6px; padding: 0 8px; border-radius: 6px; z-index: 2;
    background: #2f7fd3; color: #fff; font-size: .85rem; line-height: 36px; text-decoration: none;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gantt-bar.is-rented { background: #1f8a4c; }
.gantt-bar.is-returned { background: #8793a1; }
.gantt-bar.is-free_loaner { background: #b06a00; }
.gantt-bar.is-insurance_loaner { background: #7a4fb5; }
.gantt-selection { position: absolute; top: 4px; bottom: 4px; z-index: 3; border: 2px dashed var(--accent); border-radius: 6px; background: rgba(11, 107, 203, .15); pointer-events: none; }
.gantt-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 12px; font-size: .85rem; }
.gantt-legend span { display: inline-flex; align-items: center; gap: 6px; }
.gantt-legend .gantt-bar { position: static; display: inline-block; width: 22px; height: 14px; padding: 0; }

/* 予約の登録 */
.datetime { display: flex; gap: 8px; }
.datetime select { width: 120px; flex: none; }
.picked { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; }
.results { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; max-height: 280px; overflow-y: auto; }
.result { min-height: 46px; padding: 8px 14px; text-align: left; font-size: 1rem; font-family: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.check input.quantity { width: 76px; min-height: 38px; height: 38px; text-align: right; }
.quote { margin-top: 20px; padding: 14px 18px; border-radius: 10px; background: #f3f8fe; border: 1px solid #cfe2f7; }
.quote dl { margin: 0; }
.quote dl div { display: flex; justify-content: space-between; padding: 3px 0; }
.quote dd { margin: 0; font-variant-numeric: tabular-nums; }
.quote .total { margin-top: 6px; padding-top: 8px; border-top: 1px solid #cfe2f7; font-weight: 700; font-size: 1.2rem; }
.filters { flex-wrap: wrap; align-items: center; }
.filters select, .filters input[type=date] { width: auto; }
[hidden] { display: none !important; }
table.nowrap td { white-space: nowrap; }

/* 貸渡・返却 */
a.stat { display: block; color: inherit; text-decoration: none; }
input[type=datetime-local] { width: 100%; min-height: 46px; padding: 9px 12px; font-size: 1rem; font-family: inherit; color: var(--ink); background: #fff; border: 1px solid #b9c4d0; border-radius: 8px; }
table.detail th { width: 1%; padding-right: 20px; vertical-align: top; font-size: .85rem; }
.panel-alert { border-color: #e7b9b4; background: #fffafa; }
.panel-alert h2 { color: var(--danger); }
.form-foot { flex-wrap: wrap; }

/* キズの記録（車の展開図） */
.damage-cols { display: grid; grid-template-columns: minmax(260px, 420px) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 820px) { .damage-cols { grid-template-columns: 1fr; } }
.car-diagram { display: block; width: 100%; height: auto; }
.car-diagram.is-interactive { cursor: crosshair; touch-action: manipulation; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }

/* 売上・稼働率（横棒グラフ） */
.bar-col { width: 34%; min-width: 120px; }
.bar { height: 16px; min-width: 2px; border-radius: 4px; background: var(--accent); }
tr.sum td { border-top: 2px solid var(--line); font-weight: 700; }
.stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 820px) { .stats, .stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* メニューが長いので、高さが足りないときは縦に動かせるようにする */
@media (min-width: 821px) { .nav { position: sticky; top: 0; height: 100vh; overflow-y: auto; } .nav a, .nav button { padding: 10px 12px; } }
.stats-4 .stat .num { font-size: 1.6rem; white-space: nowrap; }
