:root {
  --bg: #0f172a;
  --panel: #131f37;
  --panel-2: #16213e;
  --text: #e5e7eb;
  --subtext: #9fb0c8;
  --accent: #1d4ed8;
  --line: #294163;
  --pos: #34d399;
  --neg: #f87171;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  background: linear-gradient(180deg, #0b1222 0%, var(--bg) 100%);
  color: var(--text);
  line-height: 1.55;
}

a { color: #93c5fd; text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  max-width: 1560px;
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.55rem;
}

.topbar-right {
  color: var(--subtext);
  font-size: 0.92rem;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.nav-link {
  background: #0f223f;
  border: 1px solid #31517f;
  color: #dbeafe;
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 600;
  text-decoration: none;
}

.nav-link:hover { filter: brightness(1.08); text-decoration: none; }
.nav-link.active {
  background: var(--accent);
  border-color: #3f6bc0;
  color: #fff;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}

.col-12 { grid-column: span 12; }
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }
.col-3 { grid-column: span 3; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.card h2, .card h3 {
  margin: 0 0 10px;
  font-size: 1.02rem;
  color: #f1f5f9;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid #263d61;
}

.summary-row:last-child { border-bottom: none; }
.summary-row span:first-child { color: #b9cae3; }

.metric { font-size: 1.45rem; font-weight: 760; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--subtext); }
.empty {
  color: var(--subtext);
  background: #111b30;
  border: 1px dashed #335075;
  border-radius: 10px;
  padding: 10px;
}

.list { display: grid; gap: 8px; }
.item {
  background: #101d36;
  border: 1px solid #2c4368;
  border-radius: 10px;
  padding: 10px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid #2b4366;
  border-radius: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  border-bottom: 1px solid #2b4366;
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #0f223d;
  color: #bfd3ee;
  position: sticky;
  top: 0;
  z-index: 2;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84rem;
}

/* Timeline table improvements */
.timeline-wrap {
  overflow-x: auto;
  max-width: 100%;
}

.timeline-table {
  min-width: 800px;
}

.timeline-table th,
.timeline-table td {
  white-space: nowrap;
  min-width: 80px;
}

.timeline-table .sticky-col {
  position: sticky;
  left: 0;
  background: #0f223d;
  z-index: 3;
  min-width: 120px;
}

.timeline-table thead .sticky-col {
  z-index: 4;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.btn-page {
  background: #0f223f;
  border: 1px solid #31517f;
  color: #dbeafe;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.btn-page:hover:not(:disabled) {
  filter: brightness(1.15);
}

.btn-page:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-info {
  color: var(--subtext);
  font-size: 0.9rem;
}

/* Analysis page improvements */
.analysis-wrap {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 14px;
}

.analysis-content .markdown {
  padding: 16px;
  line-height: 1.7;
}

.analysis-content .markdown p {
  margin: 0.8em 0;
}

.analysis-content .markdown h1,
.analysis-content .markdown h2,
.analysis-content .markdown h3 {
  margin: 1.2em 0 0.6em;
  color: #f1f5f9;
}

.analysis-content .markdown h1 { font-size: 1.6rem; }
.analysis-content .markdown h2 { font-size: 1.3rem; }
.analysis-content .markdown h3 { font-size: 1.1rem; }

.draft-list button {
  width: 100%;
  text-align: left;
  background: #0f223f;
  color: #dbeafe;
  border: 1px solid #33598e;
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
}

.draft-list button.active {
  background: var(--accent);
  border-color: #3f6bc0;
  color: #fff;
}

.draft-sidebar { max-height: 80vh; overflow-y: auto; }
.draft-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: #0f223f;
  border: 1px solid #31517f;
  color: #dbeafe;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  margin-bottom: 6px;
}
.draft-btn.active { background: var(--accent); border-color: #3f6bc0; color: #fff; }
.draft-btn:hover { filter: brightness(1.08); }

.markdown h1, .markdown h2, .markdown h3 { margin: 0.6em 0 0.3em; }
.markdown p { margin: 0.3em 0; }
.markdown ul { margin: 0.2em 0 0.2em 1.2em; padding-left: 0; }
.markdown li { margin: 0.2em 0; }
.markdown blockquote { 
  border-left: 3px solid #365a8d; 
  margin: 0.8em 0; 
  padding-left: 1em; 
  color: #c1d2ea;
  background: rgba(54, 90, 141, 0.1);
  border-radius: 4px;
}
.markdown strong { color: #f3f4f6; font-weight: 700; }
.markdown em { color: #cbd5e1; font-style: italic; }

.markdown code.inline-code {
  background: #1e3a5f;
  color: #fbbf24;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: ui-monospace, monospace;
}

.markdown pre {
  background: #0a1628;
  border: 1px solid #2c4368;
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 1em 0;
}

.markdown pre code {
  background: none;
  color: #e2e8f0;
  font-size: 0.88rem;
  line-height: 1.5;
}

/* Markdown tables */
.markdown-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
}

.markdown-table th,
.markdown-table td {
  border: 1px solid #2c4368;
  padding: 10px;
}

.markdown-table th {
  background: #0f223d;
  color: #bfd3ee;
  font-weight: 600;
}

.markdown-table tr:nth-child(even) {
  background: rgba(22, 33, 62, 0.3);
}

.markdown-body {
  background: #101d36;
  border: 1px solid #2c4368;
  border-radius: 10px;
  padding: 12px;
  min-height: 320px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Legend bar */
.legend-bar {
  grid-column: span 12;
  position: relative;
}

.legend-toggle {
  background: #0f223f;
  border: 1px solid #31517f;
  color: #dbeafe;
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
}

.legend-toggle:hover { filter: brightness(1.15); }

.legend-items {
  display: none;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-top: 8px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.88rem;
  color: var(--subtext);
}

.legend-bar.open .legend-items { display: flex; }

/* Action cards for overview page */
.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.action-card {
  display: flex;
  gap: 12px;
  background: #101d36;
  border: 1px solid #2c4368;
  border-left: 4px solid #3b82f6;
  border-radius: 10px;
  padding: 14px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.action-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.action-card.positive {
  border-left-color: var(--pos);
  background: linear-gradient(90deg, rgba(52, 211, 153, 0.05) 0%, #101d36 100%);
}

.action-card.negative {
  border-left-color: var(--neg);
  background: linear-gradient(90deg, rgba(248, 113, 113, 0.05) 0%, #101d36 100%);
}

.action-card.neutral {
  border-left-color: #3b82f6;
}

.action-icon {
  font-size: 2rem;
  flex-shrink: 0;
}

.action-content {
  flex: 1;
}

.action-title {
  margin: 0 0 6px;
  font-size: 1rem;
  color: #f1f5f9;
  font-weight: 700;
}

.action-description {
  margin: 0;
  font-size: 0.9rem;
  color: var(--subtext);
  line-height: 1.5;
}

/* Sector cards for sectors page */
.sector-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.sector-card {
  background: #101d36;
  border: 1px solid #2c4368;
  border-radius: 10px;
  padding: 14px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.sector-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.sector-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #263d61;
}

.sector-icon {
  font-size: 1.5rem;
}

.sector-name {
  font-size: 1.05rem;
  color: #f1f5f9;
}

.sector-direction {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.sector-description {
  font-size: 0.88rem;
  color: var(--subtext);
  line-height: 1.5;
}

/* Watchlist sectors */
.watchlist-sectors {
  display: grid;
  gap: 16px;
}

.sector-group {
  background: #0f1d33;
  border: 1px solid #263d61;
  border-radius: 10px;
  padding: 12px;
}

.sector-group-title {
  margin: 0 0 10px;
  font-size: 1rem;
  color: #93c5fd;
  padding-bottom: 8px;
  border-bottom: 1px solid #263d61;
}

.watchlist-items {
  display: grid;
  gap: 10px;
}

.watchlist-item {
  background: #101d36;
  border: 1px solid #2c4368;
  border-radius: 8px;
  padding: 10px;
  font-size: 0.9rem;
}

.watchlist-item strong {
  color: #f1f5f9;
  display: block;
  margin-bottom: 6px;
}

.watchlist-item div {
  margin: 4px 0;
  line-height: 1.5;
}

/* Alerts */
.alert-group {
  margin-bottom: 20px;
}

.alert-date {
  font-size: 1.1rem;
  color: #93c5fd;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.alerts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.alert-item {
  background: #101d36;
  border: 1px solid #2c4368;
  border-radius: 10px;
  padding: 12px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.alert-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.alert-item.alert-rise {
  border-left: 3px solid var(--pos);
  background: linear-gradient(90deg, rgba(52, 211, 153, 0.05) 0%, #101d36 100%);
}

.alert-item.alert-fall {
  border-left: 3px solid var(--neg);
  background: linear-gradient(90deg, rgba(248, 113, 113, 0.05) 0%, #101d36 100%);
}

.alert-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid #263d61;
}

.alert-time {
  font-size: 0.85rem;
  color: var(--subtext);
  font-family: ui-monospace, monospace;
}

.alert-icon {
  font-size: 1.2rem;
}

.alert-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.alert-stock {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.alert-stock strong {
  font-size: 1rem;
  color: #f1f5f9;
}

.alert-ticker {
  font-size: 0.8rem;
  color: var(--subtext);
  font-family: ui-monospace, monospace;
}

.alert-detail {
  font-size: 0.95rem;
  font-weight: 600;
}

.alert-rise .alert-detail {
  color: var(--pos);
}

.alert-fall .alert-detail {
  color: var(--neg);
}

.alert-price {
  font-size: 0.9rem;
  color: #93c5fd;
  font-family: ui-monospace, monospace;
}

/* Responsive design */
@media (max-width: 1100px) {
  .col-8, .col-6, .col-4, .col-3 { grid-column: span 12; }
  .analysis-wrap { grid-template-columns: 1fr; }
}

@media (max-width: 800px) {
  .app { padding: 14px; }
  .topline { align-items: flex-start; flex-direction: column; }
  .topbar h1 { font-size: 1.3rem; }
  .alerts-grid { grid-template-columns: 1fr; }
  .action-grid { grid-template-columns: 1fr; }
  .sector-grid { grid-template-columns: 1fr; }
}

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 0.75rem; font-weight: 600; margin-left: 6px; }
.badge.pos { background: rgba(76,175,80,0.2); color: #4caf50; }
.badge.neg { background: rgba(244,67,54,0.2); color: #f44336; }
.badge.neutral { background: rgba(158,158,158,0.2); color: #9e9e9e; }
.badge.hold { background: rgba(33,150,243,0.2); color: #2196f3; }

/* Watchlist items */
.watchlist-items { display: flex; flex-direction: column; gap: 12px; }
.watchlist-item { background: var(--card-bg, #1e1e2e); padding: 12px 16px; border-radius: 8px; border-left: 3px solid #444; }
.watchlist-item-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }

/* Sector cards */
.sector-topstock { font-size: 0.9rem; margin-top: 4px; }
.sector-volume { margin-top: 2px; color: #aaa; }
