/* storekanri — 店舗向け資料アプリ
   スマホ優先で書き、PC(>=900px)は末尾の「PC レイアウト」で上書きする。
   ・スマホ: タップ領域 44px 以上、横スクロールを出さない、下タブは安全領域を避ける
   ・PC:     下タブ → 左サイドバー。横スクロールで隠れる物を作らない（マウスでは操作しづらいため）
   ⚠️ CSP が style-src 'self' なので HTML 側に style="" を書かないこと（効かない）。 */

:root {
    --navy:      #14295c;
    --navy-2:    #1d3a7d;
    --orange:    #ef9421;
    --cyan:      #0d9dc7;
    --bg:        #f4f6fa;
    --card:      #ffffff;
    --line:      #e3e7ee;
    --text:      #1b2233;
    --muted:     #6b7383;
    --danger:    #c62828;
    --ok:        #1b7f4b;
    --radius:    14px;
    --bar-h:     56px;
    --tab-h:     58px;
    --safe-b:    env(safe-area-inset-bottom, 0px);
    color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* ⚠️ overflow-x: hidden は html にだけ付ける。
   body にも付けると body 自身がスクロール領域になり、スクロールする箱が2つできる。
   その状態だと「ホイールが効かず、スクロールバーを掴まないと動かない」ことが起きる。 */
html {
    overflow-x: hidden;
    overscroll-behavior-y: none;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP',
                 'Yu Gothic UI', 'Meiryo', sans-serif;
    font-size: 15px;
    line-height: 1.6;
}

body.app {
    padding-top:    calc(var(--bar-h) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--tab-h) + var(--safe-b) + 8px);
}

a { color: var(--navy-2); }
button { font: inherit; }

.hidden { display: none !important; }

/* ── 上部バー ───────────────────────────────────────────────────────────── */
.app-bar {
    position: fixed;
    inset: 0 0 auto 0;
    height: calc(var(--bar-h) + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 12px 0;
    background: var(--navy);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 40;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .18);
}

.app-bar .logo { width: 28px; height: 28px; flex: 0 0 auto; border-radius: 7px; background: #fff; }

.app-bar .titles { min-width: 0; flex: 1 1 auto; }
.app-bar .t1 { font-size: 11px; opacity: .75; line-height: 1.2; }
.app-bar .t2 {
    font-size: 15px; font-weight: 700; line-height: 1.25;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.icon-btn {
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: 0; color: #fff; border-radius: 50%;
    position: relative; cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, .14); }
.icon-btn svg { width: 22px; height: 22px; }

.badge-dot {
    position: absolute; top: 7px; right: 6px;
    min-width: 17px; height: 17px; padding: 0 4px;
    border-radius: 9px; background: var(--orange); color: #fff;
    font-size: 10px; font-weight: 700; line-height: 17px; text-align: center;
}

/* ── 下タブ ─────────────────────────────────────────────────────────────── */
.tabbar {
    position: fixed;
    inset: auto 0 0 0;
    height: calc(var(--tab-h) + var(--safe-b));
    padding-bottom: var(--safe-b);
    background: #fff;
    border-top: 1px solid var(--line);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    z-index: 40;
}
.tabbar a {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; text-decoration: none; color: var(--muted); font-size: 10px; position: relative;
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.on { color: var(--navy); font-weight: 700; }
.tabbar a .badge-dot { top: 6px; right: calc(50% - 20px); }

/* ── 汎用 ───────────────────────────────────────────────────────────────── */
main { padding: 12px 12px 4px; max-width: 720px; margin: 0 auto; }

.sec-title {
    font-size: 12px; font-weight: 700; color: var(--muted);
    margin: 18px 2px 8px; letter-spacing: .04em;
    /* 店名が見出しになることがある。長くても折り返さず省略する */
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sec-title:first-child { margin-top: 4px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}
.card + .card { margin-top: 10px; }

.row {
    display: flex; align-items: center; gap: 10px;
    padding: 13px 14px; min-height: 56px;
    border-bottom: 1px solid var(--line);
    background: none; border-left: 0; border-right: 0; border-top: 0;
    width: 100%; text-align: left; color: inherit; cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:active { background: #f0f3f9; }
.row .grow { flex: 1 1 auto; min-width: 0; }
/* l1 / l2 は span で作るので display を指定しないと1行に潰れる */
.row .l1 {
    display: block; font-size: 14px; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row .l2 { display: block; font-size: 12px; color: var(--muted); }
.row .chev { flex: 0 0 auto; color: #b7bfcd; }
.row .chev svg { width: 18px; height: 18px; display: block; }

.pill {
    display: inline-block; padding: 1px 8px; border-radius: 999px;
    font-size: 10px; font-weight: 700; line-height: 18px; white-space: nowrap;
}
.pill.new     { background: var(--orange); color: #fff; }
.pill.domo    { background: #e8f1fb; color: var(--navy-2); }
.pill.partner { background: #e6f6fa; color: #0b7d9e; }
.pill.cat     { background: #eef0f5; color: #4a5468; }
.pill.off     { background: #f0f1f4; color: #8b93a3; }

.thumb {
    flex: 0 0 auto; width: 38px; height: 38px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    background: #eef2f9; color: var(--navy-2);
}
.thumb svg { width: 20px; height: 20px; }
.thumb.doc  { background: #fdf0e0; color: #b96b06; }
.thumb.news { background: #e9f7ef; color: var(--ok); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 46px; padding: 0 18px; border-radius: 12px;
    border: 1px solid transparent; background: var(--navy); color: #fff;
    font-size: 15px; font-weight: 700; cursor: pointer; text-decoration: none;
}
/* ボタン内アイコンは必ずサイズを固定する（未指定だとボタン一杯に伸びる） */
.btn svg { width: 18px; height: 18px; flex: 0 0 auto; }
.btn:active { opacity: .85; }
.btn.block { width: 100%; }
.btn.ghost { background: #fff; color: var(--navy); border-color: var(--line); }
.btn.warn  { background: var(--danger); }
.btn.sm    { min-height: 38px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn[disabled] { opacity: .5; cursor: default; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
    flex: 0 0 auto; padding: 7px 14px; border-radius: 999px;
    border: 1px solid var(--line); background: #fff; color: var(--muted);
    font-size: 13px; cursor: pointer;
}
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; font-weight: 700; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
    width: 100%; padding: 12px 14px; font-size: 16px;   /* 16px 未満だと iOS が拡大する */
    border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--text);
}
.field textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
.field input:focus, .field select:focus, .field textarea:focus {
    outline: 2px solid var(--cyan); outline-offset: 1px; border-color: transparent;
}
.field .hint { font-size: 11px; color: var(--muted); margin-top: 5px; }
/* チェックボックス1個だけの行。input を width:100% にしないよう上書きする */
label.field { display: flex; align-items: center; gap: 10px; font-size: 14px; min-height: 44px; }
label.field input[type="checkbox"],
label.field input[type="radio"] { width: 20px; height: 20px; flex: 0 0 auto; }

/* ホーム画面に追加の案内 */
.install-card .row { border-bottom: 0; padding-bottom: 4px; }
.install-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 0 14px 14px; }
.steps { list-style: none; margin: 8px 0 0; padding: 0; counter-reset: step; }
.steps li {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 2px; font-size: 14px; border-bottom: 1px solid var(--line);
}
.steps li:last-child { border-bottom: 0; }
.steps li::before {
    counter-increment: step; content: counter(step);
    flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%;
    background: var(--navy); color: #fff; font-size: 12px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}
.steps .thumb { width: 34px; height: 34px; }

.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 36px 16px; }
.empty svg { width: 40px; height: 40px; opacity: .35; display: block; margin: 0 auto 10px; }

.alert { border-radius: 12px; padding: 11px 13px; font-size: 13px; margin-bottom: 12px; }
.alert.err  { background: #fdecec; color: var(--danger); }
.alert.ok   { background: #e9f7ef; color: var(--ok); }
.alert.info { background: #eaf1fb; color: var(--navy-2); }

.spinner {
    width: 22px; height: 22px; border-radius: 50%;
    border: 2.5px solid #d7dce6; border-top-color: var(--navy);
    animation: spin .8s linear infinite; margin: 32px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 新着ポップアップ（ボトムシート） ─────────────────────────────────────── */
.sheet-back {
    position: fixed; inset: 0; background: rgba(14, 20, 34, .45);
    z-index: 60; display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
    background: #fff; width: 100%; max-width: 560px;
    border-radius: 18px 18px 0 0; padding: 6px 0 calc(12px + var(--safe-b));
    max-height: 82vh; display: flex; flex-direction: column;
    animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: .4; } }
.sheet .grip { width: 40px; height: 4px; border-radius: 2px; background: #d8dde7; margin: 8px auto 4px; }
.sheet .sheet-head { padding: 6px 18px 10px; display: flex; align-items: center; gap: 10px; }
.sheet .sheet-head h2 { font-size: 17px; margin: 0; flex: 1 1 auto; }
/* シート/モーダル内の閉じるボタンは白背景なので暗い色にする */
.sheet .icon-btn, .modal .icon-btn { color: var(--muted); }
.sheet .icon-btn:active, .modal .icon-btn:active { background: #eef0f5; }
.sheet .sheet-body { overflow-y: auto; padding: 0 12px; -webkit-overflow-scrolling: touch; }
.sheet .sheet-foot { padding: 12px 16px 0; display: flex; gap: 10px; }
.sheet .sheet-foot .btn { flex: 1 1 0; }

/* 本文表示（お知らせ詳細） */
.body-text { white-space: pre-wrap; word-break: break-word; font-size: 14px; padding: 0 2px; }

/* ── ログイン画面 ───────────────────────────────────────────────────────── */
body.login {
    min-height: 100dvh;
    display: flex; align-items: center; justify-content: center;
    padding: 24px 18px calc(24px + var(--safe-b));
    background: linear-gradient(170deg, #16305f 0%, #1d3a7d 55%, #0d9dc7 160%);
}
.login-card {
    width: 100%; max-width: 380px; background: #fff;
    border-radius: 18px; padding: 26px 20px 22px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, .25);
}
.login-card .brand { text-align: center; margin-bottom: 18px; }
.login-card .brand img { width: 132px; height: auto; }
.login-card h1 { font-size: 15px; text-align: center; margin: 10px 0 18px; color: var(--muted); font-weight: 600; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 52px; }
.pw-toggle {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    width: 44px; height: 44px; border: 0; background: none; color: var(--muted); cursor: pointer;
}
.pw-toggle svg { width: 20px; height: 20px; }
.login-note { font-size: 11px; color: var(--muted); text-align: center; margin-top: 16px; line-height: 1.7; }

/* ── 管理画面 ───────────────────────────────────────────────────────────── */
body.admin { padding-top: calc(var(--bar-h) + env(safe-area-inset-top, 0px)); padding-bottom: 28px; }
body.admin main { max-width: 980px; }
.admin-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0; scrollbar-width: none; }
.admin-tabs::-webkit-scrollbar { display: none; }

.kpi { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 4px; }
.kpi .k { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.kpi .k b { display: block; font-size: 20px; color: var(--navy); }
.kpi .k span { font-size: 11px; color: var(--muted); }

.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.list { border-collapse: collapse; font-size: 13px; }
/* ⚠️ nowrap を付けないと、幅の足りないスマホで1文字ずつ縦に折り返されて読めなくなる。
   横スクロールさせる方が正しい（tablewrap が overflow-x:auto を持っている）。 */
table.list th, table.list td {
    padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap;
}
table.list th { font-size: 11px; color: var(--muted); background: #fafbfd; position: sticky; top: 0; }
/* 名前・タイトルは長くなるので、この列だけ幅を切って省略記号にする */
table.list td:first-child { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
table.list td:first-child .l2 { font-size: 11px; color: var(--muted); }

.modal-back {
    position: fixed; inset: 0; background: rgba(14, 20, 34, .5); z-index: 70;
    display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
.modal {
    background: #fff; width: 100%; max-width: 620px; max-height: 92vh;
    border-radius: 18px 18px 0 0; display: flex; flex-direction: column;
}
.modal .m-head { padding: 16px 18px 8px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.modal .m-head h2 { font-size: 16px; margin: 0; flex: 1 1 auto; }
.modal .m-body { padding: 16px 18px; overflow-y: auto; }
.modal .m-foot { padding: 12px 18px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); display: flex; gap: 10px; }
.modal .m-foot .btn { flex: 1 1 0; }

.picker { border: 1px solid var(--line); border-radius: 12px; max-height: 240px; overflow-y: auto; }
.picker label { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.picker label:last-child { border-bottom: 0; }
.picker input { width: 18px; height: 18px; flex: 0 0 auto; }

.cred {
    background: #101a33; color: #d8ecff; border-radius: 12px; padding: 12px 14px;
    font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace; font-size: 14px;
    word-break: break-all; user-select: all;
}

@media (min-width: 700px) {
    .modal-back, .sheet-back { align-items: center; padding: 20px; }
    .modal, .sheet { border-radius: 18px; }
    .sheet { max-height: 86vh; }
    .sheet .grip { display: none; }
}

/* ══ PC レイアウト (>=900px) ═══════════════════════════════════════════════
   下タブを左サイドバーに変え、本文を広く使う。
   ⚠️ 横スクロールに隠れる物を作らないこと。マウスだと横スクロールはまず気づかれない
      （スマホでは指で流せるチップ列が、PCでは「切れて見えないだけ」になる）。 */
@media (min-width: 900px) {
    :root { --side-w: 216px; }

    body.app {
        padding-top:    var(--bar-h);
        padding-bottom: 0;
        padding-left:   var(--side-w);
    }

    .app-bar { padding-left: 16px; height: var(--bar-h); }
    .app-bar .t2 { font-size: 16px; }

    /* 下タブ → 左サイドバー */
    .tabbar {
        inset: var(--bar-h) auto 0 0;
        width: var(--side-w);
        height: auto;
        padding: 12px 10px;
        display: flex;
        flex-direction: column;
        gap: 4px;
        border-top: 0;
        border-right: 1px solid var(--line);
    }
    .tabbar a {
        flex-direction: row;
        justify-content: flex-start;
        gap: 12px;
        padding: 0 14px;
        min-height: 46px;
        border-radius: 11px;
        font-size: 14px;
    }
    .tabbar a:hover { background: #f0f3f9; }
    .tabbar a.on    { background: var(--navy); color: #fff; }
    .tabbar a .badge-dot { position: static; margin-left: auto; }

    main { max-width: 900px; padding: 20px 24px 40px; margin: 0 auto; }

    /* チップは折り返す。PCで横スクロールに隠すと「無い」のと同じ */
    .chips, .admin-tabs { flex-wrap: wrap; overflow-x: visible; }
    .chip { cursor: pointer; }
    .chip:hover { border-color: #b9c2d4; }

    .row { padding: 14px 18px; }
    .row:hover { background: #f7f9fd; }
    .icon-btn:hover { background: rgba(255, 255, 255, .14); }
    .sheet .icon-btn:hover, .modal .icon-btn:hover { background: #eef0f5; }
    .btn:hover { filter: brightness(1.06); }

    /* 月/店舗ごとの塊を2列にして縦の移動を減らす（系列・管理者は行数が多い）
       ⚠️ 1fr ではなく minmax(0, 1fr)。長い店名がある列が押し広げられて画面外に溢れる。 */
    .grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 16px; align-items: start; }
    .grid2 .sec-title { margin-top: 14px; }
}

@media (min-width: 900px) {
    body.admin { padding-left: 0; padding-bottom: 40px; }
    body.admin main { max-width: 1160px; padding: 8px 24px 40px; }

    /* 🔴 表に max-height + overflow を付けるとホイールを表が吸い取り、
       ページ側が動かなくなる（「スクロールバーを掴まないと動かない」の正体）。
       PC では表は画面幅に収まるので、素直にページごとスクロールさせる。 */
    body.admin .tablewrap { max-height: none; overflow: visible; }
    /* 上の overflow を外したので、見出し行はページのスクロールに対して貼り付く */
    body.admin table.list th { top: calc(var(--bar-h) + 8px); z-index: 5; }

    table.list td:first-child { max-width: 380px; }
}
