:root {
  --bg: #0b1020;
  --bg-2: #121933;
  --card: #182042;
  --card-2: #1d2754;
  --line: #2a3460;
  --text: #e8ecff;
  --muted: #8d97c8;
  --accent: #6c8cff;
  --accent-2: #4a6ae6;
  --bull: #2ecc71;
  --bear: #ef4444;
  --neutral: #f1c40f;
  --shadow: 0 6px 22px rgba(0,0,0,.35);
  --radius: 14px;
  --safe: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb; --bg-2: #eef0f8; --card: #ffffff; --card-2: #f4f6fc;
    --line: #e3e7f3; --text: #131838; --muted: #5b6694;
    --shadow: 0 6px 22px rgba(20,28,80,.08);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg), var(--bg-2));
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; cursor: pointer; border: 0; }
input, select, textarea { font: inherit; }
a { color: var(--accent); }

.view { display: none; }
.view.active { display: block; }

/* Auth */
#view-auth.active { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow);
}
.brand { font-size: 28px; margin: 4px 0; letter-spacing: -0.5px; }
.brand-sm { font-size: 18px; margin: 0; letter-spacing: -0.3px; }
.muted { color: var(--muted); font-size: 14px; margin: 0 0 16px; }
.tabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab { background: none; color: var(--muted); padding: 10px 14px; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-color: var(--accent); }
.auth-form { display: none; flex-direction: column; gap: 12px; }
.auth-form.active { display: flex; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-form input {
  padding: 12px 14px; border: 1px solid var(--line); background: var(--card-2);
  color: var(--text); border-radius: 10px;
}
button.primary {
  background: var(--accent); color: #fff; padding: 12px 16px;
  border-radius: 10px; font-weight: 600;
}
button.primary:hover { background: var(--accent-2); }
button.ghost {
  background: transparent; color: var(--muted); padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px;
}
button.ghost:hover { color: var(--text); }
.msg { color: var(--muted); font-size: 13px; min-height: 1em; margin-top: 8px; }
.msg.error { color: var(--bear); }
.msg.ok { color: var(--bull); }

/* App shell */
#view-app { padding-bottom: calc(72px + var(--safe)); }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: rgba(11,16,32,0.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
@media (prefers-color-scheme: light) {
  .topbar { background: rgba(246,247,251,0.85); }
}
.user-chip { display: flex; align-items: center; gap: 8px; }
.user-chip span { font-size: 13px; color: var(--muted); }

main { padding: 12px 16px 24px; max-width: 880px; margin: 0 auto; }

.pane { display: none; }
.pane.active { display: block; }

.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar { margin-bottom: 12px; }
.toolbar .dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--bear); margin-left: 4px;
}
.toolbar .dot.online { background: var(--bull); }

.cards { display: flex; flex-direction: column; gap: 12px; }

/* Card */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow);
}
.card.bull { border-left: 4px solid var(--bull); }
.card.bear { border-left: 4px solid var(--bear); }
.card.neutral { border-left: 4px solid var(--neutral); }
.card .head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.card .ticker { font-weight: 700; font-size: 18px; letter-spacing: -0.3px; }
.card .price { font-variant-numeric: tabular-nums; color: var(--muted); }
.card .type { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--card-2); color: var(--muted); }
.card .conf {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.card .conf.Strong { background: rgba(46,204,113,.18); color: var(--bull); }
.card .conf.Moderate { background: rgba(241,196,15,.18); color: var(--neutral); }
.card .conf.Weak { background: rgba(141,151,200,.18); color: var(--muted); }
.card .headline {
  margin: 12px 0 4px;
  padding: 12px 14px;
  background: var(--card-2);
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.55;
  border-left: 3px solid var(--accent);
}
.card.bull .headline { border-left-color: var(--bull); }
.card.bear .headline { border-left-color: var(--bear); }
.card.neutral .headline { border-left-color: var(--neutral); }

.why-details { margin-top: 10px; }
.why-details summary {
  cursor: pointer; padding: 6px 8px; border-radius: 8px;
  list-style: none; user-select: none;
}
.why-details summary::-webkit-details-marker { display: none; }
.why-details summary::before { content: "▸ "; color: var(--muted); }
.why-details[open] summary::before { content: "▾ "; }
.why-details summary:hover { background: var(--card-2); }

.card .meta {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 12px;
  margin-top: 10px; font-size: 13px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.card .meta b { color: var(--text); font-weight: 600; }
.card .why { margin-top: 10px; font-size: 13px; }
.card .signals { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.card .signal { font-size: 12px; color: var(--muted); }
.card .signal .arrow { display: inline-block; width: 1em; }
.card .signal.bull .arrow { color: var(--bull); }
.card .signal.bear .arrow { color: var(--bear); }
.card .actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.card .actions button { padding: 6px 10px; font-size: 12px; }

.inline-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px; margin-bottom: 14px;
}
.inline-form input {
  padding: 10px 12px; border: 1px solid var(--line); background: var(--card-2);
  color: var(--text); border-radius: 10px; min-width: 0;
}
.inline-form button { grid-column: span 1; }

/* Form grid (used for portfolio + watch + admin forms) */
.form-grid {
  display: grid; gap: 10px; margin-bottom: 14px;
  grid-template-columns: 1fr;
}
@media (min-width: 720px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1024px) {
  .form-grid { grid-template-columns: 1fr 1fr 1fr; }
}
.form-grid label {
  display: flex; flex-direction: column; gap: 6px; font-size: 13px;
  color: var(--muted); position: relative;
}
.form-grid label > span { font-weight: 600; color: var(--text); }
.form-grid input {
  padding: 10px 12px; border: 1px solid var(--line); background: var(--card-2);
  color: var(--text); border-radius: 10px;
}
.form-grid .form-submit {
  align-self: end; grid-column: 1 / -1; margin-top: 6px;
  width: max-content; min-width: 160px;
}
.hint { font-size: 11px; color: var(--muted); line-height: 1.4; }
.small { font-size: 13px; }

/* Autocomplete dropdown */
.autocomplete { position: relative; }
.ac-results {
  position: absolute; left: 0; right: 0; top: 100%; margin-top: 2px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  z-index: 30; box-shadow: var(--shadow);
  max-height: 280px; overflow-y: auto;
}
.ac-item {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.ac-item:last-child { border-bottom: 0; }
.ac-item:hover, .ac-item.active { background: var(--card-2); }
.ac-item .sym { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.ac-item .name { color: var(--muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-item .ex { color: var(--muted); font-size: 11px; }

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.55); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
  width: 100%; max-width: 460px;
}
.modal-card h3 { margin: 0 0 14px; }

/* msg-block (e.g. registration disabled banner) */
.msg-block {
  display: none; padding: 14px; border: 1px solid var(--line);
  background: var(--card-2); border-radius: 10px; color: var(--muted); font-size: 14px;
}
.auth-form.msg-block.active, .msg-block.active { display: block; }

.stack { display: flex; flex-direction: column; gap: 16px; }
.stack fieldset {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  background: var(--card); display: flex; flex-direction: column; gap: 10px;
}
.stack legend { padding: 0 6px; font-size: 13px; color: var(--muted); }
.stack label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.stack input[type=text], .stack input[type=number], .stack input:not([type=checkbox]) {
  padding: 10px 12px; border: 1px solid var(--line); background: var(--card-2);
  color: var(--text); border-radius: 10px;
}
.switch { display: flex; align-items: center; gap: 10px; flex-direction: row !important; }
.switch input[type=checkbox] { width: 20px; height: 20px; }

/* Mobile bottom nav */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; gap: 0;
  background: rgba(11,16,32,0.95); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + var(--safe));
}
@media (prefers-color-scheme: light) {
  .tabbar { background: rgba(246,247,251,0.95); }
}
.tabbar .tabbtn {
  flex: 1; background: transparent; color: var(--muted);
  padding: 10px 4px; font-size: 12px; border-radius: 10px;
}
.tabbar .tabbtn.active { background: var(--card); color: var(--text); }

/* Wider screens: top nav, no bottom bar */
@media (min-width: 720px) {
  .tabbar {
    position: static; padding: 0; background: transparent; backdrop-filter: none;
    border-top: 0; border-bottom: 1px solid var(--line);
    margin: 8px auto 16px; max-width: 880px;
  }
  .tabbar .tabbtn {
    flex: 0 0 auto; font-size: 14px; padding: 10px 16px; border-radius: 0;
    border-bottom: 2px solid transparent;
  }
  .tabbar .tabbtn.active { background: transparent; border-color: var(--accent); }
  #view-app { padding-bottom: 24px; }
  .card .meta { grid-template-columns: repeat(3, 1fr); }
  main { padding-top: 4px; }
}

@media (min-width: 1024px) {
  main { max-width: 1040px; }
  .card .meta { grid-template-columns: repeat(4, 1fr); }
}
