:root {
  --green: #0a8f3c;
  --green-light: #33cc33;
  --blue: #1f5fa8;
  --purple: #66669a;
  --bg: #f3f8f3;
  --card: #ffffff;
  --text: #1d2b1f;
  --muted: #5b6b5e;
  --line: #c9dccb;
  --error: #c62828;
  --error-bg: #fdecec;
  --ok-bg: #e7f6ea;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic", "YuGothic", "Meiryo", sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

header.site {
  background: var(--green);
  color: #fff;
  padding: 16px;
}
header.site h1 { margin: 0; font-size: 22px; letter-spacing: 0.04em; }
header.site p { margin: 4px 0 0; font-size: 14px; opacity: 0.9; }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }

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

.login { max-width: 420px; margin: 32px auto; }
.login h2 { margin-top: 0; }
.login label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.login input { display: block; width: 100%; margin-top: 4px; }

input[type=text], input[type=email], input[type=password], select {
  font: inherit;
  font-size: 16px;            /* iPhone で入力時に拡大されないようにする */
  padding: 6px 8px;
  border: 1px solid #9fb8a3;
  border-radius: 4px;
  background: #fff;
  min-width: 0;
}

button {
  font: inherit;
  background: var(--green);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 10px 28px;
  cursor: pointer;
}
button:hover { background: #087a33; }

.whoami { text-align: right; margin: 0 0 12px; font-size: 14px; }
.notice { background: var(--ok-bg); border-left: 4px solid var(--green); padding: 8px 12px; }
.error { background: var(--error-bg); border-left: 4px solid var(--error); padding: 8px 12px; color: var(--error); }

.settings { display: flex; flex-wrap: wrap; gap: 8px 32px; }
.setting .name { font-weight: bold; margin-right: 8px; }
.setting label { margin-right: 12px; white-space: nowrap; }

table.rules { width: 100%; border-collapse: collapse; background: var(--card); }
table.rules th {
  background: var(--green-light);
  color: #fff;
  font-weight: bold;
  padding: 8px;
  border: 1px solid var(--line);
}
table.rules th:first-child { background: var(--blue); }
table.rules th:last-child { background: var(--purple); }
table.rules td { border: 1px solid var(--line); padding: 4px; vertical-align: top; }
/* 番号の列: 番号と ▲ ▼ ＋ － を横 1 列に並べ、行の高さを入力欄 1 つ分にする */
table.rules td.no { background: var(--blue); color: #fff; font-weight: bold; white-space: nowrap; vertical-align: middle; width: 1%; }
table.rules td.no .num { display: inline-block; min-width: 1.6em; text-align: right; margin-right: 4px; }
table.rules td.no .move { display: inline-flex; gap: 2px; vertical-align: middle; }
table.rules td.no .move button {
  background: #fff;
  color: var(--blue);
  font-size: 12px;
  font-weight: bold;
  line-height: 1;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 3px;
}
table.rules td.no .move button:hover { background: #dce8f6; }
table.rules td.no .move button[data-move="add"],
table.rules td.no .move button[data-move="del"] { font-size: 14px; }
table.rules td.no .move button[data-move="del"] { color: var(--error); }
table.rules td.no .move button:disabled { opacity: 0.4; cursor: default; background: #fff; }

/* 条件の欄: 文字の欄を広く、含む／含まないは文字に合わせて狭く */
table.rules .cond { display: flex; gap: 4px; }
table.rules .cond input[type=text] { flex: 1 1 auto; width: 0; }
table.rules .cond select { flex: 0 0 auto; width: auto; font-size: 14px; padding: 6px 0 6px 2px; }
/* 「含まない」を選んでいるときは赤くして、ひと目で分かるようにする */
table.rules .cond select:has(option[value="not_contains"]:checked) { color: var(--error); font-weight: bold; }
/* 条件の3列を広めに、転送先の列は残りの幅で */
table.rules th.cond-col { width: 22%; }
table.rules td input[type=email] { width: 100%; }
tr.has-error td { background: var(--error-bg); }
.row-error { display: block; color: var(--error); font-size: 13px; }

.hint { color: var(--muted); font-size: 14px; padding-left: 1.4em; }
.hint li { margin: 2px 0; }
.actions { text-align: center; margin: 16px 0 32px; }
.saved-at { display: inline-block; margin-left: 16px; color: var(--green); font-weight: bold; }

/* 保存直後に画面上部へ数秒だけ重ねて出す通知 */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: #fff;
  color: var(--green);
  border: 2px solid var(--green);
  font-weight: bold;
  padding: 12px 32px;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  animation: toast 3.5s ease forwards;
}
@keyframes toast {
  0%   { opacity: 0; transform: translate(-50%, -12px); }
  8%   { opacity: 1; transform: translate(-50%, 0); }
  80%  { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}
@keyframes toast-fade {
  0%, 80% { opacity: 1; }
  100%    { opacity: 0; visibility: hidden; }
}
@media (prefers-reduced-motion: reduce) {
  .toast { animation-name: toast-fade; }
}

/* スマホ: 1行を1枚のカードにする */
@media (max-width: 767px) {
  main { padding: 12px; }
  table.rules, table.rules tbody, table.rules tr, table.rules td { display: block; width: 100%; }
  table.rules thead { display: none; }
  table.rules tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 12px;
    overflow: hidden;
    background: var(--card);
  }
  table.rules td { border: 0; border-bottom: 1px solid #edf3ee; padding: 8px 12px; }
  table.rules td:last-child { border-bottom: 0; }
  table.rules td::before {
    content: attr(data-label);
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 2px;
  }
  table.rules td.no { width: 100%; padding: 6px 12px; }
  table.rules td.no .num { text-align: left; margin-right: 12px; }
  table.rules td.no .move { gap: 6px; }
  table.rules td.no .move button { width: 34px; height: 26px; font-size: 14px; }
  table.rules td.no::before { display: none; }
  table.rules .cond select { font-size: 16px; padding: 6px 4px; }   /* iPhone で拡大されないように 16px */
  .settings { flex-direction: column; }
  .actions button { width: 100%; }
  .saved-at { display: block; margin: 8px 0 0; }
}
