:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #0f766e;
  --accent-hover: #0d9488;
  --danger: #b91c1c;
  --ok: #047857;
  --warn: #b45309;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #e8eef2 0%, var(--bg) 240px);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 960px; margin: 0 auto; padding: 24px 16px 48px; }
.nav {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 24px; gap: 12px; flex-wrap: wrap;
}
.brand { font-size: 1.35rem; font-weight: 700; color: var(--text); }
.brand span { color: var(--accent); }
.nav-links { display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: 0.95rem; }
.nav-links form { margin: 0; }
.nav-links button.link {
  background: none; border: 0; padding: 0; color: var(--accent);
  font: inherit; cursor: pointer;
}
.nav-links button.link:hover { text-decoration: underline; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
h1, h2 { margin: 0 0 14px; font-size: 1.15rem; }
.muted { color: var(--muted); font-size: 0.9rem; }

label { display: block; font-size: 0.88rem; margin: 10px 0 4px; color: #374151; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 0.95rem; background: #fff;
}
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.create-row { display: flex; gap: 8px; align-items: flex-end; }
.create-row > div { flex: 1.4; min-width: 0; }
.create-row .narrow { flex: 0 0 88px; }
.create-row .term { flex-basis: 118px; }
.create-row label { margin-top: 0; }
.search-row { display: flex; gap: 8px; align-items: flex-end; }
.search-row > div { flex: 1; min-width: 0; }
.search-row .status { flex: 0 0 118px; }
.search-row label { margin-top: 0; }
.search-row .btn { white-space: nowrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.btn {
  display: inline-block; border: none; border-radius: 8px; padding: 9px 14px;
  background: var(--accent); color: #fff; cursor: pointer; font-size: 0.92rem;
}
.btn:hover { background: var(--accent-hover); }
.btn.secondary { background: #e5e7eb; color: #111827; }
.btn.danger { background: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 0.82rem; }

.flash {
  padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 0.92rem;
}
.flash.ok { background: #ecfdf5; color: var(--ok); border: 1px solid #a7f3d0; }
.flash.error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.flash.info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.82rem; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 0.75rem; background: #e5e7eb; color: #374151;
}
.badge.watching { background: #e0f2fe; color: #075985; }
.badge.partial_alerting, .badge.alerting { background: #ffedd5; color: var(--warn); }
.badge.partial_done { background: #ecfdf5; color: var(--ok); }
.badge.pending { background: #e0f2fe; color: #075985; }
.badge.alerting { background: #ffedd5; color: var(--warn); }
.badge.done, .badge.partial_done { background: #ecfdf5; color: var(--ok); }
.badge.closed, .badge.stopped, .badge.expired { background: #f3f4f6; color: #6b7280; }
.badge.frozen { background: #fee2e2; color: var(--danger); }
.badge.empty { background: #f3f4f6; color: #6b7280; }
.badge.open { background: #e0f2fe; color: #075985; }
@keyframes manual-flash {
  0%, 100% { background: #fff; }
  50% { background: #fecaca; }
}
tr.manual-due {
  animation: manual-flash 1s steps(2, end) infinite;
}
tr.manual-due td { color: #b91c1c; font-weight: 600; }
.link-box { font-family: Consolas, monospace; }
.link-row { display: flex; gap: 8px; align-items: center; }
.link-row input { flex: 1; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.sort-head { display: inline-block; color: inherit; text-decoration: none; cursor: pointer; line-height: 1.25; }
.sort-head span { display: block; margin-top: 2px; color: var(--text); font-size: 0.78rem; font-weight: 600; }
.sort-head:hover span { text-decoration: underline; }
.time-line { color: var(--text); font-size: 0.85rem; white-space: nowrap; line-height: 1.35; }
.time-dot { margin: 0 3px; color: var(--muted); }
.view-cell { text-align: right; white-space: nowrap; }
.row-actions form { margin: 0; }
.fill-row {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(110px, 0.8fr) minmax(0, 1.6fr);
  gap: 12px;
  align-items: end;
}
.fill-row label { margin-top: 0; }
.slot-block { margin-top: 16px; }
.slot-block h2 { font-size: 1rem; margin-bottom: 8px; }
@media (max-width: 760px) {
  .fill-row { grid-template-columns: 1fr; }
}
.account-card { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; }
.account-card h2 { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.account-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px 18px;
  margin: 4px 0 12px;
}
.account-meta span { display: block; color: var(--muted); font-size: 0.78rem; margin-bottom: 2px; }
.account-meta strong { font-weight: 600; font-size: 0.92rem; word-break: break-all; }
.account-actions { justify-content: flex-end; margin-bottom: 8px; }
.mail-action-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 4px;
}
.mail-action-row .ssl-field { flex: 1 1 200px; min-width: 180px; max-width: 280px; }
.mail-action-row .note-field { flex: 2 1 220px; min-width: 180px; }
.mail-action-row > .btn { white-space: nowrap; }
.mail-checks { display: flex; flex-wrap: wrap; gap: 4px 20px; margin-top: 8px; }
.mail-checks .mail-enabled { margin: 0; }
.test-line { display: flex; gap: 8px; align-items: center; }
.test-line input { flex: 1; min-width: 0; }
.test-line .btn { white-space: nowrap; }

.login-box { max-width: 400px; margin: 80px auto; }
.login-box h1 { font-size: 1.5rem; }
.hint { margin-top: 8px; font-size: 0.85rem; color: var(--muted); }
.req { color: var(--danger); cursor: help; font-weight: 700; margin-left: 2px; }
.suggest { position: relative; }
.suggest-list {
  position: absolute; z-index: 20; left: 0; right: 0; top: 100%;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  max-height: 240px; overflow: auto; box-shadow: 0 8px 20px rgba(0,0,0,.08);
}
.suggest-list button {
  display: block; width: 100%; text-align: left; background: #fff; color: var(--text);
  border: none; border-bottom: 1px solid var(--line); padding: 8px 12px; cursor: pointer;
}
.suggest-list button:hover { background: #f3f4f6; }
dialog {
  position: fixed; inset: unset; top: 50%; left: 50%;
  transform: translate(-50%, -50%); margin: 0;
  border: none; border-radius: 12px; padding: 20px;
  width: min(420px, 92vw); max-height: calc(100vh - 2rem); overflow: auto;
  box-shadow: 0 16px 40px rgba(15, 23, 42, .18);
}
dialog.wide { width: min(680px, 94vw); }
dialog::backdrop { background: rgba(15, 23, 42, .35); }
.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 40; max-width: min(480px, 92vw); padding: 12px 18px;
  border-radius: 10px; font-size: 0.95rem; text-align: center;
  box-shadow: 0 10px 24px rgba(15, 23, 42, .16);
}
.toast.ok { background: #ecfdf5; color: var(--ok); border: 1px solid #a7f3d0; }
.toast.error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.toast.info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.toast.hide { opacity: 0; transform: translateX(-50%) translateY(-8px); transition: opacity .3s, transform .3s; }
.quote-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.quote-name {
  border: 0; background: transparent; padding: 0; color: var(--accent);
  font: inherit; cursor: pointer;
}
.quote-name:hover { text-decoration: underline; }
.lamp {
  width: 10px; height: 10px; border-radius: 50%; background: #d1d5db; display: inline-block;
}
.lamp.ok { background: #16a34a; }
.lamp.timeout, .lamp.error { background: #dc2626; }
