:root {
  --color-bg: #f7f7f5;
  --color-surface: #ffffff;
  --color-text: #1f2328;
  --color-muted: #5b6169;
  --color-border: #e1e4e8;
  --color-healthy: #1a7f37;
  --color-healthy-bg: #e6f4ea;
  --color-warning: #b42318;
  --color-warning-bg: #fdeceb;
  --color-wait: #7a5b00;
  --color-wait-bg: #fff6dd;
  --color-accent: #2a5adb;
  --radius: 10px;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

a { color: var(--color-accent); }

.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  max-width: 1100px;
  margin: 0 auto;
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
  color: var(--color-text);
}

.main-nav {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.main-nav a {
  text-decoration: none;
  color: var(--color-text);
  font-weight: 600;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
}

.main-nav a.active,
.main-nav a:hover {
  background: var(--color-bg);
  color: var(--color-accent);
}

.benchmark-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  padding: 0.6rem 1rem 0.8rem;
  max-width: 1100px;
  margin: 0 auto;
  font-size: 0.92rem;
}

/* Shared by the benchmark strip and the portfolio totals bar — both reuse
   the same label/value metric markup. */
.metric {
  display: flex;
  flex-direction: column;
}

.metric-label {
  color: var(--color-muted);
  font-size: 0.78rem;
}

.metric-value {
  font-weight: 700;
}

.metric-value.positive { color: var(--color-healthy); }
.metric-value.negative { color: var(--color-warning); }

.stale-warning {
  color: var(--color-warning);
  font-weight: 600;
}

.notifications {
  max-width: 1100px;
  margin: 0.5rem auto 0;
  padding: 0 1rem;
}

.notification-banner {
  background: var(--color-wait-bg);
  border: 1px solid var(--color-wait);
  color: var(--color-wait);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
}

.notification-banner button {
  background: none;
  border: none;
  color: inherit;
  font-weight: 700;
  cursor: pointer;
}

.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
  min-height: 60vh;
}

.loading-message,
.empty-state,
.error-state {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  color: var(--color-muted);
}

.error-state {
  border-color: var(--color-warning);
  color: var(--color-warning);
}

/* Risk ladder */
.ladder-intro {
  margin-bottom: 1rem;
}

.ladder-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ladder-rung {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.ladder-rung > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
}

.ladder-rung > summary::-webkit-details-marker { display: none; }

.ladder-rung .rung-rating {
  background: var(--color-bg);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.85rem;
  color: var(--color-muted);
  flex-shrink: 0;
}

.ladder-rung .rung-body {
  padding: 0 1rem 1rem;
  color: var(--color-muted);
}

.ladder-rung[data-current="true"] {
  border-color: var(--color-accent);
}

/* Screener */
.screener-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.screener-controls input[type="search"],
.screener-controls select {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.95rem;
}

.screener-controls label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.verdict-section {
  margin-bottom: 1.5rem;
}

.verdict-section h2 {
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stock-card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 640px) {
  .stock-card-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 960px) {
  .stock-card-grid { grid-template-columns: repeat(3, 1fr); }
}

.stock-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stock-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.stock-card-name {
  font-weight: 700;
}

.stock-card-symbol {
  color: var(--color-muted);
  font-size: 0.85rem;
}

.stock-card-price {
  text-align: right;
}

.stock-card-price .change.positive { color: var(--color-healthy); }
.stock-card-price .change.negative { color: var(--color-warning); }

.verdict-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  width: fit-content;
}

.verdict-badge.looks-healthy { background: var(--color-healthy-bg); color: var(--color-healthy); }
.verdict-badge.warning-signs { background: var(--color-warning-bg); color: var(--color-warning); }
.verdict-badge.wait { background: var(--color-wait-bg); color: var(--color-wait); }

.stock-card-reason {
  font-size: 0.9rem;
  color: var(--color-muted);
}

.check-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem 0.5rem;
  font-size: 0.85rem;
}

.check-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
}

.check-outcome { font-weight: 700; }
.check-outcome.pass { color: var(--color-healthy); }
.check-outcome.fail { color: var(--color-warning); }
.check-outcome.unknown { color: var(--color-muted); }

.sparkline { color: var(--color-muted); width: 100%; height: 32px; }
.sparkline.sparkline-up { color: var(--color-healthy); }
.sparkline.sparkline-down { color: var(--color-warning); }
.sparkline-empty { font-size: 0.8rem; color: var(--color-muted); }

.stock-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

button, .button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: 0.45rem 0.75rem;
  color: var(--color-text);
  text-decoration: none;
}

button.primary, .button.primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
  font-weight: 700;
}

button.link {
  border: none;
  background: none;
  color: var(--color-accent);
  padding: 0.2rem;
  text-decoration: underline;
}

/* Portfolio */
.purchase-form {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}

@media (min-width: 640px) {
  .purchase-form { grid-template-columns: repeat(2, 1fr); }
  .purchase-form .full-width { grid-column: 1 / -1; }
}

.purchase-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.purchase-form input, .purchase-form select, .purchase-form textarea {
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font: inherit;
}

.field-error {
  color: var(--color-warning);
  font-size: 0.82rem;
  font-weight: 500;
}

.holdings-table-wrap { overflow-x: auto; }

table.holdings-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

table.holdings-table th, table.holdings-table td {
  padding: 0.6rem 0.7rem;
  text-align: right;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  font-size: 0.9rem;
}

table.holdings-table th:first-child, table.holdings-table td:first-child {
  text-align: left;
}

.positive { color: var(--color-healthy); }
.negative { color: var(--color-warning); }

.portfolio-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin: 1rem 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
}

.benchmark-verdict {
  font-weight: 700;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  background: var(--color-wait-bg);
  border: 1px solid var(--color-wait);
  color: var(--color-wait);
}

.benchmark-verdict.positive { background: var(--color-healthy-bg); border-color: var(--color-healthy); color: var(--color-healthy); }
.benchmark-verdict.negative { background: var(--color-warning-bg); border-color: var(--color-warning); color: var(--color-warning); }

.concentration-warning, .holding-flag {
  color: var(--color-warning);
  font-weight: 600;
  font-size: 0.85rem;
}

/* Stock detail */
.detail-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.check-detail-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.check-detail-list > li {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
}

.check-detail-list summary {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-weight: 600;
}

.check-detail-list .detail-text {
  margin: 0.5rem 0 0;
  color: var(--color-muted);
  font-size: 0.92rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: 1rem; }
}

.modal-panel {
  background: var(--color-surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.25rem;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
}

@media (min-width: 640px) {
  .modal-panel { border-radius: var(--radius); }
}

.modal-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

.site-footer {
  max-width: 1100px;
  margin: 2rem auto 1rem;
  padding: 0 1rem;
  color: var(--color-muted);
  font-size: 0.82rem;
  text-align: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
