  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

  * { box-sizing: border-box; margin: 0; padding: 0; }

  body {
    font-family: 'Inter', system-ui, sans-serif;
    background: #0d0d1a;
    color: #e2e8f0;
    min-height: 100vh;
    padding: 28px 32px;
    overflow-x: hidden;
  }

  /* Ambient background blobs */
  body::before {
    content: '';
    position: fixed;
    top: -200px; left: -150px;
    width: 600px; height: 600px;
    background: radial-gradient(circle, rgba(139,92,246,0.18) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
  }
  body::after {
    content: '';
    position: fixed;
    bottom: -150px; right: -100px;
    width: 500px; height: 500px;
    background: radial-gradient(circle, rgba(59,130,246,0.14) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
  }

  /* Everything above the blobs */
  .page { position: relative; z-index: 1; max-width: 1400px; margin: 0 auto; }

  /* ── Header ── */
  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
  }
  .header-left { display: flex; align-items: center; gap: 14px; }
  .logo {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, #8b5cf6, #3b82f6);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
  }
  h1 {
    font-size: 1.2rem;
    font-weight: 700;
    color: #f8fafc;
    letter-spacing: -0.02em;
  }
  .header-right { display: flex; align-items: center; gap: 10px; font-size: 0.75rem; color: #64748b; }

  /* ── Glass mixin ── */
  .glass {
    background: rgba(255,255,255,0.04);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 16px;
  }

  /* ── Market closed banner ── */
  #closed-banner {
    display: none;
    align-items: center;
    gap: 8px;
    background: rgba(251,146,60,0.08);
    border: 1px solid rgba(251,146,60,0.2);
    color: #fdba74;
    padding: 10px 16px;
    border-radius: 12px;
    margin-bottom: 20px;
    font-size: 0.82rem;
    font-weight: 500;
  }
  #closed-banner .dot { width: 7px; height: 7px; background: #f59e0b; border-radius: 50%; flex-shrink: 0; }

  /* ── Summary cards ── */
  .summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
  }
  .summary-card {
    padding: 18px 20px;
    position: relative;
    overflow: hidden;
  }
  .summary-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  }
  .summary-card .s-label {
    font-size: 0.68rem;
    font-weight: 500;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 8px;
  }
  .summary-card .s-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: #f1f5f9;
    letter-spacing: -0.03em;
    line-height: 1;
  }
  .summary-card .s-sub {
    font-size: 0.72rem;
    color: #475569;
    margin-top: 4px;
  }

  /* ── Status bar ── */
  .statusbar {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
    font-size: 0.75rem;
    color: #475569;
    flex-wrap: wrap;
  }
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
  }
  .badge .bdot { width: 6px; height: 6px; border-radius: 50%; }
  .badge-open { background: rgba(34,197,94,0.12); border: 1px solid rgba(34,197,94,0.25); color: #4ade80; }
  .badge-open .bdot { background: #4ade80; box-shadow: 0 0 6px #4ade80; animation: pulse 2s infinite; }
  .badge-closed { background: rgba(251,146,60,0.1); border: 1px solid rgba(251,146,60,0.2); color: #fb923c; }
  .badge-closed .bdot { background: #f59e0b; }
  @keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

  .sep { width: 1px; height: 14px; background: rgba(255,255,255,0.08); }

  /* ── Main grid ── */
  .main { display: grid; grid-template-columns: 320px 1fr; gap: 18px; }

  /* ── Chart panel ── */
  .chart-panel { padding: 22px; display: flex; flex-direction: column; }
  .panel-title {
    font-size: 0.7rem;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 18px;
  }
  .chart-wrap { flex: 1; display: flex; align-items: center; justify-content: center; }

  /* ── Cards panel ── */
  .cards-panel { display: flex; flex-direction: column; }
  .cards-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
  }
  .cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
  }

  /* ── Stock card ── */
  .stock-card {
    padding: 16px;
    cursor: default;
    transition: transform 0.15s, border-color 0.15s;
    position: relative;
    overflow: hidden;
  }
  .stock-card:hover { transform: translateY(-2px); }
  .stock-card::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(255,255,255,0.03) 0%, transparent 60%);
    pointer-events: none;
  }
  .stock-card.up { border-color: rgba(34,197,94,0.2); }
  .stock-card.up::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, transparent, #22c55e, transparent);
    border-radius: 16px 16px 0 0;
  }
  .stock-card.down { border-color: rgba(239,68,68,0.2); }
  .stock-card.down::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, transparent, #ef4444, transparent);
    border-radius: 16px 16px 0 0;
  }

  .card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
  .card-symbol { font-size: 0.9rem; font-weight: 700; color: #f1f5f9; letter-spacing: 0.01em; }
  .card-weight {
    font-size: 0.65rem;
    font-weight: 600;
    color: #475569;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.06);
    padding: 2px 7px;
    border-radius: 20px;
  }

  .card-ltp { font-size: 1.35rem; font-weight: 800; color: #f8fafc; letter-spacing: -0.02em; margin-bottom: 4px; }

  .card-day {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 12px;
  }
  .card-day .arrow { font-size: 0.65rem; }

  .card-divider { height: 1px; background: rgba(255,255,255,0.05); margin-bottom: 10px; }

  .card-meta { display: flex; flex-direction: column; gap: 4px; }
  .card-meta-row { display: flex; justify-content: space-between; align-items: center; }
  .card-meta-label { font-size: 0.67rem; color: #475569; }
  .card-meta-val { font-size: 0.72rem; font-weight: 600; color: #94a3b8; }

  .pnl-pill {
    display: inline-flex;
    align-items: center;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
  }
  .pnl-pill.up { background: rgba(34,197,94,0.12); color: #4ade80; }
  .pnl-pill.down { background: rgba(239,68,68,0.1); color: #f87171; }

  .stale-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.6rem;
    font-weight: 600;
    background: rgba(245,158,11,0.1);
    border: 1px solid rgba(245,158,11,0.2);
    color: #fbbf24;
    padding: 1px 6px;
    border-radius: 20px;
  }

  /* ── Colors ── */
  .green { color: #4ade80; }
  .red   { color: #f87171; }

  /* ── Toast ── */
  #toast {
    position: fixed;
    bottom: 28px; right: 28px;
    display: none;
    align-items: center;
    gap: 10px;
    background: rgba(127,29,29,0.9);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(239,68,68,0.3);
    color: #fca5a5;
    padding: 12px 18px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
    z-index: 100;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  }

  /* ── Responsive ── */
  @media (max-width: 960px) {
    .main { grid-template-columns: 1fr; }
    .summary { grid-template-columns: repeat(2, 1fr); }
    body { padding: 20px 18px; }
  }

  /* ── Ratings panel ── */
  .ratings-panel {
    margin-top: 18px;
    padding: 22px;
  }
  .ratings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
  }
  .ratings-header-left { display: flex; align-items: center; gap: 12px; }
  .ratings-timestamp { font-size: 0.7rem; color: #334155; }

  .calc-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, rgba(139,92,246,0.2), rgba(59,130,246,0.2));
    border: 1px solid rgba(139,92,246,0.35);
    color: #a78bfa;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 7px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: opacity 0.15s;
    font-family: inherit;
  }
  .calc-btn:hover { opacity: 0.85; }
  .calc-btn:disabled { opacity: 0.4; cursor: not-allowed; }

  .ratings-empty {
    text-align: center;
    padding: 32px 0;
    color: #334155;
    font-size: 0.82rem;
  }

  .ratings-loading {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 32px 0;
    color: #475569;
    font-size: 0.82rem;
  }
  .spinner {
    width: 16px; height: 16px;
    border: 2px solid rgba(139,92,246,0.2);
    border-top-color: #8b5cf6;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  .ratings-error {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 20px 0;
    color: #f87171;
    font-size: 0.82rem;
  }

  .ratings-table-wrap { display: none; overflow-x: auto; }
  .ratings-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
  }
  .ratings-table th {
    text-align: left;
    padding: 6px 12px;
    font-size: 0.65rem;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-bottom: 1px solid rgba(255,255,255,0.06);
  }
  .ratings-table th:not(:first-child) { text-align: center; }
  .ratings-table th:last-child { text-align: right; }
  .ratings-table td {
    padding: 9px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    vertical-align: middle;
  }
  .ratings-table td:not(:first-child) { text-align: center; }
  .ratings-table td:last-child { text-align: right; }
  .ratings-table tr:last-child td { border-bottom: none; }

  .rating-val { font-weight: 700; font-size: 0.85rem; }
  .rating-val.high  { color: #4ade80; }
  .rating-val.mid   { color: #f59e0b; }
  .rating-val.low   { color: #f87171; }

  .sentiment-pill {
    display: inline-flex;
    align-items: center;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: 20px;
  }
  .sentiment-pill.bullish { background: rgba(34,197,94,0.1);   color: #4ade80; }
  .sentiment-pill.neutral { background: rgba(148,163,184,0.1); color: #94a3b8; }
  .sentiment-pill.bearish { background: rgba(239,68,68,0.1);   color: #f87171; }

  .entry-price { font-weight: 600; color: #f1f5f9; }
  .vs-ltp { font-size: 0.72rem; font-weight: 600; }
  .vs-ltp.above { color: #94a3b8; }
  .vs-ltp.below { color: #f59e0b; }

  .td-symbol { font-weight: 700; color: #f1f5f9; }
  .td-rationale { font-size: 0.68rem; color: #475569; max-width: 220px; }

  /* Analyst target column */
  .td-target { white-space: nowrap; }
  .tgt-median { font-weight: 600; color: #f1f5f9; font-size: 0.78rem; }
  .tgt-upside { font-size: 0.68rem; font-weight: 700; }
  .tgt-upside.up   { color: #4ade80; }
  .tgt-upside.down { color: #f87171; }
  .tgt-range { font-size: 0.62rem; color: #475569; margin-top: 2px; }
  .tgt-none { color: #334155; }

  /* ── Chat panel ── */
  .chat-panel {
    margin-top: 18px;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 0;
  }
  .chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
  }
  .chat-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 60px;
    max-height: 420px;
    overflow-y: auto;
    padding-right: 4px;
    margin-bottom: 14px;
  }
  .chat-messages::-webkit-scrollbar { width: 4px; }
  .chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

  .chat-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.78rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
  }
  .chat-bubble.user {
    align-self: flex-end;
    background: rgba(139,92,246,0.18);
    border: 1px solid rgba(139,92,246,0.25);
    color: #e2e8f0;
    border-bottom-right-radius: 4px;
  }
  .chat-bubble.assistant {
    align-self: flex-start;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.07);
    color: #cbd5e1;
    border-bottom-left-radius: 4px;
  }
  .chat-bubble.thinking {
    align-self: flex-start;
    background: transparent;
    border: none;
    color: #334155;
    font-size: 0.72rem;
    padding: 4px 0;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .thinking-dots span {
    display: inline-block;
    width: 5px; height: 5px;
    background: #475569;
    border-radius: 50%;
    animation: blink 1.2s infinite;
  }
  .thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
  .thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
  @keyframes blink { 0%,80%,100% { opacity:0.2 } 40% { opacity:1 } }

  .chat-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
  }
  .chat-input {
    flex: 1;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    color: #f1f5f9;
    font-size: 0.78rem;
    font-family: inherit;
    padding: 10px 14px;
    resize: none;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.15s;
    max-height: 120px;
    overflow-y: auto;
  }
  .chat-input::placeholder { color: #334155; }
  .chat-input:focus { border-color: rgba(139,92,246,0.45); }
  .chat-send {
    background: linear-gradient(135deg, rgba(139,92,246,0.25), rgba(59,130,246,0.25));
    border: 1px solid rgba(139,92,246,0.4);
    color: #a78bfa;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .chat-send:hover { opacity: 0.8; }
  .chat-send:disabled { opacity: 0.35; cursor: not-allowed; }
  .chat-empty {
    text-align: center;
    padding: 18px 0 8px;
    color: #334155;
    font-size: 0.75rem;
  }
  .chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
  }
  .chat-suggestion {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    color: #475569;
    font-size: 0.7rem;
    padding: 5px 11px;
    border-radius: 20px;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.15s, color 0.15s;
  }
  .chat-suggestion:hover { border-color: rgba(139,92,246,0.35); color: #94a3b8; }

  /* ── PWA: CSV import + status bar ── */
  .import-bar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    margin-bottom: 20px;
  }
  .import-btn {
    display: inline-flex; align-items: center; gap: 7px;
    background: linear-gradient(135deg, rgba(139,92,246,0.25), rgba(59,130,246,0.25));
    border: 1px solid rgba(139,92,246,0.4);
    color: #a78bfa; font-size: 0.8rem; font-weight: 600;
    padding: 9px 16px; border-radius: 12px; cursor: pointer; font-family: inherit;
  }
  .import-btn:hover { opacity: 0.85; }
  .import-hint { font-size: 0.72rem; color: #475569; }
  #csv-input { display: none; }

  .empty-state {
    text-align: center; padding: 60px 20px; color: #64748b;
  }
  .empty-state h2 { font-size: 1.1rem; color: #e2e8f0; margin-bottom: 10px; font-weight: 700; }
  .empty-state p { font-size: 0.85rem; margin-bottom: 22px; line-height: 1.6; }

  .offline-banner {
    display: none; align-items: center; gap: 8px;
    background: rgba(251,146,60,0.08); border: 1px solid rgba(251,146,60,0.2);
    color: #fdba74; padding: 9px 14px; border-radius: 10px;
    margin-bottom: 16px; font-size: 0.78rem; font-weight: 500;
  }
