@layer original, interacao, variacao;

html {
  color-scheme: light dark;
  font-family: sans-serif;
}

body {
  margin: 0;
  display: flex;
  overflow-y: scroll;
}

a:visited {
  color: LinkText;
}

#btnMenu {
  display: none;
  position: fixed;
  z-index: 2;
  top: 1rem;
  left: 1rem;
  box-sizing: border-box;
  width: 1.5rem;
  height: 1.5rem;
  border: 0;
  padding: 0;
  background-color: transparent;
  font-size: 1.5rem;
  font-weight: bold;
  user-select: none;

  @media (max-width: 960px) {
    display: inline-block;
  }
}

#menu {
  position: sticky;
  top: 0;

  ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
  }

  @media (max-width: 960px) {
    visibility: hidden;
    position: fixed;
    top: 0;
    left: -201px;
    bottom: 0;
    z-index: 3;
    width: 200px;
    border-right: 1px solid #ddd;
    background-color: Canvas;
    transition: left 0.25s ease;

    @media (prefers-color-scheme: dark) {
      border-color: #333;
    }

    &.abrindo {
      visibility: visible;
    }

    &.aberto {
      left: 0;
    }
  }
}

#menu a {
  display: block;
  padding: 1em;
  text-decoration: none;
}

#menu a:hover {
  background-color: Highlight;
  color: HighlightText;
}

#menu a.menu-ativo {
  border-left: 5px solid Highlight;
  padding-left: calc(1em - 5px);
}

#versao {
  margin: 1rem;
  opacity: 0.5;
  font-family: monospace;
}

main {
  flex-grow: 1;
  padding: 0 1em 1em 1em;
  transition: filter 0.25s ease;
  max-width: 900px;
}

main[inert],
div[inert],
table[inert] {
  filter: grayscale(1) opacity(0.3);
}

a[inert] {
  filter: saturate(0) opacity(0.5);
}

main > section:not(.section-ativa) {
  display: none;
}

thead {
  background-color: Canvas;
  color: CanvasText;
  position: sticky;
  top: 0;
  z-index: 1;
}

.form-group {
  margin-bottom: 0.5rem;
  display: flex;
  align-items: baseline;
}

.form-group > label {
  display: flex;
  gap: 0.5ch;
  align-items: baseline;
}

.form-group > label > span:first-child,
.form-label {
  display: inline-block;
  width: 14ch;
  text-align: right;
  padding: 0.5em 0;
}

.form-label {
  margin-right: 0.5ch;
}

.form-label + span {
  width: 20ch;
}

label:has(input[type="checkbox"]),
label:has(input[type="radio"]) {
  cursor: pointer;
  margin-right: 1em;
}

label:has(textarea) {
  width: 100%;
}

.radio-list {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  padding: 0.5em;
  gap: 1em;
}

button {
  cursor: pointer;
  white-space: nowrap;
  padding: 0.5em;
  font-size: 1rem;
  transition: transform 0.1s;
  border-radius: 0.25em;
  border: none;
}

button[type=submit] {
  background-color: Highlight;
  color: HighlightText;
}

button:disabled {
  filter: grayscale(1);
  opacity: 0.5;
  cursor: default;
}

button:not(:disabled):active {
  transform: scale(0.95);
}

button > img {
  vertical-align: text-bottom;
}

button[aria-pressed="true"] {
  background-color: darkgray;
  box-shadow: 0 0 5px rgba(0, 123, 255, 0.7);
}

button.processando {
  cursor: wait;
  opacity: 0.5;
}

button.processando > img {
  display: none;
}

button.processando > .icone-processando {
  display: inline-block;
}

input,
select,
textarea {
  padding: 0.5em;
  font-size: 1rem;
}

input:focus::placeholder,
textarea:focus::placeholder {
  visibility: hidden;
}

textarea {
  flex-grow: 1;
  min-height: 10em;
}

select {
  cursor: pointer;
}

input[type="text"]:read-only {
  border: none;
  background-color: transparent;
  color: inherit;
  padding: 0;
}

input[type="text"]:read-only:focus {
  outline: none;
}

input[name="instituicao"],
select[name="instituicao"],
input[name="investimento"],
input[name="nome"],
select[name="nome"] {
  width: 60ch;
}

input[data-validar="data"] {
  width: 10ch;
}

input[data-validar="dataHora"] {
  width: 17ch;
}

input[data-validar="moeda"] {
  width: 16ch;
}

input[data-validar="percentual"] {
  width: 5ch;
}

.grid {
  border-collapse: collapse;
  margin-bottom: 1em;

  @media (max-width: 960px) {
    margin: 0 -1em;
  }

  th,
  td {
    border-bottom-style: solid;
    border-bottom-width: 1px;
    padding: 0.5rem;
  }

  th {
    text-align: left;
    vertical-align: bottom;
  }

  a {
    text-decoration: none;
  }

  a:hover {
    text-decoration: underline;
  }

  input[data-validar="moeda"] {
    text-align: right;
  }

  tfoot {
    border-top-style: solid;
    border-top-width: 2px;
  }

  tfoot td {
    font-weight: bold;
    vertical-align: top;
  }

  @layer original {
    th,
    td {
      border-color: #ddd;

      @media (prefers-color-scheme: dark) {
        border-color: #333;
      }
    }

    tfoot {
      border-color: #bbb;
    }

    tfoot td {
      background-color: #fffcfc;

      @media (prefers-color-scheme: dark) {
        background-color: #000a0a;
      }
    }
  }
}

@layer interacao {
  .grid tbody tr:hover td,
  .grid tbody tr:focus-within td {
    background-color: ghostwhite;

    @media (prefers-color-scheme: dark) {
      background-color: darkslateblue;
    }
  }
}

.grid th.valor {
  text-align: right;
}

.grid td.valor {
  text-align: right;
}

@layer variacao {
  .alerta {
    background-color: #ff7d7d;

    @media (prefers-color-scheme: dark) {
      background-color: #a53a43;
    }
  }
}

.sucesso {
  background-color: palegreen;

  @media (prefers-color-scheme: dark) {
    background-color: green;
  }
}

.inativo {
  opacity: 0.6;
}

.negativo {
  color: darkred;
}

.positivo {
  color: darkgreen;
}

.valor:not(th) {
  font-family: monospace;
}

.iq {
  display: inline-block;
  font-size: 0.6em;
  font-weight: bold;
  padding: 0.3em;
  border-radius: 50%;
  background-color: Highlight;
  color: HighlightText;
  cursor: default;
  vertical-align: text-bottom;
}

span[title] {
  cursor: help;
}

@layer variacao {
  @media (prefers-color-scheme: dark) {
    .negativo {
      color: coral;
    }

    .positivo {
      color: lightgreen;
    }

    .grid tr:hover .negativo {
      color: peachpuff;
    }
  }

  .pontuacaoNegativa {
    background-color: #ff7d7d;
    border-color: #ef6d6d;

    @media (prefers-color-scheme: dark) {
      background-color: #a53a43;
      border-color: #b54a53;
    }
  }

  .pontuacaoPoupanca {
    background-color: #ffc6a5;
    border-color: #efb595;

    @media (prefers-color-scheme: dark) {
      background-color: #9b6242;
      border-color: #ab7252;
    }
  }

  .pontuacaoLca {
    background-color: #fff9b3;
    border-color: #efe9a3;

    @media (prefers-color-scheme: dark) {
      background-color: #7e772d;
      border-color: #8e873d;
    }
  }

  .pontuacaoPositiva {
    background-color: #b3e5b3;
    border-color: #a3d5a3;

    @media (prefers-color-scheme: dark) {
      background-color: #517e51;
      border-color: #618e61;
    }
  }
}

button {
  user-select: none;
  outline-offset: 4px;
}

.icone-processando {
  font-size: 16px;
  display: inline-block;
  width: 16px;
  height: 16px;
  display: none;
}

.acao {
  font-family: "Noto Color Emoji", "Segoe UI Emoji", "Apple Color Emoji", sans-serif;
  display: inline-block;
  margin-right: 1rem;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: none;
  outline-offset: 0;
}

.acao:not(:disabled):hover,
.acao:not(:disabled):focus {
  transform: scale(1.25);
}

.acao:not(:disabled):active {
  transform: scale(0.9);
}

.lista-restricoes {
  margin: 0;
  padding: 0 0 0 1em;
  color: darkred;

  li:not(:last-of-type) {
    margin-bottom: 0.5em;
  }
}

.confirmar {
  max-width: 50ch;
  border: none;
  border-radius: 1em;

  &::backdrop {
    background-color: CanvasText;
    opacity: 0.5;
  }

  .grid {
    width: 100%;
    margin-bottom: 2em;
  }

  .botoes {
    display: flex;
    justify-content: center;
    gap: 1em;

    button {
      flex: 1;
    }
  }
}
