:root {
  --bg: #f8f9fb;
  --panel: #ffffff;
  --line: #e8ebf0;
  --line-subtle: #f0f1f4;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --surface: #f1f5f9;
  --blue: #3b82f6;
  --blue-light: #dbeafe;
  --blue-dark: #1d4ed8;
  --red: #ef4444;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --green: #22c55e;
  --green-bg: #f0fdf4;
  --green-dark: #16a34a;
  --amber: #f59e0b;
  --amber-bg: #fffbeb;
  --amber-dark: #d97706;
  --purple: #8b5cf6;
  --purple-bg: #f5f3ff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.08);
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; margin: 0; }
body { min-height: 100vh; }
button, input { font: inherit; }

.main {
  width: min(1200px, calc(100% - 40px));
  margin: 0 auto;
  padding: 24px 0 80px;
}

.header-row {
  display: flex;
  align-items: center;
  margin-bottom: 22px;
}

.credential-toggle {
  display: none;
}

.cred-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.input-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-3);
  pointer-events: none;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  outline: none;
  padding: 10px 14px 10px 36px;
  font-size: 14px;
  font-weight: 500;
  transition: border-color .2s, box-shadow .2s;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}

input::placeholder { color: var(--text-3); font-weight: 400; }

button {
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#scanBtn {
  background: var(--blue);
  color: #fff;
  padding: 10px 20px;
  white-space: nowrap;
  height: 42px;
}

#scanBtn:hover { background: var(--blue-dark); transform: translateY(-1px); box-shadow: var(--shadow); }
#scanBtn:active { transform: translateY(0); }
#scanBtn:disabled { opacity: .7; cursor: wait; transform: none; box-shadow: none; }

.btn-icon-spin {
  width: 18px;
  height: 18px;
  display: none;
}

#scanBtn:disabled .btn-icon-spin { display: block; animation: spin .8s linear infinite; }
#scanBtn:disabled .btn-label { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.summary:empty { display: none; }

.summary > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: box-shadow .2s;
}

.summary > div:hover { box-shadow: var(--shadow); }

.summary-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.summary-icon.ecs { background: #fef2f2; color: #dc2626; }
.summary-icon.eip { background: var(--blue-light); color: var(--blue); }
.summary-icon.vpn { background: var(--purple-bg); color: var(--purple); }

.summary-icon svg {
  width: 20px;
  height: 20px;
}

.summary strong {
  display: block;
  font-size: 24px;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.summary span {
  display: block;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  margin-top: 1px;
}

.summary p {
  grid-column: 1 / -1;
  color: var(--text-3);
  font-size: 13px;
  padding: 8px 0 0;
}

.errors {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.error, .notice {
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
  overflow-wrap: anywhere;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.error {
  color: #991b1b;
  background: var(--red-bg);
  border: 1px solid var(--red-border);
}

.notice {
  color: #1e40af;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
}

.resources {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}

.resources.empty { display: block; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  background: var(--panel);
  border: 2px dashed var(--line);
  border-radius: var(--radius-xl);
  padding: 40px 20px;
  text-align: center;
}

.empty-icon-wrap {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: var(--surface);
  display: grid;
  place-items: center;
  margin-bottom: 16px;
}

.empty-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
  opacity: .5;
}

.empty-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-2);
  margin-bottom: 4px;
}

.empty-sub {
  font-size: 14px;
  color: var(--text-3);
  max-width: 340px;
  line-height: 1.5;
}

.resource-card {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  overflow: hidden;
  transition: box-shadow .2s, border-color .2s;
}

.resource-card:hover {
  border-color: #d0d5dd;
  box-shadow: var(--shadow-lg);
}

.card-accent {
  height: 3px;
}

.card-accent.ecs { background: linear-gradient(90deg, #ef4444, #f97316); }
.card-accent.eip { background: linear-gradient(90deg, #3b82f6, #06b6d4); }
.card-accent.vpn { background: linear-gradient(90deg, #8b5cf6, #ec4899); }

.card-body {
  padding: 18px 20px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.service-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: contain;
  display: block;
}

.service-badge {
  min-width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  padding: 0 8px;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .02em;
}

.service-badge.eip { background: var(--blue); }
.service-badge.vpn { background: var(--purple); }

.card-top-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

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

.status.active { color: var(--green-dark); background: var(--green-bg); }
.status.pending { color: var(--amber-dark); background: var(--amber-bg); }
.status.bad { color: #dc2626; background: var(--red-bg); }
.status.muted { color: var(--text-3); background: var(--surface); }

.resource-card h2 {
  font-size: 17px;
  line-height: 1.3;
  letter-spacing: -0.02em;
  font-weight: 700;
  overflow-wrap: anywhere;
  margin-bottom: 2px;
}

.resource-type {
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 2px;
}

.resource-id {
  color: var(--text-3);
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  overflow-wrap: anywhere;
  margin-bottom: 14px;
}

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

.facts div {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.facts .wide { grid-column: 1 / -1; }

.fact-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  margin-top: 2px;
  fill: none;
  stroke: var(--text-3);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.facts dt {
  color: var(--text-3);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  line-height: 1;
}

.facts dd {
  margin: 2px 0 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  overflow-wrap: anywhere;
  line-height: 1.3;
}

.card-actions {
  display: flex;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--line-subtle);
  background: #fafbfc;
}

.card-actions button {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 10px;
}

.secondary {
  flex: 1;
  color: var(--text-2);
  background: var(--panel);
  border: 1px solid var(--line);
}

.secondary:hover { background: var(--surface); color: var(--text); border-color: #cdd3dc; }

.stop {
  color: var(--amber-dark);
  background: var(--amber-bg);
  border: 1px solid #fde68a;
}

.stop:hover { background: #fef3c7; border-color: var(--amber-dark); }

.danger {
  color: var(--red);
  background: var(--red-bg);
  border: 1px solid var(--red-border);
}

.danger:hover { background: #fee2e2; border-color: var(--red); }

dialog {
  width: min(640px, calc(100% - 24px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: none;
  border-radius: var(--radius-xl);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 25px 80px rgba(0,0,0,.25);
  padding: 28px;
}

dialog::backdrop { background: rgba(15, 23, 42, .5); backdrop-filter: blur(4px); }

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

.dialog-head h2, #deleteDialog h2, #stopDialog h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.dialog-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  margin-bottom: 14px;
}

.dialog-icon-wrap.danger { background: var(--red-bg); color: var(--red); }
.dialog-icon-wrap.warn-color { background: var(--amber-bg); color: var(--amber-dark); }

.btn-icon {
  width: 36px;
  height: 36px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text-2);
  display: grid;
  place-items: center;
  padding: 0;
  transition: all .15s;
}

.btn-icon:hover { background: var(--panel); color: var(--text); border-color: #cdd3dc; }

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

.detail-grid div {
  min-width: 0;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: var(--radius);
}

.detail-grid dt {
  color: var(--text-3);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 2px;
}

.detail-grid dd {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.raw-json {
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.raw-json summary {
  cursor: pointer;
  color: var(--text-3);
  font-weight: 600;
  font-size: 13px;
  padding: 6px 0;
  user-select: none;
}

.raw-json summary:hover { color: var(--text-2); }

pre {
  white-space: pre-wrap;
  overflow: auto;
  max-height: 48vh;
  background: #1e293b;
  color: #e2e8f0;
  border-radius: var(--radius);
  padding: 16px;
  font-size: 12px;
  line-height: 1.6;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

.warn {
  margin: 8px 0 14px;
  font-size: 14px;
  line-height: 1.5;
  color: #991b1b;
}

.muted-warn { color: var(--text-2); }

.mono {
  margin: 0 0 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
  color: var(--text-2);
}

#deleteConfirmation {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  outline: none;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 16px;
  transition: border-color .2s, box-shadow .2s;
}

#deleteConfirmation:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(239,68,68,.12);
}

.checks {
  display: grid;
  gap: 8px;
  margin: 0 0 20px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 14px;
  cursor: pointer;
}

.check input { width: auto; cursor: pointer; accent-color: var(--blue); }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.dialog-actions button {
  padding: 10px 20px;
  font-size: 14px;
  border-radius: var(--radius);
}

.btn-ghost {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text-2);
}

.btn-ghost:hover { background: var(--surface); color: var(--text); }

.btn-danger {
  background: var(--red);
  color: #fff;
  border: none;
}

.btn-danger:hover { background: #dc2626; }

.btn-stop {
  background: var(--amber);
  color: #fff;
  border: none;
}

.btn-stop:hover { background: var(--amber-dark); }

@media (max-width: 840px) {
  .main {
    width: min(100% - 28px, 1200px);
    padding-top: 18px;
  }

  .header-row {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
  }

  .credential-toggle {
    width: 100%;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
    color: var(--text);
    padding: 0 14px;
  }

  .credential-toggle svg {
    width: 20px;
    height: 20px;
    color: var(--text-3);
    transition: transform .15s;
  }

  .credential-toggle[aria-expanded="true"] svg {
    transform: rotate(180deg);
  }

  .cred-bar {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 12px;
  }

  .cred-bar.collapsed {
    display: none;
  }

  input {
    min-height: 46px;
    font-size: 16px;
  }

  #scanBtn {
    width: 100%;
    min-height: 48px;
  }

  .summary {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
  }

  .summary > div {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
  }

  .summary-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .summary strong {
    font-size: 22px;
  }

  .summary span {
    font-size: 12px;
  }
}

@media (max-width: 540px) {
  .main {
    width: min(100% - 20px, 1200px);
    padding-top: 12px;
    padding-bottom: 40px;
  }

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

  .summary > div {
    padding: 12px 10px;
  }

  .summary-icon {
    width: 30px;
    height: 30px;
  }

  .summary-icon svg {
    width: 16px;
    height: 16px;
  }

  .summary strong {
    font-size: 20px;
  }

  .summary span {
    line-height: 1.2;
  }

  .resources {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .resource-card {
    border-radius: 20px;
  }

  .resource-card:hover {
    box-shadow: var(--shadow);
  }

  .card-body {
    padding: 16px;
  }

  .card-top {
    margin-bottom: 12px;
  }

  .service-icon,
  .service-badge {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 9px;
  }

  .status {
    font-size: 10px;
    padding: 4px 8px;
  }

  .resource-card h2 {
    font-size: 16px;
  }

  .resource-id {
    font-size: 10px;
    margin-bottom: 12px;
  }

  .facts {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .facts div {
    background: var(--surface);
    border-radius: 12px;
    padding: 10px;
  }

  .facts .wide {
    grid-column: auto;
  }

  .facts dd {
    font-size: 14px;
  }

  .card-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px 16px 16px;
  }

  .card-actions button {
    min-height: 44px;
  }

  .empty-state {
    min-height: 220px;
    border-radius: 20px;
  }

  dialog {
    width: min(100% - 18px, 640px);
    padding: 18px;
    border-radius: 20px;
  }

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

  .dialog-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .dialog-actions button {
    min-height: 44px;
  }
}
