:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-strong: #f8f6ef;
  --ink: #1f211d;
  --muted: #706b60;
  --line: #ded7c8;
  --line-strong: #c9bfad;
  --green: #2f8f63;
  --green-soft: #dff1e6;
  --red: #b54b45;
  --red-soft: #f5dedb;
  --amber: #a9751f;
  --amber-soft: #f5ead2;
  --blue: #356f8d;
  --blue-soft: #dcebf1;
  --shadow: 0 18px 40px rgba(31, 33, 29, 0.09);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.96), rgba(244, 241, 234, 0.96)),
    repeating-linear-gradient(90deg, rgba(31, 33, 29, 0.035) 0, rgba(31, 33, 29, 0.035) 1px, transparent 1px, transparent 72px);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: inherit;
}

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-panel {
  width: min(100%, 520px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.brand-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
}

.mark {
  width: 14px;
  height: 14px;
  border: 2px solid var(--green);
  border-left-color: var(--amber);
  border-bottom-color: var(--blue);
  border-radius: 50%;
  display: inline-block;
}

.gate h1,
.topbar h1 {
  margin: 12px 0 0;
  font-size: 2rem;
  line-height: 1.06;
}

.gate-copy,
.fine-print,
.panel-head p,
.schema-list p,
.source-note p,
.filings-head p {
  color: var(--muted);
  line-height: 1.5;
}

.gate-form {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}

.password-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.form-error,
.error-text {
  color: var(--red);
}

.shake {
  animation: shake 0.42s ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  50% {
    transform: translateX(6px);
  }
  75% {
    transform: translateX(-3px);
  }
}

.workspace {
  width: min(100%, 1480px);
  margin: 0 auto;
  padding: 20px;
}

.topbar,
.panel-head,
.filings-head,
.tool-row,
.refresh-tools,
.run-signal,
.topbar-actions,
.mini-row,
.detail-actions {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
}

.topbar-actions,
.detail-actions,
.tool-row,
.refresh-tools {
  gap: 8px;
  flex-wrap: wrap;
}

.button,
.toggle,
.icon-text {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 13px;
  min-height: 42px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  white-space: nowrap;
}

.button:hover,
.toggle:hover,
.icon-text:hover {
  border-color: var(--ink);
}

.button:disabled,
.toggle:disabled {
  cursor: wait;
  opacity: 0.62;
}

.button.primary {
  background: var(--ink);
  color: #fffdf8;
  border-color: var(--ink);
}

.button.ghost,
.icon-text {
  background: transparent;
}

.toggle.active {
  color: #0f3f2b;
  background: var(--green-soft);
  border-color: #9ed2b5;
}

.status-strip,
.message,
.control-band,
.panel,
.metric {
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
  border-radius: 8px;
}

.status-strip {
  min-height: 68px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.run-signal {
  gap: 12px;
}

.run-signal div {
  display: grid;
  gap: 3px;
}

.run-signal span:last-child,
#lastRefreshText {
  color: var(--muted);
  font-size: 0.88rem;
}

.status-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(47, 143, 99, 0.38);
  animation: pulse 1.7s infinite;
}

.status-strip.is-error .status-dot {
  background: var(--red);
  animation: none;
}

.status-strip.is-paused .status-dot {
  background: var(--amber);
  animation: none;
}

.status-dot.loading {
  background: var(--blue);
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(47, 143, 99, 0.38);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(47, 143, 99, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(47, 143, 99, 0);
  }
}

.message {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.message.error {
  background: var(--red-soft);
  border-color: #e4aaa5;
}

.message.warning {
  background: var(--amber-soft);
  border-color: #e6ca8c;
}

.message.info {
  background: var(--blue-soft);
  border-color: #a8cad9;
}

.control-band {
  display: grid;
  grid-template-columns: minmax(240px, 1.4fr) auto minmax(220px, 0.8fr);
  gap: 10px;
  align-items: end;
  padding: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  padding: 10px 11px;
  min-height: 42px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 118px;
  text-transform: none;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 143, 99, 0.12);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 12px 0;
}

.metric {
  padding: 14px;
}

.metric span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 1.9rem;
  line-height: 1;
}

.metric p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 12px;
  margin-top: 12px;
}

.panel {
  padding: 14px;
  box-shadow: 0 1px 0 rgba(31, 33, 29, 0.04);
}

.panel-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head.compact {
  align-items: flex-start;
}

.panel h2,
.panel h3 {
  margin: 0;
}

.panel h2 {
  font-size: 1.12rem;
}

.panel h3 {
  font-size: 0.95rem;
}

.panel-head p,
.filings-head p {
  margin: 4px 0 0;
  font-size: 0.88rem;
}

.filters {
  display: grid;
  grid-template-columns: 150px 106px 150px auto;
  gap: 8px;
  align-items: end;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 4px;
}

.checkbox-label input {
  width: 18px;
  min-height: 18px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

th,
td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8f6ef;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.is-selected {
  background: #f8fbf5;
}

tbody tr:last-child td {
  border-bottom: 0;
}

td strong {
  display: block;
}

td span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.positive {
  color: var(--green);
  font-weight: 800;
}

.negative {
  color: var(--red);
  font-weight: 800;
}

.muted,
.empty-state {
  color: var(--muted);
}

.empty-state {
  margin: 0;
  line-height: 1.5;
}

.flag-cloud,
td:nth-child(8) {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.flag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 7px;
  color: #3f3520;
  background: var(--amber-soft);
  border: 1px solid #e7cb91;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
}

.quality {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 76px;
  min-height: 26px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 900;
  border: 1px solid;
}

.quality.good {
  color: #0f4e33;
  background: var(--green-soft);
  border-color: #9ed2b5;
}

.quality.watch {
  color: #28566c;
  background: var(--blue-soft);
  border-color: #a8cad9;
}

.quality.fragile {
  color: #7a5317;
  background: var(--amber-soft);
  border-color: #e7cb91;
}

.quality.risk {
  color: #7c2c28;
  background: var(--red-soft);
  border-color: #e4aaa5;
}

.sparkline {
  width: 92px;
  height: 32px;
}

.sparkline polyline {
  fill: none;
  stroke: var(--green);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.alerts-panel {
  align-self: start;
}

.alert-item {
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

.alert-item:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.alert-item div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.alert-item p {
  margin: 6px 0 10px;
  color: var(--muted);
  line-height: 1.42;
}

.mini-row {
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.ticker-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.ticker-summary div {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  border-radius: 8px;
  padding: 10px;
}

.ticker-summary span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.ticker-summary strong {
  display: block;
  margin-top: 6px;
  font-size: 1.15rem;
}

.detail-chart {
  width: 100%;
  height: 170px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
}

.research-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.note-field {
  margin-top: 10px;
}

.flag-block,
.filings-block {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

.flag-block {
  display: grid;
  grid-template-columns: minmax(180px, 0.7fr) minmax(0, 1.3fr);
  gap: 12px;
}

.flag-block p {
  color: var(--muted);
  margin: 6px 0 0;
  line-height: 1.5;
}

.filings-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.filing-list {
  display: grid;
  gap: 8px;
}

.filing-item {
  display: grid;
  grid-template-columns: 76px 104px 1fr;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--ink);
  text-decoration: none;
  border-radius: 8px;
  padding: 9px 10px;
}

.filing-item:hover {
  border-color: var(--ink);
}

.filing-item span,
.filing-item p {
  color: var(--muted);
  margin: 0;
  font-size: 0.86rem;
}

.tools-panel textarea {
  min-height: 260px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
}

.schema-list,
.source-note {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 12px;
}

.schema-list span,
.source-note strong {
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 900;
  text-transform: uppercase;
}

.schema-list p,
.source-note p {
  margin: 6px 0 0;
  font-size: 0.9rem;
}

@media (max-width: 1120px) {
  .main-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .alerts-panel {
    align-self: auto;
  }

  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .workspace {
    padding: 14px;
  }

  .topbar,
  .status-strip,
  .panel-head,
  .filings-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .detail-actions,
  .refresh-tools {
    width: 100%;
  }

  .topbar-actions .button,
  .detail-actions .button,
  .refresh-tools .toggle {
    flex: 1 1 auto;
  }

  .control-band,
  .metric-grid,
  .ticker-summary,
  .research-grid,
  .flag-block {
    grid-template-columns: 1fr;
  }

  .control-band .button {
    width: 100%;
  }

  .password-row {
    grid-template-columns: 1fr;
  }

  .gate-panel {
    padding: 24px;
  }

  .gate h1,
  .topbar h1 {
    font-size: 1.65rem;
  }

  .filing-item {
    grid-template-columns: 1fr;
  }
}
