:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a2332;
  --bg-input: #0d1421;
  --border: #1e293b;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.1);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.1);
  --yellow: #eab308;
  --yellow-bg: rgba(234, 179, 8, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
}

/* ── Language Toggle ── */
.lang-toggle-wrap {
  padding: 8px 16px;
  margin-top: 8px;
}

.lang-toggle-btn {
  width: 100%;
  padding: 8px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 1px;
}

.lang-toggle-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* ── Auth Page ── */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(135deg, #0a0e17 0%, #111827 50%, #0a0e17 100%);
}

.auth-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.5);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo h1 {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, #3b82f6, #22c55e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

.auth-logo p {
  color: var(--text-muted);
  font-size: 14px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.auth-tab.active {
  background: var(--accent);
  color: white;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-group input, .form-group select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--accent);
}

.form-group input::placeholder {
  color: var(--text-muted);
}

.btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-success {
  background: var(--green);
  color: white;
}

.btn-success:hover { background: #16a34a; }

.btn-danger {
  background: var(--red);
  color: white;
}

.btn-danger:hover { background: #dc2626; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 13px;
  width: auto;
}

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.alert-error {
  background: var(--red-bg);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--red);
}

.alert-success {
  background: var(--green-bg);
  border: 1px solid rgba(34,197,94,0.3);
  color: var(--green);
}

/* ── Dashboard ── */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 10;
}

.sidebar-logo {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.sidebar-logo h2 {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, #3b82f6, #22c55e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-logo span {
  font-size: 11px;
  color: var(--text-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: right;
}

.nav-item:hover, .nav-item.active {
  color: var(--text-primary);
  background: rgba(59,130,246,0.08);
  border-right: 3px solid var(--accent);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: white;
}

.user-name {
  font-size: 14px;
  font-weight: 500;
}

.main-content {
  flex: 1;
  margin-right: 260px;
  padding: 24px 32px;
}

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

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
}

/* ── Stats Cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
}

.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Bot Control ── */
.bot-control {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.bot-status-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.running {
  background: var(--green);
  box-shadow: 0 0 8px rgba(34,197,94,0.5);
  animation: pulse 2s infinite;
}

.status-dot.stopped {
  background: var(--red);
}

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

/* ── Grid Display ── */
.grid-table {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

.grid-table h3 {
  padding: 16px 20px;
  font-size: 16px;
  border-bottom: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px 16px;
  text-align: right;
  font-size: 13px;
}

th {
  background: rgba(0,0,0,0.2);
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 11px;
}

td {
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: rgba(59,130,246,0.03); }

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.badge-idle { background: rgba(100,116,139,0.2); color: var(--text-muted); }
.badge-buy { background: var(--green-bg); color: var(--green); }
.badge-sell { background: var(--yellow-bg); color: var(--yellow); }
.badge-filled { background: var(--green-bg); color: var(--green); }
.badge-pending { background: var(--yellow-bg); color: var(--yellow); }

/* ── Settings Page ── */
.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.settings-section h3 {
  font-size: 16px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

/* ── Pages ── */
.page { display: none; }
.page.active { display: block; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    position: fixed;
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    height: auto;
    flex-direction: row;
    padding: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    overflow-x: auto;
  }

  .sidebar-logo, .sidebar-footer { display: none; }

  .nav-item {
    flex-direction: column;
    padding: 10px 16px;
    font-size: 11px;
    gap: 4px;
    border-right: none !important;
    white-space: nowrap;
  }

  .nav-item.active {
    border-bottom: 2px solid var(--accent);
  }

  .main-content {
    margin-right: 0;
    margin-bottom: 60px;
    padding: 16px;
  }

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

  .bot-control {
    flex-direction: column;
    gap: 12px;
  }
}

/* ── Loading ── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  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); } }

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,14,23,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

/* ── Wallet ── */
.wallet-coin {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  min-width: 140px;
}

.wallet-coin-name {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 4px;
}

.wallet-coin-amount {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.wallet-coin-usd {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── AI Chat ── */
.ai-chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 140px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ai-msg {
  display: flex;
  gap: 12px;
  max-width: 85%;
}

.ai-msg.ai-user {
  align-self: flex-start;
  flex-direction: row-reverse;
}

.ai-msg.ai-bot {
  align-self: flex-end;
}

.ai-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.ai-bot .ai-msg-avatar {
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: white;
}

.ai-user .ai-msg-avatar {
  background: var(--green);
  color: white;
}

.ai-msg-content {
  flex: 1;
}

.ai-msg-text {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-bot .ai-msg-text {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.ai-user .ai-msg-text {
  background: var(--accent);
  color: white;
}

.ai-msg-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.ai-input-bar {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.ai-input-bar input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

.ai-input-bar input:focus {
  border-color: var(--accent);
}

.ai-input-bar .btn {
  width: auto;
  padding: 12px 24px;
}

.ai-typing {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}

.ai-typing span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1); }
}

/* ── Charts ── */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  overflow: hidden;
}

.chart-container h3 {
  padding: 16px 20px;
  font-size: 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.chart-wrap {
  padding: 16px 20px 20px;
  position: relative;
  height: 280px;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

.hidden { display: none !important; }
