:root {
  color-scheme: dark;
  --bg: #06101d;
  --bg-deep: #030a12;
  --panel: rgba(8, 27, 45, 0.92);
  --panel-strong: #0a1929;
  --line: #143e5d;
  --line-bright: #1f78ae;
  --cyan: #46c9ff;
  --cyan-soft: #9be9ff;
  --blue: #0d62b8;
  --text: #eefaff;
  --muted: #83a8bd;
  --muted-2: #57798d;
  --danger: #e15270;
  --success: #42d3a1;
  --warning: #f0bb55;
  font-family: Inter, "Segoe UI", "Microsoft YaHei UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 76% 12%, rgba(16, 104, 170, 0.17), transparent 32rem),
    radial-gradient(circle at 15% 88%, rgba(41, 197, 246, 0.08), transparent 30rem),
    var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.grid-backdrop {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image:
    linear-gradient(rgba(66, 173, 225, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(66, 173, 225, 0.08) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(to bottom, black, transparent 88%);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
}

.login-card {
  position: relative;
  width: min(440px, 100%);
  padding: 34px;
  border: 1px solid var(--line-bright);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(11, 36, 59, 0.98), rgba(5, 18, 31, 0.98));
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.5), inset 0 1px rgba(255, 255, 255, 0.04);
}

.login-card::before,
.panel::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 24px;
  width: 72px;
  height: 2px;
  background: var(--cyan);
  box-shadow: 0 0 18px var(--cyan);
}

.brand-lockup,
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 1px solid #55d9ff;
  border-radius: 13px;
  color: #effbff;
  background: linear-gradient(145deg, #0d6dbd, #07375d);
  box-shadow: inset 0 0 18px rgba(70, 201, 255, 0.2), 0 0 24px rgba(70, 201, 255, 0.13);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.brand-mark.small {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  font-size: 14px;
}

.brand-lockup h1 {
  margin: 2px 0;
  font-size: 27px;
  letter-spacing: -0.03em;
}

.brand-lockup p,
.sidebar-brand span {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--cyan);
  font-size: 10px !important;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.signal-line {
  height: 1px;
  margin: 28px 0;
  background: linear-gradient(90deg, transparent, var(--line-bright), transparent);
}

.form-stack,
.form-grid {
  display: grid;
  gap: 16px;
}

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

.form-grid .span-2 {
  grid-column: span 2;
}

label {
  display: grid;
  gap: 7px;
}

label > span {
  color: #aed0e2;
  font-size: 12px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #1a4f72;
  border-radius: 9px;
  outline: none;
  color: var(--text);
  background: #061421;
  padding: 11px 12px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(70, 201, 255, 0.1);
}

.button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 15px;
  color: var(--text);
  font-weight: 700;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button.primary {
  border-color: #55d9ff;
  background: linear-gradient(135deg, #0c72c4, #0b4d86);
  box-shadow: 0 8px 24px rgba(13, 98, 184, 0.25);
}

.button.primary:hover {
  background: linear-gradient(135deg, #1389dc, #0d62a7);
}

.button.secondary {
  border-color: #245b7b;
  color: #b9e8fa;
  background: #0a263c;
}

.button.danger {
  border-color: #a53953;
  color: #ffd9e1;
  background: #552033;
}

.button.wide {
  width: 100%;
}

.form-error {
  min-height: 20px;
  margin: -4px 0 0;
  color: #ff8fa6;
  font-size: 12px;
}

.security-note {
  margin: 24px 0 0;
  color: var(--muted-2);
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.08em;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #123b58;
  background: rgba(4, 15, 26, 0.96);
  box-shadow: 12px 0 44px rgba(0, 0, 0, 0.25);
}

.sidebar-brand {
  padding: 24px 22px;
  border-bottom: 1px solid #12344c;
}

.sidebar-brand strong {
  display: block;
  margin-bottom: 3px;
  font-size: 16px;
}

nav {
  display: grid;
  gap: 5px;
  padding: 22px 14px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 9px;
  color: #83a9bd;
  background: transparent;
  padding: 12px 13px;
  text-align: left;
  font-weight: 650;
}

.nav-item span {
  color: #396f90;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 10px;
}

.nav-item:hover {
  color: #d9f4ff;
  background: #09233a;
}

.nav-item.active {
  border-color: #1a6b9e;
  color: #effbff;
  background: linear-gradient(90deg, rgba(13, 98, 184, 0.42), rgba(8, 38, 60, 0.72));
  box-shadow: inset 3px 0 var(--cyan);
}

.nav-item.active span {
  color: var(--cyan);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 20px 22px;
  border-top: 1px solid #12344c;
  color: var(--muted-2);
  font-size: 11px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 10px var(--success);
}

.workspace {
  min-width: 0;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 28px;
  border-bottom: 1px solid #123f5d;
  background: rgba(5, 20, 35, 0.93);
  backdrop-filter: blur(18px);
}

.topbar h2 {
  margin: 0;
  font-size: 21px;
}

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

.admin-pill {
  margin-right: 8px;
  border: 1px solid #235c80;
  border-radius: 999px;
  color: #a9e7fb;
  background: #09253b;
  padding: 8px 13px;
  font-size: 12px;
  font-weight: 700;
}

.icon-button,
.modal-close {
  border: 1px solid #1c506f;
  border-radius: 8px;
  color: #afd8e9;
  background: #092236;
}

.icon-button {
  width: 38px;
  height: 38px;
}

.icon-button.danger:hover {
  border-color: #a43b56;
  color: #ffdce4;
  background: #4b1b2d;
}

.page-container {
  padding: 24px 28px 44px;
}

.page {
  display: none;
}

.page.active {
  display: block;
  animation: page-in 180ms ease;
}

@keyframes page-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 13px;
}

.metric-card,
.panel,
.template-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(10, 29, 47, 0.95), rgba(6, 21, 34, 0.95));
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.2);
}

.metric-card {
  overflow: hidden;
  padding: 18px;
}

.metric-card::after {
  content: "";
  position: absolute;
  right: -18px;
  bottom: -26px;
  width: 74px;
  height: 74px;
  border: 1px solid rgba(70, 201, 255, 0.14);
  border-radius: 50%;
}

.metric-card span {
  color: var(--muted);
  font-size: 11px;
}

.metric-card strong {
  display: block;
  margin-top: 9px;
  color: var(--cyan-soft);
  font-size: 29px;
  font-variant-numeric: tabular-nums;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.75fr);
  gap: 14px;
  margin-top: 14px;
}

.panel {
  padding: 20px;
}

.hero-panel {
  min-height: 225px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  overflow: hidden;
  background:
    linear-gradient(125deg, rgba(10, 43, 70, 0.96), rgba(5, 22, 37, 0.95)),
    var(--panel);
}

.hero-panel::after {
  content: "AT";
  position: absolute;
  right: 32px;
  top: 12px;
  color: rgba(70, 201, 255, 0.055);
  font-size: 140px;
  font-weight: 900;
}

.hero-panel > * {
  position: relative;
  z-index: 1;
}

.hero-panel h3,
.panel h3,
.page-toolbar h3 {
  margin: 2px 0 7px;
  font-size: 18px;
}

.hero-panel p:not(.eyebrow),
.page-toolbar p,
.modal-hint {
  margin: 0;
  max-width: 620px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.panel-heading,
.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-toolbar {
  min-height: 50px;
  margin-bottom: 14px;
}

.filter-group,
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.search-input {
  width: min(300px, 38vw);
}

.live-badge {
  border: 1px solid rgba(66, 211, 161, 0.44);
  border-radius: 999px;
  color: #73eabd;
  background: rgba(31, 105, 81, 0.2);
  padding: 5px 9px;
  font: 700 10px ui-monospace, SFMono-Regular, Consolas, monospace;
}

.runtime-summary {
  display: grid;
  gap: 12px;
  margin-top: 22px;
}

.runtime-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed #17415c;
  padding-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
}

.runtime-row strong {
  color: #dff8ff;
}

.table-panel {
  padding: 0;
  overflow: hidden;
}

.table-scroll {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  border-bottom: 1px solid #12364f;
  padding: 13px 14px;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  z-index: 2;
  top: 0;
  color: #6fa4bf;
  background: #071a2a;
  font-size: 10px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

tbody tr:hover {
  background: rgba(22, 75, 107, 0.19);
}

td.note-cell {
  max-width: 240px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
}

.align-right {
  text-align: right;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 10px;
  font-weight: 750;
}

.status-badge::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.status-active,
.status-online {
  border-color: rgba(66, 211, 161, 0.35);
  color: #62dfb0;
  background: rgba(30, 107, 81, 0.16);
}

.status-unused {
  border-color: rgba(70, 201, 255, 0.34);
  color: #72dafc;
  background: rgba(13, 98, 184, 0.16);
}

.status-banned,
.status-blocked {
  border-color: rgba(225, 82, 112, 0.4);
  color: #ff8ea5;
  background: rgba(124, 37, 56, 0.2);
}

.status-expired,
.status-unbound,
.status-offline {
  border-color: rgba(131, 168, 189, 0.3);
  color: #91acbb;
  background: rgba(70, 88, 100, 0.18);
}

.row-actions {
  display: inline-flex;
  justify-content: flex-end;
  gap: 6px;
}

.mini-button {
  border: 1px solid #235a7a;
  border-radius: 6px;
  color: #a8d9ed;
  background: #092237;
  padding: 5px 8px;
  font-size: 10px;
}

.mini-button:hover {
  border-color: var(--cyan);
  color: white;
}

.mini-button.danger {
  border-color: #7d3348;
  color: #ff9eb2;
  background: #351522;
}

.empty-state {
  padding: 64px 20px;
  color: var(--muted-2);
  text-align: center;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.72fr) minmax(0, 1.28fr);
  gap: 14px;
}

.form-panel {
  align-self: start;
}

.stack-list {
  display: grid;
  gap: 9px;
  margin-top: 16px;
}

.stack-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid #153e59;
  border-radius: 9px;
  background: #071a2a;
  padding: 12px;
}

.stack-item strong {
  display: block;
  margin-bottom: 4px;
  color: #dff7ff;
  font: 700 12px ui-monospace, SFMono-Regular, Consolas, monospace;
}

.stack-item p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

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

.template-card {
  padding: 18px;
}

.template-card.inactive {
  opacity: 0.55;
}

.template-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.template-card h4 {
  margin: 0;
}

.template-card p {
  min-height: 54px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.template-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted-2);
  font-size: 10px;
}

dialog {
  color: var(--text);
}

.modal {
  width: min(570px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid var(--line-bright);
  border-radius: 14px;
  background: linear-gradient(145deg, #0b2237, #06131f);
  padding: 22px;
  box-shadow: 0 28px 100px rgba(0, 0, 0, 0.68);
}

.modal.wide-modal {
  width: min(760px, calc(100vw - 32px));
}

.modal::backdrop {
  background: rgba(0, 6, 12, 0.78);
  backdrop-filter: blur(7px);
}

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

.modal-header h3 {
  margin: 0;
}

.modal-close {
  width: 34px;
  height: 34px;
  font-size: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 22px;
}

.modal-hint {
  margin: -8px 0 18px;
}

.code-output {
  max-height: 360px;
  overflow: auto;
  border: 1px solid #1c5375;
  border-radius: 9px;
  color: #b9edff;
  background: #030d16;
  padding: 15px;
  font: 12px/1.7 ui-monospace, SFMono-Regular, Consolas, monospace;
  user-select: all;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-top: 26px;
}

.check-label input {
  width: auto;
}

.reason-preset-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.reason-preset {
  min-height: 32px;
  border: 1px solid #24506d;
  border-radius: 7px;
  color: var(--muted);
  background: #071724;
  padding: 0 11px;
  font-size: 11px;
  font-weight: 650;
}

.reason-preset:hover {
  color: var(--text);
  border-color: #3781ad;
}

.reason-preset.active {
  color: #eafaff;
  border-color: #3ccfff;
  background: #0a4266;
}

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

.settings-grid .panel {
  position: relative;
}

.settings-hint {
  margin: -4px 0 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.inline-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 0.65fr);
  gap: 12px;
}

.settings-reasons,
.settings-actions {
  grid-column: 1 / -1;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
}

.toast {
  position: fixed;
  z-index: 100;
  right: 22px;
  bottom: 22px;
  max-width: 420px;
  border: 1px solid #287aa7;
  border-radius: 9px;
  color: #dff8ff;
  background: #09253a;
  padding: 12px 15px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: none;
}

.toast.error {
  border-color: #a94159;
  color: #ffdce4;
  background: #421827;
}

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

  .template-grid {
    grid-template-columns: repeat(2, minmax(230px, 1fr));
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .sidebar-brand {
    justify-content: center;
    padding: 18px 10px;
  }

  .sidebar-brand > div:last-child,
  .nav-item:not(.active)::after,
  .sidebar-footer span:last-child {
    display: none;
  }

  .nav-item {
    justify-content: center;
    padding: 12px 8px;
    font-size: 0;
  }

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

  .inline-fields {
    grid-template-columns: 1fr;
  }

  .nav-item span {
    font-size: 11px;
  }

  .sidebar-footer {
    justify-content: center;
  }

  .topbar,
  .page-container {
    padding-left: 18px;
    padding-right: 18px;
  }

  .dashboard-grid,
  .split-layout {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .login-shell {
    padding: 16px;
  }

  .login-card {
    padding: 26px 20px;
  }

  .topbar {
    align-items: flex-start;
  }

  .admin-pill {
    display: none;
  }

  .metric-grid,
  .template-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .span-2 {
    grid-column: span 1;
  }

  .page-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-group,
  .toolbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .search-input {
    width: 100%;
  }

  .hero-panel {
    align-items: flex-start;
    flex-direction: column;
  }
}
