/* ==========================================================================
   PBN Control Panel v9 — Professional Redesign Overrides
   --------------------------------------------------------------------------
   This stylesheet EXTENDS the existing panel styles. It does not redefine
   :root or html[data-theme="light"] variables — it consumes them.
   Load this file AFTER the base stylesheet so overrides take effect.
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. GLOBAL TRANSITIONS & ACCESSIBILITY
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  transition: background-color 0.2s ease,
              border-color 0.2s ease,
              color 0.2s ease,
              box-shadow 0.2s ease,
              transform 0.2s ease,
              opacity 0.2s ease;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Custom thin scrollbar, brand colored */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--brand) transparent;
}
*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background-color: var(--brand);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: content-box;
  opacity: 0.6;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: var(--brand-2, var(--brand));
}

/* --------------------------------------------------------------------------
   8. TYPOGRAPHY — heading hierarchy, monospace domains, readability
   -------------------------------------------------------------------------- */
h1, h2, h3, h4 {
  letter-spacing: -0.01em;
  line-height: 1.25;
}
h1 { font-weight: 700; font-size: 1.5rem; }
h2 { font-weight: 700; font-size: 1.2rem; }
h3 { font-weight: 600; font-size: 1.02rem; }

body, .view, .tbl {
  line-height: 1.55;
}

/* Domain names, hostnames, IPs, code-like values -> monospace */
.tbl td.domain,
.tbl td[data-col="domain"],
.tbl td:first-child a,
td.mono,
.mono,
.domain-name,
code {
  font-family: "SFMono-Regular", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
  letter-spacing: -0.01em;
}

/* --------------------------------------------------------------------------
   1. SIDEBAR — PRO VISUAL
   -------------------------------------------------------------------------- */
.sidebar {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: relative;
}

.nav {
  padding: 6px 8px;
}

.nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 14px;
  margin: 2px 0;
  border-radius: var(--r3);
  border-left: 3px solid transparent;
  color: var(--muted);
  cursor: pointer;
}

.nav a .i {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.85;
}

.nav a .t {
  font-weight: 500;
  font-size: 0.93rem;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav a:hover .i {
  opacity: 1;
}

/* Active nav item */
.nav a.active,
.nav a[aria-current="page"] {
  border-left-color: var(--brand);
  background: linear-gradient(90deg, color-mix(in srgb, var(--brand) 14%, transparent), transparent 85%);
  color: var(--text);
  font-weight: 600;
}

.nav a.active .i {
  opacity: 1;
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--brand) 50%, transparent));
}

/* Divider lines between nav groups: after footprint/analytics group and after security */
.nav a[data-v="footprint"],
.nav a[data-v="security"] {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

/* Badge indicators — more contrast */
.badge-n {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--line-2);
  margin-left: auto;
}

.badge-n.warn {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 40%, transparent);
}

/* Sidebar bottom: network health score */
.sidebar::after {
  content: "";
  order: 99;
}

.sidebar-health {
  margin-top: auto;
  padding: 14px 16px 16px;
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
}

.sidebar-health .sh-label {
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.68rem;
  margin-bottom: 6px;
}

.sidebar-health .sh-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  margin-top: 6px;
}

.sidebar-health .sh-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ok), var(--brand));
}

/* Mobile responsive sidebar collapse — smoother */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--sh-lg);
  }
  .sidebar.open,
  .sidebar[data-open="true"] {
    transform: translateX(0);
  }
}

/* --------------------------------------------------------------------------
   6. SECTION HEADERS — clean, breadcrumb-style indicator + actions
   -------------------------------------------------------------------------- */
.view > .head,
.view > .view-head,
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.view-header h1,
.view-header h2,
.view > .head h1,
.view > .head h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.view-header h1::before,
.view > .head h1::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 18px;
  border-radius: 2px;
  background: var(--brand);
}

.view-header .actions,
.view > .head .actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* --------------------------------------------------------------------------
   GLOBAL POLISH — cards, buttons, focus, loading skeleton
   -------------------------------------------------------------------------- */
.card {
  border: 1px solid var(--line);
  box-shadow: var(--sh);
  border-radius: var(--r);
  background: var(--surface);
}

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

.btn {
  position: relative;
  overflow: hidden;
  border-radius: var(--r3);
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
  filter: brightness(0.96);
}

/* ripple-like effect on click */
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255,255,255,0.35) 0%, transparent 60%);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
}

.btn:active::after {
  opacity: 1;
  transform: scale(1.4);
  transition: 0s;
}

.btn-warn:hover { box-shadow: 0 0 0 3px var(--warn-bg); }
.btn-ok:hover { box-shadow: 0 0 0 3px var(--ok-bg); }

/* Skeleton shimmer loading state */
.skeleton,
.is-loading .tbl td,
[data-loading="true"] {
  position: relative;
  color: transparent !important;
  background: linear-gradient(
    100deg,
    var(--surface-2) 30%,
    var(--surface-3) 50%,
    var(--surface-2) 70%
  );
  background-size: 200% 100%;
  animation: pbn-shimmer 1.4s ease-in-out infinite;
  border-radius: 6px;
}

@keyframes pbn-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* --------------------------------------------------------------------------
   2. DASHBOARD — ACTION-FIRST
   -------------------------------------------------------------------------- */

/* Alert box */
.alert {
  border-left: 4px solid var(--info);
  border-radius: var(--r3);
  padding: 16px 18px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.alert.warn,
.alert[data-level="warn"] {
  border-left-color: var(--warn);
  background: var(--warn-bg);
}

.alert.bad,
.alert[data-level="bad"],
.alert[data-level="critical"] {
  border-left-color: var(--bad);
  background: var(--bad-bg);
}

.alert.ok,
.alert[data-level="ok"] {
  border-left-color: var(--ok);
  background: var(--ok-bg);
}

.alert .alert-cta,
.alert .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

/* Stat cards */
.stat-card,
.card.stat {
  position: relative;
  padding: 20px 20px 18px;
  border-top: 3px solid var(--brand);
  border-radius: var(--r);
  cursor: default;
}

.stat-card:hover,
.card.stat:hover {
  transform: translateY(-3px);
  box-shadow: var(--sh-lg);
}

.stat-card[data-tone="ok"],
.card.stat[data-tone="ok"] { border-top-color: var(--ok); }
.stat-card[data-tone="warn"],
.card.stat[data-tone="warn"] { border-top-color: var(--warn); }
.stat-card[data-tone="bad"],
.card.stat[data-tone="bad"] { border-top-color: var(--bad); }

.stat-card .stat-value,
.card.stat .stat-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.stat-card .stat-label,
.card.stat .stat-label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

/* Priority table — health bar gradient (green -> yellow -> red) */
.health-bar {
  position: relative;
  width: 100%;
  min-width: 80px;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
}

.health-bar .health-bar-fill {
  height: 100%;
  border-radius: 999px;
  /* Fill width should be set inline via style="width: NN%" per-row by app JS */
  background: linear-gradient(90deg, var(--bad) 0%, var(--warn) 50%, var(--ok) 100%);
}

.health-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.health-bar-wrap .health-score-text {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  width: 32px;
  text-align: right;
}

/* --------------------------------------------------------------------------
   4. PBN LIST TABLE — SCAN EFFICIENCY
   -------------------------------------------------------------------------- */
.tbl {
  border-collapse: separate;
  border-spacing: 0;
}

.tbl thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  padding: 10px 14px;
}

.tbl tbody tr {
  border-bottom: 1px solid var(--line);
}

.tbl tbody tr:hover {
  background: var(--surface-2);
}

.tbl tbody tr td {
  padding: 10px 14px;
}

/* Missing / stale rows */
.tbl tbody tr.missing,
.tbl tbody tr[data-status="missing"] {
  border-left: 3px solid var(--bad);
  background: var(--bad-bg);
}

.tbl tbody tr.stale,
.tbl tbody tr[data-status="stale"] {
  border-left: 3px solid var(--warn);
  background: var(--warn-bg);
}

/* Status badge — bigger, more contrast, rounded pill */
.ok, .warn, .bad, .info {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.01em;
}

.ok { background: var(--ok-bg); color: var(--ok); }
.warn { background: var(--warn-bg); color: var(--warn); }
.bad { background: var(--bad-bg); color: var(--bad); }
.info { background: var(--info-bg); color: var(--info); }

.ok::before, .warn::before, .bad::before, .info::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* Health score column — visual bar instead of just a number */
.tbl td.health,
.tbl td[data-col="health"] {
  min-width: 110px;
}

/* --------------------------------------------------------------------------
   3. MONITOR SECTION — SSL URGENCY
   -------------------------------------------------------------------------- */
#v-monitor .tbl tbody tr[data-ssl-days] {
  transition: background-color 0.2s ease;
}

/* SSL expiry < 7 days: urgent red */
#v-monitor .tbl tbody tr.ssl-critical,
#v-monitor .tbl tbody tr[data-ssl-urgency="critical"] {
  background: rgba(251, 113, 133, 0.08);
  color: var(--bad);
}

/* SSL expiry < 14 days: warning yellow */
#v-monitor .tbl tbody tr.ssl-warning,
#v-monitor .tbl tbody tr[data-ssl-urgency="warning"] {
  background: rgba(251, 191, 36, 0.08);
  color: var(--warn);
}

/* Domain DOWN rows */
#v-monitor .tbl tbody tr.is-down,
#v-monitor .tbl tbody tr[data-status="down"] {
  border-left: 3px solid var(--bad);
}

/* SSL badge urgent — pulsing animation, subtle */
.ssl-badge.urgent,
.badge-ssl-urgent {
  animation: pbn-pulse 1.8s ease-in-out infinite;
}

@keyframes pbn-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(251, 113, 133, 0.35); }
  50% { opacity: 0.85; box-shadow: 0 0 0 5px rgba(251, 113, 133, 0); }
}

/* --------------------------------------------------------------------------
   7. FOOTPRINT SECTION — risk cards & "Cara Fix" expandable
   -------------------------------------------------------------------------- */
.risk-card {
  border: 1px solid var(--line);
  border-radius: var(--r2);
  padding: 16px;
  background: var(--surface);
  margin-bottom: 12px;
}

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

/* Risk severity gauge */
.risk-gauge {
  position: relative;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  margin-top: 10px;
}

.risk-gauge .risk-gauge-fill {
  height: 100%;
  border-radius: 999px;
}

.risk-card[data-severity="low"] .risk-gauge-fill { background: var(--ok); width: 25%; }
.risk-card[data-severity="medium"] .risk-gauge-fill { background: var(--warn); width: 55%; }
.risk-card[data-severity="high"] .risk-gauge-fill { background: var(--bad); width: 85%; }
.risk-card[data-severity="critical"] .risk-gauge-fill { background: var(--bad); width: 100%; }

.risk-card[data-severity="low"] { border-left: 3px solid var(--ok); }
.risk-card[data-severity="medium"] { border-left: 3px solid var(--warn); }
.risk-card[data-severity="high"],
.risk-card[data-severity="critical"] { border-left: 3px solid var(--bad); }

/* "Cara Fix" expandable */
.risk-fix {
  margin-top: 10px;
  border-top: 1px dashed var(--line);
  padding-top: 0;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.3s ease, padding-top 0.3s ease;
}

.risk-fix.open,
.risk-fix[data-open="true"] {
  max-height: 400px;
  opacity: 1;
  padding-top: 10px;
}

.risk-fix-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--brand);
  cursor: pointer;
  background: none;
  border: none;
  padding: 6px 0;
}

.risk-fix-toggle::after {
  content: "▾";
  transition: transform 0.2s ease;
  font-size: 0.7rem;
}

.risk-fix-toggle[aria-expanded="true"]::after,
.risk-fix-toggle.open::after {
  transform: rotate(-180deg);
}

.risk-fix ol,
.risk-fix ul {
  margin: 0;
  padding-left: 18px;
  font-size: 0.85rem;
  color: var(--muted);
}

.risk-fix li {
  margin-bottom: 4px;
}

/* --------------------------------------------------------------------------
   LIGHT THEME ADJUSTMENTS
   -------------------------------------------------------------------------- */
html[data-theme="light"] .nav a.active,
html[data-theme="light"] .nav a[aria-current="page"] {
  background: linear-gradient(90deg, color-mix(in srgb, var(--brand) 10%, transparent), transparent 85%);
}

html[data-theme="light"] #v-monitor .tbl tbody tr.ssl-critical,
html[data-theme="light"] #v-monitor .tbl tbody tr[data-ssl-urgency="critical"] {
  background: rgba(251, 113, 133, 0.06);
}

html[data-theme="light"] #v-monitor .tbl tbody tr.ssl-warning,
html[data-theme="light"] #v-monitor .tbl tbody tr[data-ssl-urgency="warning"] {
  background: rgba(251, 191, 36, 0.06);
}

html[data-theme="light"] .skeleton,
html[data-theme="light"] .is-loading .tbl td,
html[data-theme="light"] [data-loading="true"] {
  background: linear-gradient(
    100deg,
    var(--surface-2) 30%,
    var(--surface) 50%,
    var(--surface-2) 70%
  );
  background-size: 200% 100%;
}

/* --------------------------------------------------------------------------
   RESPONSIVE FINE-TUNING
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .stat-card .stat-value,
  .card.stat .stat-value {
    font-size: 1.5rem;
  }

  .view-header,
  .view > .head {
    flex-direction: column;
    align-items: flex-start;
  }

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