/* Watch Arbitrage Dashboard — Custom styles (Bootstrap 5 base via CDN) */

:root {
  --sidebar-width: 220px;
  --sidebar-bg: #1a1d23;
  --sidebar-text: #adb5bd;
  --sidebar-active: #ffffff;
  --sidebar-accent: #3d8bcd;
  --topbar-height: 56px;
  --card-radius: 8px;
  --status-green: #28a745;
  --status-yellow: #ffc107;
  --status-red: #dc3545;
  --status-blue: #17a2b8;
}

/* ── Layout ─────────────────────────────────────────────────────── */

body {
  background: #f4f6f9;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 0.9rem;
}

.dashboard-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 1.1rem 1.2rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.sidebar-brand .brand-icon {
  font-size: 1.4rem;
}

.sidebar-brand .brand-text {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  line-height: 1.2;
}

.sidebar-brand .brand-sub {
  font-size: 0.7rem;
  color: var(--sidebar-text);
}

.sidebar-nav {
  flex: 1;
  padding: 0.5rem 0;
}

.sidebar-section {
  padding: 0.6rem 1rem 0.2rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.3);
  font-weight: 600;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 1.2rem;
  color: var(--sidebar-text);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all 0.15s;
  font-size: 0.87rem;
}

.sidebar-nav a:hover {
  color: #fff;
  background: rgba(255,255,255,0.06);
}

.sidebar-nav a.active {
  color: var(--sidebar-active);
  border-left-color: var(--sidebar-accent);
  background: rgba(61,139,205,0.12);
}

.sidebar-nav a .nav-icon {
  width: 18px;
  text-align: center;
  opacity: 0.8;
}

.sidebar-footer {
  padding: 0.8rem 1.2rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.78rem;
  color: rgba(255,255,255,0.35);
}

/* ── Main content ────────────────────────────────────────────────── */

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid #e9ecef;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-weight: 600;
  font-size: 1rem;
  color: #212529;
  flex: 1;
}

.topbar-user {
  font-size: 0.82rem;
  color: #6c757d;
}

.page-body {
  padding: 1.5rem;
  flex: 1;
}

/* ── Cards ───────────────────────────────────────────────────────── */

.card {
  border: none;
  border-radius: var(--card-radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.card-header {
  background: #fff;
  border-bottom: 1px solid #f0f0f0;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.85rem 1.1rem;
  border-radius: var(--card-radius) var(--card-radius) 0 0 !important;
}

.stat-card {
  background: #fff;
  border-radius: var(--card-radius);
  padding: 1.1rem 1.3rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
  color: #212529;
}

.stat-card .stat-label {
  font-size: 0.78rem;
  color: #6c757d;
  margin-top: 0.3rem;
}

.stat-card .stat-icon {
  font-size: 1.8rem;
  opacity: 0.15;
}

/* ── Status indicators ───────────────────────────────────────────── */

.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
}

.status-dot.active, .status-dot.healthy { background: var(--status-green); }
.status-dot.tripped { background: var(--status-red); animation: pulse-red 1.5s infinite; }
.status-dot.paused { background: var(--status-yellow); }
.status-dot.up { background: var(--status-green); }
.status-dot.down { background: var(--status-red); }

@keyframes pulse-red {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.badge-intent-buy { background: #d1ecf1; color: #0c5460; }
.badge-intent-sell { background: #d4edda; color: #155724; }
.badge-status-active { background: #d4edda; color: #155724; }
.badge-status-expired { background: #e2e3e5; color: #383d41; }
.badge-status-review { background: #fff3cd; color: #856404; }
.badge-status-matched { background: #cce5ff; color: #004085; }
.badge-status-sold { background: #d4edda; color: #155724; }
.badge-match-confirmed { background: #d4edda; color: #155724; }
.badge-match-negotiation { background: #fff3cd; color: #856404; }
.badge-match-open { background: #cfe2ff; color: #084298; }
.badge-status-new { background: #cce5ff; color: #004085; }
.badge-status-pursuing { background: #d1ecf1; color: #0c5460; }
.badge-status-won { background: #d4edda; color: #155724; }
.badge-status-lost { background: #f8d7da; color: #721c24; }

.badge-sm {
  font-size: 0.72rem;
  padding: 0.2em 0.55em;
  border-radius: 4px;
  font-weight: 600;
}

/* ── Progress bars ───────────────────────────────────────────────── */

.cost-bar-container {
  height: 8px;
  background: #e9ecef;
  border-radius: 4px;
  overflow: hidden;
}

.cost-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}

.cost-bar.low { background: var(--status-green); }
.cost-bar.medium { background: var(--status-yellow); }
.cost-bar.high { background: var(--status-red); }

/* ── Tables ──────────────────────────────────────────────────────── */

.table-sm td, .table-sm th {
  padding: 0.45rem 0.6rem;
  font-size: 0.84rem;
}

.table-hover tbody tr:hover {
  background: #f8f9fa;
  cursor: pointer;
}

.table-responsive {
  border-radius: var(--card-radius);
  overflow: hidden;
}

/* ── Match cards ─────────────────────────────────────────────────── */

.match-card {
  background: #fff;
  border-radius: var(--card-radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin-bottom: 1rem;
  border-left: 4px solid transparent;
  overflow: hidden;
}

.match-card.confirmed { border-left-color: var(--status-green); }
.match-card.negotiation { border-left-color: var(--status-yellow); }
.match-card.open { border-left-color: #0d6efd; }

.match-card-header {
  padding: 0.8rem 1rem;
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.match-card-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.match-party {
  padding: 0.9rem 1rem;
}

.match-party:first-child {
  border-right: 1px solid #f0f0f0;
}

.match-party-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: #6c757d;
  margin-bottom: 0.3rem;
}

.match-price {
  font-size: 1.1rem;
  font-weight: 700;
  color: #212529;
}

.match-margin {
  padding: 0.6rem 1rem;
  background: #f8f9fa;
  border-top: 1px solid #e9ecef;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.margin-value {
  font-weight: 700;
  font-size: 1rem;
}

.margin-value.confirmed { color: var(--status-green); }
.margin-value.negotiation { color: #856404; }
.margin-value.open { color: #0d6efd; }

.mismatch-banner {
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 4px;
  padding: 0.4rem 0.7rem;
  font-size: 0.78rem;
  color: #856404;
  margin: 0.5rem 1rem 0;
}

/* ── CB status table ─────────────────────────────────────────────── */

.cb-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6c757d;
  font-weight: 600;
}

.cb-tripped-card {
  background: #fff8f8;
  border: 1px solid #f5c6cb;
  border-radius: var(--card-radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

/* ── Log viewer ──────────────────────────────────────────────────── */

.log-entry {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.78rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid #f0f0f0;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}

.log-entry:last-child { border-bottom: none; }
.log-entry .log-time { color: #6c757d; margin-right: 0.5rem; }
.log-entry.ERROR { color: #dc3545; }
.log-entry.WARNING { color: #856404; }
.log-entry.INFO { color: #212529; }

/* ── Filters bar ─────────────────────────────────────────────────── */

.filters-bar {
  background: #fff;
  border-radius: var(--card-radius);
  padding: 0.8rem 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: flex-end;
}

.filters-bar .form-control,
.filters-bar .form-select {
  font-size: 0.84rem;
  height: 34px;
  padding: 0.3rem 0.6rem;
}

.filters-bar .form-label {
  font-size: 0.75rem;
  margin-bottom: 0.2rem;
  color: #6c757d;
}

/* ── Charts ──────────────────────────────────────────────────────── */

.chart-container {
  position: relative;
  height: 220px;
}

.chart-container-lg {
  position: relative;
  height: 300px;
}

/* ── Toggle switch ───────────────────────────────────────────────── */

.form-check-input.toggle-sm {
  width: 2.2em;
  height: 1.1em;
  cursor: pointer;
}

/* ── Settings tabs ───────────────────────────────────────────────── */

.settings-section {
  margin-bottom: 1.5rem;
}

.settings-section h6 {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6c757d;
  border-bottom: 1px solid #e9ecef;
  padding-bottom: 0.4rem;
  margin-bottom: 0.9rem;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.7rem;
}

.setting-label {
  flex: 1;
  font-size: 0.85rem;
}

.setting-desc {
  font-size: 0.74rem;
  color: #6c757d;
  margin-top: 0.1rem;
}

.setting-input {
  width: 120px;
}

/* ── Pagination ──────────────────────────────────────────────────── */

.page-link {
  font-size: 0.83rem;
  padding: 0.3rem 0.65rem;
}

/* ── Login page ──────────────────────────────────────────────────── */

.login-wrapper {
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 2.5rem;
  width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.login-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-logo .logo-icon {
  font-size: 2.5rem;
}

.login-logo h1 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-top: 0.5rem;
  color: #212529;
}

/* ── Expandable rows ─────────────────────────────────────────────── */

.detail-row td {
  background: #f8f9fa;
  padding: 1rem !important;
}

.detail-panel {
  font-size: 0.83rem;
}

.detail-panel .raw-msg,
.raw-msg {
  background: #1a1d23;
  color: #abb2bf;
  font-family: monospace;
  font-size: 0.8rem;
  padding: 0.7rem;
  border-radius: 4px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 120px;
  overflow-y: auto;
}

.raw-msg-toggle {
  padding: 0.5rem 1rem;
  border-top: 1px solid #e9ecef;
}

.raw-msg-toggle > summary {
  font-size: 0.78rem;
  color: #6c757d;
  cursor: pointer;
  user-select: none;
}

.raw-msg-toggle > summary:hover {
  color: #0d6efd;
}

.raw-msg-toggle .raw-msg {
  max-height: 220px;
  line-height: 1.6;
}

/* Raw message highlight tokens */
.rmsg-price   { color: #f0c040; font-weight: 600; }
.rmsg-new     { color: #4ec9b0; font-weight: 600; }  /* new-with-date: N1/26 */
.rmsg-year    { color: #9cdcfe; }                     /* year codes: 2023Y */
.rmsg-cond    { color: #ce9178; }                     /* New / Used / LNIB */
.rmsg-acc     { color: #b5cea8; }                     /* FS / NP / NB */
.rmsg-intent  { color: #c586c0; font-weight: 600; }   /* WTS / WTB / LF */

/* ── Listing detail fields (labeled key/value grid) ─────────────── */

.detail-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.12rem 0;
  margin-top: 0.5rem;
  font-size: 0.76rem;
  color: #212529;
}

.detail-field {
  width: 50%;
  padding-right: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-field-wide {
  width: 100%;
}

.detail-label {
  font-weight: 600;
  color: #495057;
  margin-right: 0.2rem;
}

/* ── Miscellaneous ───────────────────────────────────────────────── */

.text-money { font-family: 'JetBrains Mono', monospace; font-weight: 600; }
.text-small-muted { font-size: 0.76rem; color: #6c757d; }

.action-btn-group .btn {
  font-size: 0.78rem;
  padding: 0.2rem 0.6rem;
}

.sparkline-bar {
  display: inline-block;
  width: 4px;
  background: var(--sidebar-accent);
  border-radius: 2px;
  vertical-align: bottom;
  margin-right: 1px;
}

/* ── Responsive ──────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main-content { margin-left: 0; }
  .match-card-body { grid-template-columns: 1fr; }
}
