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

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --link: #7dd3fc;
  --accent: #3b82f6;
  --positive: #22c55e;
  --negative: #ef4444;
  --radius: 8px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#last-updated {
  font-size: 12px;
  color: var(--text-muted);
}

/* Main Grid */
main {
  padding: 16px;
}

/* Weather Bar */
.weather-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.weather-card {
  flex: 1 1 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.loading-card {
  justify-content: center;
  width: 100%;
}

.weather-city {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 48px;
}

.weather-emoji {
  font-size: 24px;
  line-height: 1;
}

.weather-temp {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.weather-label {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
}

.weather-details {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr 360px;
  gap: 14px;
}

.panel-toyo     { grid-column: 1 / 3; }
.panel-bookmarks { grid-column: 1 / -1; }

/* Panel */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow: hidden;
}

.panel h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.panel-title-link {
  color: inherit;
  text-decoration: none;
}

.panel-title-link:hover {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Category Tabs */
.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
}

.tab-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  padding: 3px 8px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text); border-color: var(--accent); }
.tab-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Article List */
.article-list {
  max-height: 480px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.article-list::-webkit-scrollbar { width: 4px; }
.article-list::-webkit-scrollbar-track { background: transparent; }
.article-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.article-card {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.article-card:last-child { border-bottom: none; }

.article-card.has-image {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.article-img {
  width: 80px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--surface2);
}

.article-body {
  flex: 1;
  min-width: 0;
}

.article-card a,
.article-body a {
  display: block;
  color: var(--link);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 3px;
}

.article-card a:hover,
.article-body a:hover { text-decoration: underline; color: #bae6fd; }

.article-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.article-source {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.article-card time {
  font-size: 11px;
  color: var(--text-muted);
}

/* Stock Cards */
.stock-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 10px;
}

.stock-card:last-child { margin-bottom: 0; }

.stock-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 8px;
}

.stock-name {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.stock-values {
  text-align: right;
}

.stock-price {
  display: block;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stock-change {
  display: block;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.stock-change.positive { color: var(--positive); }
.stock-change.negative { color: var(--negative); }

#panel-stocks canvas {
  display: block;
  width: 100% !important;
  height: 70px !important;
}

/* Search bar in header */
.search-form {
  display: flex;
  flex: 1;
  max-width: 480px;
  gap: 6px;
  margin: 0 20px;
}

.search-form input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.search-form input:focus { border-color: var(--accent); }
.search-form input::placeholder { color: var(--text-muted); }

.btn-search {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  padding: 6px 14px;
  white-space: nowrap;
  transition: border-color 0.15s;
}

.btn-search:hover { border-color: var(--accent); color: var(--accent); }

/* Bookmarks */
.bookmark-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bookmark-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  max-width: 360px;
}

.bookmark-item a {
  color: var(--link);
  text-decoration: none;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 280px;
}

.bookmark-item a:hover { text-decoration: underline; }

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-primary:hover { background: #2563eb; }

/* States */
.loading {
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px 0;
  text-align: center;
}

.error-msg {
  color: var(--negative);
  font-size: 13px;
  padding: 12px 0;
}

.wsj-fallback {
  padding: 16px 0;
  text-align: center;
}

.wsj-fallback p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.wsj-fallback a.btn-primary {
  display: inline-block;
  text-decoration: none;
}

/* Footer */
footer {
  margin-top: 24px;
  border-top: 1px solid var(--border);
  padding: 16px;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}

.footer-note {
  font-size: 12px;
  color: var(--text-muted);
}

.footer-credit {
  font-size: 12px;
  color: var(--text-muted);
}

.footer-author {
  color: var(--text);
  font-weight: 600;
}

.footer-credit a {
  color: var(--link);
  text-decoration: none;
}

.footer-credit a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 960px) {
  .grid {
    grid-template-columns: 1fr 1fr;
  }
  #panel-stocks, .panel-toyo, .panel-bookmarks {
    grid-column: 1 / -1;
  }
  .search-form {
    max-width: 280px;
    margin: 0 10px;
  }
}

@media (max-width: 600px) {
  .search-form { display: none; }
}

@media (max-width: 600px) {
  .grid { grid-template-columns: 1fr; }
  header h1 { font-size: 16px; }
}
