@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

:root {
  --page-bg: #f8fafc;
  --card-bg: #ffffff;
  --card-hover: #f1f5f9;
  --border: rgba(0, 0, 0, 0.06);
  --text: #0f172a;
  --text-muted: #64748b;
  --text-secondary: #475569;
  --primary: #3b82f6;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --surface: #ffffff;
}

body.dark {
  --page-bg: #0a0e1a;
  --card-bg: #111827;
  --card-hover: #1a2332;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --text-secondary: #cbd5e1;
  --surface: #111827;
}

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

html {
  font-size: 16px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--page-bg);
  color: var(--text);
  transition: background 0.3s ease, color 0.3s ease;
  min-width: 320px;
  overflow-x: hidden;
}

/* FIXED NAVBAR */
.navbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 60px;
  display: flex;
  align-items: center;
}

.navbar-container {
  width: 100%;
  max-width: 100%;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  height: 100%;
}

.navbar-brand {
  font-size: 1.125rem;
  font-weight: 800;
  background: linear-gradient(135deg, #3b82f6, #10b981);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
  flex-shrink: 0;
}

.nav-right-section {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.desktop-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-link,
.dropdown-toggle {
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-weight: 600;
  font-size: 0.8125rem;
  transition: all 0.2s;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  background: transparent;
  border: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-link:hover,
.dropdown-toggle:hover,
.nav-link.active {
  background: rgba(59, 130, 246, 0.1);
  color: var(--primary);
}

.dropdown {
  position: relative;
}

.dropdown-arrow {
  font-size: 0.625rem;
  transition: transform 0.2s;
}

.dropdown.open .dropdown-arrow {
  transform: rotate(180deg);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  box-shadow: 0 0.625rem 1.875rem rgba(0, 0, 0, 0.15);
  min-width: 13.75rem;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-0.625rem);
  transition: all 0.2s;
  z-index: 200;
}

.dropdown.open .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  padding: 0.625rem 1rem;
  color: var(--text);
  text-decoration: none;
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: all 0.15s;
  border-bottom: 1px solid var(--border);
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover {
  background: var(--card-hover);
  color: var(--primary);
  padding-left: 1.125rem;
}

.theme-toggle {
  width: 2.25rem;
  height: 2.25rem;
  min-width: 2.25rem;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 1rem;
  transition: all 0.2s;
}

.theme-toggle:hover {
  transform: scale(1.05);
  border-color: var(--primary);
}

.mobile-menu-btn {
  display: none;
  width: 2.25rem;
  height: 2.25rem;
  min-width: 2.25rem;
  border-radius: 0.5rem;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 1.125rem;
  transition: all 0.2s;
}

/* MOBILE DROPDOWN */
.mobile-dropdown {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  backdrop-filter: blur(4px);
}

.mobile-dropdown.active {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 3.75rem;
}

.mobile-dropdown-content {
  background: var(--card-bg);
  border-radius: 1rem;
  width: calc(100% - 2rem);
  max-width: 25rem;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  box-shadow: 0 1.25rem 3.75rem rgba(0, 0, 0, 0.4);
}

.mobile-dropdown-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--card-bg);
  z-index: 1;
}

.mobile-dropdown-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
}

.mobile-close-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--card-hover);
  border: none;
  color: var(--text);
  font-size: 1.25rem;
}

.mobile-dropdown-section {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.mobile-dropdown-section:last-child {
  border-bottom: none;
}

.mobile-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03125rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.mobile-nav-link {
  padding: 0.75rem 1rem;
  color: var(--text);
  text-decoration: none;
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0.5rem;
  transition: all 0.15s;
  margin-bottom: 0.25rem;
}

.mobile-nav-link:hover {
  background: var(--card-hover);
  color: var(--primary);
}

/* DASHBOARD LAYOUT */
.dashboard-layout {
  width: 100%;
  max-width: 100%;
  padding: 1rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  min-height: calc(100vh - 60px);
}

.top-row,
.main-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  width: 100%;
}

/* CARDS */
.market-data-card,
.config-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem;
  box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 15rem;
  width: 100%;
  overflow: hidden;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.card-title a {
  color: var(--primary);
  text-decoration: none;
}

.card-title a:hover {
  color: var(--success);
}

/* TABLE WRAPPER - PROPER SCROLLING */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
}

.data-table,
.order-table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.data-table th,
.order-table th {
  background: var(--primary);
  color: white;
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.03125rem;
  padding: 0.625rem 0.5rem;
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 10;
  white-space: nowrap;
}

.data-table td,
.order-table td {
  padding: 0.625rem 0.5rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tbody tr:hover,
.order-table tbody tr:hover {
  background: var(--card-hover);
}

.atm-row {
  background: #fef3c7 !important;
  font-weight: 600;
}

body.dark .atm-row {
  background: rgba(245, 158, 11, 0.2) !important;
}

.loading-cell {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  white-space: normal;
}

#pnl-summary-table td {
  font-weight: 700;
  font-size: 1rem;
}

/* FORM STYLES */
.config-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex-shrink: 0;
}

.checkbox-group {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.625rem;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text);
  cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  min-width: 1rem;
  cursor: pointer;
  accent-color: var(--primary);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.form-field label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
}

.form-field input,
.custom-dropdown-selected {
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--text);
  font-size: 0.8125rem;
  width: 100%;
}

.form-field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 0.1875rem rgba(59, 130, 246, 0.1);
}

.custom-dropdown {
  position: relative;
  width: 100%;
}

.custom-dropdown-selected {
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-dropdown-options {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--card-bg);
  position: absolute;
  width: 100%;
  max-height: 12.5rem;
  overflow-y: auto;
  display: none;
  z-index: 100;
  box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.15);
  margin-top: 0.25rem;
}

.custom-dropdown-options li {
  padding: 0.5rem 0.625rem;
  cursor: pointer;
  color: var(--text);
  font-size: 0.8125rem;
}

.custom-dropdown-options li:hover {
  background: var(--card-hover);
}

.custom-dropdown-options li.selected {
  background: var(--primary);
  color: white;
}

.custom-dropdown.open .custom-dropdown-options {
  display: block;
}

.config-form button[type="submit"] {
  background: var(--primary);
  color: white;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.config-form button[type="submit"]:hover {
  background: #2563eb;
}

.order-book-section {
  margin-top: 1.5rem;
  padding: 0;
  border: none;
  box-shadow: none;
  background: transparent;
}

/* NOTIFICATION */
.notification-container {
  position: fixed;
  top: 4.375rem;
  right: 1.25rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  max-width: calc(100% - 2.5rem);
}

.notification {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.75rem;
  box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.15);
  min-width: 15.625rem;
  max-width: 21.875rem;
}

/* RESPONSIVE BREAKPOINTS */
@media (min-width: 48rem) {

  .top-row,
  .main-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .checkbox-group {
    grid-template-columns: repeat(2, 1fr);
  }

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

@media (min-width: 64rem) {
  .dashboard-layout {
    padding: 1.5rem;
  }

  .form-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 63.9375rem) {
  .desktop-nav {
    display: none !important;
  }

  .mobile-menu-btn {
    display: flex;
  }
}

@media (max-width: 47.9375rem) {
  html {
    font-size: 14px;
  }

  .navbar-brand {
    font-size: 1rem;
  }

  .dashboard-layout {
    padding: 0.75rem;
    gap: 0.75rem;
  }

  .market-data-card,
  .config-section {
    padding: 0.75rem;
    min-height: 12.5rem;
  }

  .notification-container {
    top: 3.75rem;
    right: 0.625rem;
    left: 0.625rem;
  }

  .notification {
    min-width: auto;
    width: 100%;
    max-width: 100%;
  }
}

@media (max-width: 29.9375rem) {
  html {
    font-size: 13px;
  }

  .dashboard-layout {
    padding: 0.5rem;
    gap: 0.5rem;
  }

  .market-data-card,
  .config-section {
    padding: 0.625rem;
  }
}

/* SCROLLBAR */
::-webkit-scrollbar {
  width: 0.375rem;
  height: 0.375rem;
}

::-webkit-scrollbar-track {
  background: var(--card-hover);
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 0.1875rem;
}

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

.desktop-nav .dropdown:last-child .dropdown-menu {
  left: auto !important;
  right: 0 !important;
}
