:root {
  --bg: #071018;
  --surface: #0d1923;
  --surface-2: #122330;
  --line: #203543;
  --text: #e8f1f5;
  --muted: #8197a4;
  --accent: #2dd4a8;
  --accent-2: #45a7ff;
  --danger: #ff6b72;
  --warning: #f6c85f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: radial-gradient(circle at 80% -10%, #12334a 0, transparent 30%), var(--bg); color: var(--text); min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.shell { display: grid; grid-template-columns: 245px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 20px; border-right: 1px solid var(--line); background: rgba(7, 16, 24, .92); backdrop-filter: blur(16px); display: flex; flex-direction: column; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 42px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #02110d; font-weight: 900; }
.brand strong, .brand small { display: block; }
.brand small { color: var(--muted); margin-top: 3px; }
nav { display: grid; gap: 8px; }
.nav-item { border: 0; border-radius: 10px; padding: 12px 14px; text-align: left; color: var(--muted); background: transparent; }
.nav-item:hover, .nav-item.active { color: var(--text); background: var(--surface-2); box-shadow: inset 3px 0 var(--accent); }
.sidebar-note { margin-top: auto; padding: 14px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: 12px; line-height: 1.6; }

main { padding: 30px clamp(24px, 4vw, 58px) 60px; overflow: hidden; }
.topbar { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin-bottom: 30px; }
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(26px, 4vw, 38px); margin-bottom: 0; letter-spacing: -.03em; }
h2 { margin-bottom: 18px; font-size: 20px; }
.eyebrow { color: var(--accent); font-size: 11px; letter-spacing: .18em; font-weight: 800; margin-bottom: 7px; }
.muted { color: var(--muted); line-height: 1.6; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.pill { display: inline-flex; padding: 7px 11px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); }
.pill.good { color: var(--accent); background: rgba(45, 212, 168, .1); border-color: rgba(45, 212, 168, .35); }
.pill.bad { color: var(--danger); background: rgba(255, 107, 114, .1); border-color: rgba(255, 107, 114, .35); }
.pill.neutral { color: var(--muted); }

.view { display: none; animation: reveal .18s ease; }
.view.active { display: block; }
@keyframes reveal { from { opacity: .4; transform: translateY(5px); } }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric, .panel { background: linear-gradient(145deg, rgba(18, 35, 48, .92), rgba(10, 23, 32, .92)); border: 1px solid var(--line); border-radius: 14px; }
.metric { padding: 20px; min-height: 132px; }
.metric span, .metric small { display: block; color: var(--muted); }
.metric strong { display: block; font-size: 25px; margin: 16px 0 5px; }
.panel { padding: 24px; margin-bottom: 18px; box-shadow: 0 18px 55px rgba(0, 0, 0, .14); }
.panel-grid { display: grid; gap: 18px; }
.panel-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.panel-heading h2 { margin-bottom: 0; }
.button { border: 1px solid transparent; border-radius: 9px; padding: 10px 15px; color: var(--text); background: var(--surface-2); }
.button.primary { color: #00110d; background: var(--accent); font-weight: 800; }
.button.secondary { border-color: var(--line); }
.button.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.button.danger { background: var(--danger); color: #1a0305; font-weight: 800; }
.button:disabled { opacity: .45; cursor: not-allowed; }

.flow { display: flex; align-items: center; gap: 9px; margin: 26px 0; overflow-x: auto; }
.flow-node { min-width: 105px; border: 1px solid var(--line); background: var(--bg); padding: 12px; border-radius: 9px; }
.flow-node span, .flow-node small { display: block; }
.flow-node small { color: var(--muted); margin-top: 4px; }
.flow i { color: var(--accent); font-style: normal; }
.code-box { min-height: 120px; max-height: 330px; overflow: auto; background: #050c12; color: #a9c5d4; border: 1px solid #162936; border-radius: 10px; padding: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.check-list { list-style: none; padding: 0; margin: 20px 0 0; display: grid; gap: 14px; }
.check-list li::before { content: "✓"; color: var(--accent); font-weight: 900; margin-right: 10px; }

label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
input, select, textarea { width: 100%; color: var(--text); background: #08131c; border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px; outline: none; }
textarea { resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(45, 212, 168, .08); }
.inline-form { display: flex; gap: 12px; align-items: end; margin: 22px 0; }
.grow { flex: 1; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; align-items: start; margin: 22px 0; }
.form-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.selection-sector { grid-column: span 2; }
.align-end { align-self: end; }
.full { grid-column: 1 / -1; }
.search-results { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.search-result { border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--text); padding: 7px 11px; }
.quote-card { min-height: 90px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding: 18px; border: 1px solid var(--line); border-radius: 11px; background: rgba(5, 12, 18, .55); }
.quote-card div span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.quote-card div strong { font-size: 18px; }
.empty { display: grid; place-items: center; color: var(--muted); }
canvas { width: 100%; height: 390px; display: block; border-radius: 10px; background: #050c12; }

.table-wrap { overflow-x: auto; margin-top: 18px; }
table { width: 100%; border-collapse: collapse; min-width: 620px; }
th, td { padding: 13px 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 12px; font-weight: 600; }
.empty-cell { color: var(--muted); text-align: center; padding: 35px; }
.positive { color: var(--danger); }
.negative { color: var(--accent); }
.analysis-result { min-height: 220px; padding: 22px; background: #08131c; border: 1px solid var(--line); border-radius: 11px; }
.analysis-result h3 { margin: 22px 0 10px; }
.score-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.score-box { padding: 14px; background: var(--surface-2); border-radius: 9px; }
.score-box span, .score-box strong { display: block; }
.score-box span { color: var(--muted); font-size: 12px; }
.score-box strong { margin-top: 8px; font-size: 20px; }
.danger-panel { border-color: rgba(255, 107, 114, .28); }
.warning { color: var(--warning); font-size: 12px; line-height: 1.6; }
.task-progress { min-height: 170px; display: flex; align-items: center; justify-content: center; gap: 16px; }
.task-progress p { margin: 5px 0 0; }
.spinner { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.recommendation-grid { display: grid; gap: 14px; margin: 18px 0 26px; }
.recommendation-card { padding: 20px; border: 1px solid var(--line); border-radius: 12px; background: linear-gradient(145deg, rgba(18, 35, 48, .74), rgba(7, 16, 24, .82)); }
.recommendation-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.recommendation-head > div { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.recommendation-head > strong { color: var(--accent); font-size: 28px; white-space: nowrap; }
.recommendation-head > strong small { color: var(--muted); font-size: 12px; }
.stock-code { padding: 0; border: 0; color: var(--text); background: transparent; font-size: 18px; font-weight: 800; text-align: left; }
.stock-code:hover { color: var(--accent); }
.risk-tag { padding: 4px 8px; border-radius: 999px; font-size: 11px; border: 1px solid var(--line); }
.risk-low { color: var(--accent); border-color: rgba(45, 212, 168, .35); }
.risk-medium { color: var(--warning); border-color: rgba(246, 200, 95, .35); }
.risk-high { color: var(--danger); border-color: rgba(255, 107, 114, .35); }
.recommendation-card > p { color: #bdd0d9; line-height: 1.75; margin: 16px 0; }
.recommendation-metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.recommendation-metrics div { padding: 11px; border-radius: 8px; background: #08131c; }
.recommendation-metrics span, .recommendation-metrics strong { display: block; }
.recommendation-metrics span { color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.card-actions { display: flex; gap: 9px; margin-top: 16px; }

dialog { color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: min(470px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 5, 9, .75); backdrop-filter: blur(4px); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
#toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; max-width: 420px; padding: 12px 16px; border-radius: 9px; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); transform: translateY(120px); opacity: 0; transition: .2s ease; }
#toast.show { transform: translateY(0); opacity: 1; }
#toast.error { border-color: rgba(255, 107, 114, .5); color: #ffc4c7; }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-grid.two { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; width: 100%; height: auto; padding: 16px; }
  .brand { margin-bottom: 16px; }
  nav { display: flex; overflow-x: auto; }
  .nav-item { white-space: nowrap; }
  .sidebar-note { display: none; }
  main { padding: 22px 15px 45px; }
  .topbar { align-items: flex-start; }
  .top-actions { flex-direction: column; align-items: flex-end; }
  .metric-grid, .form-grid, .form-grid.compact { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
  .selection-sector { grid-column: auto; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .quote-card, .score-row, .recommendation-metrics { grid-template-columns: repeat(2, 1fr); }
  .recommendation-head { flex-direction: column; }
}
