*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: #0d1117; color: #c9d1d9; min-height: 100vh; line-height: 1.5;
}
a { color: #58a6ff; text-decoration: none; }
a:hover { text-decoration: underline; }

header {
  background: #161b22; border-bottom: 1px solid #30363d;
  padding: 8px 16px; display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap;
}
header h1 { font-size: 18px; font-weight: 600; color: #f0f6fc; }
#statusBar { flex: 1; font-size: 11px; color: #8b949e; }
#statusBar .ok { color: #3fb950; }
#statusBar .err { color: #f85149; }
header button, .btn {
  background: #21262d; color: #c9d1d9; border: 1px solid #30363d;
  padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 12px;
  transition: background .15s;
}
header button:hover, .btn:hover { background: #30363d; }
.btn-primary { background: #238636; border-color: #2ea043; color: #fff; }
.btn-primary:hover { background: #2ea043; }
.btn-danger { background: #da3633; border-color: #f85149; color: #fff; }
.btn-danger:hover { background: #f85149; }
.btn-sm { padding: 2px 8px; font-size: 11px; }

nav#tabs {
  background: #161b22; border-bottom: 1px solid #30363d;
  display: flex; gap: 0; overflow-x: auto; padding: 0 8px;
}
nav#tabs button.tab {
  background: transparent; color: #8b949e; border: none; border-bottom: 2px solid transparent;
  padding: 10px 16px; cursor: pointer; font-size: 13px; white-space: nowrap;
  transition: color .15s, border-color .15s;
}
nav#tabs button.tab:hover { color: #c9d1d9; }
nav#tabs button.tab.active { color: #f0f6fc; border-bottom-color: #f78166; }
nav#tabs button.tab.dragging { opacity: 0.4; }
nav#tabs button.tab.drag-over { border-left: 2px solid #58a6ff; }

#toolbar {
  background: #161b22; border-bottom: 1px solid #30363d;
  padding: 8px 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
#toolbar.hidden { display: none; }
#toolbar input[type="text"], #toolbar input[type="search"] {
  background: #0d1117; border: 1px solid #30363d; color: #c9d1d9;
  padding: 5px 10px; border-radius: 6px; font-size: 12px; outline: none; min-width: 180px;
}
#toolbar input:focus { border-color: #58a6ff; }
#toolbar select {
  background: #0d1117; border: 1px solid #30363d; color: #c9d1d9;
  padding: 5px 10px; border-radius: 6px; font-size: 12px; outline: none;
}

.table-wrapper { margin: 0 16px 40px; overflow-x: auto; }
.table-wrapper.hidden { display: none; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
thead th {
  background: #161b22;
  padding: 8px 10px; text-align: left; border-bottom: 1px solid #30363d;
  cursor: pointer; user-select: none; white-space: nowrap; font-weight: 600;
}
thead th:hover { background: #21262d; }
tbody td { padding: 6px 10px; border-bottom: 1px solid #21262d; vertical-align: middle; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: #161b22; }
tbody tr.selected { background: #1f2a37; }
.star { color: #8b949e; cursor: pointer; font-size: 14px; transition: color .15s; }
.star.fav { color: #d29922; }
.green { color: #3fb950; }
.red { color: #f85149; }
.sort-arrow { font-size: 10px; margin-left: 2px; }
.sort-arrow.active { color: #f78166; }

.panel { margin: 0 16px 40px; }
.panel.hidden { display: none; }

#chartContainer { margin: 16px 16px 0; background: #161b22; border: 1px solid #30363d; border-radius: 8px; padding: 16px; }
#chartContainer.hidden { display: none; }
#chartContainer h3 { font-size: 14px; margin-bottom: 8px; color: #f0f6fc; }
.chart-controls { display: flex; gap: 4px; margin: 8px 0; flex-wrap: wrap; align-items: center; }
.chart-controls .btn-range { background: #21262d; color: #8b949e; border: 1px solid #30363d; padding: 2px 10px; border-radius: 4px; cursor: pointer; font-size: 11px; }
.chart-controls .btn-range:hover { background: #30363d; color: #c9d1d9; }
.chart-controls .btn-range.active { background: #238636; color: #fff; border-color: #2ea043; }
.chart-controls .btn-zoom { background: #21262d; color: #c9d1d9; border: 1px solid #30363d; padding: 2px 8px; border-radius: 4px; cursor: pointer; font-size: 11px; }
.chart-controls .btn-zoom:hover { background: #30363d; }
#chartSpinner { display: none; text-align: center; padding: 40px; color: #8b949e; }
#chartSpinner.visible { display: block; }
.chart-spinner-spinner { display: inline-block; width: 30px; height: 30px; border: 3px solid #30363d; border-top-color: #58a6ff; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Cards */
.cards { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card {
  background: #161b22; border: 1px solid #30363d; border-radius: 8px;
  padding: 12px 16px; min-width: 140px; flex: 1;
}
.card .label { font-size: 10px; color: #8b949e; text-transform: uppercase; letter-spacing: .5px; }
.card .value { font-size: 20px; font-weight: 600; margin-top: 4px; }
.card .sub { font-size: 11px; color: #8b949e; margin-top: 2px; }

/* Section headers */
.section-title {
  font-size: 14px; font-weight: 600; color: #f0f6fc;
  padding: 12px 0 4px; display: flex; align-items: center; gap: 8px;
}
.section-title button { margin-left: auto; }

/* Modals */
.modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
  background: #161b22; border: 1px solid #30363d; border-radius: 12px;
  padding: 20px 24px; max-width: 560px; width: 90%; max-height: 80vh; overflow-y: auto;
}
.modal-content h2 { font-size: 16px; font-weight: 600; margin-bottom: 16px; color: #f0f6fc; }
.modal-content label { display: block; font-size: 12px; color: #8b949e; margin: 8px 0 4px; }
.modal-content input, .modal-content select, .modal-content textarea {
  width: 100%; background: #0d1117; border: 1px solid #30363d; color: #c9d1d9;
  padding: 7px 10px; border-radius: 6px; font-size: 13px; outline: none;
}
.modal-content input:focus, .modal-content select:focus, .modal-content textarea:focus { border-color: #58a6ff; }
.modal-content textarea { resize: vertical; min-height: 60px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.form-row { display: flex; gap: 8px; }
.form-row > * { flex: 1; }

/* Progress */
#progressLog { max-height: 300px; overflow-y: auto; font-size: 11px; margin-top: 12px; }
.progress-log-entry { padding: 2px 0; border-bottom: 1px solid #21262d; }
.progress-log-entry.error { color: #f85149; }
.progress-log-entry.warn { color: #d29922; }
.progress-stages { display: flex; gap: 8px; margin: 8px 0; }
.progress-stage {
  flex: 1; background: #21262d; border-radius: 6px; padding: 8px;
  text-align: center; font-size: 11px;
}
.progress-stage.done { border: 1px solid #3fb950; }
.progress-stage.active { border: 1px solid #58a6ff; }
.progress-stage.error { border: 1px solid #f85149; }
.progress-stage .count { font-size: 14px; font-weight: 600; }

/* Quick actions in rows */
.asset-actions { display: flex; gap: 3px; }
.asset-actions button { padding: 2px 6px; font-size: 10px; border-radius: 3px; border: 1px solid #30363d; background: #21262d; color: #8b949e; cursor: pointer; line-height: 1; white-space: nowrap; }
.asset-actions button:hover { background: #30363d; color: #c9d1d9; }
.asset-actions .btn-buy { border-color: #3fb950; color: #3fb950; }
.asset-actions .btn-buy:hover { background: #3fb95020; }
.asset-actions .btn-sell { border-color: #f85149; color: #f85149; }
.asset-actions .btn-sell:hover { background: #f8514920; }

/* Analysis */
#analysisLoading { padding: 16px; color: #58a6ff; font-size: 13px; }
#analysisContent { padding: 16px 0; line-height: 1.7; }
#analysisContent h1, #analysisContent h2, #analysisContent h3 { color: #f0f6fc; margin: 12px 0 6px; }
#analysisContent p { margin: 6px 0; }
#analysisContent ul, #analysisContent ol { margin: 6px 0 6px 20px; }
#analysisContent li { margin: 2px 0; }
#analysisContent strong { color: #f0f6fc; }
#analysisContent table {
  width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 12px;
}
#analysisContent th, #analysisContent td {
  padding: 4px 8px; border: 1px solid #30363d; text-align: left;
}
#analysisContent th { background: #21262d; }
#analysisContent code { background: #21262d; padding: 1px 5px; border-radius: 3px; font-size: 11px; }
#analysisContent pre { background: #21262d; padding: 10px; border-radius: 6px; overflow-x: auto; margin: 8px 0; }
#analysisContent pre code { background: transparent; padding: 0; }
#recHistoryList { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }

/* Toast */
#toastContainer { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #161b22; border: 1px solid #30363d; border-radius: 8px;
  padding: 10px 16px; font-size: 12px; min-width: 200px; box-shadow: 0 4px 12px rgba(0,0,0,.5);
  animation: slideIn .2s ease;
}
.toast.success { border-color: #3fb950; }
.toast.error { border-color: #f85149; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #0d1117; }
::-webkit-scrollbar-thumb { background: #30363d; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #484f58; }

/* Small text */
.text-sm { font-size: 11px; color: #8b949e; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-2 { margin-top: 8px; }
.mb-2 { margin-bottom: 8px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

#settingsTabs { display: flex; gap: 0; border-bottom: 1px solid #30363d; margin-bottom: 12px; }
#settingsTabs button {
  background: transparent; color: #8b949e; border: none; border-bottom: 2px solid transparent;
  padding: 6px 12px; cursor: pointer; font-size: 12px;
}
#settingsTabs button.active { color: #f0f6fc; border-bottom-color: #f78166; }
.settings-section.hidden { display: none; }
