:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --surface-3: #eef2f7;
  --border: #e4e9f0;
  --border-strong: #d4dbe6;

  --text: #1b2430;
  --text-muted: #64748b;
  --text-dim: #94a3b8;

  --blue: #2563eb;
  --blue-soft: #e8f0fe;
  --green: #16a34a;
  --green-soft: #e6f6ec;
  --red: #dc2626;
  --red-soft: #fdeaea;
  --amber: #d97706;
  --amber-soft: #fdf1e3;
  --violet: #7c3aed;
  --violet-soft: #f0eafe;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);

  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --radius: 10px;
  --radius-sm: 7px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.45;
  min-height: 100vh;
  padding: 16px 20px;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--surface-2);
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* Icons */
.icon {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* filled glyphs */
#i-pause rect,
#i-play polygon {
  fill: currentColor;
  stroke: none;
}

/* Full-width container */
.app-container {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Surfaces */
.header,
.metric-card,
.panel,
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  gap: 12px;
  flex-wrap: wrap;
}

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

.logo-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--blue);
  background: var(--blue-soft);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: clamp(14px, 2.5vw, 17px);
  font-weight: 700;
  letter-spacing: -0.2px;
}

.brand-text h1 span {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 12px;
  margin-left: 6px;
}

.network-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--green);
  font-weight: 600;
  margin-top: 2px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

.pulse-green {
  box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.5);
  animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
  0% {
    box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.5);
  }

  70% {
    box-shadow: 0 0 0 6px rgba(22, 163, 74, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(22, 163, 74, 0);
  }
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Badges & Buttons */
.badge {
  padding: 4px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.badge.dry-run {
  background: var(--amber-soft);
  color: var(--amber);
  border: 1px solid rgba(217, 119, 6, 0.25);
}

.badge.live-mode {
  background: var(--green-soft);
  color: var(--green);
  border: 1px solid rgba(22, 163, 74, 0.25);
}

.badge.count-badge {
  background: var(--surface-3);
  color: var(--text-muted);
}

.btn {
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.btn .icon {
  font-size: 15px;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}

.btn-primary:hover {
  background: #1d4fd7;
}

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

.btn-secondary:hover {
  background: var(--surface-2);
}

.btn-danger {
  background: var(--surface);
  color: var(--red);
  border-color: rgba(220, 38, 38, 0.35);
}

.btn-danger:hover {
  background: var(--red-soft);
}

/* Metrics Grid - Responsive Auto Fit */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  width: 100%;
}

.metric-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  min-width: 0;
}

.metric-icon {
  font-size: 18px;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.metric-icon.blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.metric-icon.green {
  background: var(--green-soft);
  color: var(--green);
}

.metric-icon.amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.metric-icon.violet {
  background: var(--violet-soft);
  color: var(--violet);
}

.metric-info {
  min-width: 0;
}

.metric-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-online {
  color: var(--green);
}

.status-offline {
  color: var(--red);
}

/* Address Action Bar & Links */
.address-action-bar {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.icon-btn,
.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
  flex-shrink: 0;
}

.icon-btn:hover,
.icon-link:hover {
  background: var(--blue-soft);
  color: var(--blue);
  border-color: rgba(37, 99, 235, 0.3);
}

.icon-btn .icon,
.icon-link .icon {
  font-size: 14px;
}

/* Toast Notifications */
.toast-notification {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(12px);
  transition: all 0.25s ease;
  z-index: 9999;
  pointer-events: none;
}

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

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  width: 100%;
}

.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: clamp(360px, 48vh, 560px);
  width: 100%;
}

.panel.full-width {
  height: auto;
  min-height: 240px;
  width: 100%;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  gap: 8px;
  flex-wrap: wrap;
}

.panel-header h3 {
  font-size: 13.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.panel-header h3 .icon {
  font-size: 16px;
  color: var(--text-muted);
}

.panel-body {
  padding: 12px;
  flex: 1;
  overflow-y: auto;
}

.scrollable-table {
  overflow-x: auto;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

.pulse-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--blue);
  white-space: nowrap;
}

.pulse-live .dot {
  background: var(--blue);
  animation: pulse-green 2s infinite;
}

/* Mempool Stream Cards */
.mempool-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tx-func {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--blue);
  background: var(--blue-soft);
  padding: 2px 6px;
  border-radius: 4px;
}

.tx-token {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text);
}

.tx-amount {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.tx-time {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* Position Cards */
.position-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px;
  margin-bottom: 10px;
}

.position-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;

}

.pos-symbol {
  font-size: 15px;
  font-weight: 700;
}

.pnl-badge {
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 13px;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.pnl-positive {
  background: var(--green-soft);
  color: var(--green);
}

.pnl-negative {
  background: var(--red-soft);
  color: var(--red);
}

.position-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 6px;
  margin: 10px 0;
  font-size: 12.5px;
  color: var(--text);
}

.progress-bar-bg {
  height: 5px;
  background: var(--surface-3);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 5px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--green);
  transition: width 0.3s ease;
}

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

/* Audit Log Table */
.data-table {
  width: 100%;
  min-width: 650px;
  border-collapse: collapse;
  font-size: 12.5px;
}

.data-table th,
.data-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 1;
}

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

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

.mono {
  font-family: var(--font-mono);
}

.badge-pass {
  background: var(--green-soft);
  color: var(--green);
}

.badge-fail {
  background: var(--red-soft);
  color: var(--red);
}

/* Empty States */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 16px;
}

.empty-icon {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  margin-bottom: 8px;
}

.empty-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 3px;
}

.table-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 24px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(27, 36, 48, 0.4);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 20px;
  box-shadow: var(--shadow-md);
}

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

.modal-header h2 {
  font-size: 15px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.modal-header h2 .icon {
  font-size: 17px;
  color: var(--text-muted);
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  padding: 4px;
  border-radius: 5px;
}

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
}

.form-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

.form-group input[type="number"],
.form-group input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  width: 100%;
}

.form-group input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

.toggle-group {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.toggle-group label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toggle-group label span {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

.toggle-checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
  cursor: pointer;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

@media (max-width: 960px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  body {
    padding: 12px 14px;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .metric-card {
    padding: 10px 12px;
    gap: 10px;
  }

  .metric-icon {
    width: 34px;
    height: 34px;
    font-size: 16px;
  }

  .metric-value {
    font-size: 18px;
  }

  .panel {
    height: 380px;
  }
}

@media (max-width: 640px) {
  .header {
    flex-direction: column;
    align-items: stretch;
  }

  .brand {
    justify-content: space-between;
    width: 100%;
  }

  .header-controls {
    justify-content: space-between;
    width: 100%;
    border-top: 1px solid var(--border);
    padding-top: 10px;
  }

  .header-controls .btn {
    flex: 1;
    justify-content: center;
  }

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

  .toast-notification {
    left: 20px;
    right: 20px;
    text-align: center;
  }
}

@media (max-width: 480px) {
  body {
    padding: 8px;
  }

  .app-container {
    gap: 10px;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .metric-card {
    padding: 10px 8px;
    gap: 8px;
  }

  .brand-text h1 span {
    display: block;
    margin-left: 0;
    margin-top: 2px;
  }

  .mempool-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .mempool-item > div:last-child {
    text-align: left !important;
    display: flex;
    justify-content: space-between;
    width: 100%;
    border-top: 1px dashed var(--border);
    padding-top: 4px;
  }

  .position-header {
    flex-direction: column;
    gap: 6px;
  }

  .pnl-badge {
    align-self: flex-start;
  }

  .modal-card {
    padding: 14px;
  }

  .modal-footer {
    flex-direction: column;
  }

  .modal-footer .btn {
    width: 100%;
  }
}