/* 現場管理アプリ（共通の核）。会社ごとの色は config/company.js から上書きする。
   文字は最小14px、ボタンは大きく（指で押しやすい）。 */
:root {
    --brand: #F68D1E;
    --brand-deep: #DE7708;
    --brand-text: #A85D08;
    --brand-wash: #FAE5CE;
    --bg: #F0F2F4;
    --card: #FFFFFF;
    --card-2: #F0F2F4;
    --hair: #E3E6E9;
    --line: #CCCCCC;
    --ink: #333333;
    --ink-2: #4C4948;
    --muted: #6F7378;
    --ok: #2C7A56;
    --ok-bg: #E4F0E9;
    --warn: #9C6C0A;
    --warn-bg: #FBF0DA;
    --bad: #C0392B;
    --bad-bg: #FBE4E0;
    --info: #237CD5;
    --info-bg: #E7F1FC;
    --done: #7C8085;
    --done-bg: #EAECEF;
    --shadow: 0 1px 3px rgba(51,51,51,.08);
    --lift: 0 10px 28px rgba(51,51,51,.18);
    --radius: 12px;
    --tabbar-h: 64px;
    --header-h: 56px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --brand: #F79B3A;
        --brand-deep: #F68D1E;
        --brand-text: #F7A84E;
        --brand-wash: #40290F;
        --bg: #16181A;
        --card: #212426;
        --card-2: #2A2E31;
        --hair: #33373A;
        --line: #43484C;
        --ink: #EDEFF1;
        --ink-2: #CFD3D6;
        --muted: #A0A6AB;
        --ok: #6FC49B;
        --ok-bg: #1D3A2B;
        --warn: #DCA44E;
        --warn-bg: #3A2D13;
        --bad: #EC8074;
        --bad-bg: #3D211C;
        --info: #6FB0F0;
        --info-bg: #1B2E44;
        --done: #9AA0A5;
        --done-bg: #2A2E31;
        --shadow: 0 1px 3px rgba(0,0,0,.4);
        --lift: 0 10px 28px rgba(0,0,0,.5);
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* ===== 枠 ===== */
.shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.header {
    position: sticky; top: 0; z-index: 20;
    height: calc(var(--header-h) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 12px 0;
    display: flex; align-items: center; gap: 10px;
    background: var(--card); border-bottom: 1px solid var(--hair);
}
.header .mark { width: 36px; height: 36px; background: var(--mark) center / contain no-repeat; flex: none; }
.header .title { font-size: 16px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header .who { font-size: 14px; color: var(--muted); max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header .iconbtn { width: 44px; height: 44px; }
.main { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); }
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    display: flex; justify-content: center;
    background: var(--card); border-top: 1px solid var(--hair);
}
.tabbar .inner { display: flex; width: 100%; max-width: 960px; }
.tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 500; min-height: 48px;
}
.tab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.on { color: var(--brand-text); font-weight: 700; }
.tab.primary .plus {
    width: 52px; height: 52px; margin-top: -22px; border-radius: 50%;
    background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center;
    box-shadow: var(--lift);
}
.tab.primary .plus svg { stroke: #fff; width: 28px; height: 28px; }
.tab.primary span.t { margin-top: 0; }

/* ===== 見出し・文字 ===== */
h1 { font-size: 22px; margin: 4px 0 16px; line-height: 1.4; }
h2 { font-size: 17px; margin: 24px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { height: 12px; }

/* ===== カード・リスト ===== */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card.flush { padding: 0; overflow: hidden; }
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--hair); text-decoration: none; color: inherit; min-height: 60px; background: var(--card); width: 100%; border-left: 0; border-right: 0; border-top: 0; text-align: left; cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item:active { background: var(--card-2); }
.item .main-t { font-weight: 700; overflow-wrap: anywhere; }
.item .sub-t { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.item.stack { flex-direction: column; align-items: stretch; gap: 10px; }
.item.stack > .row > .btn { flex: 1 1 0; white-space: nowrap; }
.chev { color: var(--muted); flex: none; }
.chev svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 14px; font-weight: 700; background: var(--done-bg); color: var(--done); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.info { background: var(--info-bg); color: var(--info); }
.chip.brand { background: var(--brand-wash); color: var(--brand-text); }

/* ===== ボタン ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 52px; padding: 0 20px; border-radius: 12px;
    border: 2px solid var(--brand); background: var(--card); color: var(--brand-text);
    font-size: 17px; font-weight: 700; cursor: pointer; text-decoration: none; line-height: 1.2;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.small svg { width: 20px; height: 20px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.quiet { border-color: var(--line); color: var(--ink-2); }
.btn.block { display: flex; width: 100%; }
.btn.big { min-height: 64px; font-size: 19px; }
.btn.small { min-height: 44px; font-size: 15px; padding: 0 14px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.iconbtn { background: none; border: 0; color: var(--ink-2); cursor: pointer; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; }
.iconbtn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ===== 入力 ===== */
.field { margin-bottom: 16px; }
.field > label, .label { display: block; font-size: 14px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }
.field .hint { font-size: 14px; color: var(--muted); margin-top: 4px; }
.input, select.input, textarea.input {
    width: 100%; min-height: 52px; padding: 10px 14px; border-radius: 10px;
    border: 1.5px solid var(--line); background: var(--card); font-size: 17px;
}
textarea.input { min-height: 104px; resize: vertical; }
/* iPhoneのSafariは日付欄の幅と文字寄せを独自に決めて枠からはみ出すため、ほかの欄にそろえる */
input[type=date].input { -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%; text-align: left; }
input[type=date].input::-webkit-date-and-time-value { text-align: left; }
.input:focus { outline: 3px solid var(--brand-wash); border-color: var(--brand); }
.check { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 10px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--card); margin-bottom: 8px; cursor: pointer; }
.check input[type=checkbox] { width: 28px; height: 28px; flex: none; accent-color: var(--brand); }
.check.on { border-color: var(--brand); background: var(--brand-wash); }
.check .kind { margin-left: auto; }
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--card); min-height: 44px; padding: 0 12px; font-size: 15px; cursor: pointer; color: var(--ink-2); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--brand); color: #fff; font-weight: 700; }

/* ===== メッセージ ===== */
.notice { padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 15px; background: var(--info-bg); color: var(--ink); border: 1px solid var(--line); }
.notice.warn { background: var(--warn-bg); }
.notice.bad { background: var(--bad-bg); }
.notice.ok { background: var(--ok-bg); }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: #333; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 15px; box-shadow: var(--lift); max-width: 90%; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
.busy { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; }
.busy .box { background: var(--card); border-radius: 14px; padding: 22px 26px; text-align: center; min-width: 220px; }
.spin { width: 36px; height: 36px; border: 4px solid var(--hair); border-top-color: var(--brand); border-radius: 50%; margin: 0 auto 10px; animation: sp 0.9s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.loading { text-align: center; padding: 40px 0; color: var(--muted); }

/* ===== モーダル ===== */
.sheet-bg { position: fixed; inset: 0; z-index: 78; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 720px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
.sheet h3 { margin: 0 0 12px; font-size: 18px; }
@media (min-width: 720px) { .sheet-bg { align-items: center; } .sheet { border-radius: 18px; } }

/* ===== 写真 ===== */
.folder { margin-bottom: 12px; }
.folder-h { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer; min-height: 56px; }
.folder-h .name { font-weight: 700; flex: 1; }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 8px 0; }
@media (min-width: 640px) { .photo-grid { grid-template-columns: repeat(5, 1fr); } }
.photo-grid .ph { aspect-ratio: 1; background: var(--card-2) center / cover no-repeat; border-radius: 8px; border: 0; padding: 0; cursor: pointer; }
.viewer { position: fixed; inset: 0; z-index: 75; background: #000; display: flex; flex-direction: column; }
.viewer .bar { display: flex; gap: 8px; padding: 10px; padding-top: calc(10px + env(safe-area-inset-top)); color: #fff; align-items: center; }
.viewer .img { flex: 1; background: center / contain no-repeat; }
.viewer .btn { border-color: #fff; color: #fff; background: transparent; }
.viewer .btn.danger { border-color: #ff8a80; color: #ff8a80; }
.picked { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.picked .p { width: 72px; height: 72px; border-radius: 8px; background: var(--card-2) center / cover no-repeat; position: relative; }
.picked .p button { position: absolute; top: -6px; right: -6px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: var(--bad); color: #fff; font-size: 16px; cursor: pointer; }
.progress { height: 10px; background: var(--hair); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }

/* ===== 表 ===== */
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--hair); text-align: left; vertical-align: top; }
.table th { color: var(--muted); font-weight: 700; font-size: 14px; }
.table td.num, .table th.num { text-align: right; }

/* ===== ログイン ===== */
.login { max-width: 420px; margin: 0 auto; padding: 48px 20px; }
.login .logo { height: 72px; background: var(--logo) center / contain no-repeat; margin-bottom: 24px; }
.qrbox { text-align: center; }
.qrbox canvas, .qrbox svg, .qrbox img { width: 240px; height: 240px; image-rendering: pixelated; background: #fff; padding: 8px; border-radius: 8px; }

/* ===== 印刷（QRカード） ===== */
.print-only { display: none; }
@media print {
    body * { visibility: hidden; }
    .print-only, .print-only * { visibility: visible; }
    .print-only { display: block; position: absolute; left: 0; top: 0; width: 100%; text-align: center; padding: 20mm 10mm; color: #000; background: #fff; }
    .print-only .qr img { width: 70mm; height: 70mm; }
    .print-only h2 { font-size: 22pt; }
}

/* ===== PC（幅1024以上）: 左のメニュー、現場は一覧と詳細の2列（デモのPC表示に合わせる） ===== */
.sidebar { display: none; }
@media (min-width: 1024px) {
    .shell { flex-direction: row; }
    .header, .tabbar { display: none; }
    .only-phone { display: none !important; }
    .sidebar {
        display: flex; flex-direction: column; gap: 4px; flex: none;
        position: sticky; top: 0; height: 100vh; height: 100dvh; width: 214px;
        background: var(--card); border-right: 1px solid var(--hair); padding: 16px 12px;
    }
    .side-brand { display: flex; align-items: center; gap: 10px; padding: 0 4px 14px; }
    .side-brand .mark { width: 40px; height: 40px; flex: none; background: var(--mark) center / contain no-repeat; }
    .side-name { display: flex; flex-direction: column; line-height: 1.35; }
    .side-name b { font-size: 15px; }
    .side-name span { font-size: 13px; color: var(--muted); }
    .side-nav { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-size: 15px; }
    .side-nav svg, .side-add svg, .side-out svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
    .side-nav:hover { background: var(--card-2); }
    .side-nav.on { background: var(--card-2); color: var(--ink); font-weight: 700; }
    .side-add { display: flex; align-items: center; justify-content: center; gap: 7px; margin-top: 10px; padding: 12px 0; border-radius: 10px; background: var(--brand); color: #fff; font-size: 15px; font-weight: 700; text-decoration: none; }
    .side-add:hover { background: var(--brand-deep); }
    .side-foot { margin-top: auto; padding: 10px 6px 0; border-top: 1px solid var(--hair); }
    .side-who { font-size: 14px; font-weight: 700; margin-bottom: 4px; overflow-wrap: anywhere; }
    .side-out { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 6px; border: 0; border-radius: 8px; background: none; color: var(--muted); font-size: 14px; cursor: pointer; }
    .side-out:hover { background: var(--card-2); color: var(--ink); }
    .main { max-width: 1180px; margin: 0; padding: 20px 28px 40px; }
    .split { display: flex; gap: 20px; align-items: flex-start; }
    .split-list { flex: 0 0 380px; position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow: auto; padding: 2px 4px 2px 2px; }
    .split-detail { flex: 1 1 auto; min-width: 0; }
    .item:hover { background: var(--card-2); }
    .item.on { background: var(--brand-wash); box-shadow: inset 4px 0 0 var(--brand); }
    .toast-wrap { bottom: 24px; }
    /* PCは横幅があるので、職人の行も名前の右にボタンを並べる */
    .item.stack { flex-direction: row; align-items: center; }
    .item.stack > .row > .btn { flex: none; }
    .split-detail .table th { width: 9em; }
}
@media (min-width: 1024px) and (max-width: 1199px) {
    .sidebar { width: 188px; }
    .split-list { flex-basis: 320px; }
}
