:root {
  --bg: #0c0e12;
  --surface: #14171e;
  --surface-hover: #1a1e28;
  --border: #2a2f3b;
  --text: #e8eaef;
  --text-muted: #8b92a3;
  --accent: #00c853;
  --accent-dim: rgba(0, 200, 83, 0.15);
  --error: #ff5252;
  --error-bg: rgba(255, 82, 82, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* Make the HTML `hidden` attribute always win */
[hidden] {
  display: none !important;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
  position: relative;
  background:
    radial-gradient(1200px circle at 18% 12%, rgba(0, 200, 83, 0.18), transparent 60%),
    radial-gradient(900px circle at 86% 22%, rgba(0, 136, 255, 0.16), transparent 55%),
    radial-gradient(700px circle at 52% 92%, rgba(255, 82, 82, 0.10), transparent 55%),
    linear-gradient(180deg, #07080b 0%, var(--bg) 45%, #08090c 100%);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem 1rem 4rem;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.06) 0,
      rgba(255, 255, 255, 0.06) 1px,
      transparent 1px,
      transparent 26px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.05) 0,
      rgba(255, 255, 255, 0.05) 1px,
      transparent 1px,
      transparent 26px
    );
  opacity: 0.06;
  mix-blend-mode: overlay;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(1200px circle at 50% 35%, transparent 0%, rgba(0, 0, 0, 0.55) 70%);
  opacity: 0.9;
}

.app {
  width: 100%;
  max-width: 680px;
  position: relative;
  z-index: 1;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.logo-icon {
  font-size: 1.75rem;
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Main */
.main {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Tabs */
.tabs {
  display: inline-flex;
  align-self: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem;
  gap: 0.25rem;
}

.tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.tab.active {
  background: rgba(0, 200, 83, 0.14);
  color: var(--text);
}

.tab:focus-visible {
  outline: 2px solid rgba(0, 200, 83, 0.6);
  outline-offset: 2px;
}

.panel {
  display: block;
}

/* Form */
.search-form {
  margin-bottom: 0.5rem;
}

.combo {
  position: relative;
}

.input-wrap {
  display: flex;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.search-form input {
  flex: 1;
  min-width: 0;
  padding: 0.85rem 1rem;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  outline: none;
}

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

.btn-submit {
  position: relative;
  padding: 0.85rem 1.5rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

.btn-submit:hover:not(:disabled) {
  background: #00e676;
  transform: translateY(-1px);
}

.btn-submit:active:not(:disabled) {
  transform: translateY(0);
}

.btn-submit:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.btn-loader {
  display: none;
  width: 20px;
  height: 20px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn-submit.loading .btn-text {
  visibility: hidden;
}

.btn-submit.loading .btn-loader {
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -10px 0 0 -10px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.hint {
  margin: 0.5rem 0 0 0.6rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Company list loading status */
.fetching {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.6rem 0 0 0.6rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.fetching-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* History */
.history-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.history-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.history-sub {
  margin: 0.25rem 0 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.btn-secondary {
  padding: 0.6rem 0.9rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  white-space: nowrap;
}

.btn-secondary:hover {
  background: var(--surface-hover);
  border-color: rgba(0, 200, 83, 0.25);
}

.history-empty {
  padding: 1rem 1.25rem;
  color: var(--text-muted);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.history-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

.history-item-title {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.history-company {
  font-weight: 700;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-meta {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-family: var(--font-mono);
}

.history-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-ghost {
  padding: 0.45rem 0.7rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.btn-ghost:hover {
  background: var(--surface-hover);
  border-color: rgba(0, 200, 83, 0.25);
}

.btn-danger:hover {
  border-color: rgba(255, 82, 82, 0.5);
  background: rgba(255, 82, 82, 0.08);
}

.history-snippet {
  padding: 0.95rem 1.1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Suggestions dropdown */
.suggestions {
  position: absolute;
  z-index: 50;
  left: 0;
  right: 0;
  top: calc(100% + 10px);
  background: rgba(20, 23, 30, 0.98);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  backdrop-filter: blur(8px);
}

.suggestions-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.suggestions-list {
  max-height: 320px;
  overflow: auto;
}

.suggestion {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.suggestion:hover,
.suggestion[aria-selected="true"] {
  background: var(--surface-hover);
}

.suggestion-main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.suggestion-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggestion-sub {
  color: var(--text-muted);
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggestion-symbol {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(0, 200, 83, 0.25);
  background: rgba(0, 200, 83, 0.08);
  color: #9ff0bf;
  flex-shrink: 0;
}

.suggestions-empty {
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Ensure [hidden] overrides our display rules */
.result[hidden],
.error[hidden],
.loading[hidden] {
  display: none !important;
}

/* Result */
.result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.result-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.result-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.result-header h2 span {
  color: var(--accent);
}

.result-body {
  padding: 1.25rem 1.5rem;
}

.analysis-content {
  font-size: 0.95rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Error */
.error {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: var(--error-bg);
  border: 1px solid rgba(255, 82, 82, 0.3);
  border-radius: var(--radius);
  color: var(--error);
}

.error-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.error p {
  margin: 0;
  font-size: 0.95rem;
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Footer */
.footer {
  margin-top: 3rem;
  text-align: center;
}

.footer p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Responsive */
@media (max-width: 540px) {
  .input-wrap {
    flex-direction: column;
  }

  .btn-submit {
    width: 100%;
  }
}
