:root {
  --ink: #16201c;
  --muted: #62706a;
  --paper: #f7f4ed;
  --panel: #fffdf7;
  --line: #d9d0c0;
  --green: #1f7a52;
  --red: #b42318;
  --blue: #1e5b8f;
  --amber: #b46b12;
  --shadow: 0 18px 50px rgba(35, 31, 24, .10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(22, 32, 28, .035) 1px, transparent 1px), linear-gradient(90deg, rgba(22, 32, 28, .035) 1px, transparent 1px);
  background-size: 28px 28px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  background: rgba(247, 244, 237, .88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

h1, h2, p { margin: 0; }
h1 { font-size: 28px; letter-spacing: 0; }
h2 { font-size: 18px; letter-spacing: 0; }
.eyebrow { color: var(--amber); font-size: 12px; font-weight: 700; text-transform: uppercase; }

.layout {
  position: relative;
  display: grid;
  gap: 18px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.hero-panel {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  border-top: 5px solid var(--green);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}

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

.metrics div {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #faf7ee;
}

.metrics span { display: block; font-size: 23px; font-weight: 800; }
.metrics small, .hint, .muted { color: var(--muted); }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.mini-card {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 14px;
  background: #fffaf0;
  min-width: 0;
}

.mini-card h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.kv {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 7px;
  font-size: 13px;
  line-height: 1.45;
}

.kv b { color: var(--muted); font-weight: 600; }
.kv span { overflow-wrap: anywhere; }

.switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}

input, select, button {
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid var(--line);
  font: inherit;
}

input, select {
  padding: 0 12px;
  background: #fffdf7;
  color: var(--ink);
}

button {
  border-color: #133d2b;
  background: #173f2e;
  color: #fff;
  padding: 0 15px;
  font-weight: 700;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

input[type="checkbox"] { min-height: auto; }

.service-list, .audit-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

#auditList, #backupList {
  max-height: 352px;
  overflow-y: auto;
  padding-right: 4px;
}

.service-row, .provider-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 90px 90px 120px;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.provider-list {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.provider-row {
  grid-template-columns: minmax(0, 1fr) auto minmax(360px, auto);
  gap: 12px;
  padding: 8px 0;
}

.provider-main {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.provider-title-line, .provider-meta-line {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.provider-title-line strong {
  white-space: nowrap;
}

.provider-title-line .muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.provider-url {
  min-width: 160px;
  max-width: min(440px, 45vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.provider-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.provider-form input {
  width: 100%;
}

.field-title {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  margin-top: 2px;
}

.target-row, .form-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.provider-form .target-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 12px;
  align-items: stretch;
  margin-top: 2px;
}

.provider-form .target-row label {
  display: flex;
  align-items: center;
  min-height: 44px;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #faf7ee;
  color: var(--ink);
  line-height: 1.25;
}

.provider-form .target-row input[type="checkbox"] {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin: 0;
}

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

.provider-apply-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 6px;
}

.select-all, .mini-checks label, .provider-apply-actions label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #faf7ee;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

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

.select-all input, .mini-checks input {
  width: 14px;
  height: 14px;
  margin: 0;
}

.compact-button {
  min-height: 30px;
  padding: 6px 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  min-height: 28px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: #ece4d5;
  color: var(--muted);
}

.badge.ok { background: #dbeee4; color: var(--green); }
.badge.bad { background: #f6ded9; color: var(--red); }

.audit-item {
  border-left: 3px solid var(--blue);
  background: #faf7ee;
  padding: 10px 12px;
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 380px;
  padding: 12px 14px;
  border-radius: 7px;
  background: #16201c;
  color: #fff;
  opacity: 0;
  transform: translateY(8px);
  transition: .18s ease;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(420px, calc(100vw - 34px));
}

.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  background: var(--ink);
  color: #fff;
  border-radius: 6px;
  font-weight: 900;
  margin-bottom: 18px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.login-form label {
  display: grid;
  align-items: stretch;
  color: var(--ink);
  font-weight: 700;
}

.login-form input { margin-top: 6px; }
.login-form button { width: 100%; }
.form-error { color: var(--red); font-size: 14px; }

@media (max-width: 720px) {
  .topbar, .hero-panel { align-items: flex-start; }
  .topbar, .hero-panel, .service-row, .provider-row, .provider-form { grid-template-columns: 1fr; flex-direction: column; }
  .provider-row { align-items: stretch; }
  .provider-title-line, .provider-meta-line, .provider-apply-actions { flex-wrap: wrap; justify-content: flex-start; }
  .provider-url { max-width: 100%; }
  .provider-form .target-row { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: 1fr; width: 100%; }
  .service-row { display: grid; }
}
