/*
  PulseChain Explorer — stylesheet.

  CLASS INVENTORY — this is a CONTRACT for the views layer (js/views/*,
  js/sidebar.js, js/app.js). Those modules style NOTHING themselves; they
  only apply the classes below. Every class listed here is defined further
  down in this file.

  Layout
    .sidebar          fixed-width left nav (collapses above #main on narrow screens)
    .addr-item        one watched-address row inside .sidebar
    .addr-item.active the currently selected address row
    .addr-form        small add-address form (input + button) inside .sidebar

  Content containers
    .card             generic bordered panel/section
    .card-title       heading at the top of a .card
    .card-title-bar   flex row pairing a .card-title with a trailing widget
                       (e.g. .poll-indicator) — .card-title's own margin
                       collapses to 0 when nested inside this

  Live-poll indicator (small "next refresh" progress bar + label)
    .poll-indicator          wrapper; add .is-paused / .is-updating for state
    .poll-bar                fixed-width track
    .poll-bar-fill           the filled portion; JS sets its width inline as
                              a computed percentage (0–100%), not a style choice
    .poll-label               "Next update in Ns" / "Updating…" / "Paused" text

  Detail key/value grid
    .kv               2-column grid wrapper
    .kv-row           one logical row (use with display:contents so .kv-k/.kv-v
                       still land in the parent .kv grid's two columns)
    .kv-k             the key/label cell
    .kv-v             the value cell

  Tables (wrap in a .table-wrap for independent horizontal scroll)
    .table-wrap       overflow-x:auto container — put this AROUND every .table
    .table            the table element itself

  Badges (small pill labels)
    .badge            base pill
    .badge-in         incoming tx / positive direction
    .badge-out        outgoing tx / negative direction
    .badge-self       self-transfer / neutral
    .badge-token      token-related tag
    .badge-ok         success / confirmed
    .badge-fail       failure / reverted

  Text & misc
    .mono             monospace, tabular numerals
    .muted            secondary/dim text color
    .link             wrapper for a small group of inline text links
    .btn              primary gradient button
    .btn-ghost        secondary outline/ghost button
    .copy             small icon-only copy-to-clipboard button
    .row-new          highlight animation for a freshly-arrived live table row

  Widgets
    .toast            transient bottom-right notification (see #toast-root)
    .spinner          small inline loading indicator (.spinner-dot inside it)
    .error-box        inline error message, optionally containing a .btn-ghost retry button
    .hex-dump         monospace, wrapped block for raw hex/calldata display
    .collapsible      styling hook for a native <details> element
*/

/* ---------------------------------------------------------------------- */
/* Design tokens                                                          */
/* ---------------------------------------------------------------------- */

:root {
  --bg: #f6f4f9;
  --panel: #ffffff;
  --panel-2: #f2eff7;
  --line: #e2dced;
  --text: #1b1725;
  --muted: #6c6480;
  --accent: #c81f80;
  --accent-2: #7a2fe0;
  --ok: #1a9c6c;
  --ok-bg: color-mix(in srgb, var(--ok) 16%, transparent);
  --err: #d13d3d;
  --err-bg: color-mix(in srgb, var(--err) 14%, transparent);
  --radius: 12px;
  --sidebar-w: 290px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0b12;
    --panel: #16131d;
    --panel-2: #1d1927;
    --line: #2b2537;
    --text: #ece9f1;
    --muted: #9a92ab;
    --accent: #e0399a;
    --accent-2: #9b4dff;
    --ok: #3ddc97;
    --ok-bg: color-mix(in srgb, var(--ok) 16%, transparent);
    --err: #ff6b6b;
    --err-bg: color-mix(in srgb, var(--err) 16%, transparent);
  }
}

/* ---------------------------------------------------------------------- */
/* Base / reset                                                           */
/* ---------------------------------------------------------------------- */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------------- */
/* Page shell                                                             */
/* ---------------------------------------------------------------------- */

.layout {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

#main-col {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#app-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

#app-header .brand {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.01em;
}

#app-header .brand::before {
  content: "";
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  vertical-align: middle;
}

.chain-note {
  font-size: 12.5px;
}

#main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 20px;
}

#app-footer {
  padding: 14px 20px 24px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--line);
}

/* ---------------------------------------------------------------------- */
/* Sidebar                                                                */
/* ---------------------------------------------------------------------- */

.sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.addr-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 4px;
  font-size: 13.5px;
}

.addr-item:hover {
  background: var(--panel-2);
}

.addr-item.active {
  background: var(--panel-2);
  border-color: var(--accent);
}

.addr-form {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

.addr-form input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 9px 10px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: 13px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  outline: none;
}

.addr-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

/* ---------------------------------------------------------------------- */
/* Cards                                                                  */
/* ---------------------------------------------------------------------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
}

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

.card-title-bar .card-title { margin-bottom: 0; }

/* ---------------------------------------------------------------------- */
/* Live-poll indicator ("next refresh" progress bar)                     */
/* ---------------------------------------------------------------------- */

.poll-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  flex: 0 0 auto;
}

.poll-bar {
  width: 56px;
  height: 4px;
  border-radius: 2px;
  background: var(--panel-2);
  overflow: hidden;
  flex: 0 0 auto;
}

.poll-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-2);
  border-radius: 2px;
  transition: width 1s linear;
}

.poll-indicator.is-paused .poll-bar-fill {
  background: var(--muted);
  transition: none;
}

@keyframes poll-pulse {
  0%, 100% { opacity: .35; }
  50% { opacity: 1; }
}

.poll-indicator.is-updating .poll-bar-fill {
  width: 100%;
  background: var(--accent);
  animation: poll-pulse 1s ease-in-out infinite;
  transition: none;
}

.poll-label {
  min-width: 88px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------------- */
/* Key/value detail grid                                                  */
/* ---------------------------------------------------------------------- */

.kv {
  display: grid;
  grid-template-columns: 160px 1fr;
  row-gap: 10px;
  column-gap: 14px;
  font-size: 13.5px;
}

.kv-row {
  display: contents;
}

.kv-k {
  color: var(--muted);
  font-size: 12.5px;
  padding-top: 2px;
}

.kv-v {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------------------------------------------------------------------- */
/* Tables                                                                 */
/* ---------------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  white-space: nowrap;
}

.table th, .table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.table thead th {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--panel-2);
  position: sticky;
  top: 0;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr:hover {
  background: var(--panel-2);
}

/* ---------------------------------------------------------------------- */
/* Badges                                                                 */
/* ---------------------------------------------------------------------- */

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-in { background: var(--ok-bg); color: var(--ok); }
.badge-out { background: var(--err-bg); color: var(--accent); }
.badge-self { background: var(--panel-2); color: var(--muted); }
.badge-token { background: color-mix(in srgb, var(--accent-2) 20%, transparent); color: var(--accent-2); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-fail { background: var(--err-bg); color: var(--err); }

/* ---------------------------------------------------------------------- */
/* Text & misc                                                            */
/* ---------------------------------------------------------------------- */

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.muted { color: var(--muted); }

.link {
  display: inline-flex;
  gap: 10px;
  font-size: 12.5px;
}

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  border: 0;
  border-radius: 9px;
  padding: 9px 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  transition: filter .15s, transform .05s;
}

.btn:hover:not(:disabled) { filter: brightness(1.1); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }

.btn-ghost {
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  background: none;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 13px;
}

.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  flex: 0 0 auto;
}

.copy:hover { border-color: var(--accent); color: var(--accent); }

@keyframes row-new-fade {
  from { background: color-mix(in srgb, var(--accent) 25%, transparent); }
  to { background: transparent; }
}

.row-new {
  animation: row-new-fade 1.6s ease-out;
}

/* ---------------------------------------------------------------------- */
/* Toast                                                                  */
/* ---------------------------------------------------------------------- */

#toast-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 9px;
  font-size: 13px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .2s, transform .2s;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ---------------------------------------------------------------------- */
/* Spinner                                                                */
/* ---------------------------------------------------------------------- */

.spinner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.spinner-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}

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

/* ---------------------------------------------------------------------- */
/* Error box                                                              */
/* ---------------------------------------------------------------------- */

.error-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--err);
  background: var(--err-bg);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13.5px;
}

/* ---------------------------------------------------------------------- */
/* Hex dump / collapsible                                                 */
/* ---------------------------------------------------------------------- */

.hex-dump {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  max-height: 260px;
  overflow-y: auto;
}

.collapsible {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 12px;
  background: var(--panel);
}

.collapsible > summary {
  cursor: pointer;
  padding: 8px 0;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  list-style: revert;
}

.collapsible[open] > summary {
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}

/* ---------------------------------------------------------------------- */
/* Responsive                                                             */
/* ---------------------------------------------------------------------- */

@media (max-width: 900px) {
  .layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    flex: none;
    position: static;
    height: auto;
    max-height: 40vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .kv {
    grid-template-columns: 130px 1fr;
  }
}
