:root {
  --bg: #0b0f12;
  --bg-elevated: rgba(20, 24, 28, 0.78);
  --panel: rgba(25, 30, 33, 0.7);
  --panel-strong: rgba(31, 37, 42, 0.86);
  --panel-soft: rgba(40, 48, 53, 0.78);
  --border: rgba(159, 184, 163, 0.18);
  --border-strong: rgba(212, 174, 82, 0.45);
  --gold: #d4b15a;
  --gold-soft: #f1de9f;
  --text: #edf1ef;
  --text-muted: #aab5ae;
  --green: #6bc98a;
  --red: #ee6d73;
  --amber: #f0bc64;
  --shadow: rgba(3, 7, 10, 0.42);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Segoe UI", "Inter", sans-serif;
  background-color: var(--bg);
  background-image:
    linear-gradient(115deg, rgba(52, 91, 68, 0.22), transparent 42%),
    linear-gradient(295deg, rgba(155, 116, 42, 0.12), transparent 36%),
    linear-gradient(180deg, #12191a, #090d0f 78%);
  background-attachment: fixed;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.012), rgba(255,255,255,0.012)),
    linear-gradient(90deg, rgba(144, 164, 125, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(144, 164, 125, 0.03) 1px, transparent 1px);
  background-size: auto, 32px 32px, 32px 32px;
  pointer-events: none;
  opacity: 0.72;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  position: relative;
  z-index: 1;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: linear-gradient(160deg, rgba(29, 40, 35, 0.82), rgba(12, 17, 18, 0.78));
  backdrop-filter: blur(22px) saturate(135%);
  border-right: 1px solid var(--border);
  box-shadow: inset -1px 0 0 rgba(255,255,255,0.03);
  padding: 20px 14px 14px;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 4px 8px 26px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(212,177,90,0.2), rgba(241,222,159,0.08));
  border: 1px solid rgba(212,177,90,0.7);
  color: var(--gold-soft);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.15), 0 0 16px rgba(212,177,90,0.16);
}

.brand small {
  display: block;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 0.6rem;
  letter-spacing: 0.18em;
}

.side-nav {
  display: grid;
  gap: 6px;
}

.side-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 10px;
  color: #dfe7e4;
  text-decoration: none;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.side-nav a span {
  width: 18px;
  color: var(--gold-soft);
  text-align: center;
}

.side-nav a:hover,
.side-nav a:focus-visible {
  background: rgba(255,255,255,0.03);
  border-color: rgba(212,177,90,0.25);
  color: var(--text);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: linear-gradient(135deg, rgba(212,177,90,0.22), rgba(255,255,255,0.04));
  color: var(--gold-soft);
  border: 1px solid rgba(212,177,90,0.5);
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-info strong,
.user-info small {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.user-info strong {
  font-size: 0.83rem;
}

.user-info small {
  color: var(--text-muted);
  font-size: 0.68rem;
}

.icon-button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 6px 8px;
}

.icon-button:hover {
  color: var(--gold-soft);
}

.main-column {
  min-width: 0;
}

.content {
  max-width: 1380px;
  margin: 0 auto;
  padding: 32px clamp(18px, 3vw, 48px) 80px;
}

.content:has(.login-wrap) {
  min-height: 100vh;
  display: grid;
  align-content: start;
  padding-top: clamp(48px, 12vh, 120px);
}

.mobile-top,
.mobile-nav { display: none; }

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

.page-heading h1 {
  margin: 0;
  font-size: clamp(1.8rem, 2vw, 2.4rem);
  font-family: Georgia, "Times New Roman", serif;
  color: #f5f1e8;
}

.page-heading p {
  margin: 7px 0 0;
  color: var(--text-muted);
}

.card {
  background:
    linear-gradient(145deg, rgba(35, 47, 40, 0.78), rgba(17, 23, 24, 0.76) 58%, rgba(16, 21, 23, 0.84));
  border: 1px solid rgba(194, 211, 194, 0.2);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(18px) saturate(125%);
}

.login-wrap {
  width: min(100%, 460px);
  margin: 0 auto;
  padding: clamp(24px, 5vw, 38px);
  border-color: rgba(212, 177, 90, 0.34);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.46), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.login-wrap h2 {
  font: 700 1.9rem Georgia, "Times New Roman", serif;
  color: #f6f0d7;
  margin: 0 0 24px;
}

.login-wrap form > input:not([type="hidden"]) {
  margin-bottom: 16px;
}

.login-wrap input[type="submit"] {
  width: 100%;
  min-height: 46px;
}

.login-wrap > .muted {
  display: block;
  border-top: 1px solid var(--border);
  margin: 24px 0 0;
  padding-top: 16px;
  line-height: 1.6;
}

.card h2, .card h3 {
  margin-top: 0;
  color: var(--gold-soft);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.metric {
  background: linear-gradient(180deg, rgba(25, 29, 31, 0.88), rgba(18, 22, 24, 0.7));
  border: 1px solid var(--border);
  border-top: 2px solid var(--gold);
  border-radius: 14px;
  padding: 18px 18px 16px;
  min-height: 110px;
  box-shadow: 0 12px 28px rgba(0,0,0,0.18);
}

.metric span {
  display: block;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font: 1.9rem Georgia, serif;
  color: #f6f0d7;
}

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

.section-title h3 {
  margin: 0;
}

.row-title {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.row-title:hover {
  color: var(--gold-soft);
}

.server-row,
.machine-row,
.plugin-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.5fr) minmax(120px, 1fr) minmax(120px, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px 4px;
  border-top: 1px solid var(--border);
}

.server-row:first-of-type,
.machine-row:first-of-type,
.plugin-row:first-of-type {
  border-top: none;
}

.row-meta {
  color: var(--text-muted);
  font-size: 0.83rem;
  line-height: 1.55;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.status-dot::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  box-shadow: 0 0 12px rgba(255,255,255,0.2);
}

.status-dot.online::before { background: var(--green); box-shadow: 0 0 12px rgba(107,201,138,0.8); }
.status-dot.stale::before { background: var(--amber); box-shadow: 0 0 12px rgba(240,188,100,0.75); }
.status-dot.offline::before { background: var(--red); box-shadow: 0 0 12px rgba(238,109,115,0.8); }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.72rem;
  line-height: 1.4;
  font-weight: 700;
}
.badge-online { background: rgba(107,201,138,0.14); color: var(--green); }
.badge-offline { background: rgba(238,109,115,0.14); color: var(--red); }
.badge-stale { background: rgba(240,188,100,0.14); color: var(--amber); }
.badge-expired, .badge-rejected { background: rgba(238,109,115,0.14); color: var(--red); }
.badge-pending, .badge-sent { background: rgba(240,188,100,0.14); color: var(--amber); }
.badge-applied { background: rgba(107,201,138,0.14); color: var(--green); }
.badge-unknown { background: rgba(170,181,174,0.14); color: var(--text-muted); }

.button,
button.primary,
input[type=submit] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, #d4b15a, #b88d39);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  color: #181713;
  font-weight: 700;
  text-decoration: none;
  padding: 10px 16px;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(184,141,57,0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.button:hover,
button.primary:hover,
input[type=submit]:hover { transform: translateY(-1px); }

button.secondary {
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 14px;
  cursor: pointer;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 650;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

button.secondary:hover {
  background: rgba(212, 177, 90, 0.1);
  border-color: rgba(212, 177, 90, 0.42);
  color: var(--gold-soft);
  transform: translateY(-1px);
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--gold-soft);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
  box-shadow: none;
}

button.danger {
  background: linear-gradient(135deg, rgba(238,109,115,0.9), rgba(178,70,78,0.9));
  border: none;
  border-radius: 10px;
  color: white;
  padding: 9px 14px;
  cursor: pointer;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 7px 12px 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(20, 27, 26, 0.56);
  color: #d9e2dc;
  text-decoration: none;
  font-size: 0.86rem;
  font-weight: 600;
  backdrop-filter: blur(10px);
  transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.back-link:hover {
  border-color: rgba(212, 177, 90, 0.46);
  background: rgba(212, 177, 90, 0.08);
  color: var(--gold-soft);
  transform: translateX(-2px);
}

.back-link::first-letter {
  color: var(--gold-soft);
}

.tabs {
  display: flex;
  gap: 6px;
  margin: -4px -4px 20px;
  padding: 4px 4px 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 177, 90, 0.45) transparent;
}

.tab-button {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 650;
  cursor: pointer;
  transition: color 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.tab-button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
}

.tab-button[aria-selected="true"] {
  color: var(--gold-soft);
  border-color: rgba(212, 177, 90, 0.28);
  background: linear-gradient(180deg, rgba(212, 177, 90, 0.14), rgba(212, 177, 90, 0.045));
  box-shadow: inset 0 -2px 0 var(--gold);
}

.tab-panel[hidden] { display: none; }

.tab-panel h2 {
  margin: 0 0 8px;
  color: #f1e8cb;
  font: 600 1.2rem Georgia, "Times New Roman", serif;
}

.setting-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
  gap: 12px;
  margin-top: 16px;
}

.setting,
.field-group {
  min-width: 0;
  padding: 15px;
  border: 1px solid rgba(159, 184, 163, 0.15);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(34, 43, 39, 0.62), rgba(14, 19, 20, 0.5));
}

.setting > label:not(.switch),
.field-group > label {
  color: #c6d0c9;
  font-weight: 600;
}

.setting input[type="number"],
.setting select,
.field-group select {
  margin-top: 4px;
}

.setting small,
.field-group small {
  display: block;
  margin-top: 8px;
  line-height: 1.5;
}

.setting-grid > .muted {
  align-self: center;
  padding: 8px 2px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 28px;
  margin: 0;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.switch input[type="checkbox"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch-track {
  position: relative;
  flex: 0 0 40px;
  width: 40px;
  height: 23px;
  border: 1px solid rgba(170, 181, 174, 0.32);
  border-radius: 999px;
  background: rgba(7, 10, 11, 0.78);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: background 0.18s ease, border-color 0.18s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #aab5ae;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.38);
  transition: transform 0.18s ease, background 0.18s ease;
}

.switch input[type="checkbox"]:checked + .switch-track {
  background: rgba(107, 201, 138, 0.22);
  border-color: rgba(107, 201, 138, 0.66);
}

.switch input[type="checkbox"]:checked + .switch-track::after {
  transform: translateX(17px);
  background: var(--green);
}

.switch input[type="checkbox"]:focus-visible + .switch-track {
  outline: 2px solid var(--gold-soft);
  outline-offset: 3px;
}

.switch input[type="checkbox"]:disabled + .switch-track { opacity: 0.48; }

.save-dock {
  position: sticky;
  z-index: 5;
  bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin: 16px 0 20px;
  padding: 14px 16px;
  border: 1px solid rgba(212, 177, 90, 0.32);
  border-radius: 9px;
  background: rgba(18, 24, 23, 0.94);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(20px) saturate(130%);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.18s ease, visibility 0.18s ease, transform 0.18s ease;
}

.save-dock.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.save-summary { min-width: 0; }
.save-summary > strong { color: var(--gold-soft); }
.save-actions { display: flex; flex: 0 0 auto; gap: 9px; }
.save-actions .primary,
.save-actions .secondary { min-height: 40px; }

.diff-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.save-warning {
  display: block;
  margin-top: 8px;
  color: var(--amber);
}

.history-entry {
  padding: 14px 0;
  border-top: 1px solid var(--border);
}

.history-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.history-heading strong { margin-right: auto; }
.history-entry details { margin-top: 10px; color: var(--text-muted); }
.history-entry pre { overflow: auto; padding: 12px; border-radius: 7px; background: rgba(5, 8, 9, 0.66); }

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  align-items: end;
}

.filter-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type=text],
input[type=email],
input[type=password],
input[type=number],
input[type=search],
select {
  width: 100%;
  background: rgba(11, 15, 18, 0.75);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 40px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.24);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

input[type=text]:focus,
input[type=email]:focus,
input[type=password]:focus,
input[type=number]:focus,
input[type=search]:focus,
select:focus {
  outline: none;
  border-color: rgba(212, 177, 90, 0.8);
  box-shadow: 0 0 0 3px rgba(212, 177, 90, 0.15), inset 0 1px 3px rgba(0, 0, 0, 0.24);
}

label {
  display: block;
  margin: 0 0 6px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.muted {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.alert {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.alert-error { background: rgba(238,109,115,0.12); border: 1px solid rgba(238,109,115,0.4); color: #ffd5d7; }
.alert-success { background: rgba(107,201,138,0.12); border: 1px solid rgba(107,201,138,0.4); color: #d6f5df; }

.notice-stale {
  background: rgba(240,188,100,0.12);
  border-left: 3px solid var(--amber);
  border-radius: 10px;
  color: #f4e0a2;
  padding: 12px 14px;
  margin-bottom: 14px;
}

code.token {
  display: block;
  background: rgba(11, 15, 18, 0.88);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-top: 10px;
  word-break: break-all;
  color: var(--gold-soft);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.pagination a,
.pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  border-radius: 9px;
  text-decoration: none;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  color: var(--text);
  font-size: 0.9rem;
}

.pagination .current {
  background: linear-gradient(135deg, rgba(212,177,90,0.2), rgba(212,177,90,0.08));
  border-color: rgba(212,177,90,0.5);
  color: var(--gold-soft);
}

.pagination .disabled {
  opacity: 0.45;
  pointer-events: none;
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 220px minmax(0,1fr); }
  .metric-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 680px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .mobile-top { display: flex; position: sticky; top: 0; z-index: 10; align-items: center; justify-content: space-between; padding: 10px 14px; background: rgba(18,22,24,0.86); border-bottom: 1px solid var(--border); backdrop-filter: blur(12px); }
  .mobile-top .brand { padding: 0; }
  .mobile-nav { display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px; background: rgba(18,22,24,0.9); border-bottom: 1px solid var(--border); }
  .mobile-nav a { flex: 1 0 auto; text-align: center; color: var(--text-muted); text-decoration: none; padding: 9px 10px; border-radius: 8px; }
  .mobile-nav a:hover { background: rgba(255,255,255,0.02); }
  .content { padding: 22px 12px 80px; }
  .content:has(.login-wrap) { padding-top: clamp(32px, 8vh, 72px); }
  .login-wrap { padding: 24px 20px; }
  .page-heading { flex-direction: column; align-items: flex-start; }
  .server-row, .machine-row, .plugin-row { grid-template-columns: 1fr auto; }
  .server-row > :nth-child(2), .server-row > :nth-child(3), .machine-row > :nth-child(2), .machine-row > :nth-child(3), .plugin-row > :nth-child(2), .plugin-row > :nth-child(3) { grid-column: 1 / -1; }
  .metric-grid { grid-template-columns: 1fr; }
  .filter-actions { flex-wrap: wrap; }
}
