:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #656d76;
  --line: #d8dee4;
  --accent: #345d7e;
  --accent-dark: #284961;
  --danger: #b42318;
  --ok: #067647;
  --warn: #b54708;
  --soft-blue: #edf4ff;
  --soft-green: #ecfdf3;
  --soft-red: #fef3f2;
  --soft-amber: #fffaeb;
  --soft-accent: #eef4fa;
  --shadow: 0 8px 20px rgba(31, 35, 40, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 20px;
  min-height: 62px;
  padding: 10px clamp(14px, 3vw, 28px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  box-shadow: none;
}

.brand,
.nav a {
  color: var(--text);
  text-decoration: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  font-weight: 700;
  white-space: nowrap;
}

.header-menu {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.menu-toggle {
  display: none;
}

.nav {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.nav a {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 5px;
  color: var(--muted);
  font-weight: 600;
}

.nav a:hover {
  background: var(--soft-accent);
  color: var(--accent-dark);
}

.page {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 30px clamp(14px, 3vw, 24px) 56px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  margin-bottom: 7px;
  font-size: 28px;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  letter-spacing: 0;
}

p {
  margin: 0;
  color: var(--muted);
}

.actions,
.card-actions,
.row-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.actions form,
.card-actions form,
.page-head form,
.logout-form {
  margin: 0;
}

button,
.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: #2f3a45;
  color: white;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

button:hover,
.button:hover {
  background: #1f2933;
}

.secondary,
.ghost {
  background: #eef0f2;
  color: var(--text);
}

.ghost {
  background: #2f3a45;
  color: white;
}

.small {
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: #eef0f2;
  color: var(--text);
  text-decoration: none;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.danger,
.danger-action {
  color: var(--danger);
}

.danger-action {
  background: #f3eeee;
}

.danger-action:hover {
  background: var(--soft-red);
  color: var(--danger);
}

.login-panel,
.form,
.empty,
.site-card,
.history-item,
.guide {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  box-shadow: none;
}

.login-panel {
  max-width: 420px;
  margin: clamp(28px, 8vh, 76px) auto;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-panel p {
  margin-bottom: 18px;
}

.form {
  display: grid;
  gap: 20px;
  padding: clamp(18px, 3vw, 24px);
}

.form.compact {
  padding: 0;
  border: 0;
  box-shadow: none;
}

.form.wide {
  max-width: 940px;
}

.settings-page-head,
.settings-form {
  max-width: 940px;
  margin-left: auto;
  margin-right: auto;
}

.test-mail-form {
  margin-top: 16px;
}

.fixed-setting {
  display: grid;
  gap: 5px;
  align-content: start;
  min-height: 40px;
  padding-top: 1px;
}

.fixed-setting span {
  font-weight: 600;
}

.fixed-setting strong {
  font-size: 16px;
}

.form-section {
  display: grid;
  gap: 14px;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 7px;
  font-weight: 600;
}

.field-label {
  color: var(--text);
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 10px 11px;
  background: white;
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 93, 126, 0.14);
}

textarea {
  resize: vertical;
  font-family: Consolas, monospace;
}

.help-text {
  font-size: 13px;
}

.field-error {
  color: var(--danger);
  font-size: 13px;
}

.email-list-field {
  display: grid;
  gap: 10px;
}

.email-values {
  display: none;
}

.email-items {
  display: flex;
  min-height: 44px;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f9fafb;
}

.email-empty {
  color: var(--muted);
  font-size: 14px;
  line-height: 24px;
}

.email-chip {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--text);
  font-weight: 600;
}

.email-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-remove {
  width: 22px;
  height: 22px;
  min-height: 22px;
  padding: 0;
  border-radius: 999px;
  background: #eef0f2;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
}

.email-remove:hover {
  background: #e2e5e8;
  color: var(--text);
}

.email-add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.email-input-label {
  min-width: 0;
}

.checks {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.check input {
  width: auto;
}

.duration-field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.duration-field legend {
  margin-bottom: 7px;
  padding: 0;
  font-weight: 600;
}

.duration-inputs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.advanced-settings {
  border-top: 1px solid var(--line);
  padding-top: 4px;
}

.advanced-settings summary {
  min-height: 40px;
  display: flex;
  align-items: center;
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

.advanced-content {
  padding-top: 10px;
}

.site-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 16px;
}

.site-card,
.history-item {
  display: grid;
  gap: 12px;
  padding: clamp(14px, 2.2vw, 18px);
}

.site-card {
  border-top: 3px solid var(--accent);
}

.site-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  min-width: 0;
}

.history-top {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
}

.site-title-block {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: start;
  gap: 8px;
  min-width: 0;
}

.site-title-block h2 {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

.site-link-icon {
  width: 30px;
  height: 30px;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  background: #eef0f2;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  line-height: 1;
}

.site-link-icon:hover {
  background: #e2e5e8;
}

.site-url {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.status-stack {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-start;
  max-width: none;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.metrics div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f9fafb;
}

.metrics dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metrics dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
  min-width: 0;
}

.metric-note {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.countdown {
  color: var(--text);
}

.countdown.soon {
  color: var(--text);
}

.compact-metrics {
  grid-template-columns: repeat(2, minmax(0, 140px));
}

.pill,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill {
  background: #eef4fa;
  color: var(--accent-dark);
}

.status.on {
  background: var(--soft-green);
  color: var(--ok);
}

.status.off {
  background: #f2f4f7;
  color: var(--muted);
}

.status.warn {
  background: var(--soft-amber);
  color: var(--warn);
}

.status.bad {
  background: var(--soft-red);
  color: var(--danger);
}

.error-text {
  color: var(--danger);
  overflow-wrap: anywhere;
}

.is-hidden {
  display: none !important;
}

.empty,
.guide {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.guide {
  max-width: 860px;
}

.guide ol {
  margin: 0;
  padding-left: 22px;
  color: var(--text);
}

.guide li + li {
  margin-top: 8px;
}

.guide code {
  padding: 2px 5px;
  border-radius: 4px;
  background: #eef0f2;
  color: var(--text);
  font-size: 0.95em;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-filter {
  display: flex;
  align-items: end;
  gap: 10px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
}

.history-filter label {
  flex: 1 1 320px;
}

.history-message {
  color: var(--text);
}

.history-diff {
  max-height: 260px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f7f9fb;
  color: var(--text);
  font: 12px/1.5 Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.messages {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.message {
  max-height: 1000px;
  padding: 11px 13px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: white;
  box-shadow: none;
  overflow: hidden;
  transition: opacity 0.22s ease, transform 0.22s ease, max-height 0.22s ease, margin 0.22s ease, padding 0.22s ease;
}

.message.is-hiding {
  max-height: 0;
  margin: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  transform: translateY(-6px);
}

.message.success {
  border-color: #abefc6;
  background: var(--soft-green);
}

.message.error {
  border-color: #fecdca;
  background: var(--soft-red);
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(31, 35, 40, 0.34);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease;
}

.confirm-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.confirm-dialog {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: var(--shadow);
  transform: translateY(8px) scale(0.98);
  transition: transform 0.16s ease;
}

.confirm-overlay.is-open .confirm-dialog {
  transform: translateY(0) scale(1);
}

.confirm-dialog h2 {
  font-size: 18px;
}

.confirm-dialog p {
  color: var(--text);
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px 14px;
    padding-bottom: 9px;
  }

  .menu-toggle {
    display: inline-flex;
    justify-self: end;
    min-height: 36px;
    padding: 7px 12px;
    background: #eef0f2;
    color: var(--text);
  }

  .menu-toggle:hover {
    background: #e2e5e8;
  }

  .header-menu {
    display: grid;
    grid-column: 1 / -1;
    max-height: 0;
    overflow: hidden;
    padding: 0;
    border-top: 0 solid transparent;
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
    transition: max-height 0.24s ease, opacity 0.18s ease, transform 0.18s ease, padding 0.18s ease, border-color 0.18s ease;
  }

  .topbar.menu-open .header-menu {
    display: grid;
    gap: 10px;
    max-height: 360px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }

  .nav {
    display: grid;
    justify-content: stretch;
    gap: 6px;
  }

  .nav a,
  .logout-form,
  .logout-form button {
    width: 100%;
  }

  .nav a {
    justify-content: flex-start;
    min-height: 40px;
    padding: 9px 10px;
    background: #f7f8f9;
  }

  .logout-form button {
    justify-content: center;
  }

  .site-grid,
  .form-grid.two,
  .form-grid.three {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  .page {
    padding: 20px 14px 40px;
  }

  .page-head,
  .history-top {
    flex-direction: column;
  }

  .site-main {
    grid-template-columns: 1fr;
  }

  .status-stack {
    justify-content: flex-start;
    max-width: none;
  }

  .actions,
  .actions form,
  .actions button,
  .actions .button,
  .email-add-row,
  .email-add-row button,
  .history-filter,
  .history-filter .small,
  .card-actions,
  .card-actions form,
  .card-actions button,
  .card-actions .small {
    width: 100%;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .email-add-row {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 24px;
  }

  .login-panel {
    margin: 24px auto;
  }

  .confirm-actions,
  .confirm-actions button {
    width: 100%;
  }
}
