:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --surface-3: #f8fafb;
  --text: #1d2733;
  --muted: #667085;
  --line: #d6dee6;
  --line-soft: #e8edf2;
  --ok: #147a51;
  --warning: #9a6500;
  --danger: #b3261e;
  --accent: #1f5f7a;
  --accent-2: #287a63;
  --shadow: 0 10px 28px rgba(20, 32, 46, .07);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 22px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 2;
  box-shadow: 0 2px 14px rgba(20, 32, 46, .05);
  backdrop-filter: blur(8px);
}
.topbar > div {
  display: grid;
  gap: 1px;
}
.topbar nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.topbar nav a {
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.topbar nav a.active,
.topbar nav a:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.topbar nav a.logout-link {
  border: 1px solid var(--line);
  color: var(--danger);
}
.topbar nav a.logout-link:hover {
  background: #fff1f2;
}
.nav-user {
  align-items: center;
  background: var(--surface-2);
  border-radius: 6px;
  color: var(--muted);
  display: inline-flex;
  font-size: 13px;
  font-weight: 700;
  height: 34px;
  line-height: 1;
  padding: 0 10px;
}
.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 26px 22px 40px;
}
.muted,
.label,
small { color: var(--muted); }
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}
h1 { font-size: 28px; margin: 0; letter-spacing: 0; }
h2 { font-size: 19px; margin: 24px 0 12px; }
.page-subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-width: 0;
  box-shadow: var(--shadow);
}
.card strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 20px;
}
.card .time-value {
  color: var(--accent);
  font-size: 19px;
}
.card .time-zone {
  display: block;
  margin-top: 3px;
}
.card.compact strong { font-size: 14px; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--surface-2);
  color: var(--text);
}
.badge.ok,
.badge.success,
.badge.sent { background: #e7f5ee; color: var(--ok); }
.badge.warning,
.badge.pending,
.badge.baseline { background: #fff4db; color: var(--warning); }
.badge.error,
.badge.failed { background: #fde8e7; color: var(--danger); }
.banner {
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(20, 32, 46, .04);
}
.banner.ok { background: #e7f5ee; border-color: #bde5cf; color: var(--ok); }
.banner.warning { background: #fff4db; border-color: #f2d28a; color: var(--warning); }
.banner.danger { background: #fde8e7; border-color: #f5b7b1; color: var(--danger); }
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}
.table-wrap,
.table-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  box-shadow: var(--shadow);
}
.table-panel-head {
  position: sticky;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 760px;
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line-soft);
}
.table-panel-head span {
  color: var(--muted);
  font-size: 13px;
}
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}
.pagination a,
.pagination span {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  display: inline-flex;
  font-size: 14px;
  font-weight: 700;
  min-height: 34px;
  padding: 6px 10px;
}
.pagination a:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.pagination .active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.pagination .disabled {
  color: var(--muted);
  opacity: .55;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top;
}
th {
  background: var(--surface-3);
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}
tbody tr:hover {
  background: #fbfcfd;
}
td { overflow-wrap: anywhere; }
td.wide { min-width: 260px; }
.empty {
  color: var(--muted);
  text-align: center;
}
.filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr)) auto;
  gap: 10px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.settings-form {
  display: grid;
  gap: 14px;
  margin-bottom: 22px;
}
.template-form {
  display: grid;
  gap: 18px;
  margin-bottom: 14px;
}
.template-form label {
  display: grid;
  gap: 8px;
}
.template-form label > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.template-form textarea {
  width: 100%;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font: 14px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
  resize: vertical;
}
.form-actions,
.inline-form {
  display: flex;
  gap: 10px;
  align-items: center;
}
.settings-form fieldset {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  padding: 14px;
  box-shadow: var(--shadow);
}
.settings-form legend {
  color: #344054;
  font-weight: 700;
  padding: 0 6px;
}
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}
.setting-field {
  display: grid;
  gap: 5px;
  min-width: 0;
}
.setting-field span {
  color: var(--muted);
  font-size: 13px;
}
input, select, button, .button {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid var(--line);
  padding: 8px 10px;
  font: inherit;
  background: var(--surface);
  color: var(--text);
}
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  cursor: pointer;
  font-weight: 700;
}
button:hover,
.button:hover {
  filter: brightness(.96);
  text-decoration: none;
}
button:disabled {
  opacity: .55;
  cursor: not-allowed;
}
.button.secondary {
  background: var(--surface);
  color: var(--accent);
}
.action-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}
.action-list form,
.action-list button { width: 100%; }
.detail {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}
dl {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 8px 14px;
}
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
.signature-toggle {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 18px;
}
.signature-toggle h2 {
  margin: 0;
}
.toggle-form {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}
.toggle-row {
  align-items: center;
  background: var(--surface-2);
  border-radius: 6px;
  display: inline-flex;
  font-weight: 700;
  gap: 8px;
  min-height: 38px;
  padding: 7px 10px;
}
.toggle-row input {
  min-height: 18px;
  width: 18px;
}
.email-body {
  white-space: pre-wrap;
  background: #101828;
  color: #f8fafc;
  padding: 14px;
  border-radius: 8px;
  overflow: auto;
}
.login-box {
  max-width: 460px;
  background: rgba(255, 255, 255, .98);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 22px 60px rgba(20, 32, 46, .16);
}
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 18% 12%, rgba(40, 122, 99, .14), transparent 28%),
    radial-gradient(circle at 84% 18%, rgba(31, 95, 122, .15), transparent 30%),
    linear-gradient(135deg, #f8fafb 0%, #eef3f7 100%);
}
.login-shell {
  width: min(460px, calc(100vw - 32px));
}
.login-page .login-box {
  max-width: none;
}
.login-brand {
  align-items: center;
  display: flex;
  gap: 14px;
  margin-bottom: 22px;
}
.login-brand img {
  flex: 0 0 auto;
  height: 58px;
  object-fit: contain;
  width: 58px;
}
.login-brand h1 {
  font-size: 23px;
  line-height: 1.15;
  margin: 0;
}
.login-brand p {
  color: var(--muted);
  margin: 5px 0 0;
}
.login-box form {
  display: grid;
  gap: 14px;
}
.login-box label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 700;
  gap: 6px;
}
.login-box input {
  width: 100%;
}
.login-box button {
  width: 100%;
}
.turnstile-box {
  min-height: 65px;
  display: flex;
  align-items: center;
}

@media (max-width: 820px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .container { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
  dl { grid-template-columns: 1fr; }
}
