/*
 * 配色はライト / ダークの 2 種類。既定は OS の設定に合わせる（自動）。
 * 画面上部の切替で固定でき、<html data-theme="light|dark"> で指定する（Cookie に保存し、サーバーが付ける）
 */
:root {
  color-scheme: light dark; /* 入力欄・日付選択・スクロールバー・ダイアログ等のブラウザ標準の部品も配色に合わせる */
  --link: #2563eb;
  --shadow: rgba(0, 0, 0, .06);
  --shadow-strong: rgba(15, 23, 42, .14);
  --count-bg: #d93025;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #d9dde3;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --danger-bg: #fdecec;
  --danger-text: #9b1c1c;
  --success-bg: #e8f6ee;
  --success-text: #1e6b3a;
  --warning-bg: #fff6e0;
  --warning-text: #7a4b00;
  /* 旧システムのランク色（COLOR_RANK1〜5） */
  --rank-1: #87ceeb;
  --rank-2: #e0ffff;
  --rank-3: #90ee90;
  --rank-4: #f0e68c;
  --rank-5: #ff7f50;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--link); }

/* ヘッダー（partials/app_header.php） */
.icon { width: 18px; height: 18px; flex: none; }
.app-header { background: var(--surface); border-bottom: 1px solid var(--border); position: relative; z-index: 20; }
.app-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 16px; }
.app-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; }
.app-logo { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: var(--primary-text); }
.app-logo .icon { width: 17px; height: 17px; }
.app-shop { display: flex; align-items: center; gap: 6px; padding: 3px 12px 3px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg); font-size: 13px; }
.app-shop .icon { width: 16px; height: 16px; color: var(--muted); }
.app-shop-brand { color: var(--muted); }
.app-shop-switch { margin-left: 4px; font-size: 12px; }
.app-bar-end { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-left: auto; }
.app-terminal { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; }
.app-terminal > .icon { color: var(--muted); }
.chip { display: inline-block; padding: 1px 10px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; }
.chip-ok { background: var(--success-bg); color: var(--success-text); border-color: transparent; }
.chip-muted { color: var(--muted); }

/* ドロップダウン（<details>。外側のクリック・Esc で閉じる処理は app.js） */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary .icon:last-child { width: 14px; height: 14px; transition: transform .15s; }
.menu[open] > summary .icon:last-child { transform: rotate(180deg); }
.menu-trigger { display: flex; align-items: center; gap: 6px; padding: 3px 8px 3px 4px; border: 1px solid transparent; border-radius: 999px; color: var(--text); font-size: 13px; }
.menu-trigger:hover, .menu[open] > .menu-trigger { background: var(--bg); border-color: var(--border); }
.avatar { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: var(--primary-text); font-size: 13px; font-weight: 700; }
.menu-panel { position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; min-width: 230px; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 32px var(--shadow-strong); }
.menu-end .menu-panel { left: auto; right: 0; }
.menu-panel-wide { min-width: 320px; }
.menu-head { display: flex; flex-direction: column; padding: 6px 10px 8px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.menu-panel form { margin: 0; }
.menu-item { display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px; background: none; color: var(--text); font: inherit; font-size: 14px; text-align: left; text-decoration: none; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--bg); }
.menu-item .icon { margin-top: 2px; color: var(--muted); }
.menu-item small { display: block; color: var(--muted); font-size: 12px; line-height: 1.4; }
.menu-item-danger, .menu-item-danger .icon { color: var(--danger-text); }

/* 主要メニュー（タブ） */
.app-tabs { display: flex; flex-wrap: wrap; align-items: stretch; gap: 2px; padding: 0 10px; }
.app-tabs > a, .app-tab-summary { display: flex; align-items: center; gap: 6px; padding: 9px 12px 10px; border-bottom: 2px solid transparent; color: var(--muted); font-size: 14px; text-decoration: none; white-space: nowrap; }
.app-tabs > a:hover, .app-tab-summary:hover { color: var(--text); background: var(--bg); }
.app-tabs > a[aria-current="page"], .app-tab-summary[aria-current="page"] { color: var(--text); font-weight: 600; border-bottom-color: var(--primary); }
.app-tabs > a[aria-current="page"] .icon, .app-tab-summary[aria-current="page"] .icon { color: var(--primary); }
.app-tabs .menu { display: flex; }
.count { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--count-bg); color: #fff; font-size: 11px; font-weight: 700; line-height: 1; }

@media (max-width: 640px) {
  .app-bar { padding: 8px 12px; }
  .menu-trigger-label, .app-shop-brand { display: none; }
  .app-tabs { padding: 0 4px; }
  .app-tabs > a, .app-tab-summary { padding: 8px 9px; font-size: 13px; gap: 4px; }
  .menu-panel-wide { min-width: 260px; }
}

.app-main { max-width: 1100px; margin: 0 auto; padding: 16px; }

h1 { font-size: 22px; margin: 8px 0 16px; }
h2 { font-size: 17px; margin: 24px 0 8px; }
.muted { color: var(--muted); }
.pre { white-space: pre-wrap; }

.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; }

.detail { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; background: var(--surface); padding: 12px 16px; border: 1px solid var(--border); }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }

.btn {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

.search { display: flex; gap: 8px; margin-bottom: 16px; }
.search input { flex: 1; min-width: 0; padding: 8px; border: 1px solid var(--border); border-radius: 6px; font: inherit; }

.shop-list { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }

.rank-1, .rank-2, .rank-3, .rank-4, .rank-5 { padding: 4px 8px; border-radius: 4px; }
.rank-1 { background: var(--rank-1); }
.rank-2 { background: var(--rank-2); }
.rank-3 { background: var(--rank-3); }
.rank-4 { background: var(--rank-4); }
.rank-5 { background: var(--rank-5); }

/* 画面共通の部品 */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.page-head h1 small { font-size: 14px; font-weight: 400; color: var(--muted); }
.actions, .row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row-actions { justify-content: flex-end; }
.inline-form { display: inline; margin: 0; }
.breadcrumb { margin: 0; font-size: 13px; }
.hint { font-size: 13px; color: var(--muted); margin: 4px 0 12px; }
.req { font-style: normal; font-size: 11px; color: var(--danger-text); margin-left: 4px; }
.num { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.error-list { margin: 0; padding-left: 20px; }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); }
.alert p { margin: 4px 0; }
.secret { font-size: 18px; padding: 2px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; user-select: all; }

.btn-small { padding: 4px 10px; font-size: 13px; }
.btn-danger { color: var(--danger-text); border-color: var(--danger-text); }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.section-nav { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0 16px; font-size: 14px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; scroll-margin-top: calc(var(--sticky-offset, 0px) + 12px); }

/* 顧客詳細: 顧客名とページ内リンクを上部に固定（高さは app.js が --sticky-offset に設定） */
.sticky-head {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: 0 -16px 16px;
  padding: 10px 16px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 6px var(--shadow);
}
.sticky-head h1 { margin: 2px 0; font-size: 20px; }
.back-link { display: inline-block; padding-top: 6px; font-size: 13px; text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.sticky-head .section-nav { margin: 6px 0 0; padding-bottom: 8px; }
.section-nav a { padding: 2px 0; border-bottom: 2px solid transparent; text-decoration: none; }
.section-nav a:hover { border-bottom-color: var(--border); }
.section-nav a.is-active { color: var(--text); font-weight: 700; border-bottom-color: var(--primary); }
.panel h2 { margin-top: 4px; }
.panel .detail { border: 0; padding: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.table tfoot th, .table tfoot td { border-top: 2px solid var(--border); font-weight: 600; }

/* フォーム */
.form { max-width: 760px; }
.form fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 8px 16px 12px; margin: 0 0 16px; background: var(--surface); }
.form legend { font-weight: 700; padding: 0 6px; }
.field select, .field textarea { width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: var(--surface); color: var(--text); }
.field input:not([type="radio"]):not([type="checkbox"]) { background: var(--surface); color: var(--text); }
.field-short { max-width: 260px; }
.choices { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; }
/* ラジオ・チェックボックスは「ボタン＋文字」を 1 組として並べる */
.choices label { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; cursor: pointer; }
.choices input[type="radio"], .choices input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--primary); }
.choices input[type="text"] { flex: 1 1 200px; min-width: 0; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font: inherit; }
.phone-row { display: flex; gap: 8px; margin-bottom: 6px; }
.phone-row input { flex: 1 1 0; min-width: 0; padding: 8px; border: 1px solid var(--border); border-radius: 6px; font: inherit; }
.form-actions { display: flex; align-items: center; gap: 16px; margin-top: 8px; }

.inline-add { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; margin-bottom: 12px; }
.inline-add .field { margin-bottom: 0; }
.field-grow { flex: 1 1 280px; }
.search .field { margin-bottom: 0; }
.search { align-items: flex-end; flex-wrap: wrap; }

@media (max-width: 640px) {
  .table { display: block; overflow-x: auto; }
  /* 固定部分が画面を占領しないよう、リンクは 1 行の横スクロールに */
  .sticky-head h1 { font-size: 17px; }
  .sticky-head .page-head .actions .btn { padding: 4px 10px; font-size: 13px; }
  .sticky-head .section-nav { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; scrollbar-width: thin; }
  .detail { grid-template-columns: 1fr; }
  .detail dt { margin-top: 6px; }
  .phone-row { flex-direction: column; gap: 4px; margin-bottom: 12px; }
  .field-short { max-width: none; }
}

/* 着信の状況 */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; border: 1px solid transparent; }
.badge-danger { background: var(--danger-bg); color: var(--danger-text); }
.badge-ok { background: var(--success-bg); color: var(--success-text); }
.badge-muted { background: var(--bg); color: var(--muted); border-color: var(--border); }
.table tr.is-missed td:first-child { box-shadow: inset 3px 0 0 var(--danger-text); }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 4px 12px; border-radius: 6px; text-decoration: none; }
.tabs a[aria-current="page"] { background: var(--primary); color: var(--primary-text); }

/* ログイン画面 */
.auth-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.auth-main { width: 100%; max-width: 380px; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 24px; }
.card-title { margin-top: 0; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); }
.field input:not([type="radio"]):not([type="checkbox"]) { width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 6px; font: inherit; }
.alert { padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; }
.alert-danger { background: var(--danger-bg); color: var(--danger-text); }
.alert-success { background: var(--success-bg); color: var(--success-text); }


/* ダーク: OS の設定（自動）または切替で固定 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1f2226;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --border: #3a3f46;
    --primary: #3b6fd8;
    --primary-text: #ffffff;
    --link: #8ab4f8;
    --danger-bg: #3b1d1d;
    --danger-text: #f5b4b4;
    --success-bg: #1b3325;
    --success-text: #a6e3bd;
    --warning-bg: #3a2e12;
    --warning-text: #f3d48b;
    --shadow: rgba(0, 0, 0, .5);
    --shadow-strong: rgba(0, 0, 0, .6);
    --count-bg: #e5534b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a;
  --surface: #1f2226;
  --text: #e6e8eb;
  --muted: #9aa1ab;
  --border: #3a3f46;
  --primary: #3b6fd8;
  --primary-text: #ffffff;
  --link: #8ab4f8;
  --danger-bg: #3b1d1d;
  --danger-text: #f5b4b4;
  --success-bg: #1b3325;
  --success-text: #a6e3bd;
  --warning-bg: #3a2e12;
  --warning-text: #f3d48b;
  --shadow: rgba(0, 0, 0, .5);
  --shadow-strong: rgba(0, 0, 0, .6);
  --count-bg: #e5534b;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

/* ランクの色は旧システムと同じ明るい背景のため、文字は常に濃い色 */
.rank-1, .rank-2, .rank-3, .rank-4, .rank-5 { color: #1f2328; }

/* 入力欄（個別の指定が無いものも含めて配色に合わせる） */
input:not([type="radio"]):not([type="checkbox"]):not([type="submit"]):not([type="button"]), select, textarea {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
::placeholder { color: var(--muted); opacity: 1; }

/* 担当者確認のダイアログ（共用端末） */
.operator-dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; max-width: 420px; width: calc(100% - 32px); }
.operator-dialog::backdrop { background: rgba(0, 0, 0, .5); }
.operator-dialog h2 { margin-top: 0; }



/* 着信の折り返し */
.small { font-size: 12px; }
.btn-link { background: none; border: 0; padding: 0 2px; color: var(--link); text-decoration: underline; cursor: pointer; font: inherit; }
.btn-link.small { font-size: 12px; }

/* ページ送り */
.pager { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin: 16px 0; }
.pager a, .pager-current { min-width: 36px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; text-align: center; text-decoration: none; background: var(--surface); }
.pager a:hover { border-color: var(--primary); }
.pager-current { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.pager-edge { color: var(--muted); }

/* 共用端末の担当者確認の方法（CTI 端末画面） */
.mode-option { display: flex; align-items: baseline; gap: 6px; margin: 6px 0; cursor: pointer; flex-wrap: wrap; }
.mode-option input { accent-color: var(--primary); margin: 0; }

/* ブランド・店舗（店舗名の入力欄） */
.shop-name-input { flex: 1 1 220px; min-width: 0; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font: inherit; }

/* 閉じられる警告 */
.alert-dismissible { display: flex; align-items: flex-start; gap: 12px; }
.alert-dismissible > span { flex: 1; }
.alert-close { flex: none; width: 26px; height: 26px; margin: -2px -4px 0 0; border: 0; border-radius: 6px; background: none; color: inherit; font-size: 18px; line-height: 1; cursor: pointer; opacity: .7; }
.alert-close:hover, .alert-close:focus-visible { opacity: 1; background: rgba(127, 127, 127, .18); }

/* 回数券・コース */
.badge-warn { background: var(--warning-bg); color: var(--warning-text); }
.add-toggle { margin-bottom: 12px; }
.add-toggle > summary { list-style: none; cursor: pointer; }
.add-toggle > summary::-webkit-details-marker { display: none; }
.add-toggle[open] > summary { margin-bottom: 10px; }
.ticket-list { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 10px; }
.ticket { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.ticket-done { opacity: .7; }
.ticket-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; }
.ticket-count b { font-size: 18px; color: var(--primary); }
.ticket-done .ticket-count b { color: var(--muted); }
.ticket-uses { margin: 6px 0; padding-left: 1.4em; font-size: 13px; }
.ticket-uses li { margin: 2px 0; }
.ticket .row-actions { justify-content: flex-start; margin-top: 6px; }
.ticket .row-actions input[type="date"] { padding: 3px 6px; border: 1px solid var(--border); border-radius: 6px; font: inherit; font-size: 13px; background: var(--surface); color: var(--text); }

/* 来店の明細・メニューのマスタ */
.items-editor { margin: 8px 0 4px; flex-basis: 100%; }
.items-quick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { padding: 4px 10px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.items-picker { max-width: 420px; }
.items-table.is-empty thead, .items-table.is-empty tfoot { display: none; }
.items-table input[type="text"], .items-table input[type="number"] { width: 100%; min-width: 0; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: var(--surface); color: var(--text); }
.items-table input[readonly] { background: var(--bg); }
.input-num { max-width: 110px; text-align: right; }
.visit-items { margin: 0 0 4px; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 4px; }
.visit-items li { padding: 1px 8px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; background: var(--surface); }
.visit-items li.is-product { border-style: dashed; }
.visit-items .item-note { color: var(--muted); }
.menus-table tr.is-inactive td { opacity: .6; }
.menus-table input, .menus-table select { padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: var(--surface); color: var(--text); max-width: 100%; }
.summary-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px 24px; margin: 0; }
.summary-cols dt { font-weight: 600; margin-bottom: 4px; }
.summary-cols dd { margin: 0; }

/* 顧客詳細の上部「次回の電話で話すこと」（その場で編集） */
.next-call { padding: 10px 16px; }
.next-call.has-note { border-left: 4px solid var(--warning-text); background: var(--warning-bg); }
.next-call-edit > summary { list-style: none; display: grid; grid-template-columns: max-content 1fr max-content; gap: 4px 16px; align-items: start; cursor: pointer; }
.next-call-edit > summary::-webkit-details-marker { display: none; }
.next-call-title { font-weight: 600; }
.next-call-edit[open] .next-call-toggle { visibility: hidden; }
.next-call-form { margin-top: 10px; }
.next-call-form textarea { display: block; width: 100%; min-height: 6em; padding: 8px; border: 1px solid var(--border); border-radius: 6px; font: inherit; line-height: 1.6; background: var(--surface); color: var(--text); resize: vertical; }
.next-call-form .actions { margin-top: 6px; }
@media (max-width: 640px) {
  .next-call-edit > summary { grid-template-columns: 1fr max-content; }
  .next-call-text { grid-column: 1 / -1; grid-row: 2; }
}
