:root {
  --bg: #f4f6f3;
  --panel: #ffffff;
  --ink: #1f2a22;
  --muted: #6b766d;
  --line: #dfe5dd;
  --accent: #2f7d4a;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --radius: 8px;
  --s-prospect: #8a94a6;
  --s-contract: #2f6fd6;
  --s-started: #e08a1e;
  --s-done: #2e9e57;
  --s-paid: #8a4fc7;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
}
[hidden] { display: none !important; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
input:disabled, select:disabled, textarea:disabled { background: #f3f4f2; color: var(--ink); }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
h1, h2, h3 { margin: 0; }
h3 { font-size: 15px; margin-bottom: 10px; }
.hint { color: var(--muted); font-size: 12px; margin: 0 0 10px; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 7px 12px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f2f5f1; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, #fff); }
.btn.line { background: #06c755; color: #fff; border-color: #06c755; font-weight: 600; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); padding: 28px; border-radius: 12px; width: min(360px, 100%); display: grid; gap: 14px; box-shadow: 0 6px 30px rgba(0,0,0,.08); }
.login-card h1 { font-size: 20px; text-align: center; }

/* layout */
#app-view { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font-weight: 700; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.tabs button.active { background: color-mix(in srgb, var(--accent) 12%, #fff); color: var(--accent); font-weight: 600; }
.user { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); }
main { flex: 1; min-height: 0; }
.tab-pane { height: 100%; overflow: auto; padding: 16px; }

/* map tab */
.map-pane { display: flex; padding: 0; overflow: hidden; }
.sidebar { width: 340px; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--panel); min-height: 0; }
.sidebar-head { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.sidebar-head #add-customer { grid-column: 1 / -1; }
#map { flex: 1; min-height: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 8px 12px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.customer-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.customer-list li { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.customer-list li:hover { background: #f5f8f4; }
.customer-list .name { font-weight: 600; }
.customer-list .sub { color: var(--muted); font-size: 12px; grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.customer-list .money { font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.customer-list .empty { color: var(--muted); cursor: default; display: block; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; color: #fff; font-size: 11px; font-weight: 600; white-space: nowrap; }

@media (max-width: 760px) {
  .map-pane { flex-direction: column-reverse; }
  .sidebar { width: 100%; height: 45%; border-right: 0; border-top: 1px solid var(--line); }
  #map { min-height: 55%; }
  .user span { display: none; }
}

/* pins & tooltip */
.cust-tip { min-width: 200px; font-size: 13px; }
.lpin { position: absolute; transform: translate(-50%, -100%); display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.lpin:hover { z-index: 10; }
.lpin svg { display: block; filter: drop-shadow(0 2px 2px rgba(0,0,0,.35)); }
.lpin-label {
  display: flex; align-items: center; gap: 5px; white-space: nowrap; margin-bottom: 2px;
  background: #fff; border: 2px solid; border-radius: 999px; padding: 1px 3px 1px 9px;
  font-size: 13px; line-height: 18px; box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.lpin-label b { max-width: 9em; overflow: hidden; text-overflow: ellipsis; }
.labels-off .lpin-label { display: none; }
/* 新着の申し送りがあるピン：点滅＋「新着」表示 */
.lpin.unread { z-index: 5; }
.lpin-new {
  background: #e53935; color: #fff; font-size: 12px; font-weight: 700; line-height: 18px;
  padding: 0 8px; border-radius: 999px; margin-bottom: 2px; white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,.3); animation: blink-new 1s ease-in-out infinite;
}
.lpin.unread svg { animation: blink-pin 1s ease-in-out infinite; }
@keyframes blink-pin {
  0%, 100% { opacity: 1; transform: scale(1); filter: drop-shadow(0 0 0 rgba(229,57,53,0)); }
  50% { opacity: .35; transform: scale(1.12); filter: drop-shadow(0 0 6px rgba(229,57,53,.9)); }
}
@keyframes blink-new { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.lpin.unread svg { transform-origin: 50% 100%; }
.new-badge { display: inline-block; margin-left: 6px; background: #e53935; color: #fff; font-size: 11px; font-weight: 700; padding: 0 7px; border-radius: 999px; vertical-align: 1px; animation: blink-new 1s ease-in-out infinite; }
.tip-new { color: #e53935; font-weight: 700; margin-top: 4px; }
/* 来店日・着工日の 3日前／1日前のお知らせ */
.lpin-remind {
  color: #fff; font-size: 12px; font-weight: 700; line-height: 18px; padding: 0 8px; border-radius: 999px;
  margin-bottom: 2px; white-space: nowrap; box-shadow: 0 1px 4px rgba(0,0,0,.3); border: 2px solid #fff;
}
.lpin-remind.visit { background: #0f8b8d; }
.lpin-remind.start { background: #d9730d; }
.lpin-remind.soon { font-size: 13px; padding: 1px 10px; }
.lpin-remind.today { font-size: 14px; border-color: #ffd54f; box-shadow: 0 0 0 2px rgba(255,213,79,.6), 0 1px 4px rgba(0,0,0,.3); }
.remind-badge { display: inline-block; margin-left: 6px; color: #fff; font-size: 11px; font-weight: 700; padding: 0 7px; border-radius: 999px; vertical-align: 1px; }
.remind-badge.visit { background: #0f8b8d; }
.remind-badge.start { background: #d9730d; }
.tip-remind { font-weight: 700; margin-top: 4px; }
.tip-remind.visit { color: #0f8b8d; }
.tip-remind.start { color: #d9730d; }
.cust-tip table { border-collapse: collapse; }
.cust-tip th { text-align: left; color: var(--muted); font-weight: normal; padding-right: 8px; white-space: nowrap; vertical-align: top; }
.cust-tip td { white-space: normal; max-width: 240px; }
.cust-tip .tip-name { font-weight: 700; font-size: 14px; margin-bottom: 4px; display: flex; gap: 6px; align-items: center; }
.cust-tip .tip-foot { color: var(--muted); font-size: 11px; margin-top: 4px; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,30,22,.45); display: grid; place-items: center; z-index: 2000; padding: 16px; }
.modal {
  background: var(--panel); border-radius: 12px; width: min(820px, 100%); max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.modal-head h2 { font-size: 17px; margin-right: auto; display: flex; gap: 8px; align-items: center; }
.modal-body { padding: 16px; overflow: auto; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 12px; align-items: end; }
.form-grid .span2 { grid-column: span 2; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 480px) { .form-grid .span2 { grid-column: 1 / -1; } }
.form-section { font-weight: 600; font-size: 13px; color: var(--accent); grid-column: 1 / -1; margin-top: 6px; border-bottom: 1px solid var(--line); padding-bottom: 3px; }
.addr-row { display: flex; gap: 6px; }
.mini-map { height: 260px; border-radius: 8px; border: 1px solid var(--line); grid-column: 1 / -1; }

.detail-tabs { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.detail-tabs .btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.count { background: rgba(0,0,0,.08); border-radius: 999px; padding: 0 6px; font-size: 11px; }
.btn.active .count { background: rgba(255,255,255,.25); }
.info-table { width: 100%; border-collapse: collapse; }
.info-table th { text-align: left; color: var(--muted); font-weight: normal; width: 8em; padding: 6px 8px 6px 0; vertical-align: top; }
.info-table td { padding: 6px 0; border-bottom: 1px solid var(--line); word-break: break-all; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; position: relative; background: #eef1ed; border-radius: 8px; overflow: hidden; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; cursor: zoom-in; }
.gallery figcaption { font-size: 11px; color: var(--muted); padding: 4px 6px; background: #fff; }
.gallery .del { position: absolute; top: 4px; right: 4px; background: rgba(255,255,255,.9); border: 0; border-radius: 50%; width: 26px; height: 26px; cursor: pointer; color: var(--danger); }
.pdf-tile { display: flex; aspect-ratio: 1; align-items: center; justify-content: center; flex-direction: column; text-decoration: none; color: var(--ink); font-size: 36px; }
.pdf-tile small { font-size: 11px; padding: 0 6px; text-align: center; word-break: break-all; }
.file-list { list-style: none; padding: 0; margin: 0; }
.file-list li { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.file-list li a { flex: 1; word-break: break-all; }
.file-thumb { width: 48px; height: 48px; flex: none; border-radius: 6px; object-fit: cover; background: #eef1ed; cursor: zoom-in; }
.file-thumb.pdf { display: inline-flex; align-items: center; justify-content: center; font-size: 26px; cursor: default; }
.uploader { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.empty-note { color: var(--muted); padding: 20px 0; text-align: center; }

.chat { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow: auto; padding: 4px; }
.msg { max-width: 80%; background: #eef3ec; border-radius: 10px; padding: 8px 10px; align-self: flex-start; }
.msg.mine { align-self: flex-end; background: color-mix(in srgb, var(--accent) 14%, #fff); }
.msg .meta { font-size: 11px; color: var(--muted); display: flex; gap: 8px; }
.msg .body { white-space: pre-wrap; word-break: break-word; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; }
.chat-form textarea { resize: vertical; min-height: 42px; }
.chat-form .btn { align-self: flex-end; }
.msg-files { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.msg-images { display: flex; flex-wrap: wrap; gap: 4px; }
.msg-images img { width: 120px; height: 120px; object-fit: cover; border-radius: 6px; cursor: zoom-in; background: #dde3db; }
.msg-file { display: flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; text-decoration: none; color: var(--ink); max-width: 100%; }
.msg-file .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.msg-file small { color: var(--muted); flex: none; }
.attach-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.attach-chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #eef3ec; border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 12px; max-width: 100%; overflow: hidden; }
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 0 4px; }
@media (max-width: 480px) { .msg { max-width: 92%; } .msg-images img { width: 96px; height: 96px; } }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 3000; display: grid; place-items: center; }
.lightbox img { max-width: 96vw; max-height: 88vh; }
.lightbox .lb-bar { position: fixed; top: calc(10px + env(safe-area-inset-top, 0px)); right: 10px; display: flex; gap: 8px; }
.lightbox .lb-nav { position: fixed; top: 50%; transform: translateY(-50%); font-size: 30px; background: rgba(255,255,255,.15); color: #fff; border: 0; width: 48px; height: 64px; cursor: pointer; border-radius: 8px; }
.lightbox .prev { left: 10px; } .lightbox .next { right: 10px; }
.lightbox .lb-caption { position: fixed; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); color: #ddd; font-size: 12px; }

/* charts */
.charts-head { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.charts-head label { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; }
.charts-head select { width: auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .k { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.chart-box { position: relative; height: 280px; }

/* admin */
.admin-grid { display: grid; gap: 12px; max-width: 900px; }
.table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.table th, .table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: normal; font-size: 12px; }
.table-wrap { overflow-x: auto; }

/* gantt */
.gantt-view { position: fixed; inset: 0; z-index: 1500; background: var(--panel); display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px); }
.gantt-head { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.gantt-head h2 { font-size: 17px; }
.gantt-head .legend { padding: 0; }
.gantt-head #gantt-fullscreen { margin-left: auto; }
.gantt { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 16px 10px; overflow: hidden; }
.g-row { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.g-name { width: 170px; flex: none; padding: 0 8px 0 0; display: flex; flex-direction: column; justify-content: center; overflow: hidden; cursor: pointer; }
.g-name b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.g-name small { color: var(--muted); font-size: 11px; white-space: nowrap; }
.g-track { position: relative; flex: 1; min-width: 0; }
.g-header { height: 40px; }
.g-month { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--line); font-size: 12px; padding: 2px 4px; color: var(--muted); overflow: hidden; white-space: nowrap; }
.g-month.cur { color: var(--accent); font-weight: 700; }
.g-week { position: absolute; bottom: 0; height: 14px; border-left: 1px solid #eef0ec; font-size: 9px; color: #a3aba4; padding-left: 2px; }
.g-grid { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--line); pointer-events: none; }
.g-today { position: absolute; top: 0; bottom: 0; border-left: 2px solid var(--danger); pointer-events: none; z-index: 2; }
.g-today-label { position: absolute; top: 0; transform: translateX(-50%); background: var(--danger); color: #fff; font-size: 10px; padding: 0 4px; border-radius: 3px; z-index: 3; }
.g-weekend { position: absolute; top: 0; bottom: 0; background: rgba(0,0,0,.025); pointer-events: none; }
.g-bar { position: absolute; top: 18%; bottom: 18%; border-radius: 4px; color: #fff; font-size: 11px; padding: 0 6px; white-space: nowrap; overflow: hidden; display: flex; align-items: center; cursor: pointer; min-width: 3px; z-index: 1; }
.g-bar.clip-l { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.g-bar.clip-r { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.g-body { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.g-empty { color: var(--muted); padding: 40px; text-align: center; }
@media (max-width: 760px) { .g-name { width: 96px; } .g-week { display: none; } }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: #263228; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 4000; box-shadow: 0 4px 16px rgba(0,0,0,.2); max-width: 90vw; }
.toast.err { background: var(--danger); }
