/* LiveLive — real-time quotes & news dashboard. */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0b0e14;
  --surface: #131722;
  --surface-2: #1a2030;
  --border: #262d40;
  --text: #e6e9f0;
  --text-muted: #8a93a6;
  --primary: #2563eb;
  --primary-hover: #3b82f6;
  --up: #16c784;
  --down: #ea3943;
  --warn: #f0a020;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0,0,0,0.35);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #16203a 0%, var(--bg) 55%) fixed;
  color: var(--text);
  min-height: 100vh;
  padding: 1rem 1.25rem 3rem;
}

[hidden] { display: none !important; }

#app { max-width: 1280px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.25rem; }

/* Top bar */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 0.55rem; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%; align-self: center;
  background: var(--up); box-shadow: 0 0 12px var(--up);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }
.brand h1 { font-size: 1.3rem; letter-spacing: -0.02em; }
.brand-sub { color: var(--text-muted); font-size: 0.85rem; }

#auth-bar { display: flex; gap: 0.5rem; align-items: center; }
#auth-error { color: var(--down); font-size: 0.85rem; }

/* Buttons & inputs */
button {
  background: var(--primary); color: #fff; border: none; border-radius: var(--radius);
  padding: 0.55rem 1.1rem; font-size: 0.95rem; font-weight: 600; cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
button:hover:not(:disabled) { background: var(--primary-hover); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: default; }
#stop-btn { background: var(--down); }
#stop-btn:hover:not(:disabled) { background: #ff5a68; }
#sign-out-btn { background: var(--surface-2); }

label { font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
input[type="text"], input[type="number"] {
  width: 100%; padding: 0.55rem 0.7rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); color: var(--text);
  font-size: 0.95rem; font-family: inherit;
}
input:focus { outline: none; border-color: var(--primary); }

/* Controls */
#controls {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}
.control-row { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field.grow { flex: 1 1 280px; }
.field:not(.grow) { width: 130px; }
.opt { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text-muted); opacity: 0.8; }
label code { font-family: ui-monospace, monospace; background: var(--surface-2); padding: 0.05rem 0.3rem; border-radius: 4px; text-transform: none; letter-spacing: 0; }

/* Crypto picker — equal-width grid cells so labels line up in clean columns */
#crypto-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.5rem; margin-bottom: 0.85rem; }
.crypto-chip {
  display: flex; align-items: center; gap: 0.5rem; cursor: pointer; user-select: none;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.5rem 0.7rem; font-size: 0.9rem; font-weight: 600; color: var(--text-muted);
  transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
}
.crypto-chip:hover { border-color: var(--primary); color: var(--text); }
.crypto-chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.crypto-chip .tick { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--border); transition: background 0.12s ease, box-shadow 0.12s ease; }
.crypto-chip .ticker-label { flex: none; min-width: 2.8rem; }
.crypto-chip .coin-name { margin-left: auto; font-weight: 400; opacity: 0.75; font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crypto-chip.checked { color: #fff; background: var(--primary); border-color: var(--primary); }
.crypto-chip.checked .tick { background: #fff; box-shadow: 0 0 8px rgba(255,255,255,0.6); }
.crypto-chip.checked .coin-name { opacity: 0.9; }

#status-bar { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.75rem; font-size: 0.85rem; color: var(--text-muted); }
#status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted); flex: none; }
#status-dot.idle { background: var(--text-muted); }
#status-dot.live { background: var(--up); box-shadow: 0 0 10px var(--up); animation: pulse 1.4s ease-in-out infinite; }
#status-dot.done { background: var(--primary); }
#status-dot.error { background: var(--down); }

/* Section titles */
.section-title { font-size: 1.05rem; margin-bottom: 0.75rem; letter-spacing: -0.01em; }

/* Charts grid */
#charts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 1rem; }
.sym-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.9rem 1rem 1rem; display: flex; flex-direction: column; gap: 0.6rem;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.sym-card.up { border-top: 2px solid var(--up); }
.sym-card.down { border-top: 2px solid var(--down); }
.sym-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.sym-name { font-weight: 700; font-size: 1.1rem; letter-spacing: 0.02em; }
.sym-right { display: flex; align-items: baseline; gap: 0.6rem; }
.sym-price { font-variant-numeric: tabular-nums; font-size: 1.15rem; font-weight: 600; }
.sym-change { font-variant-numeric: tabular-nums; font-size: 0.9rem; font-weight: 600; padding: 0.1rem 0.45rem; border-radius: 6px; }
.sym-change.up { color: var(--up); background: rgba(22,199,132,0.12); }
.sym-change.down { color: var(--down); background: rgba(234,57,67,0.12); }
.sym-change.flat { color: var(--text-muted); background: var(--surface-2); }
.sym-chart { width: 100%; height: 120px; display: block; }
.sym-stats { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; font-size: 0.78rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.sym-stats b { color: var(--text); font-weight: 600; margin-left: 0.2rem; }
.sym-waiting { color: var(--text-muted); font-size: 0.8rem; font-style: italic; }

/* News grid */
#news-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1rem; align-items: start; }
.news-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.news-card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.7rem 1rem; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.news-card-head .sym-name { font-size: 0.95rem; }
.news-count { font-size: 0.75rem; color: var(--text-muted); }
.news-list { list-style: none; max-height: 460px; overflow-y: auto; }
.news-item { padding: 0.7rem 1rem; border-bottom: 1px solid var(--border); display: flex; gap: 0.7rem; }
.news-item:last-child { border-bottom: none; }
.news-thumb { width: 52px; height: 52px; flex: none; border-radius: 6px; object-fit: cover; background: var(--surface-2); }
.news-body { min-width: 0; }
.news-title { font-size: 0.88rem; font-weight: 600; line-height: 1.3; }
.news-title a { color: var(--text); text-decoration: none; }
.news-title a:hover { color: var(--primary-hover); text-decoration: underline; }
.news-meta { margin-top: 0.2rem; font-size: 0.72rem; color: var(--text-muted); display: flex; gap: 0.4rem; flex-wrap: wrap; }
.news-meta .src { color: var(--primary-hover); font-weight: 600; }
.news-desc { margin-top: 0.3rem; font-size: 0.78rem; color: var(--text-muted); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.news-state { padding: 0.9rem 1rem; font-size: 0.82rem; color: var(--text-muted); }
.news-state.error { color: var(--down); }

/* Spinner */
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; margin-right: 0.4rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 1.5rem; z-index: 50; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); width: min(720px, 100%); max-height: 86vh; display: flex; flex-direction: column; animation: pop 0.18s ease; }
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 1.1rem; }
#summary-close { background: transparent; color: var(--text-muted); font-size: 1.5rem; line-height: 1; padding: 0 0.25rem; }
#summary-close:hover { color: var(--text); background: transparent; }
.modal-body { padding: 1.1rem 1.25rem; overflow: auto; }
.summary-meta { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.summary-chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0.3rem 0.8rem; font-size: 0.8rem; color: var(--text-muted); }
.summary-chip b { color: var(--text); }
.summary-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.summary-table th, .summary-table td { text-align: right; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.summary-table th { color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 0.68rem; letter-spacing: 0.04em; position: sticky; top: 0; background: var(--surface); }
.summary-table th:first-child, .summary-table td:first-child { text-align: left; font-weight: 700; }
.summary-table td.pos { color: var(--up); }
.summary-table td.neg { color: var(--down); }
.summary-table .table-wrap { overflow-x: auto; }

@media (max-width: 600px) {
  body { padding: 0.75rem; }
  #topbar { flex-direction: column; align-items: flex-start; gap: 0.6rem; }
  .field:not(.grow) { width: 100px; }
}
