:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #64748b;
  --border: #d8dee8;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --send: #0f766e;
  --send-hover: #115e59;
  --danger: #b91c1c;
  --sidebar: #16233b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #2b3d5f;
  --base: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: var(--base);
  line-height: 1.6;
}

.layout { display: flex; min-height: 100vh; }

/* サイドバー */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { padding: 24px 20px 20px; border-bottom: 1px solid #24365a; }
.brand-name { color: #fff; font-size: 20px; font-weight: 700; letter-spacing: .04em; }
.brand-sub { font-size: 12px; margin-top: 2px; }
.nav { display: flex; flex-direction: column; padding: 12px 0; }
.nav a {
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 12px 20px;
  border-left: 4px solid transparent;
}
.nav a span { display: block; font-size: 12px; opacity: .75; }
.nav a:hover { background: #1f3050; color: #fff; }
.nav a.is-active { background: var(--sidebar-active); border-left-color: #60a5fa; color: #fff; font-weight: 700; }
.mock-note { margin-top: auto; padding: 16px 20px; font-size: 12px; opacity: .7; }

/* メイン */
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; }
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-head h1 { font-size: 24px; margin: 0; }
.page-head h1 small { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 10px; }
.section-title { font-size: 16px; margin: 28px 0 10px; }
.card .section-title:first-child { margin-top: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
}
.hint, .sub { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; margin: 0; }

/* ボタン */
.btn {
  font: inherit;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #f1f5f9; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-send { background: var(--send); border-color: var(--send); color: #fff; font-weight: 700; }
.btn-send:hover { background: var(--send-hover); }
.btn-danger { background: #fff; border-color: #fca5a5; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 4px 12px; font-size: 13px; }
.btn-lg { padding: 10px 40px; font-size: 17px; }
/* 新規顧客追加は文字を 1.5 倍 */
.btn-add { font-size: calc(var(--base) * 1.5); font-weight: 700; padding: 10px 24px; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar-info { color: var(--muted); font-size: 13px; }

/* 表：登録した顧客が 1 行ずつ縦に並ぶ */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; background: #f8fafc; }
.table tbody tr:hover { background: #f8fafc; }
.table td.wrap { word-break: break-all; }
.col-check { width: 40px; }
.col-action { width: 1%; white-space: nowrap; text-align: right; }
.table td.col-action { text-align: right; }
.table td.col-action .btn + .btn { margin-left: 6px; }
.sig-cell { white-space: pre-wrap; font-size: 12px; color: var(--muted); max-width: 320px; }

/* フォーム */
.form .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.label { font-weight: 600; font-size: 14px; }
.label em { font-style: normal; font-size: 11px; color: #fff; background: var(--danger); border-radius: 4px; padding: 1px 6px; margin-left: 8px; vertical-align: 1px; }
input[type=text], input[type=email], input[type=datetime-local], select, textarea {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; line-height: 1.7; }
input:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; border-color: var(--primary); }
.is-invalid { border-color: var(--danger) !important; background: #fff7f7 !important; }
.error { color: var(--danger); font-size: 13px; font-weight: 600; min-height: 0; }
.error:empty { display: none; }
.row { display: flex; gap: 16px; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.dirty-badge { color: #b45309; font-size: 13px; font-weight: 600; }
.signature-preview {
  margin: 0;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 6px;
  white-space: pre-wrap;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
}
code { background: #eef2ff; padding: 0 4px; border-radius: 4px; font-size: 12px; }

/* タブ */
.tabs { display: flex; gap: 4px; margin-top: 24px; }
.tab {
  font: inherit;
  border: 1px solid var(--border);
  border-bottom: none;
  background: #e9eef5;
  padding: 8px 24px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  color: var(--muted);
}
.tab.is-active { background: var(--surface); color: var(--text); font-weight: 700; }
.tab-panel { border-top-left-radius: 0; }

.status { font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.status-on { background: #dcfce7; color: #166534; }
.status-off { background: #e5e7eb; color: #4b5563; }
.status-done { background: #e0e7ff; color: #3730a3; }

/* ポップアップ（画面正面） */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal[hidden] { display: none; }
.modal-box {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
  max-height: calc(100vh - 32px);
  overflow: auto;
}
.modal-box h2 { margin: 0 0 16px; font-size: 19px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.confirm-body { white-space: pre-wrap; }
.confirm-body .mail-preview { background: #f8fafc; border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; font-size: 13px; max-height: 260px; overflow: auto; margin-top: 10px; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #0f172a;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
  z-index: 200;
  max-width: calc(100vw - 48px);
}

/* スマートフォン幅 */
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .nav { flex-direction: row; overflow-x: auto; padding: 0; }
  .nav a { border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; padding: 10px 14px; }
  .nav a.is-active { border-bottom-color: #60a5fa; }
  .mock-note { display: none; }
  .main { padding: 20px 16px 48px; }
  .page-head { flex-wrap: wrap; }
  .row { flex-direction: column; gap: 0; }
  .card { padding: 14px; overflow-x: auto; }
}

/* サイドバー下部（ログイン中の人） */
.side-foot { margin-top: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 8px; }
.side-foot .mock-note { margin: 0; padding: 0; }
.me { font-size: 12px; color: #fff; word-break: break-all; }
.btn-side { background: transparent; color: var(--sidebar-text); border-color: #3b4f75; align-self: flex-start; }
.btn-side:hover { background: #1f3050; color: #fff; }

/* ログイン */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--sidebar); }
.login-box { background: var(--surface); border-radius: 12px; padding: 32px 28px; width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 4px; }
.login-brand { font-size: 22px; font-weight: 700; color: var(--sidebar); }
.btn-block { width: 100%; padding: 10px; font-size: 16px; }
.loading { min-height: 100vh; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.loading[hidden], .login[hidden], .layout[hidden] { display: none; }
.btn:disabled { opacity: .6; cursor: wait; }
.err-note { color: var(--danger); font-size: 12px; }

/* 改修（D1〜D7） */
.inline-row { display: flex; gap: 8px; align-items: center; }
.inline-row select { flex: 1; min-width: 0; }
.head-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 28px 0 10px; }
.head-row .section-title { margin: 0; }
.status-text { font-size: 12px; color: var(--muted); }
.status-text.is-error { color: var(--danger); font-weight: 600; }
.warn-note { color: var(--danger); font-size: 13px; font-weight: 600; }
.source-banner { background: #eef4ff; border: 1px solid #c7d7fe; color: #1e3a8a; border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.source-banner.is-schedule { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }
.source-banner.is-deleted { background: #fef2f2; border-color: #fecaca; color: var(--danger); }
.readonly { padding: 8px 10px; background: #f1f5f9; border: 1px solid var(--border); border-radius: 6px; }
.test-note { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; border-radius: 6px; padding: 8px 10px; font-size: 13px; margin: 0 0 10px; white-space: normal; }
.status-test { background: #fff7ed; color: #9a3412; }
