:root {
  --bg: #101315;
  --panel: #181d1f;
  --panel-strong: #202629;
  --line: #313a3d;
  --text: #eef3f1;
  --soft: #c6d0cc;
  --muted: #92a09b;
  --teal: #35d0b2;
  --amber: #f1b94f;
  --blue: #79a8ff;
  --rose: #e9707b;
  --ink: #0d1112;
  --shadow: 0 14px 34px rgba(0, 0, 0, .24);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.page-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 32px clamp(18px, 4vw, 48px) 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(53, 208, 178, .08), transparent);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.6px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(28px, 4vw, 44px);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 21px;
}

h3 {
  margin-bottom: 3px;
  font-size: 16px;
}

.subtitle {
  max-width: 820px;
  margin-bottom: 0;
  color: var(--soft);
  line-height: 1.75;
}

.header-actions {
  display: flex;
  align-items: flex-end;
}

.header-actions a,
button {
  min-height: 40px;
  padding: 9px 13px;
  color: var(--teal);
  background: transparent;
  border: 1px solid rgba(53, 208, 178, .45);
  border-radius: 6px;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.header-actions a:hover {
  border-color: var(--teal);
  background: rgba(53, 208, 178, .08);
}

.layout {
  width: min(1440px, calc(100% - 36px));
  margin: 22px auto 56px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 200px 105px auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  color: var(--text);
  background: #111618;
  border: 1px solid var(--line);
  border-radius: 6px;
}

input:focus,
select:focus,
button:focus,
a:focus {
  outline: 2px solid rgba(53, 208, 178, .55);
  outline-offset: 2px;
}

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

.summary-strip div,
.selected-panel,
.template-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-strip div {
  padding: 14px 16px;
}

.summary-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.summary-strip strong {
  display: block;
  margin-top: 7px;
  color: var(--text);
  font-size: 26px;
}

.selected-panel {
  margin-bottom: 14px;
  padding: 16px;
}

.panel-heading,
.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 12px;
}

.status-text {
  color: var(--amber);
  font-size: 12px;
}

.selected-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 30px;
}

.selection-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.primary-action {
  color: var(--ink);
  background: var(--teal);
  border-color: var(--teal);
  font-weight: 800;
}

button:disabled {
  cursor: wait;
  opacity: .65;
}

.selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  padding: 5px 8px;
  color: var(--soft);
  background: #121719;
  border: 1px solid #334044;
  border-radius: 999px;
  font-size: 12px;
}

.chip-remove {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  padding: 0;
  min-height: 0;
  color: var(--rose);
  border-color: rgba(233, 112, 123, .35);
  border-radius: 50%;
}

.template-sections {
  display: grid;
  gap: 14px;
}

.template-section {
  padding: 16px;
}

.section-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  color: var(--soft);
  background: #121719;
  border: 1px solid #344044;
  border-radius: 999px;
  font-size: 12px;
}

.select-visible {
  min-height: 28px;
  padding: 4px 9px;
  color: var(--ink);
  background: var(--teal);
  border-color: var(--teal);
  font-size: 12px;
  font-weight: 800;
}

.template-description {
  max-width: 820px;
  margin: -4px 0 14px;
  color: var(--muted);
  line-height: 1.65;
}

.company-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(238px, 1fr));
  gap: 8px;
}

.company-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  min-height: 58px;
  padding: 9px 10px;
  background: #13191b;
  border: 1px solid #293236;
  border-radius: 7px;
}

.company-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--teal);
}

.company-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.company-name {
  overflow: hidden;
  color: var(--text);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.company-sub {
  display: flex;
  min-width: 0;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.company-industry {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticker {
  color: var(--amber);
  font-weight: 800;
}

.market-badge {
  flex: 0 0 auto;
  min-width: 38px;
  padding: 3px 6px;
  color: var(--ink);
  background: var(--blue);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

.empty-state,
.error-state {
  padding: 16px;
  color: var(--muted);
  background: #13191b;
  border: 1px solid #293236;
  border-radius: 7px;
}

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

@media (max-width: 980px) {
  .page-header,
  .toolbar,
  .summary-strip {
    grid-template-columns: 1fr 1fr;
  }

  .page-header {
    display: grid;
  }
}

@media (max-width: 680px) {
  .layout {
    width: min(100% - 24px, 1440px);
  }

  .toolbar,
  .summary-strip,
  .panel-heading,
  .section-heading {
    grid-template-columns: 1fr;
  }

  .panel-heading,
  .section-heading {
    display: grid;
  }

  .section-meta {
    justify-content: flex-start;
  }
}
