/* ============================================================
   GARP Terminal — motyw "edytorialny terminal finansowy"
   Fraunces (display) · IBM Plex Sans (UI) · IBM Plex Mono (dane)
   ============================================================ */
:root {
  --bg: #0a0e16;
  --bg-deep: #070a11;
  --panel: #0f1521;
  --panel-2: #141c2b;
  --panel-3: #18212f;
  --line: #222d3f;
  --line-soft: #1a2333;
  --text: #e9eef7;
  --muted: #8a97ac;
  --faint: #5c687d;
  --accent: #34e6a8;
  --accent-dim: #1f7f63;
  --pos: #3ad6a0;
  --warn: #e8b54a;
  --neg: #f0697b;
  /* aliasy zgodne ze starym kodem */
  --green: var(--pos);
  --yellow: var(--warn);
  --red: var(--neg);
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-sans: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --radius: 14px;
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.7);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  letter-spacing: 0.005em;
  -webkit-font-smoothing: antialiased;
}

/* Atmosfera tła: gradientowe poświaty + hairline grid */
.bg-atmos {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 600px at 12% -8%, rgba(52, 230, 168, 0.10), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, rgba(106, 166, 255, 0.07), transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
}
.bg-atmos::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 56px 56px;
  opacity: 0.25;
  mask-image: radial-gradient(circle at 50% 0%, #000 0%, transparent 80%);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--neg); min-height: 1.2em; margin: 10px 0 0; font-size: 0.9rem; }
code { font-family: var(--font-mono); font-size: 0.85em; color: var(--accent); }

/* --- Pola i przyciski --------------------------------------------------- */
input,
button,
textarea {
  font-size: 1rem;
  font-family: var(--font-sans);
  padding: 13px 15px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s;
}
input::placeholder,
textarea::placeholder { color: var(--faint); }
input:focus,
textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(52, 230, 168, 0.16); }
button {
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  border: none;
  color: #04150f;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.01em;
}
button:hover { filter: brightness(1.08); transform: translateY(-1px); }
button:active { transform: translateY(0); }

/* --- Logowanie ---------------------------------------------------------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 38px 34px 30px;
  width: 100%;
  max-width: 390px;
  text-align: center;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.brandmark, .brand {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  color: var(--text);
  text-transform: uppercase;
}
.brandmark-tick, .brand-tick { color: var(--accent); letter-spacing: -1px; margin-right: 6px; }
.brandmark-sep, .brand-sep { color: var(--accent); }
.login-card h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 2rem;
  margin: 18px 0 2px;
  letter-spacing: -0.01em;
}
.login-sub { font-size: 0.85rem; margin: 0 0 22px; }
.login-card input, .login-card button { width: 100%; margin-top: 12px; }
.login-card button { margin-top: 16px; padding: 14px; }

/* --- Topbar ------------------------------------------------------------- */
.topbar {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between;
  padding: 16px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  background: rgba(10, 14, 22, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.brand { font-size: 0.88rem; }
.search { display: flex; gap: 8px; flex: 1 1 280px; max-width: 460px; }
.search input { flex: 1; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.04em; }
.search input::placeholder { text-transform: none; letter-spacing: normal; }
.search button { white-space: nowrap; }

main { padding: clamp(18px, 4vw, 40px); max-width: 1240px; margin: 0 auto; }

/* --- Placeholder / loader ---------------------------------------------- */
.placeholder { padding: 64px 20px; text-align: center; color: var(--muted); max-width: 540px; margin: 0 auto; }
.ph-glyph {
  font-size: 3rem; color: var(--accent); font-family: var(--font-display);
  display: inline-block; margin-bottom: 10px; opacity: 0.8;
}
.ph-hint { font-size: 0.85rem; margin-top: 14px; }

/* --- Historia tickerów -------------------------------------------------- */
.history { margin: 28px auto 0; max-width: 440px; text-align: left; }
.history-head { font-family: var(--font-mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); margin-bottom: 11px; }
.history-item { display: flex; gap: 8px; margin-bottom: 8px; }
.history-go {
  flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 15px; border-radius: 11px; cursor: pointer; font-weight: 500;
}
.history-go:hover { background: var(--panel-3); border-color: var(--accent); filter: none; transform: none; }
.history-tk { font-family: var(--font-mono); font-weight: 600; letter-spacing: 0.05em; }
.history-date { font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); }
.history-del {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  width: 44px; border-radius: 11px; cursor: pointer; font-size: 1.2rem; line-height: 1; padding: 0;
}
.history-del:hover { border-color: var(--neg); color: var(--neg); background: var(--panel-2); filter: none; transform: none; }
.loader { padding: 56px 20px; text-align: center; color: var(--muted); display: flex; gap: 12px; align-items: center; justify-content: center; }
.spin { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Reveal (staggered) ------------------------------------------------- */
#result > * { animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
#result > *:nth-child(2) { animation-delay: 0.05s; }
#result > *:nth-child(3) { animation-delay: 0.1s; }
#result > *:nth-child(4) { animation-delay: 0.15s; }
#result > *:nth-child(5) { animation-delay: 0.2s; }
#result > *:nth-child(n + 6) { animation-delay: 0.24s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* --- Werdykt ------------------------------------------------------------ */
.verdict {
  --ring: var(--muted);
  display: flex; flex-wrap: wrap; align-items: center; gap: clamp(16px, 3vw, 30px);
  background: linear-gradient(135deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: 18px; padding: 24px clamp(20px, 3vw, 30px); margin-bottom: 22px;
  position: relative; overflow: hidden;
}
.verdict.buy { --ring: var(--pos); }
.verdict.hold { --ring: var(--warn); }
.verdict.avoid { --ring: var(--neg); }
.verdict::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--ring);
}
.score-circle {
  --score: 0;
  --circ: 276.46; /* 2π·44 */
  position: relative; flex: 0 0 auto;
  width: 112px; height: 112px;
  display: grid; place-items: center;
  font-family: var(--font-mono);
}
.score-svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.score-track { fill: none; stroke: var(--line); stroke-width: 7; }
.score-prog {
  fill: none; stroke: var(--ring); stroke-width: 7; stroke-linecap: round;
  stroke-dasharray: var(--circ);
  stroke-dashoffset: calc(var(--circ) * (1 - var(--score) / 100));
  filter: drop-shadow(0 0 5px color-mix(in srgb, var(--ring) 45%, transparent));
  transition: stroke-dashoffset 0.95s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.score-inner { position: relative; z-index: 1; display: grid; place-items: center; line-height: 1; }
.score-num { font-size: 1.95rem; font-weight: 600; letter-spacing: -0.02em; }
.score-cap { font-size: 0.66rem; color: var(--muted); margin-top: 4px; letter-spacing: 0.08em; }
.verdict-main { flex: 1 1 240px; min-width: 0; }
.ticker-tag {
  display: inline-block; font-family: var(--font-mono); font-size: 0.78rem; font-weight: 600;
  letter-spacing: 0.12em; color: var(--accent); border: 1px solid var(--accent-dim);
  border-radius: 6px; padding: 2px 8px; margin-bottom: 8px;
}
.verdict-main h2 {
  font-family: var(--font-display); font-weight: 600; font-size: clamp(1.5rem, 3.4vw, 2.1rem);
  margin: 0 0 10px; line-height: 1.1; letter-spacing: -0.01em;
}
.verdict-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.badge {
  display: inline-block; padding: 5px 14px; border-radius: 999px; font-weight: 600; font-size: 0.9rem;
  font-family: var(--font-mono); letter-spacing: 0.02em; border: 1px solid transparent;
}
.badge.buy { background: rgba(58, 214, 160, 0.14); color: var(--pos); border-color: rgba(58, 214, 160, 0.4); }
.badge.hold { background: rgba(232, 181, 74, 0.14); color: var(--warn); border-color: rgba(232, 181, 74, 0.4); }
.badge.avoid { background: rgba(240, 105, 123, 0.14); color: var(--neg); border-color: rgba(240, 105, 123, 0.4); }
.price-box { text-align: right; margin-left: auto; }
.price-box .price-val { font-family: var(--font-mono); font-size: 1.4rem; font-weight: 600; margin-top: 2px; }

/* --- Siatka i karty ----------------------------------------------------- */
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.section-title {
  font-family: var(--font-display); font-weight: 600; font-size: 1.35rem; letter-spacing: -0.01em;
  margin: 30px 0 14px; display: flex; align-items: center; gap: 10px;
}
.section-title::before { content: ""; width: 18px; height: 2px; background: var(--accent); border-radius: 2px; }
.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
  transition: border-color 0.2s, transform 0.2s;
}
.card:hover { border-color: #2c3a51; }
.card h3 {
  margin: 0 0 14px; font-size: 0.78rem; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.13em; font-family: var(--font-mono);
}

/* --- Kategorie scoringu ------------------------------------------------- */
.cat-row { margin-bottom: 16px; }
.cat-row:last-child { margin-bottom: 0; }
.cat-row .cat-head { display: flex; justify-content: space-between; gap: 10px; font-size: 0.92rem; margin-bottom: 6px; }
.cat-head > span:last-child { font-family: var(--font-mono); font-weight: 600; }
.bar { height: 9px; background: var(--panel-3); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; animation: grow 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
@keyframes grow { from { width: 0 !important; } }

/* --- Karty wskaźników --------------------------------------------------- */
.metric { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line-soft); }
.metric:last-child { border-bottom: none; }
.metric .label { color: var(--muted); font-size: 0.9rem; display: inline-flex; align-items: center; }
.metric .val { font-family: var(--font-mono); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.metric .val.good { color: var(--pos); }
.metric .val.mid { color: var(--warn); }
.metric .val.bad { color: var(--neg); }

/* --- Tooltipy ----------------------------------------------------------- */
.tip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; margin-left: 6px; border-radius: 50%;
  background: var(--panel-3); border: 1px solid var(--line); color: var(--muted);
  font-size: 9px; font-style: italic; font-weight: 700; cursor: help; position: relative; vertical-align: middle; font-family: var(--font-display);
}
.tip:hover { color: var(--accent); border-color: var(--accent); }
.tip:hover::after {
  content: attr(data-tip);
  position: absolute; left: 50%; bottom: 150%; transform: translateX(-50%);
  width: 250px; max-width: 64vw; padding: 10px 12px; z-index: 100;
  background: var(--bg-deep); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  font-size: 12px; font-style: normal; font-weight: 400; line-height: 1.45; text-align: left;
  white-space: normal; box-shadow: var(--shadow); font-family: var(--font-sans);
}
.tip:hover::before {
  content: ""; position: absolute; left: 50%; bottom: 150%; transform: translate(-50%, 100%);
  border: 6px solid transparent; border-top-color: var(--line); z-index: 101;
}

/* --- Wykresy ------------------------------------------------------------ */
.chart-card { min-height: 290px; }
.chart-card canvas { max-height: 240px; }

/* --- Forward / makro / flagi ------------------------------------------- */
.status-pill { font-size: 0.72rem; font-family: var(--font-mono); padding: 3px 10px; border-radius: 999px; background: var(--panel-3); border: 1px solid var(--line); color: var(--muted); vertical-align: middle; }
.chips { display: flex; flex-wrap: wrap; gap: 9px; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px; font-size: 0.85rem; }
.chip.flag { background: rgba(232, 181, 74, 0.1); border-color: rgba(232, 181, 74, 0.38); color: var(--warn); }
.macro-bar { display: flex; flex-wrap: wrap; gap: clamp(16px, 4vw, 34px); }
.macro-bar .m { font-size: 0.85rem; }
.macro-bar .m b { display: block; font-size: 1.2rem; font-family: var(--font-mono); font-weight: 600; margin-top: 2px; }

/* --- Czat AI ------------------------------------------------------------ */
.ai-card { background: linear-gradient(180deg, var(--panel-2), var(--panel)); }
.ai-card h4 { margin: 14px 0 4px; font-family: var(--font-display); font-weight: 600; }
.ai-card ul { margin: 4px 0 10px; padding-left: 20px; }
.ai-card p { margin: 6px 0; }
.chat-msgs { max-height: 480px; overflow-y: auto; display: flex; flex-direction: column; gap: 11px; padding-right: 4px; }
.chat-msg { padding: 11px 14px; border-radius: 14px; font-size: 0.93rem; line-height: 1.55; max-width: 92%; }
.chat-msg p { margin: 5px 0; }
.chat-ai { background: var(--panel-3); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 5px; }
.chat-user { background: rgba(52, 230, 168, 0.12); border: 1px solid var(--accent-dim); align-self: flex-end; border-bottom-right-radius: 5px; white-space: pre-wrap; }
.chat-srch { margin-top: 9px; font-size: 0.78rem; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 7px; font-family: var(--font-mono); }
.chat-status { color: var(--muted); font-style: italic; display: inline-flex; align-items: center; gap: 9px; }
.chat-dots { display: inline-flex; gap: 3px; }
.chat-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: 0.4; animation: cdot 1s infinite; }
.chat-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes cdot { 0%, 100% { opacity: 0.3; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-3px); } }
.chat-input-row { display: flex; gap: 9px; margin-top: 14px; }
.chat-input-row textarea { flex: 1; resize: vertical; min-height: 46px; }
.chat-input-row button { align-self: stretch; padding: 0 20px; }
.chat-hint { font-size: 0.76rem; margin-top: 9px; }

/* --- Scrollbary --------------------------------------------------------- */
.chat-msgs::-webkit-scrollbar { width: 8px; }
.chat-msgs::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

/* --- Responsywność ------------------------------------------------------ */
@media (max-width: 680px) {
  .grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .search { max-width: none; }
  .verdict { gap: 16px; }
  .score-circle { width: 84px; height: 84px; }
  .score-circle .score-num { font-size: 1.6rem; }
  .price-box { margin-left: 0; text-align: left; width: 100%; }
  .chat-msg { max-width: 96%; }
}
@media (prefers-reduced-motion: reduce) {
  #result > *, .bar > span, .chat-dots span, .spin { animation: none !important; }
}
