:root {
  --bg: #0b1120;
  --bg-elevated: #111827;
  --bg-card: #151f33;
  --bg-card-hover: #1b2842;
  --border: #25334d;
  --border-strong: #374c70;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --general: #38bdf8;
  --mobile: #a78bfa;
  --fixed: #34d399;
  --pinned: #fbbf24;
  --danger: #f87171;
  --success: #22c55e;
  --warn: #f59e0b;
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.45);
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --border: #dbe3ee;
  --border-strong: #b8c7dc;
  --text: #0f172a;
  --text-muted: #475569;
  --accent: #0284c7;
  --accent-strong: #0369a1;
  --accent-soft: rgba(2, 132, 199, 0.1);
  --general: #0284c7;
  --mobile: #7c3aed;
  --fixed: #059669;
  --pinned: #d97706;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at top right, rgba(56, 189, 248, 0.09), transparent 38%), var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
}

.app-shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: 24px 20px 44px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: var(--success);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
  animation: pulse 2.2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.brand-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  margin: 2px 0 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

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

.clock-pill {
  font-variant-numeric: tabular-nums;
  font-size: 0.84rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent-strong);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent);
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
}

.controls-bar {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.search-wrap {
  position: relative;
  flex: 1 1 320px;
  max-width: 480px;
}

.search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  opacity: 0.65;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 11px 42px 11px 38px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.94rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.kbd-hint {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  pointer-events: none;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.pill.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.pill-count {
  font-size: 0.76rem;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.pinned-bar {
  margin-top: 22px;
  padding: 16px 18px;
  border-radius: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.pinned-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.pinned-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
  transition: border-color 0.15s ease, transform 0.12s ease, background 0.15s ease;
}

.pinned-chip:hover {
  border-color: var(--pinned);
  background: var(--bg-card-hover);
  transform: translateY(-1px);
}

.pinned-chip .chip-section {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sections-container {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

.section-header.compact {
  align-items: center;
  margin-bottom: 0;
}

.section-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-title-group h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.section-desc {
  margin: 2px 0 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.section-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

.section-dot.general { background: var(--general); }
.section-dot.mobile { background: var(--mobile); }
.section-dot.fixed { background: var(--fixed); }
.section-dot.pinned { background: var(--pinned); }

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

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

body.compact-view .cards-grid {
  grid-template-columns: 1fr;
  gap: 8px;
}

.link-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px;
  border-radius: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: transform 0.14s ease, border-color 0.15s ease, background 0.15s ease;
}

.link-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  background: var(--bg-card-hover);
}

body.compact-view .link-card {
  flex-direction: row;
  align-items: center;
  padding: 10px 14px;
  gap: 16px;
}

body.compact-view .card-top {
  order: 2;
}

body.compact-view .card-link-target {
  order: 1;
  flex: 1;
}

body.compact-view .card-footer {
  order: 3;
  min-width: 190px;
  justify-content: flex-end;
  gap: 12px;
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.card-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.badge {
  font-size: 0.71rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

.category-badge {
  background: var(--accent-soft);
  color: var(--accent);
}

.scope-badge.internal {
  background: rgba(245, 158, 11, 0.14);
  color: var(--warn);
}

.scope-badge.external {
  background: rgba(148, 163, 184, 0.14);
  color: var(--text-muted);
}

.probe-badge {
  display: none;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
}

.probe-badge.visible {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.probe-badge.reachable {
  background: rgba(34, 197, 94, 0.16);
  color: var(--success);
}

.probe-badge.intranet {
  background: rgba(245, 158, 11, 0.16);
  color: var(--warn);
}

.probe-badge.timeout,
.probe-badge.unreachable,
.probe-badge.degraded {
  background: rgba(248, 113, 113, 0.16);
  color: var(--danger);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.icon-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.92rem;
  transition: background 0.12s ease, color 0.12s ease;
}

.icon-btn:hover {
  background: rgba(148, 163, 184, 0.16);
  color: var(--text);
}

.icon-btn.is-pinned {
  color: var(--pinned);
}

.icon-btn.danger:hover {
  background: rgba(248, 113, 113, 0.16);
  color: var(--danger);
}

.card-link-target {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  padding: 4px 0;
}

.alias-name {
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  word-break: break-word;
}

.card-link-target:hover .alias-name {
  color: var(--accent);
}

.open-arrow {
  font-size: 1.1rem;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.15s ease, color 0.15s ease;
}

.card-link-target:hover .open-arrow {
  transform: translate(2px, -2px);
  color: var(--accent);
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.77rem;
  color: var(--text-muted);
}

.host-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 190px;
}

.empty-state {
  margin-top: 32px;
  padding: 42px 24px;
  text-align: center;
  background: var(--bg-elevated);
  border: 1px dashed var(--border-strong);
  border-radius: 16px;
}

.empty-state h3 {
  margin: 0 0 6px;
}

.empty-state p {
  margin: 0 0 16px;
  color: var(--text-muted);
}

.portal-footer {
  margin-top: 36px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-dialog {
  width: 100%;
  max-width: 480px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.85rem;
  font-weight: 600;
}

.field input,
.field select {
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.92rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  cursor: pointer;
}

.form-error {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(248, 113, 113, 0.14);
  color: var(--danger);
  font-size: 0.84rem;
}

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

.toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
}

.toast {
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

@media (max-width: 720px) {
  body.compact-view .link-card {
    flex-direction: column;
    align-items: stretch;
  }
  body.compact-view .card-footer {
    justify-content: space-between;
  }
  .field-row {
    grid-template-columns: 1fr;
  }
}
