:root {
  --bg: #0b0f17;
  --card: #121826;
  --card2: #0e1420;
  --border: #1f2937;
  --text: #e5e7eb;
  --muted: #8b95a7;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --accent: #38bdf8;
  --purple: #a855f7;
  --amber: #f59e0b;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}
h1 { font-size: 16px; margin: 0; }
h1 small { color: var(--muted); font-weight: normal; }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 0 0 9px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

header {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 70px 12px 22px; border-bottom: 1px solid var(--border);
  background: var(--card2); flex-wrap: wrap; min-height: 52px;
  position: relative;
  justify-content: space-between;
}

.actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; min-width: 170px; }
.logo {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.badge { padding: 2px 7px; border-radius: 999px; font-size: 10px; font-weight: 700; margin-right: 4px; }
.badge.dry { background: #3f3000; color: var(--amber); }
.badge.live { background: #052e16; color: var(--green); }
.badge.on { background: #052e16; color: var(--green); }
.badge.off { background: #27172a; color: #c084fc; }
.conn { display: flex; gap: 5px; flex-wrap: wrap; font-size: 11px; align-items: center; flex: 1; min-width: 0; }
.conn .pill { background: var(--card); border: 1px solid var(--border); padding: 3px 8px; border-radius: 6px; color: var(--muted); white-space: nowrap; flex-shrink: 0; font-size: 11px; }
.conn .pill.ok { color: var(--green); border-color: #14532d; }
.conn .pill.bad { color: var(--red); border-color: #7f1d1d; }

main { display: grid; grid-template-columns: 300px 1fr 340px; gap: 14px; padding: 14px 20px; }
footer { padding: 0 20px 24px; }
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
@media (max-width: 1100px) { main { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

button.btn {
  background: var(--card2); color: var(--text); border: 1px solid var(--border);
  border-radius: 7px; padding: 6px 10px; cursor: pointer; font-size: 12px;
}
button.btn:hover { border-color: #334155; }
button.btn.primary { background: var(--blue); border-color: var(--blue); color: white; font-weight: 600; }
button.btn.danger { background: #7f1d1d; border-color: #991b1b; color: white; }
button.btn.success { background: #14532d; border-color: #166534; color: white; }
button.btn.tiny { padding: 3px 8px; font-size: 11px; margin-top: 6px; }

.actions { display: flex; gap: 5px; flex-shrink: 0; align-items: center; }
.actions button.btn { padding: 5px 9px; font-size: 11px; }

/* AI Provider Status */
.ai-provider-card {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 8px;
}
.ai-provider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 8px;
}
.ai-provider-name {
  font-weight: 600;
  color: var(--text);
}
.ai-provider-status {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.1);
}
.ai-provider-key {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.05);
}
.ai-provider-details {
  font-size: 12px;
  color: var(--muted);
}
.ai-provider-details > div {
  margin-bottom: 3px;
}
.ai-error {
  color: var(--red);
  font-size: 11px;
  margin-top: 4px;
  font-style: italic;
}

/* sentiment */
.sentiment-bar { height: 8px; border-radius: 6px; background: linear-gradient(90deg, #ef4444, #f59e0b, #22c55e); position: relative; margin: 8px 0 6px; }
.sentiment-marker { position: absolute; top: -4px; width: 4px; height: 16px; background: white; border-radius: 2px; transform: translateX(-2px); }
.sentiment-line { display: flex; justify-content: space-between; font-size: 12px; }

/* coins */
.add-coin { display: flex; gap: 8px; margin-bottom: 8px; }
.add-coin input { flex: 1; background: var(--card2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 7px 10px; }
.quick-add { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.quick-add button { background: var(--card2); border: 1px solid var(--border); color: var(--muted); border-radius: 6px; padding: 3px 9px; font-size: 11px; cursor: pointer; }
.quick-add button:hover { color: var(--text); border-color: #334155; }

.coin-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 10px; background: var(--card2); cursor: pointer; }
.coin-card.selected { border-color: var(--blue); }
.coin-top-right { display: flex; align-items: center; gap: 8px; }
.x-del { background: none; border: 1px solid transparent; color: var(--muted); border-radius: 6px; cursor: pointer; font-size: 12px; padding: 1px 7px; line-height: 1.5; }
.x-del:hover { color: var(--red); border-color: #7f1d1d; background: #2a1215; }
.coin-top { display: flex; justify-content: space-between; align-items: baseline; }
.coin-top b { font-size: 15px; }
.coin-price { font-size: 15px; font-weight: 600; }
.coin-sub { color: var(--muted); font-size: 12px; margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.coin-targets { margin-top: 6px; font-size: 11.5px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.coin-settings { margin-top: 8px; display: none; border-top: 1px dashed var(--border); padding-top: 8px; }
.coin-card.open .coin-settings { display: block; }
.coin-settings .row { display: flex; gap: 6px; margin-bottom: 6px; }
.coin-settings label { flex: 1; font-size: 11px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.coin-settings input { width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 5px 7px; font-size: 12px; }
.coin-settings .btns { display: flex; gap: 6px; flex-wrap: wrap; }

.up { color: var(--green); }
.down { color: var(--red); }

/* chart */
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.price-line { font-size: 26px; font-weight: 700; margin-top: 2px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip { background: var(--card2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: 11.5px; color: var(--muted); }
.chip b { color: var(--text); }
.chip.trend-bullish b { color: var(--green); }
.chip.trend-bearish b { color: var(--red); }
.chart-wrap { position: relative; height: 380px; }
.ai-note { margin-top: 8px; }

/* forecast grid */
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.fcell { background: var(--card2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.fcell .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.fcell .v { font-size: 17px; font-weight: 700; margin-top: 3px; }
.fcell .s { color: var(--muted); font-size: 11px; margin-top: 2px; }

/* pending */
.pending-card { border: 1px solid #713f12; background: #1a1204; border-radius: 10px; padding: 10px; margin-bottom: 8px; }
.pending-card .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.side-buy { color: var(--green); font-weight: 700; }
.side-sell { color: var(--red); font-weight: 700; }
.pending-card .meta { color: var(--muted); font-size: 12px; line-height: 1.5; }
.pending-card .btns { display: flex; gap: 8px; margin-top: 8px; }

/* news */
.news-item { border-bottom: 1px solid var(--border); padding: 9px 0; }
.news-item:last-child { border-bottom: none; }
.news-title { font-size: 13px; line-height: 1.35; }
.news-title a { color: var(--text); text-decoration: none; }
.news-title a:hover { color: var(--blue); }
.news-meta { display: flex; gap: 8px; font-size: 11px; color: var(--muted); margin-top: 3px; flex-wrap: wrap; }
.tag { padding: 1px 7px; border-radius: 999px; font-size: 10.5px; font-weight: 600; }
.tag.bullish { background: #052e16; color: var(--green); }
.tag.bearish { background: #450a0a; color: #fca5a5; }
.tag.neutral { background: #1f2937; color: var(--muted); }
.ai-summary { background: #16102b; border: 1px solid #3b2a63; border-radius: 10px; padding: 10px; font-size: 12.5px; line-height: 1.5; margin-bottom: 10px; }

/* table */
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
td { padding: 6px 8px; border-bottom: 1px solid #17202f; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: #1f2937; border: 1px solid #334155; color: var(--text);
  padding: 10px 18px; border-radius: 10px; opacity: 0; transition: all .25s; z-index: 50;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: #7f1d1d; background: #2a1215; }

/* AI advisor */
.adv-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.adv-badge { font-size: 18px; font-weight: 800; padding: 4px 16px; border-radius: 10px; letter-spacing: .05em; }
.adv-buy { background: #052e16; color: var(--green); border: 1px solid #166534; }
.adv-sell { background: #450a0a; color: #fca5a5; border: 1px solid #7f1d1d; }
.adv-hold { background: #1f2937; color: var(--muted); border: 1px solid #334155; }
.adv-summary { font-size: 13px; line-height: 1.5; margin-bottom: 10px; }
.adv-factor { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid #17202f; }
.adv-factor:last-of-type { border-bottom: none; }

/* Chat Widget */
.chat-widget {
  position: fixed;
  top: 10px;
  right: 10px;
  width: 58px;
  height: 58px;
  background: var(--bg);
  border: none;
  border-radius: 50%;
  box-shadow: none;
  z-index: 999;
  display: flex;
  flex-direction: column;
  cursor: grab;
  transition: width 0.3s ease, height 0.3s ease, border-radius 0.3s ease, box-shadow 0.3s ease;
  touch-action: none;
  user-select: none;
}

.chat-widget.dragging {
  cursor: grabbing;
  transition: none;
}

.chat-widget.chat-intro {
  animation: chat-intro 5s ease-in-out both;
}

@keyframes chat-intro {
  0%, 100% { transform: translate(0, 0) rotate(0deg) scale(1); }
  35%, 70% { transform: translate(calc(50vw - 50% - var(--chat-start-x, 0px)), calc(50vh - 50% - var(--chat-start-y, 0px))) rotate(360deg) scale(3); }
}


.chat-widget:hover {
  box-shadow: none;
  transform: scale(1.05);
}

.chat-widget.expanded {
  width: 350px;
  height: auto;
  max-height: 500px;
  border-radius: 12px;
  position: fixed;
  top: 80px;
  right: 10px;
  cursor: default;
}

.chat-widget.expanded:hover {
  transform: none;
}

.chat-widget.minimized .chat-header {
  position: relative;
  padding: 0;
  border: none;
  border-radius: 50%;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
}

.chat-widget.minimized {
  width: 58px;
  height: 58px;
  padding: 0;
}

.chat-widget.minimized .chat-icon-wrapper {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.chat-widget.minimized .chat-icon {
  display: block;
  position: absolute;
  top: 5px;
  left: 50%;
width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center;
  transform: translateX(-50%);
}

.chat-widget.minimized .chat-label {
  display: block;
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 7px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
  text-transform: uppercase;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.chat-widget.minimized .chat-title {
  display: none;
}

.chat-widget.minimized .chat-toggle {
  display: none !important;
}

.chat-widget.expanded .chat-label {
  display: none;
}

.chat-widget.expanded .chat-icon-wrapper {
  display: none;
}

.chat-widget.expanded .chat-title {
  display: block;
}

.chat-widget.expanded .chat-header {
  border-radius: 12px 12px 0 0;
  padding: 12px 16px;
  width: auto;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
}

.chat-widget.expanded .chat-title {
  display: block;
  flex: 1;
}

.chat-widget.minimized .chat-body {
  display: none;
}

.chat-widget.expanded .chat-body {
  display: flex;
  flex-direction: column;
  height: 400px;
}

.chat-widget.minimized .chat-toggle {
  display: none !important;
}

.chat-widget.expanded .chat-toggle {
  display: block;
}

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

.chat-message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
}

.chat-message.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--bg);
}

.chat-message.assistant {
  align-self: flex-start;
  background: rgba(255,255,255,0.1);
  border: 1px solid var(--border);
}

.chat-message.system {
  align-self: center;
  background: rgba(255, 255, 0, 0.1);
  border: 1px solid rgba(255, 255, 0, 0.3);
  font-size: 12px;
  text-align: center;
}

.chat-input {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.chat-input input {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--fg);
  font-size: 13px;
}

.chat-input input:focus {
  outline: none;
  border-color: var(--accent);
}

@media (max-width: 768px) {
  .chat-widget {
    top: 10px;
    right: 10px;
  }
  
  .chat-widget.expanded {
    width: 300px;
    right: 16px;
    top: 70px;
    bottom: auto;
  }
}