* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Helvetica Neue", "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background: #f2f3f5;
  color: #1f2937;
  font-size: 14px;
  line-height: 1.7;
}
a { color: #2563eb; }

/* ---- レイアウト ---- */
.topbar { background: #111827; color: #fff; }
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 24px; height: 52px;
}
.brand { font-weight: bold; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  color: #d1d5db; text-decoration: none; padding: 6px 12px; border-radius: 6px;
}
.topbar nav a:hover { background: #1f2937; }
.topbar nav a.on { background: #2563eb; color: #fff; }
.logout-form { margin: 0; }
.link-btn {
  background: none; border: 0; color: #9ca3af; cursor: pointer; font-size: 13px;
}
.link-btn:hover { color: #fff; }

.main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 64px; }
h1 { font-size: 22px; margin: 8px 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }

.card {
  background: #fff; border-radius: 8px; padding: 20px; margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.card-head h2 { margin: 0; }

.muted { color: #6b7280; }
.small { font-size: 12px; }

/* ---- フラッシュ ---- */
.flash { padding: 10px 16px; border-radius: 6px; margin-bottom: 12px; }
.flash-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.flash-warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.flash ul { margin: 4px 0 0; padding-left: 20px; }

/* ---- 統計カード ---- */
.stat-row { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-card {
  flex: 1; min-width: 150px; background: #fff; border-radius: 8px;
  padding: 16px 20px; box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.stat-num { font-size: 28px; font-weight: bold; color: #111827; }
.stat-sub { font-size: 14px; font-weight: normal; color: #9ca3af; }
.stat-label { color: #6b7280; font-size: 12px; }

/* ---- テーブル ---- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid #e5e7eb;
  vertical-align: middle;
}
.table th { color: #6b7280; font-weight: normal; font-size: 12px; white-space: nowrap; }
.table-plain th { width: 140px; }

/* ---- バッジ ---- */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px;
}
.badge-draft { background: #f3f4f6; color: #374151; }
.badge-sending { background: #fef3c7; color: #92400e; }
.badge-sent { background: #dbeafe; color: #1e40af; }
.badge-sub-active { background: #d1fae5; color: #065f46; }
.badge-sub-unsubscribed { background: #f3f4f6; color: #6b7280; }
.badge-sub-bounced { background: #fee2e2; color: #991b1b; }

/* ---- フォーム ---- */
input[type=text], input[type=email], input[type=password], input[type=number],
select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px;
  width: 100%; background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid #93c5fd; border-color: #2563eb;
}
label { display: block; }
.field-grid label { margin-bottom: 12px; }
.field-grid label:last-child { margin-bottom: 0; }
.check-label { display: flex; align-items: center; gap: 8px; }
.check-label input { width: auto; }
.inline-form { display: flex; gap: 8px; align-items: center; margin: 0; }
.inline-form input[type=text], .inline-form input[type=email] { width: auto; min-width: 200px; }
.inline-form select { width: auto; }
.add-form { margin-bottom: 16px; }
.form-actions { margin-top: 12px; display: flex; gap: 8px; }

/* ---- ボタン ---- */
.btn {
  display: inline-block; font: inherit; padding: 8px 16px; border-radius: 6px;
  border: 1px solid #d1d5db; background: #fff; color: #1f2937;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f9fafb; }
.btn-primary { background: #2563eb; border-color: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-send { background: #059669; border-color: #059669; color: #fff; }
.btn-send:hover { background: #047857; }
.btn-danger { color: #dc2626; border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 3px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn-group form { margin: 0; }

.pager { margin-top: 12px; display: flex; gap: 6px; }
.pager a, .pager-on { padding: 4px 10px; border-radius: 4px; }
.pager-on { background: #2563eb; color: #fff; }

/* ---- エディタ ---- */
.edit-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap;
}
#save-status { min-height: 20px; margin-bottom: 8px; }
.blk {
  border: 1px solid #e5e7eb; border-radius: 8px; margin-bottom: 12px; overflow: hidden;
}
.blk-head {
  display: flex; justify-content: space-between; align-items: center;
  background: #f9fafb; padding: 6px 12px; border-bottom: 1px solid #e5e7eb;
}
.blk-label { font-weight: bold; font-size: 12px; color: #374151; }
.blk-ctrl { display: flex; gap: 4px; }
.blk-body { padding: 12px; }
.ed-field { margin-bottom: 10px; font-size: 12px; color: #6b7280; }
.ed-field input, .ed-field select { margin-top: 2px; color: #1f2937; font-size: 14px; }
.add-block {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  padding-top: 8px; color: #6b7280;
}

.img-field { margin-bottom: 10px; }
.img-preview {
  border: 1px dashed #d1d5db; border-radius: 6px; padding: 8px;
  margin-bottom: 6px; text-align: center; background: #f9fafb;
}
.img-preview img { max-width: 100%; max-height: 160px; }

.rt-wrap { border: 1px solid #d1d5db; border-radius: 6px; overflow: hidden; }
.rt-bar {
  display: flex; gap: 2px; background: #f9fafb; padding: 4px;
  border-bottom: 1px solid #e5e7eb;
}
.rt-btn {
  font: inherit; font-size: 12px; padding: 3px 10px; border: 0; background: none;
  border-radius: 4px; cursor: pointer;
}
.rt-btn:hover { background: #e5e7eb; }
.rt-area { min-height: 80px; padding: 10px 12px; outline: none; }
.rt-area:focus { background: #fffef8; }

/* ---- モーダル ---- */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-back[hidden] { display: none; }
.modal {
  background: #fff; border-radius: 8px; width: 100%; max-width: 720px;
  max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-sm { max-width: 480px; }
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid #e5e7eb;
}
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
#preview-frame {
  border: 0; flex: 1; min-height: 60vh; width: 100%; margin: 0 auto;
  display: block; background: #f2f3f5; transition: width .2s;
}

/* ---- ログイン ---- */
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
}
.login-card {
  background: #fff; border-radius: 8px; padding: 32px; width: 100%; max-width: 360px;
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
}
.login-card h1 { font-size: 18px; text-align: center; margin: 0 0 20px; }
.login-card label { margin-bottom: 12px; font-size: 12px; color: #6b7280; }
.login-card input { margin-top: 2px; font-size: 14px; }
.login-card button { margin-top: 8px; }
