/* ============================================================
   Mercado Watch — Argentina / US Intelligence Desk
   Palette: void #0B0F14, panel #131922, raised #1B2330,
            ink #EDE8DC, ink-dim #93A0AD, sol #D9A441, celeste #6FA8D8, rust #C0563E
   Display: Fraunces · Body: IBM Plex Sans · Utility: IBM Plex Mono
   ============================================================ */

:root {
  --void: #0B0F14;
  --panel: #131922;
  --raised: #1B2330;
  --raised-2: #212B3A;
  --hairline: #2A3444;
  --ink: #EDE8DC;
  --ink-dim: #93A0AD;
  --ink-faint: #5C6979;
  --sol: #D9A441;
  --sol-soft: rgba(217, 164, 65, 0.14);
  --celeste: #6FA8D8;
  --celeste-soft: rgba(111, 168, 216, 0.14);
  --rust: #C0563E;
  --rust-soft: rgba(192, 86, 62, 0.16);
  --shadow-lg: 0 24px 60px -20px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--void);
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--celeste); }
input:focus-visible, button:focus-visible {
  outline: 2px solid var(--sol);
  outline-offset: 2px;
}

/* ---------- shared bits ---------- */
.btn {
  border: none;
  border-radius: 3px;
  padding: 0.7rem 1.3rem;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.btn-primary {
  background: linear-gradient(180deg, #E4B355, var(--sol));
  color: #1A1104;
  box-shadow: 0 1px 0 rgba(255,255,255,0.25) inset, 0 6px 16px -6px rgba(217,164,65,0.5);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 1px 0 rgba(255,255,255,0.3) inset, 0 10px 20px -6px rgba(217,164,65,0.6); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-sm { padding: 0.55rem 1rem; font-size: 0.8rem; }
.btn-ghost-sm {
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--ink-dim);
  border-radius: 3px;
  padding: 0.4rem 0.7rem;
  font-size: 0.78rem;
}
.btn-ghost-sm:hover { border-color: var(--celeste); color: var(--celeste); }

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse 900px 500px at 50% -10%, rgba(217,164,65,0.08), transparent),
    var(--void);
}
.sunburst {
  position: absolute;
  top: -30vw; left: 50%;
  width: 90vw; height: 90vw;
  transform: translateX(-50%);
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(217,164,65,0.07) 0deg 3deg, transparent 3deg 12deg);
  opacity: 0.6;
  pointer-events: none;
}
.login-card {
  position: relative;
  width: min(380px, 90vw);
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 2.6rem 2.2rem 2.2rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.login-seal { position: relative; width: 56px; height: 56px; margin: 0 auto 1.4rem; }
.seal-ring {
  position: absolute; inset: 0;
  border: 1.5px solid var(--sol);
  border-radius: 50%;
  opacity: 0.55;
}
.seal-sun {
  position: absolute; inset: 14px;
  background: var(--sol);
  border-radius: 50%;
  box-shadow: 0 0 24px rgba(217,164,65,0.5);
}
.login-eyebrow {
  margin: 0 0 0.3rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--celeste);
}
.login-title {
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: 1.7rem;
  line-height: 1.15;
  margin: 0 0 0.7rem;
  color: var(--ink);
}
.login-sub {
  margin: 0 0 1.6rem;
  color: var(--ink-dim);
  font-size: 0.88rem;
}
.login-card input[type="password"] {
  width: 100%;
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  color: var(--ink);
  padding: 0.75rem 0.9rem;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.login-card input[type="password"]::placeholder { color: var(--ink-faint); }
.login-card .btn { width: 100%; }
.login-error {
  min-height: 1.2rem;
  color: var(--rust);
  font-size: 0.82rem;
  margin: 0.8rem 0 0;
}
.login-impressum {
  position: relative;
  display: block;
  margin-top: 1.4rem;
  text-align: center;
  font-size: 0.76rem;
  color: var(--ink-faint);
  text-decoration: none;
}
.login-impressum:hover { color: var(--celeste); }

/* logo swap: CSS-drawn sun is the default; once /logo.png loads, body gets
   .has-logo and the real logo takes over */
.login-logo-img, .brand-logo { display: none; }
.has-logo .login-logo-img {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
}
.has-logo .seal-ring, .has-logo .seal-sun { display: none; }
.has-logo .brand-logo {
  display: block;
  height: 30px; width: 30px;
  flex: none;
  object-fit: contain;
  background: #fff;
  border-radius: 4px;
  padding: 3px;
}
.has-logo .brand-sun { display: none; }
.has-logo .login-logo-img {
  background: #fff;
  border-radius: 50%;
  padding: 10px;
}

.sidebar-foot {
  padding: 0.9rem 1.2rem;
  border-top: 1px solid var(--hairline);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
}
.sidebar-foot a { color: var(--ink-faint); text-decoration: none; }
.sidebar-foot a:hover { color: var(--celeste); }

/* ============================================================
   DASHBOARD LAYOUT
   ============================================================ */
.dashboard {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

/* ---------- sidebar ---------- */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.sidebar-head {
  padding: 1.4rem 1.2rem 1rem;
  border-bottom: 1px solid var(--hairline);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}
.brand { display: flex; align-items: center; gap: 0.65rem; }
.brand-sun {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #F0C878, var(--sol));
  flex: none;
}
.brand-title {
  margin: 0;
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: 1.05rem;
}
.brand-sub {
  margin: 0.1rem 0 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  text-transform: uppercase;
}
.sidebar-scroll { padding: 1rem 0.9rem 1.5rem; overflow-y: auto; flex: 1; }
.sidebar-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0.4rem 0.4rem 0.8rem;
}
.report-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.report-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-left: 2px solid transparent;
  border-radius: 3px;
  padding: 0.6rem 0.7rem;
  color: var(--ink-dim);
}
.report-item:hover { background: var(--raised); color: var(--ink); }
.report-item.active {
  background: var(--raised-2);
  border-left-color: var(--sol);
  color: var(--ink);
}
.report-item-date {
  display: block;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  color: var(--celeste);
  letter-spacing: 0.03em;
  margin-bottom: 0.2rem;
}
.report-item-headline {
  display: block;
  font-size: 0.82rem;
  line-height: 1.35;
}
.report-list-empty { color: var(--ink-faint); font-size: 0.82rem; padding: 0 0.4rem; }

/* ---------- main / masthead ---------- */
.main { min-height: 100vh; display: flex; flex-direction: column; }
.masthead {
  position: relative;
  overflow: hidden;
  padding: 2rem 2.4rem 1.6rem;
  border-bottom: 1px solid var(--hairline);
  background: linear-gradient(180deg, rgba(217,164,65,0.05), transparent 70%);
}
.masthead-watermark {
  position: absolute;
  top: -70px; right: -70px;
  width: 220px; height: 220px;
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(217,164,65,0.10) 0deg 4deg, transparent 4deg 16deg);
  pointer-events: none;
}
.masthead-row { position: relative; display: flex; justify-content: space-between; align-items: flex-end; gap: 1.5rem; flex-wrap: wrap; }
.masthead-eyebrow {
  margin: 0 0 0.5rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--celeste);
}
.masthead-headline {
  margin: 0;
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: clamp(1.4rem, 2.4vw, 2rem);
  line-height: 1.2;
  max-width: 40ch;
}
.masthead-meta {
  margin: 0.6rem 0 0;
  color: var(--ink-dim);
  font-size: 0.82rem;
  font-family: "IBM Plex Mono", monospace;
}
.masthead-actions { text-align: right; }
.masthead-actions-row { display: flex; gap: 0.6rem; align-items: center; justify-content: flex-end; }
.update-hint { margin: 0.5rem 0 0; color: var(--ink-faint); font-size: 0.74rem; max-width: 22ch; }

/* ---------- report body ---------- */
.report-body {
  flex: 1;
  padding: 2rem 2.4rem 4rem;
  max-width: 860px;
}
.report-body h2 {
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--sol);
  margin: 2.2rem 0 0.9rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--hairline);
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}
.report-body h2:first-child { margin-top: 0; }
.report-body h3 {
  font-family: "IBM Plex Sans", sans-serif;
  font-weight: 600;
  font-size: 1rem;
  color: var(--celeste);
  margin: 1.4rem 0 0.5rem;
}
.report-body p { color: var(--ink); margin: 0 0 0.9rem; }
.report-body ul, .report-body ol { padding-left: 1.3rem; margin: 0 0 1rem; }
.report-body li { margin-bottom: 0.45rem; }
.report-body strong { color: var(--sol); font-weight: 600; }
.report-body a { text-decoration: underline; text-underline-offset: 2px; }
.report-body code {
  background: var(--raised);
  border-radius: 3px;
  padding: 0.1rem 0.35rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85em;
}
.report-body p.alert-line {
  background: var(--rust-soft);
  border-left: 3px solid var(--rust);
  border-radius: 3px;
  padding: 0.6rem 0.9rem;
  margin: 0 0 1rem;
}
.report-body p.alert-line strong { color: var(--rust); }
.report-body blockquote {
  margin: 0 0 1rem;
  padding: 0.6rem 1rem;
  border-left: 2px solid var(--rust);
  background: var(--rust-soft);
  color: var(--ink-dim);
  font-size: 0.9rem;
}

/* sector tag stamps — auto-applied via JS to specific H2 titles */
.sector-tag {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border: 1px solid currentColor;
  border-radius: 2px;
  transform: rotate(-2deg);
  opacity: 0.85;
}
.sector-tag.ar { color: var(--celeste); }
.sector-tag.us { color: var(--ink-dim); }
.sector-tag.risk { color: var(--rust); }

/* ---------- empty state ---------- */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 2rem;
  gap: 0.5rem;
}
.empty-state-sun {
  width: 46px; height: 46px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #F0C878, var(--sol));
  margin-bottom: 0.8rem;
}
.empty-state h2 { font-family: "Fraunces", serif; margin: 0; font-size: 1.3rem; }
.empty-state p { color: var(--ink-dim); max-width: 34ch; margin: 0.3rem 0 1.3rem; }

/* ============================================================
   CHAT DRAWER
   ============================================================ */
.chat-toggle {
  position: fixed;
  right: 1.6rem; bottom: 1.6rem;
  z-index: 20;
  background: var(--raised-2);
  border: 1px solid var(--hairline);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.75rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
}
.chat-toggle:hover { border-color: var(--celeste); }
.chat-toggle-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--celeste);
  box-shadow: 0 0 8px var(--celeste);
}
.chat-drawer {
  position: fixed;
  right: 1.6rem; bottom: 5.2rem;
  z-index: 25;
  width: min(380px, calc(100vw - 3.2rem));
  height: min(520px, calc(100vh - 8rem));
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transform: translateY(12px) scale(0.98);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.16s ease, opacity 0.16s ease;
}
.chat-drawer.open { transform: translateY(0) scale(1); opacity: 1; pointer-events: auto; }
.chat-drawer-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--hairline);
  font-family: "Fraunces", serif;
  font-weight: 600;
}
.chat-log { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.9rem; }
.chat-hint { color: var(--ink-faint); font-size: 0.8rem; margin: 0; }
.chat-msg { font-size: 0.86rem; line-height: 1.5; }
.chat-msg.user { color: var(--celeste); }
.chat-msg.assistant { color: var(--ink); white-space: pre-wrap; }
.chat-msg.pending { color: var(--ink-faint); font-style: italic; }
.chat-form { display: flex; gap: 0.5rem; padding: 0.8rem; border-top: 1px solid var(--hairline); }
.chat-form input {
  flex: 1;
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  color: var(--ink);
  padding: 0.6rem 0.7rem;
  font-size: 0.85rem;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 860px) {
  .dashboard { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; border-right: none; border-bottom: 1px solid var(--hairline); max-height: 40vh; }
  .masthead { padding: 1.6rem 1.2rem; }
  .report-body { padding: 1.6rem 1.2rem 3rem; }
  .chat-drawer { right: 0.8rem; left: 0.8rem; width: auto; }
  .chat-toggle { right: 0.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ============================================================
   PRINT / PDF (via browser's native "Save as PDF")
   ============================================================ */
@media print {
  body { background: #fff; color: #111; font-size: 12pt; }
  .sidebar, .chat-toggle, .chat-drawer, .masthead-actions, .masthead-watermark,
  .empty-state, #download-pdf-btn, #update-btn { display: none !important; }
  .dashboard { display: block; }
  .main { display: block; }
  .masthead {
    background: none; border-bottom: 2px solid #111; padding: 0 0 0.8rem; margin-bottom: 1rem;
  }
  .masthead-eyebrow { color: #444; }
  .masthead-headline { color: #111; }
  .masthead-meta { color: #444; }
  .report-body { padding: 0; max-width: none; color: #111; }
  .report-body h2 { color: #111; border-bottom-color: #999; break-after: avoid; }
  .report-body h3 { color: #333; break-after: avoid; }
  .report-body strong { color: #111; }
  .report-body p, .report-body li { orphans: 3; widows: 3; }
  .sector-tag { color: #444 !important; border-color: #999; }
  a { color: #111; text-decoration: underline; }
}
