:root {
  --primary: #1565c0;
  --primary-dark: #0d47a1;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #212a32;
  --muted: #6b7a88;
  --line: #dde3e9;
  --danger: #c62828;
  --warn: #ef6c00;
  --ok: #2e7d32;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.55;
}
a { color: var(--primary); }

/* ナビ */
.a-nav {
  background: #17222b; color: #fff;
  display: flex; align-items: center; gap: 2px;
  padding: 0 12px; height: 52px; overflow-x: auto; white-space: nowrap;
}
.a-nav .brand { font-weight: 700; margin-right: 14px; font-size: 15px; flex: 0 0 auto; }
.a-nav a {
  color: #b8c4cd; text-decoration: none; padding: 6px 11px; border-radius: 6px;
  font-size: 13px; flex: 0 0 auto;
}
.a-nav a.active, .a-nav a:hover { color: #fff; background: rgba(255,255,255,.12); }
.a-nav form { margin-left: auto; flex: 0 0 auto; }
.a-nav button {
  background: none; border: 1px solid #47555f; color: #b8c4cd; padding: 5px 12px;
  border-radius: 6px; cursor: pointer; font-size: 12.5px; font-family: inherit;
}

.wrap { max-width: 1200px; margin: 0 auto; padding: 18px 16px 60px; }
h1 { font-size: 19px; margin-bottom: 14px; }
h2 { font-size: 15px; margin: 18px 0 10px; }

.flash {
  background: #e8f5e9; border: 1px solid #a5d6a7; color: #1b5e20;
  padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13.5px;
}
.errors {
  background: #ffebee; border: 1px solid #ef9a9a; color: #b71c1c;
  padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13.5px;
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 14px; }

/* テーブル */
table.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table.list th, table.list td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13.5px; vertical-align: middle; }
table.list th { background: #eef2f6; font-size: 12.5px; color: var(--muted); }
table.list tr:last-child td { border-bottom: none; }

/* フォーム */
label.f { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
label.f > span { display: block; margin-bottom: 4px; font-weight: 600; color: var(--text); }
input[type=text], input[type=number], input[type=email], input[type=password], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #90caf9; border-color: var(--primary); }
.f-row { display: flex; gap: 14px; flex-wrap: wrap; }
.f-row > label.f { flex: 1; min-width: 140px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; margin-right: 14px; cursor: pointer; }
.chk input { width: 16px; height: 16px; accent-color: var(--primary); }

.btn {
  display: inline-block; padding: 8px 16px; border-radius: 8px; border: none;
  background: var(--primary); color: #fff; font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-decoration: none; font-family: inherit; line-height: 1.4;
}
.btn:hover { background: var(--primary-dark); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.gray { background: #78909c; }
.btn.danger { background: var(--danger); }
.btn.warn { background: var(--warn); }
.btn.ok { background: var(--ok); }
.btn.outline { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
form.inline { display: inline; }

/* 卓一覧カード */
.table-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.t-card {
  background: var(--card); border: 2px solid var(--line); border-radius: 12px;
  padding: 14px; cursor: pointer; position: relative; min-height: 110px;
  display: flex; flex-direction: column; text-decoration: none; color: var(--text);
}
.t-card .t-name { font-size: 16px; font-weight: 700; }
.t-card .t-sub { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.t-card .t-status { margin-top: auto; padding-top: 8px; font-size: 12.5px; font-weight: 700; }
.t-card.free { border-color: var(--line); }
.t-card.free .t-status { color: var(--muted); }
.t-card.busy { border-color: #66bb6a; background: #f6fbf6; }
.t-card.busy .t-status { color: var(--ok); }
.t-card.checkout { border-color: #ef5350; background: #fff7f7; }
.t-card.checkout .t-status { color: var(--danger); }
.t-card.expired { border-color: #ffa726; background: #fffaf3; }
.t-card.expired .t-status { color: var(--warn); }

/* ダッシュボード */
.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }
.feed { max-height: 72vh; overflow-y: auto; }
.feed-item { border-bottom: 1px solid var(--line); padding: 10px 4px; }
.feed-item:last-child { border-bottom: none; }
.feed-item .fi-head { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.feed-item .fi-table { font-weight: 700; font-size: 15px; }
.feed-item .fi-time { color: var(--muted); margin-left: auto; font-size: 12px; }
.feed-item .fi-items { font-size: 13px; color: #37474f; margin-top: 3px; }
.call-item {
  display: flex; align-items: center; gap: 10px;
  border-radius: 10px; padding: 12px; margin-bottom: 8px; font-size: 13.5px;
}
.call-item .ci-table { font-weight: 700; font-size: 16px; }
.call-item .ci-label { font-weight: 600; }
.call-item .ci-time { margin-left: auto; font-size: 12px; color: rgba(0,0,0,.45); }
.call-item.call { background: #fff8e1; border: 1px solid #ffe082; }
.call-item.checkout { background: #ffebee; border: 1px solid #ef9a9a; }
.call-item.plan_lo { background: #ede7f6; border: 1px solid #b39ddb; }
.call-item.session_expire { background: #fff3e0; border: 1px solid #ffcc80; }
.sound-note { font-size: 12px; color: var(--muted); margin-left: 8px; }

/* 伝票 */
.bill-table { width: 100%; border-collapse: collapse; }
.bill-table th, .bill-table td { padding: 7px 8px; border-bottom: 1px dashed var(--line); font-size: 13.5px; text-align: left; }
.bill-table td.num { text-align: right; white-space: nowrap; }
.bill-total { font-size: 17px; font-weight: 700; text-align: right; padding: 12px 8px 0; }
.ops { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.tag.plan { background: #e8f5e9; color: var(--ok); }
.tag.staff { background: #ede7f6; color: #5e35b1; }
.tag.cancelled { background: #eceff1; color: #78909c; }
.muted { color: var(--muted); font-size: 12.5px; }

/* 代理注文 */
.proxy-layout { display: grid; grid-template-columns: 1.6fr 1fr; gap: 14px; align-items: start; }
@media (max-width: 900px) { .proxy-layout { grid-template-columns: 1fr; } }
.proxy-products .p-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13.5px;
}
.proxy-products .p-row:hover { background: #f0f6fc; }
.proxy-products .p-row .pp { margin-left: auto; white-space: nowrap; color: var(--muted); }
.proxy-cart .pc-item { display: flex; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.proxy-cart .pc-item .del { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 12px; }

/* モーダル(管理側 代理注文用) */
.modal-back { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45); display: none; align-items: center; justify-content: center; }
.modal-back.open { display: flex; }
.modal { background: #fff; width: 92%; max-width: 480px; border-radius: 12px; max-height: 85vh; overflow-y: auto; padding: 20px; }
.modal h3 { font-size: 16px; margin-bottom: 8px; }
.opt-group { margin: 10px 0; }
.opt-group .g-name { font-weight: 700; font-size: 13px; margin-bottom: 5px; }
.opt-group .g-name .req { color: var(--danger); font-size: 11px; margin-left: 5px; }
.opt-item { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 5px; font-size: 13.5px; cursor: pointer; }
.opt-item .delta { margin-left: auto; color: var(--muted); font-size: 12.5px; }
.qty-row { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 12px 0; }
.qty-row button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: #fff; font-size: 18px; cursor: pointer; }
.qty-row .qty { font-size: 18px; font-weight: 700; min-width: 2em; text-align: center; }

/* QR印刷 */
.qr-sheet { text-align: center; padding: 30px; }
.qr-sheet .qr-svg svg { width: 320px; height: 320px; }
.qr-sheet .b-no { font-size: 28px; font-weight: 700; margin: 12px 0 4px; }
.qr-sheet .b-url { color: var(--muted); font-size: 13px; word-break: break-all; }
@media print {
  .a-nav, .no-print { display: none !important; }
  body { background: #fff; }
}

/* ログイン */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box { width: 92%; max-width: 380px; }
.login-box h1 { text-align: center; margin-bottom: 18px; }

/* グラフ(サーバー生成のインラインSVG) */
.chart { width: 100%; }
.chart svg { display: block; max-width: 100%; }
.chart svg rect[fill="transparent"]:hover { fill: rgba(21, 101, 192, .07); }

/* 凡例: 色が何を指すか一目でわかるように大きめ・値付き */
.chart-legend { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 10px; }
.chart-legend .lg {
  display: inline-flex; align-items: baseline; gap: 6px;
  background: #f7f9fb; border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 10px; font-size: 13px; line-height: 1.5;
}
.chart-legend .lg i { align-self: center; width: 14px; height: 14px; border-radius: 3px; flex: none; }
.chart-legend .lg i.lg-line { height: 4px; border-radius: 2px; }
.chart-legend .lg i.lg-dash {
  height: 0; border-top: 2px dashed var(--danger); background: none; border-radius: 0;
}
.chart-legend .lg b { font-weight: 700; }
.chart-legend .lg em { font-style: normal; font-weight: 700; color: var(--text); }
.chart-legend .lg small { color: var(--muted); font-size: 11.5px; }

.hbars { display: flex; flex-direction: column; gap: 7px; }
.hbar { display: grid; grid-template-columns: minmax(72px, 30%) 1fr minmax(96px, auto); align-items: center; gap: 8px; }
.hbar-label { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { background: #eef2f6; border-radius: 4px; height: 18px; overflow: hidden; }
.hbar-fill { display: block; height: 100%; border-radius: 4px; transition: width .2s; }
.hbar-value { font-size: 12.5px; text-align: right; white-space: nowrap; }
.hbar-value .muted { margin-left: 4px; }

@media (max-width: 640px) {
  .hbar { grid-template-columns: minmax(64px, 34%) 1fr auto; }
  .hbar-value { font-size: 11.5px; }
  .chart-legend .lg { font-size: 12px; padding: 4px 8px; }
}

/* ダッシュボードの注文明細サムネイル */
.feed-item .fi-items { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.fi-item { display: inline-flex; align-items: center; gap: 5px; }
.fi-item b { font-weight: 700; }
.fi-thumb {
  width: 28px; height: 28px; border-radius: 5px; object-fit: cover;
  background: #eef2f6; border: 1px solid var(--line); flex: none;
}
.fi-thumb.noimg { display: inline-flex; align-items: center; justify-content: center; font-size: 14px; }

/* 商品一覧のサムネイル */
.list-thumb {
  width: 44px; height: 44px; border-radius: 6px; object-fit: cover;
  background: #eef2f6; border: 1px solid var(--line); display: block;
}
.list-thumb.noimg { display: flex; align-items: center; justify-content: center; font-size: 18px; }

/* ---- フェーズ1 ---- */
.tag.warn { background: #fff3e0; color: #ef6c00; }
.fi-note, .order-note { font-size: 13px; color: #5d4037; background: #fff8e1; border-radius: 6px; padding: 4px 8px; margin: 4px 0; white-space: pre-wrap; }
.ci-detail { margin-left: 6px; color: var(--primary-dark); }

/* ---- フェーズ2: 会計 ---- */
.bill-summary { margin-top: 10px; }
.bill-summary td { border-bottom: none; padding: 4px 8px; }
.bill-summary tr.grand td { font-size: 17px; font-weight: 700; border-top: 1px solid var(--line); padding-top: 8px; }
.bill-summary tr.muted-row td { color: var(--muted); font-size: 12.5px; }
.pay-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.pay-form { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fafbfc; display: flex; flex-direction: column; gap: 6px; }
.pay-form strong { font-size: 14px; }
.pay-form label.f { margin-bottom: 4px; }
.pay-items { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff; }
.pay-items label.chk { margin: 0; padding: 4px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.inline-details { display: inline-block; }
.inline-details summary { list-style: none; cursor: pointer; display: inline-block; }
.inline-details summary::-webkit-details-marker { display: none; }
.stats-kpis { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.stats-kpis .card { flex: 1; min-width: 150px; margin-bottom: 0; }
.stats-kpis .v { font-size: 26px; font-weight: 700; }
.stats-kpis .s { color: var(--muted); font-size: 12px; }

/* ---- フェーズ3: キッチンモニター・提供状況 ---- */
.call-item.kds_delay { background: #fce4ec; border: 1px solid #f48fb1; }
.call-item.square_canceled { background: #eceff1; border: 1px solid #b0bec5; }
.kds-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.kds-totals { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.kds-total { background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 13px; }
.kds-tools { display: flex; gap: 8px; align-items: center; }
.kds-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; align-items: start; }
.kds-card { background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.kds-card.delayed { border-color: var(--danger); background: #fff5f5; }
.kds-card.served { opacity: .55; }
.kds-card.cancelled { opacity: .6; background: #f5f5f5; border-style: dashed; }
.kds-card.cancelled .kds-name { text-decoration: line-through; }
.kds-card-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; }
.kds-table { font-size: 20px; font-weight: 800; }
.kds-no { color: var(--muted); font-size: 13px; }
.kds-time { margin-left: auto; font-weight: 700; font-size: 15px; }
.kds-card.delayed .kds-time { color: var(--danger); }
.kds-cancel-mark { color: var(--danger); font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.kds-item { padding: 6px 0; border-top: 1px dashed var(--line); }
.kds-item-main { display: flex; gap: 8px; align-items: flex-start; font-size: 15px; }
.kds-qty { font-weight: 800; min-width: 3em; }
.kds-qty small { font-weight: 500; color: var(--muted); margin-left: 2px; }
.kds-item.cooking .kds-qty { color: #ef6c00; }
.kds-item.served .kds-name { text-decoration: line-through; color: var(--muted); }
.kds-item.late .kds-name { color: var(--danger); font-weight: 700; }
.kds-item-ops { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.kds-all { width: 100%; margin-top: 8px; padding: 10px; font-size: 15px; }
body.kds-body .wrap { max-width: none; }

/* ---- フェーズ4 ---- */
tr.row-alert td { background: #fff5f5; }

/* ---- フェーズ5: テイクアウト ---- */
.kds-card.takeout { border-color: #7e57c2; background: #f8f5fd; }
.to-status { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.to-status.received { background: #fff8e1; color: #f57f17; }
.to-status.cooking { background: #fff3e0; color: #ef6c00; }
.to-status.ready { background: #e8f5e9; color: var(--ok); }
.to-status.handed { background: #eceff1; color: #78909c; }
.to-status.cancelled { background: #ffebee; color: var(--danger); }
.feed-item.takeout { border-left: 4px solid #7e57c2; }

/* ---- フェーズ6: 明細ごとの操作 ---- */
.line-ops { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.note-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 6px; }
.note-chips button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.kds-station-filter { display: inline-flex; gap: 6px; flex-wrap: wrap; margin-right: 8px; }
.kds-station-filter label { font-size: 12px; }
.set-products { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 16px; margin-top: 8px; }
.kds-card .kds-item .station { font-size: 10px; color: #78909c; margin-left: 4px; }

/* ヘルプ(「?」ボタンとモーダル) */
.help-btn { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--primary); background: #fff; color: var(--primary); font-size: 13px; font-weight: 700; line-height: 1; cursor: pointer; vertical-align: middle; margin-left: 6px; padding: 0; font-family: inherit; }
.help-btn:hover, .help-btn:focus-visible { background: var(--primary); color: #fff; outline: none; }
h1 .help-btn { width: 24px; height: 24px; font-size: 14px; }
summary .help-btn, label .help-btn { margin-left: 4px; }
.help-modal { max-width: 560px; }
.help-modal h3 { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 17px; margin-bottom: 10px; }
.help-modal h3 .help-close { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: #78909c; padding: 0 4px; }
.help-body { font-size: 14px; line-height: 1.75; }
.help-body h4 { margin: 12px 0 4px; font-size: 14px; color: var(--primary-dark); }
.help-body p { margin: 0 0 8px; }
.help-body ul { margin: 0 0 8px 18px; padding: 0; }
.help-body li { margin: 2px 0; }
.help-foot { text-align: right; margin-top: 10px; }
