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

:root {
  --bg: #fff;
  --fg: #000;
  --bg-secondary: #f8f8f8;
  --bg-hover: #f0f0f0;
  --bg-input: #fff;
  --border: #000;
  --border-light: #ccc;
  --link: #0000ee;
  --stat-bg: #d9d9d9;
  --th-bg: #ecf0f1;
  --th-hover: #dde4e6;
  --row-hover: #f5f5f5;
  --own-order: #fffde7;
  --own-order-hover: #fff9c4;
  --highlight: #e3f2fd;
  --highlight-hover: #bbdefb;
  --highlight-pulse: #90caf9;
  --warning-bg: #fff3cd;
  --muted: #666;
  --skeleton-a: #e8e8e8;
  --skeleton-b: #f5f5f5;
  --modal-overlay: rgba(0, 0, 0, 0.5);
  --status-open-bg: #e8f5e9;
  --status-open-fg: #2e7d32;
  --status-filled-bg: #e3f2fd;
  --status-filled-fg: #1565c0;
  --status-cancelled-bg: #ffebee;
  --status-cancelled-fg: #c62828;
  --good-deal: #080;
  --bad-deal: #c00;
}

body.dark-mode {
  --bg: #111;
  --fg: #eee;
  --bg-secondary: #222;
  --bg-hover: #333;
  --bg-input: #222;
  --border: #555;
  --border-light: #444;
  --link: #6cf;
  --stat-bg: #333;
  --th-bg: #2a2a2a;
  --th-hover: #3a3a3a;
  --row-hover: #252525;
  --own-order: #3d3a20;
  --own-order-hover: #4d4a30;
  --highlight: #1a3a5c;
  --highlight-hover: #2a4a6c;
  --highlight-pulse: #3a5a7c;
  --warning-bg: #4a3a10;
  --muted: #aaa;
  --skeleton-a: #333;
  --skeleton-b: #444;
  --modal-overlay: rgba(0, 0, 0, 0.7);
  --status-open-bg: #1a3a1a;
  --status-open-fg: #6c6;
  --status-filled-bg: #1a2a3a;
  --status-filled-fg: #6cf;
  --status-cancelled-bg: #3a1a1a;
  --status-cancelled-fg: #f66;
  --good-deal: #6c6;
  --bad-deal: #f66;
}

body {
  font-family: "Courier New", Courier, monospace;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--fg);
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 15px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--border);
}

h1 {
  font-size: 24px;
  font-weight: bold;
}

.header-box {
  background: #e03e2d;
  color: #000;
  padding: 4px 16px;
  display: inline-block;
}

#theme-btn {
  display: flex;
  align-items: center;
  color: var(--fg);
  cursor: pointer;
}

#theme-btn:hover {
  opacity: 0.7;
}

#theme-btn svg.hidden {
  display: none;
}

.header-right {
  display: flex;
  gap: 15px;
  align-items: center;
  flex-wrap: wrap;
}

#connect-btn,
#sell-btn {
  font-family: inherit;
  font-size: 14px;
  color: var(--fg);
  text-decoration: none;
  cursor: pointer;
}

#connect-btn:hover,
#sell-btn:hover {
  text-decoration: underline;
}

#sell-btn.hidden,
#network-indicator.hidden {
  display: none;
}

.wallet-dropdown {
  position: relative;
}

.wallet-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  min-width: 180px;
  z-index: 1000;
  margin-top: 4px;
}

.wallet-menu.hidden {
  display: none;
}

.wallet-menu a {
  display: block;
  padding: 8px 12px;
  color: var(--fg);
  text-decoration: none;
  font-size: 13px;
}

.wallet-menu a:hover {
  background: var(--bg-hover);
}

.wallet-menu-header {
  padding: 8px 12px;
  font-weight: bold;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-secondary);
  font-size: 13px;
}

.wallet-menu-divider {
  border-top: 1px solid var(--border-light);
  margin: 4px 0;
}

h2 {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 10px;
}

button {
  font-family: inherit;
  font-size: 14px;
  background: var(--fg);
  color: var(--bg);
  border: none;
  padding: 8px 16px;
  cursor: pointer;
}

button:hover {
  background: var(--muted);
}

button:disabled {
  background: var(--muted);
  opacity: 0.6;
  cursor: not-allowed;
}

.loading-dots {
  display: inline-block;
  width: 1.5em;
  text-align: left;
}

.loading-dots::after {
  content: "";
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0% {
    content: "";
  }
  25% {
    content: ".";
  }
  50% {
    content: "..";
  }
  75% {
    content: "...";
  }
  100% {
    content: "";
  }
}

a {
  color: var(--link);
}

.tagline {
  text-align: center;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: bold;
}

.api-note {
  text-align: center;
  margin-bottom: 15px;
  font-size: 13px;
}

.stats-row {
  text-align: center;
  font-size: 14px;
  margin-bottom: 15px;
}

.stat-label {
  background: var(--stat-bg);
  padding: 2px 6px;
}

.zero-stats {
  text-align: center;
  margin-bottom: 10px;
  line-height: 1.4;
}

.ticker {
  text-align: center;
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 15px;
}

#popular-pairs {
  margin-bottom: 10px;
  font-size: 13px;
}

#pairs-list {
  margin-left: 5px;
}

#filters {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  font-size: 13px;
  flex-wrap: wrap;
  gap: 10px;
}

.filter-left {
  display: flex;
  align-items: center;
  gap: 5px;
}

.filter-right {
  display: flex;
  align-items: center;
}

#filters select {
  font-family: inherit;
  font-size: 13px;
  padding: 2px 5px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--fg);
  cursor: pointer;
}

#filters input[type="radio"],
#filters input[type="checkbox"] {
  cursor: pointer;
  margin-left: 3px;
}

.my-orders-filter.hidden {
  display: none;
}

.my-orders-filter input[type="checkbox"] {
  vertical-align: middle;
  margin-top: -1px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 13px;
}

th,
td {
  text-align: center;
  padding: 6px 8px;
  border: 1px solid var(--border);
}

th {
  background: var(--th-bg);
  font-weight: bold;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover {
  background: var(--th-hover);
}

.sort-indicator {
  font-size: 10px;
  opacity: 0.7;
}

.swap-icon {
  opacity: 0.7;
  font-size: 22px;
  vertical-align: middle;
  animation: pulse 1.5s ease-in-out 3;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.7;
  }
  50% {
    opacity: 1;
  }
}

.price-cell {
  cursor: pointer;
}

.price-cell:hover {
  text-decoration: underline;
}

.market-deviation {
  font-size: 11px;
  color: var(--muted);
  margin-left: 4px;
}

.market-deviation.good-deal {
  color: var(--good-deal);
  font-weight: bold;
}

.market-deviation.bad-deal {
  color: var(--bad-deal);
}

tbody tr:hover {
  background: var(--row-hover);
}

tbody tr.own-order {
  background: var(--own-order);
}

tbody tr.own-order:hover {
  background: var(--own-order-hover);
}

tbody tr.highlighted-order {
  background: var(--highlight);
  animation: highlight-pulse 2s ease-out;
}

tbody tr.highlighted-order:hover {
  background: var(--highlight-hover);
}

@keyframes highlight-pulse {
  0% {
    background: var(--highlight-pulse);
  }
  100% {
    background: var(--highlight);
  }
}

#pagination {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 40px;
}

.warning {
  background: var(--warning-bg);
  border: 1px solid var(--border);
  padding: 10px;
  margin-bottom: 20px;
  hyphens: none;
  -webkit-hyphens: none;
}

.form-row {
  display: flex;
  gap: 20px;
  margin-bottom: 15px;
  flex-wrap: wrap;
}

.form-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-row input {
  font-family: inherit;
  font-size: 14px;
  padding: 6px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--fg);
  width: 46ch;
}

/* Action buttons in table */
.buy-btn,
.cancel-btn {
  font-family: inherit;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}

.buy-btn {
  color: var(--fg);
}

.cancel-btn {
  color: var(--bad-deal);
}

.buy-btn:hover,
.cancel-btn:hover {
  text-decoration: underline;
}

.status-filled-label {
  color: var(--good-deal);
}

.status-canceled-label {
  color: var(--bad-deal);
}

.copy-btn {
  font-family: "Segoe UI Symbol", "DejaVu Sans", Arial, sans-serif;
  font-size: 13px;
  line-height: 1;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  margin-left: 4px;
  color: var(--muted);
  vertical-align: middle;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
}

.copy-btn:hover {
  color: var(--fg);
  background: none;
}

.order-age {
  font-size: 10px;
  color: var(--muted);
  display: block;
  margin-top: 2px;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg);
  padding: 20px;
  border: 2px solid var(--border);
  max-width: 500px;
  width: 90%;
  overflow: visible;
}

.sell-modal-content {
  max-width: 900px;
}

.sell-modal-content .form-row {
  margin-bottom: 15px;
}

.sell-modal-content .form-row input {
  width: 46ch;
  min-width: 46ch;
}

.sell-modal-content .form-row input.input-error {
  border-color: var(--bad-deal);
  background-color: var(--status-cancelled-bg);
}

.amount-error {
  display: block;
  color: var(--bad-deal);
  font-size: 12px;
  margin-top: 2px;
}

.sell-modal-content .warning {
  margin-bottom: 20px;
}

.order-modal-content {
  max-width: 500px;
}

.order-modal-grid {
  margin: 15px 0;
}

.order-modal-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
}

.order-modal-row:last-child {
  border-bottom: none;
}

.order-modal-label {
  font-weight: bold;
  color: var(--muted);
}

.order-modal-row a {
  color: var(--link);
}

.order-modal-status {
  padding: 2px 8px;
  font-size: 12px;
  font-weight: bold;
}

.order-modal-status.status-open {
  background: var(--status-open-bg);
  color: var(--status-open-fg);
}

.order-modal-status.status-filled {
  background: var(--status-filled-bg);
  color: var(--status-filled-fg);
}

.order-modal-status.status-cancelled {
  background: var(--status-cancelled-bg);
  color: var(--status-cancelled-fg);
}

.order-modal-link-input {
  font-family: inherit;
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid var(--border-light);
  width: 200px;
  background: var(--bg-secondary);
  color: var(--fg);
}

.trade-id-link {
  color: var(--fg);
  text-decoration: underline;
  cursor: pointer;
}

.token-balance {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.price-info {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.verify-link {
  font-size: 11px;
  color: var(--good-deal);
}

.token-warning {
  font-size: 11px;
  color: var(--bad-deal);
  cursor: help;
}

.quick-amounts {
  display: flex;
  gap: 5px;
  margin-top: 4px;
}

.quick-amt-btn {
  font-family: inherit;
  font-size: 11px;
  padding: 2px 6px;
  background: var(--fg);
  color: var(--bg);
  border: none;
  cursor: pointer;
}

.quick-amt-btn:hover {
  background: var(--muted);
}

.token-selector-wrapper {
  position: relative;
  width: 100%;
}

.token-selector-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-top: none;
  z-index: 100;
  max-height: 250px;
  overflow-y: auto;
  box-shadow: 0 4px 6px var(--modal-overlay);
}

.token-selector-dropdown.hidden {
  display: none;
}

.token-selector-title {
  padding: 6px 10px;
  font-size: 11px;
  color: var(--muted);
  background: var(--bg-secondary);
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.token-selector-item {
  padding: 8px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
}

.token-selector-item:hover,
.token-selector-item.selected {
  background: var(--bg-hover);
}

.token-selector-empty {
  padding: 12px 10px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.token-logo {
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.token-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.token-symbol {
  font-weight: bold;
  font-size: 14px;
}

.token-name {
  font-size: 11px;
  color: var(--muted);
}

.modal-content h3 {
  font-size: 16px;
  margin-bottom: 10px;
}

.modal-content p {
  margin-bottom: 20px;
  word-break: break-all;
}

.gas-estimate {
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions button {
  flex: 1;
}

#modal-cancel,
#sell-modal-cancel {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
}

#modal-cancel:hover,
#sell-modal-cancel:hover {
  background: var(--bg-hover);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--fg);
  color: var(--bg);
  padding: 10px 20px;
  max-width: 400px;
  z-index: 1001;
}

.toast.hidden {
  display: none;
}

.toast.error {
  background: var(--bad-deal);
  color: #fff;
}

.toast.success {
  background: var(--good-deal);
  color: #fff;
}

footer {
  text-align: center;
  padding: 20px 0;
  margin-top: 20px;
  display: flex;
  justify-content: center;
  gap: 15px;
  font-size: 13px;
}

footer a {
  color: var(--link);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

.revoke-modal-content {
  max-width: 450px;
}

.revoke-intro {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 15px;
}

.revoke-list {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  padding: 12px 15px;
  margin-bottom: 15px;
  min-height: 60px;
}

.revoke-loading {
  color: var(--muted);
  font-size: 13px;
}

.revoke-empty {
  color: var(--muted);
  font-size: 13px;
}

.revoke-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
}

.revoke-row:last-child {
  border-bottom: none;
}

.revoke-token {
  font-weight: bold;
  font-size: 13px;
}

.revoke-allowance {
  font-size: 12px;
  color: var(--muted);
}

.revoke-btn {
  background: var(--bad-deal);
  color: #fff;
  border: none;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}

.revoke-btn:hover {
  opacity: 0.9;
}

.revoke-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.verify-modal-content {
  max-width: 550px;
}

.verify-intro {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 15px;
}

.verify-grid {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  padding: 12px 15px;
  margin-bottom: 15px;
}

.verify-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-light);
}

.verify-row:last-child {
  border-bottom: none;
}

.verify-file {
  font-weight: bold;
  font-size: 13px;
}

.verify-hash {
  font-family: "Courier New", monospace;
  font-size: 11px;
  background: var(--bg);
  padding: 3px 6px;
  border: 1px solid var(--border-light);
  word-break: break-all;
  max-width: 380px;
}

.verify-help {
  font-size: 12px;
  color: var(--muted);
}

.verify-help code {
  background: var(--bg-secondary);
  padding: 2px 6px;
  border: 1px solid var(--border-light);
  font-size: 11px;
}

/* Loading Skeleton */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--skeleton-a) 25%,
    var(--skeleton-b) 50%,
    var(--skeleton-a) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 2px;
  display: inline-block;
  height: 1em;
}

.skeleton-text {
  width: 60%;
  min-width: 40px;
}

.skeleton-short {
  width: 40%;
  min-width: 30px;
}

.skeleton-number {
  width: 50%;
  min-width: 50px;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Responsive */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  .header-right {
    gap: 10px;
  }

  .tagline {
    font-size: 12px;
  }

  .stats-row {
    font-size: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
  }

  .zero-stats {
    font-size: 12px;
  }

  #filters {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .filter-left {
    flex-wrap: wrap;
  }

  .filter-right {
    flex-wrap: wrap;
    gap: 5px;
  }

  .form-row {
    flex-direction: column;
  }

  .form-row input {
    width: 100%;
  }

  /* Card layout for table on mobile */
  #orders table {
    border: none;
  }

  #orders thead {
    display: none;
  }

  #orders tbody {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  #orders tbody tr {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    padding: 12px;
    background: var(--bg);
  }

  #orders tbody tr:hover {
    background: var(--row-hover);
  }

  #orders tbody tr.own-order {
    background: var(--own-order);
  }

  #orders tbody tr.highlighted-order {
    background: var(--highlight);
  }

  #orders tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border: none;
    text-align: left;
  }

  #orders tbody td::before {
    content: attr(data-label);
    font-weight: bold;
    color: var(--muted);
    flex-shrink: 0;
    margin-right: 10px;
  }

  /* Hide action column label */
  #orders tbody td:first-child::before {
    content: "";
  }

  #orders tbody td:first-child {
    justify-content: flex-start;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
    margin-bottom: 4px;
  }

  /* Pagination on mobile */
  #pagination {
    justify-content: center;
    flex-wrap: wrap;
  }

  /* Modals on mobile */
  .modal-content {
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
  }

  .sell-modal-content {
    max-width: none;
  }

  .order-modal-content {
    max-width: none;
  }

  footer {
    flex-wrap: wrap;
    gap: 10px;
  }
}
