:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #5f6368;
  --border: #d5d8dc;
  --accent: #1a56db;
  --accent-fg: #ffffff;
  --tile-bg: #f5f6f8;
  --error-bg: #fdecea;
  --error-fg: #7a1a12;
  --disclaimer-bg: #fff8e6;
  --disclaimer-fg: #5c4b00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --fg: #ecedee;
    --muted: #a0a4ab;
    --border: #33363c;
    --accent: #6d9bff;
    --accent-fg: #0b1020;
    --tile-bg: #1d2025;
    --error-bg: #3a1613;
    --error-fg: #ffb4a8;
    --disclaimer-bg: #2a230a;
    --disclaimer-fg: #f0d878;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 1.5rem;
  padding-inline: max(1rem, 4vw);
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}

.page-header h1 {
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--muted);
  margin-top: 0;
}

.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.language-switcher select {
  width: auto;
  height: auto;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}

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

.disclaimer {
  background: var(--disclaimer-bg);
  color: var(--disclaimer-fg);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  max-width: 60rem;
}

main {
  display: grid;
  gap: 2rem;
  max-width: 60rem;
}

form {
  display: grid;
  gap: 1rem;
  max-width: 40rem;
}

.field {
  display: grid;
  gap: 0.25rem;
  /* Grid items default to min-width:auto (their content's min-content size),
     not 0. Native inputs like type="date" have a different intrinsic
     min-content width than text/number/select (their day/month/year
     sub-fields + calendar icon), which can make a date field's 1fr track
     size differently from a sibling row's — even though both use the same
     1fr 1fr split — unless that auto-minimum is overridden. */
  min-width: 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 480px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

.ticker-input-wrapper {
  position: relative;
}

.symbol-suggestions {
  position: absolute;
  z-index: 10;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  max-height: 16rem;
  overflow-y: auto;
}

.symbol-suggestion {
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.symbol-suggestion.is-active,
.symbol-suggestion:hover {
  background: var(--tile-bg);
}

.checkbox-field {
  display: flex;
  align-items: center;
  flex-direction: row;
  gap: 0.5rem;
}

label {
  font-weight: 600;
  font-size: 0.9rem;
}

.hint {
  font-weight: 400;
  color: var(--muted);
}

input,
select {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-size: 1rem;
  width: 100%;
  min-width: 0;
  /* Without this, input[type="date"] renders taller than text/number/select:
     its native day/month/year sub-fields have their own intrinsic content
     height, distinct from a plain text baseline. An explicit height (rather
     than relying on padding + line-height) forces every field to the same
     box size regardless of type. */
  height: 2.75rem;
}

.checkbox-field input {
  width: auto;
}

button {
  justify-self: start;
  padding: 0.6rem 1.4rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error-message {
  background: var(--error-bg);
  color: var(--error-fg);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  max-width: 40rem;
}

.loading-message {
  color: var(--muted);
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1rem;
  margin: 0;
}

.result-tile {
  background: var(--tile-bg);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.result-tile dt {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.result-tile dd {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.transactions-table-wrapper {
  overflow-x: auto;
  max-height: 20rem;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--tile-bg);
}

.chart-controls {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.chart-controls button {
  align-self: stretch;
}

.canvas-wrapper {
  max-width: 100%;
  background: #0b1020;
  border-radius: 8px;
  overflow: hidden;
}

#preview-canvas {
  display: block;
  width: 100%;
  height: auto;
}

#chart-scrubber {
  width: 100%;
  margin-top: 0.75rem;
}

.advanced-fields {
  margin: 1rem 0;
}

.advanced-fields summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.export-progress {
  display: grid;
  gap: 0.6rem;
  margin: 1rem 0;
  max-width: 30rem;
}

.progress-row {
  display: grid;
  gap: 0.25rem;
}

.progress-row label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 400;
}

progress {
  width: 100%;
  height: 0.6rem;
}

.download-buttons {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.download-button {
  display: inline-block;
  padding: 0.6rem 1.4rem;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
  text-decoration: none;
}
