:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-soft: #e9eeeb;
  --ink: #17211d;
  --muted: #66726c;
  --line: #d4dcd7;
  --accent: #187a54;
  --accent-dark: #0f5d3e;
  --accent-soft: #dcefe6;
  --danger: #b63e35;
  --danger-soft: #f8e4e1;
  --warning: #9a6511;
  --warning-soft: #fff1d4;
  --shadow: 0 18px 50px rgba(23, 33, 29, 0.09);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: 0;
}
a { color: inherit; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.brand {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}
.brand span { color: var(--accent); }
.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 700;
  text-decoration: none;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}
.button-primary { color: white; background: var(--accent); }
.button-primary:hover { background: var(--accent-dark); }
.button-secondary { color: var(--accent-dark); background: var(--accent-soft); border-color: #b8dccb; }
.button-secondary:hover { background: #cde7da; }
.button-quiet { color: var(--ink); background: transparent; border-color: var(--line); }
.button-quiet:hover { background: var(--surface-soft); }

.flash-stack {
  position: fixed;
  z-index: 50;
  top: 18px;
  right: 18px;
  width: min(440px, calc(100vw - 36px));
}
.flash { margin-bottom: 8px; padding: 13px 15px; border: 1px solid; border-radius: 6px; box-shadow: var(--shadow); background: var(--surface); }
.flash-success { color: var(--accent-dark); border-color: #a7d4bf; background: #edf8f2; }
.flash-error { color: #7b251f; border-color: #e3b3ae; background: var(--danger-soft); }

.status-dot { width: 8px; height: 8px; flex: 0 0 8px; display: inline-block; border-radius: 50%; }
.status-dot.online { background: #1e9b68; box-shadow: 0 0 0 4px rgba(30, 155, 104, 0.12); }
.status-dot.offline { background: var(--danger); }

.login-page { min-height: 100vh; background: #e8eeea; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 32px 20px; }
.login-shell > .brand { position: fixed; top: 28px; left: 32px; }
.login-panel { width: min(430px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.login-panel h1 { margin: 0 0 28px; font-size: 29px; }
.stacked-form { display: grid; gap: 10px; }
.stacked-form .button { margin-top: 10px; }
.admin-page { background: var(--bg); }
.admin-topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-actions form { margin: 0; }
.admin-layout { max-width: 1480px; margin: 0 auto; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.admin-nav {
  position: sticky;
  top: 66px;
  height: calc(100vh - 66px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 28px 20px;
  border-right: 1px solid var(--line);
}
.admin-nav a { padding: 9px 11px; border-radius: 5px; color: var(--muted); font-weight: 650; text-decoration: none; }
.admin-nav a:hover { color: var(--ink); background: var(--surface-soft); }
.admin-nav a.active { color: var(--accent-dark); background: var(--accent-soft); }
.admin-content { min-width: 0; padding: 0 clamp(22px, 4vw, 64px) 80px; background: var(--surface); }
.admin-section { scroll-margin-top: 82px; padding: 54px 0; border-bottom: 1px solid var(--line); }
.admin-section:last-child { border-bottom: 0; }
.section-first { padding-top: 48px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.section-heading h1, .section-heading h2 { margin: 0; line-height: 1.15; }
.section-heading h1 { font-size: 34px; }
.section-heading h2 { font-size: 26px; }
.status-badge { display: inline-flex; align-items: center; gap: 9px; padding: 7px 11px; border: 1px solid; border-radius: 999px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.status-ok { color: var(--accent-dark); border-color: #a8d5bf; background: #eff8f3; }
.status-neutral { color: var(--muted); border-color: var(--line); background: var(--surface-soft); }
.status-error { color: #7b251f; border-color: #dfaaa4; background: var(--danger-soft); }
.inline-error { padding: 11px 13px; border-left: 3px solid var(--danger); background: var(--danger-soft); color: #7b251f; overflow-wrap: anywhere; }
.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)); gap: 10px; }
.metric { min-height: 112px; display: flex; flex-direction: column; justify-content: space-between; padding: 16px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { font-size: 30px; line-height: 1; }

.connection-list { margin: 0 0 24px; border-top: 1px solid var(--line); }
.connection-list > div { display: grid; grid-template-columns: 180px 1fr; gap: 20px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.connection-list dt { color: var(--muted); }
.connection-list dd { margin: 0; font-weight: 650; overflow-wrap: anywhere; }
.settings-form { display: grid; gap: 28px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.compact-grid { max-width: 900px; }
.field { min-width: 0; display: grid; gap: 7px; }
.field-wide { grid-column: 1 / -1; }
.field label, .stacked-form label { font-size: 13px; font-weight: 750; }
input[type="text"], input[type="password"], input[type="number"], textarea,
.field input, .stacked-form input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  border: 1px solid #bec9c2;
  border-radius: 5px;
  outline: 0;
  background: var(--surface);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(24, 122, 84, 0.12); }
.field-hint, .section-note { margin: 0; color: var(--muted); font-size: 12px; }
.section-note { margin: -14px 0 22px; }
.toggle-list { max-width: 900px; border-top: 1px solid var(--line); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 17px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.toggle-row span { display: grid; gap: 3px; }
.toggle-row small { color: var(--muted); }
.toggle-row input {
  appearance: none;
  width: 46px;
  height: 25px;
  flex: 0 0 46px;
  margin: 0;
  border: 1px solid #aab7b0;
  border-radius: 20px;
  background: #cfd7d2;
  position: relative;
}
.toggle-row input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: white; box-shadow: 0 1px 4px rgba(0,0,0,0.2); transition: transform 140ms ease; }
.toggle-row input:checked { border-color: var(--accent); background: var(--accent); }
.toggle-row input:checked::after { transform: translateX(21px); }
.form-footer { max-width: 900px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-top: 4px; }
.danger-check { color: var(--danger); font-size: 13px; }
.danger-check input { accent-color: var(--danger); }
.narrow-form { max-width: 560px; }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); background: var(--bg); font-size: 11px; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
.log-status { display: inline-block; padding: 3px 7px; border-radius: 4px; font-weight: 700; white-space: nowrap; }
.log-sent { color: var(--accent-dark); background: var(--accent-soft); }
.log-error { color: #7b251f; background: var(--danger-soft); }
.log-processing { color: var(--warning); background: var(--warning-soft); }
.error-cell { max-width: 330px; color: var(--muted); overflow-wrap: anywhere; }
.empty-state { padding: 34px; color: var(--muted); text-align: center; }

@media (max-width: 1120px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(120px, 1fr)); }
}

@media (max-width: 820px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-nav {
    z-index: 15;
    top: 66px;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    padding: 8px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }
  .admin-nav a { white-space: nowrap; }
  .admin-content { padding: 0 20px 60px; }
  .admin-section { scroll-margin-top: 128px; padding: 42px 0; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
}

@media (max-width: 560px) {
  .admin-topbar { padding-left: 16px; padding-right: 16px; }
  .login-shell > .brand { left: 20px; }
  .login-panel { padding: 26px 22px; }
  .section-heading { flex-direction: column; align-items: stretch; }
  .section-heading form .button { width: 100%; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric { min-height: 100px; }
  .metric strong { font-size: 26px; }
  .connection-list > div { grid-template-columns: 1fr; gap: 4px; }
  .toggle-row { align-items: flex-start; }
  .form-footer { align-items: stretch; flex-direction: column; }
  .form-footer .button { width: 100%; }
}
