:root {
  --bg-dark: #0a0b0e;
  --bg-sidebar: #0f1014;
  --bg-card: rgba(22, 24, 30, 0.85);
  --bg-card-hover: rgba(28, 31, 38, 0.95);
  --border-color: rgba(255, 255, 255, 0.06);
  --accent-primary: #3b82f6;
  --accent-secondary: #6366f1;
  --accent-success: #10b981;
  --accent-danger: #ef4444;
  --accent-warn: #f59e0b;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --glass-border: 1px solid rgba(255, 255, 255, 0.04);
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.25);
  --shadow-card-hover: 0 8px 32px rgba(0, 0, 0, 0.35);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

html {
  font-size: 14px;
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #555;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background-color: var(--bg-dark);
  background-image:
    radial-gradient(circle at 10% 20%, rgba(59, 130, 246, 0.03) 0%, transparent 20%),
    radial-gradient(circle at 90% 80%, rgba(16, 185, 129, 0.03) 0%, transparent 20%);
  color: var(--text-primary);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Animations */
@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.98);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
  }

  70% {
    box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

.view {
  display: block;
  animation: fadeInScale 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding-bottom: 20px;
  scrollbar-width: none;
  /* Firefox */
  -ms-overflow-style: none;
  /* IE/Edge */
}

.view::-webkit-scrollbar {
  display: none;
  /* Chrome/Safari/Opera */
}

.view.hidden {
  display: none;
}

/* Sidebar */
.sidebar {
  width: 220px;
  background-color: var(--bg-sidebar);
  border-right: var(--glass-border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
  transition: transform 0.3s ease-in-out;
}

.logo {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 30px;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.nav-item {
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s ease;
  font-weight: 500;
  margin-bottom: 6px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid transparent;
}

.nav-item svg {
  opacity: 0.6;
  transition: opacity 0.2s;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.05);
}

.nav-item:hover svg {
  opacity: 1;
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.1) 0%, rgba(59, 130, 246, 0.05) 100%);
  color: var(--accent-primary);
  border-color: rgba(59, 130, 246, 0.2);
  box-shadow: var(--glow-primary);
}

.nav-item.active svg {
  opacity: 1;
  stroke: var(--accent-primary);
}

/* Mobile Toggle */
.menu-toggle {
  display: none;
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 200;
  background: var(--bg-card);
  border: var(--glass-border);
  color: var(--text-primary);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  backdrop-filter: blur(10px);
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 30px;
  overflow-y: auto;
  position: relative;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  background: linear-gradient(to right, #fff, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.status-badge {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--accent-success);
  border: 1px solid rgba(16, 185, 129, 0.2);
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-success);
  animation: pulse 2s infinite;
}

/* Grid & Cards */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card-wide {
  grid-column: span 2;
}

.intelligence-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-top: 12px;
}

@media (min-width: 768px) {
  .dashboard-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
  }
}

@media (min-width: 1200px) {
  .dashboard-grid {
    /* Explicitly use 4 columns on large screens to keep layout tidy */
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
  }
}

/* Page Specific Grids */
.settings-grid,
.strategy-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

@media (min-width: 900px) {
  .settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* 2 Column for Settings */
    align-items: start;
  }

  .strategy-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* 2 Column for Strategy */
    gap: 24px;
  }
}

.card {
  background: linear-gradient(135deg, var(--bg-card) 0%, rgba(18, 20, 26, 0.9) 100%);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: var(--glass-border);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-card);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent);
}

.card:hover {
  border-color: rgba(59, 130, 246, 0.3);
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-2px);
}

.card-title {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title svg {
  opacity: 0.5;
  width: 14px;
  height: 14px;
}

.card-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

@media (min-width: 768px) {
  .card-value {
    font-size: 2rem;
  }
}

.card-value.green {
  color: var(--accent-success);
}

.card-value.red {
  color: var(--accent-danger);
}

.card-value.yellow {
  color: var(--accent-warn);
}

/* Flat Button Styles */
.btn-flat {
  padding: 10px 20px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  transition: opacity 0.15s ease;
}

.btn-flat:hover {
  opacity: 0.8;
}

.btn-flat-success {
  background: rgba(16, 185, 129, 0.12);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.25);
}

.btn-flat-warning {
  background: rgba(234, 179, 8, 0.12);
  color: #fbbf24;
  border-color: rgba(234, 179, 8, 0.25);
}

.btn-flat-primary {
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
  border-color: rgba(59, 130, 246, 0.25);
}

.btn-flat-danger {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.25);
}

.btn-flat-panic {
  background: #dc2626;
  color: white;
  border-color: #dc2626;
  font-weight: 700;
}

/* Logs Enhanced */
.log-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  margin-bottom: 12px;
}

.log-section-title {
  color: var(--text-secondary);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.log-section-title svg {
  opacity: 0.5;
}

.log-container {
  background: #0a0b0f;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  overflow-y: auto;
  max-height: 280px;
  min-height: 200px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.log-container::-webkit-scrollbar {
  width: 6px;
}

.log-container::-webkit-scrollbar-track {
  background: transparent;
}

.log-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.log-container::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.log-entry {
  padding: 8px 12px;
  margin-bottom: 4px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  border-left: 3px solid transparent;
  display: flex;
  gap: 12px;
  transition: background 0.15s ease;
}

.log-entry:hover {
  background: rgba(255, 255, 255, 0.04);
}

.log-entry.info {
  border-left-color: var(--accent-primary);
}

.log-entry.success {
  border-left-color: var(--accent-success);
}

.log-entry.error {
  border-left-color: var(--accent-danger);
}

.log-entry.warn {
  border-left-color: var(--accent-warn);
}

.log-entry:last-child {
  margin-bottom: 0;
}

.log-time {
  color: var(--text-muted);
  min-width: 70px;
}

.log-msg {
  color: var(--text-secondary);
}

.log-msg.info {
  color: var(--accent-primary);
}

.log-msg.warn {
  color: var(--accent-warn);
}

.log-msg.error {
  color: var(--accent-danger);
  font-weight: bold;
}

.log-msg.success {
  color: var(--accent-success);
}

/* UI Elements */
.btn {
  padding: 12px 24px;
  border-radius: 10px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:hover {
  filter: brightness(1.1);
}

.btn:active {
  transform: scale(0.98);
}

.btn-danger {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.8) 0%, rgba(220, 38, 38, 0.8) 100%);
  color: white;
  width: 100%;
  padding: 20px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  border: 1px solid rgba(239, 68, 68, 0.5);
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
  margin-top: auto;
  font-weight: 800;
}

/* Forms & Tables */
.form-group {
  margin-bottom: 20px;
}

label {
  display: block;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-size: 0.9rem;
}

input,
select {
  width: 100%;
  padding: 12px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

select option {
  background: #1e2028;
  color: var(--text-primary);
  padding: 10px;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 8px;
  border-bottom: 1px solid var(--border-color);
}

td {
  padding: 14px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  color: var(--text-primary);
  font-size: 0.9rem;
}

tr:last-child td {
  border-bottom: none;
}

/* Responsive */
@media (max-width: 768px) {

  /* Stack Layout? No, now we use standard mobile layout */
  body {
    flex-direction: column;
    overflow-y: auto;
  }

  .menu-toggle {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 280px;
    transform: translateX(-100%);
    background-color: rgba(17, 18, 23, 0.95);
    backdrop-filter: blur(20px);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    padding-top: 80px;
    /* Space for close btn */
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    padding: 20px;
    padding-top: 70px;
    /* Space for header toggle */
  }

  /* Responsive Grid Layouts */
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .card-wide {
    grid-column: span 1 !important;
  }

  .intelligence-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  /* Make the last item (MACD) span the full width on mobile for symmetry */
  .intelligence-grid>div:last-child {
    grid-column: span 2;
  }

  /* Strategy page two-column */
  #view-strategy>div:nth-child(2) {
    grid-template-columns: 1fr !important;
  }

  /* Price inputs responsive */
  #view-strategy .card>div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Header buttons wrap */
  .header {
    flex-wrap: wrap;
    gap: 12px;
  }
}



/* Button States */
.btn {
  transition: opacity 0.15s ease;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  opacity: 0.85;
}

.btn:active:not(:disabled) {
  opacity: 0.75;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
  filter: grayscale(0.5);
}

/* Loading Spinner for Buttons */
.btn.loading {
  position: relative;
  color: transparent !important;
}

.btn.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}



.spinning {
  animation: spin 1s linear infinite !important;
  transform-origin: center center;
  display: inline-block;
  transform-box: fill-box;
}

/* --- Toast Notifications --- */
#toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.toast {
  background: rgba(18, 18, 24, 0.95);
  backdrop-filter: blur(12px);
  color: var(--text-primary);
  padding: 16px 20px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
  min-width: 300px;
  transform: translateX(120%);
  transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
  pointer-events: auto;
  opacity: 0;
  display: flex;
  align-items: flex-start;
}

.toast.visible {
  transform: translateX(0);
  opacity: 1;
}

.toast.success {
  border-left: 4px solid var(--accent-success);
}

.toast.error {
  border-left: 4px solid var(--accent-danger);
}

.toast.info {
  border-left: 4px solid var(--accent-primary);
}

.toast-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toast-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.toast-message {
  font-size: 0.85rem;
  color: var(--text-secondary);
}