/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: #1d1d1f;
  background: #f5f5f7;
}

/* ============================================
   APP LAYOUT (no page scroll)
   ============================================ */
.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.header-brand {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px 20px;
}

.header-label {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.6);
}

.header-situation {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.02em;
}

.header-threat-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  background: rgba(255,255,255,0.08);
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.12);
}

.header-threat-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
}

.header-threat {
  font-size: 14px;
  font-weight: 600;
  color: #f0c14b;
}

.admin-link {
  font-size: 14px;
  font-weight: 500;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
}
.admin-link:hover { color: #fff; text-decoration: underline; }

/* Main: content left | tickers right */
.main {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 16px;
  padding: 16px;
}

.stream-column {
  flex-shrink: 0;
  width: 33%;
  max-width: 33%;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.main-content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto 1fr;
  gap: 16px;
}

/* ============================================
   GRID PLACEMENT
   ============================================ */
.block-situations { grid-column: 1 / -1; grid-row: 1; }
.block-news { grid-column: 1; grid-row: 2; }
.block-tweets { grid-column: 2; grid-row: 2; }
.block-chat { grid-column: 1 / -1; grid-row: 3; }

/* ============================================
   BLOCKS
   ============================================ */
.block {
  background: #fff;
  border: 1px solid #e5e5e7;
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.block-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #86868b;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.block-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* Stream */
.stream-column .block-stream { flex: none; min-height: 0; }
.stream-box {
  flex: none;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 100%;
  background: #000;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

.stream-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #86868b;
  font-size: 14px;
}

.stream-embed {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 8px;
}

.block-offline { justify-content: center; }
.block-offline .stream-offline-msg { color: #86868b; font-size: 14px; }

/* News */
.news-item {
  padding: 8px 0;
  border-bottom: 1px solid #e5e5e7;
}
.news-item:last-child { border-bottom: none; }
.news-item a { color: #1d1d1f; text-decoration: none; }
.news-item a:hover { color: #0066cc; text-decoration: underline; }
.news-source { display: block; font-size: 12px; color: #86868b; margin-top: 2px; }

/* Situations */
.situations-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  flex-direction: row;
  align-items: center;
}

.situation-item {
  font-size: 14px;
}
.situation-item a {
  color: #1d1d1f;
  text-decoration: none;
}
.situation-item a:hover {
  color: #0066cc;
  text-decoration: underline;
}
.situation-rank {
  font-weight: 600;
  color: #86868b;
  margin-right: 4px;
}
.block-situations .block-content { overflow: visible; }

/* Tweets */
.tweet-item { padding: 10px 0; border-bottom: 1px solid #e5e5e7; }
.tweet-item:last-child { border-bottom: none; }
.tweet-content { font-size: 14px; }
.tweet-link { font-size: 13px; color: #0066cc; }
.tweet-meta { margin-top: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tweet-datetime { font-size: 12px; color: #86868b; }
.tweet-stars { font-size: 14px; }
.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: #86868b;
  padding: 0 2px;
}
.star-btn:hover:not(:disabled) { color: #1d1d1f; }

/* Chat */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.chat-username {
  font-size: 12px;
  color: #86868b;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-name-edit {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  color: #86868b;
  padding: 2px;
}
.chat-name-edit:hover { color: #0066cc; }

.chat-messages {
  flex: 1;
  min-height: 80px;
  overflow-y: auto;
  padding: 8px 0;
  margin-bottom: 8px;
  border: 1px solid #e5e5e7;
  border-radius: 8px;
  background: #fafafa;
}

.chat-msg { padding: 4px 10px; font-size: 13px; }
.chat-msg-name { font-weight: 600; color: #1d1d1f; margin-right: 6px; }
.chat-msg-text { color: #333; }
.chat-msg-time { font-size: 11px; color: #86868b; margin-left: 6px; }

.chat-form { display: flex; gap: 8px; flex-shrink: 0; }
.chat-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #e5e5e7;
  border-radius: 8px;
  font-size: 14px;
}
.chat-send {
  padding: 8px 16px;
  background: #0066cc;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.chat-send:hover { opacity: 0.9; }

.loading, .empty { color: #86868b; font-size: 14px; }

/* ============================================
   SIDEBAR (right): Markets + Polymarket
   ============================================ */
.sidebar {
  flex-shrink: 0;
  width: 440px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.sidebar-section {
  background: #fff;
  border: 1px solid #e5e5e7;
  border-radius: 12px;
  padding: 14px 16px;
  overflow: hidden;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #86868b;
  margin-bottom: 12px;
}

.tickers-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ticker-widget {
  height: 140px;
  min-height: 140px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e5e5e7;
}

/* Polymarket */
.sidebar-polymarket .sidebar-title { margin-bottom: 10px; }
.polymarket-box { font-size: 14px; }
.polymarket-question {
  font-weight: 500;
  color: #1d1d1f;
  margin-bottom: 10px;
  line-height: 1.4;
}
.polymarket-odds-list { display: flex; flex-direction: column; gap: 6px; }
.polymarket-outcome {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f2;
}
.polymarket-outcome:last-child { border-bottom: none; }
.polymarket-label { color: #1d1d1f; }
.polymarket-odds { font-weight: 600; color: #0066cc; }
.polymarket-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 13px;
  color: #0066cc;
  text-decoration: none;
}
.polymarket-link:hover { text-decoration: underline; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1100px) {
  .main { flex-direction: column; }
  .stream-column {
    width: 100%;
    max-width: 100%;
    max-height: 33vh;
    order: -1;
  }
  .stream-box { max-height: 28vh; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
  }
  .sidebar-section {
    flex: 1 1 300px;
    min-width: 0;
  }
  .tickers-stack {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
  }
  .ticker-widget {
    flex: 1 1 160px;
    min-width: 160px;
    height: 140px;
  }
}

@media (max-width: 768px) {
  html, body { overflow: auto; }
  .app { min-height: 100vh; overflow: visible; }
  .main {
    flex-direction: column;
    padding: 12px;
  }
  .main-content {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr 1fr auto;
    gap: 12px;
  }
  .stream-column { max-height: 30vh; order: -1; }
  .stream-box { max-height: 26vh; }
  .block-situations { grid-column: 1; grid-row: 1; }
  .block-news { grid-column: 1; grid-row: 2; }
  .block-tweets { grid-column: 1; grid-row: 3; }
  .block-chat { grid-column: 1; grid-row: 4; }
  .header { padding: 10px 14px; }
  .header-situation { font-size: 16px; }
  .header-brand { gap: 8px 12px; }
  .block { padding: 12px 14px; }
  .block-title { font-size: 10px; }
  .chat-form { flex-wrap: wrap; }
  .chat-input { min-width: 0; }
  .star-btn { padding: 6px; min-width: 36px; min-height: 36px; touch-action: manipulation; }
  .chat-send { padding: 10px 18px; min-height: 44px; touch-action: manipulation; }
  .chat-input { min-height: 44px; padding: 10px 14px; }
  .situations-list { flex-direction: column; align-items: flex-start; gap: 6px; }
  .situation-item a { display: inline-block; padding: 4px 0; min-height: 44px; line-height: 36px; }
  .sidebar { width: 100%; flex-direction: column; }
  .sidebar-section { padding: 12px 14px; }
  .tickers-stack { flex-direction: column; gap: 12px; }
  .ticker-widget {
    flex: none;
    min-width: 0;
    height: 140px;
    min-height: 130px;
  }
  .news-item a, .tweet-content { padding: 6px 0; min-height: 44px; line-height: 1.4; }
}

@media (max-width: 480px) {
  .main { padding: 10px; gap: 12px; }
  .main-content { gap: 12px; }
}

/* ============================================
   ADMIN
   ============================================ */
/* Admin page: allow scroll (main dashboard uses overflow:hidden) */
html:has(.admin-wrap),
body:has(.admin-wrap) {
  overflow: auto;
  height: auto;
  min-height: 100vh;
}
.admin-wrap {
  min-height: 100vh;
  background: #f5f5f7;
  padding: 24px 20px;
}

.admin-header {
  max-width: 1100px;
  margin: 0 auto 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.admin-header h1 { font-size: 24px; font-weight: 600; }
.admin-logout { font-size: 15px; color: #0066cc; text-decoration: none; }
.admin-logout:hover { text-decoration: underline; }

.admin-grid {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 800px) {
  .admin-grid { grid-template-columns: 1fr; }
}

.admin-card {
  background: #fff;
  border: 1px solid #e5e5e7;
  border-radius: 12px;
  padding: 20px 24px;
}

.admin-card h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: #1d1d1f;
}

.admin-form-group { margin-bottom: 14px; }
.admin-form-group:last-of-type { margin-bottom: 16px; }
.admin-form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: #1d1d1f;
}

.admin-form-group input,
.admin-form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #e5e5e7;
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}

.admin-form-group input:focus,
.admin-form-group textarea:focus {
  outline: none;
  border-color: #0066cc;
}

.admin-form-group textarea { min-height: 80px; resize: vertical; }

.admin-checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
}
.admin-checkbox-label input { width: auto; }
.admin-hint { font-size: 13px; color: #86868b; margin-top: 6px; }

.admin-btn {
  padding: 10px 18px;
  background: #0066cc;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}
.admin-btn:hover { opacity: 0.9; }
.admin-btn-sm { padding: 6px 12px; font-size: 13px; }
.admin-btn-danger { background: #dc3545; }
.admin-btn-danger:hover { opacity: 0.9; }
.admin-list-item-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.admin-delete-form { display: inline-block; flex-shrink: 0; }

.admin-section { margin-top: 16px; }
.admin-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #e5e5e7;
}
.admin-list-item:last-child { border-bottom: none; }
.admin-list-item .title { flex: 1; font-size: 14px; padding-right: 12px; }
.admin-list-item .actions { display: flex; gap: 8px; }
.admin-success { color: #28a745; font-size: 14px; margin-bottom: 12px; }
.err { color: #c00; font-size: 14px; margin-top: 6px; }
.admin-card-full { grid-column: 1 / -1; }
.admin-empty { color: #86868b; font-size: 14px; padding: 12px 0; }

.admin-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f7;
  padding: 24px;
}
.admin-page .admin-card { width: 100%; max-width: 400px; }
.admin-page h1 { font-size: 22px; margin-bottom: 20px; }
