/* -- LAYOUT */
:root,
:host {
  interpolate-size: allow-keywords;
  font-family: var(--font-system-ui);
  font-size: 16px;
}

html {
  --basic-hover-transition: all 100ms var(--ease-in-out-2);
  --error-bg: var(--red-5);
  --placeholder-color: var(--gray-5);

  @media (prefers-color-scheme: dark) {
    --accent-color: var(--blue-6);
    --accent-color-fill: var(--blue-6);
    --accent-color-text: var(--blue-4);
    --accent-color-border: var(--blue-7);
    --element-gray: var(--gray-4);
    --basic-shadow: var(--shadow-3);
    --basic-border-color: var(--gray-7);
    color: var(--text-2);
  }

  & [data-theme=dark] {
    --accent-color: var(--blue-6);
    --accent-color-fill: var(--blue-5);
    --accent-color-text: var(--blue-4);
    --accent-color-border: var(--blue-6);
    --element-gray: var(--gray-4);
    --basic-shadow: var(--shadow-3);
    --basic-border-color: var(--gray-7);
    color: var(--text-2);
  }

  @media (prefers-color-scheme: light) {
    --accent-color: var(--blue-6);
    --accent-color-fill: var(--blue-6);
    --accent-color-text: var(--blue-6);
    --accent-color-border: var(--blue-6);
    --element-gray: var(--gray-6);
    --basic-shadow: var(--shadow-1);
    --basic-border-color: var(--gray-5);
    color: var(--text-1);
  }

  & [data-theme=light] {
    --accent-color: var(--blue-7);
    --accent-color-fill: var(--blue-6);
    --accent-color-text: var(--blue-8);
    --accent-color-border: var(--blue-7);
    --element-gray: var(--gray-6);
    --basic-shadow: var(--shadow-1);
    --basic-border-color: var(--gray-5);
    color: var(--text-1);
  }
}


.app-container {
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
  padding: var(--size-fluid-1) var(--size-fluid-3);
}

.app-main {
  margin-bottom: 10rem;

  @media screen and (width <=450px) {
    padding-bottom: var(--size-10);

    &:has(.main-action) {
      padding-bottom: var(--size-10);
    }
  }

  @media screen and (width > 450px) {
    padding-bottom: var(--size-7);
  }

}

/* -- COMMON */
button {
  background: transparent;
  border-radius: var(--radius-2);
  border: var(--border-size-1) solid var(--basic-border-color);
  padding: var(--size-relative-2) var(--size-relative-4);
  display: inline-flex;
  transition: var(--basic-hover-transition);
  gap: var(--size-relative-3);

  &:disabled {
    opacity: 0.6;
    cursor: default;
  }

  &:not(:disabled) {
    @media (hover: hover) {
      &:hover {
        border-color: var(--accent-color-text);
        color: var(--accent-color-text);
      }
    }
  }

  &.primary {
    background: var(--accent-color-fill);
    border-color: var(--accent-color-border);
    color: var(--gray-1);
    transform: scale(1);


    &:not(:disabled) {
      @media (hover: hover) {
        &:hover {
          color: var(--gray-1);
          transform: scale(1.04);
        }
      }
    }
  }

  &.large {
    padding: var(--size-relative-3) var(--size-relative-5);
    font-weight: 500;
  }

  &.green {
    color: var(--gray-1);
    background: var(--green-9);
    border-color: var(--green-10);
    transform: scale(1);

    &:not(:disabled) {
      @media (hover: hover) {
        &:hover {
          color: var(--gray-1);
          border-color: var(--green-10);
          transform: scale(1.04);
        }
      }
    }
  }

  &.dark-blue {
    color: var(--gray-1);
    background: var(--blue-7);
    border-color: var(--blue-8);
  }

  &.round {
    border-radius: var(--radius-round);
  }
}

:is(textarea, select, input:not([type=button], [type=submit], [type=reset])) {
  border: var(--border-size-1) solid var(--basic-border-color);

  &::placeholder {
    color: var(--placeholder-color);
    font-weight: normal;
  }
}

*[role=group] {
  >* {
    border-radius: 0;

    &:first-child {
      border-top-left-radius: var(--radius-2);
      border-bottom-left-radius: var(--radius-2);
      border-right: 0;
    }

    &:last-child {
      border-top-right-radius: var(--radius-2);
      border-bottom-right-radius: var(--radius-2);
      border-left: 0;
    }
  }
}

p {
  margin-bottom: var(--size-8);
}

h1,
h2,
h3 {
  margin-bottom: var(--size-relative-3);
}

h4 {
  font-weight: 600;
}

/* -- NAV */

.nav-header {
  background-color: var(--surface-1);

  @media screen and (width < 451px) {
    display: block;
    position: fixed;
    bottom: 0;
    z-index: 2;
    box-shadow: var(--shadow-4);
  }

  @media screen and (width > 450px) {
    position: relative;
  }
}

nav {
  --nav-inline-space: var(--size-fluid-1);
  font-size: var(--font-size--1);

  >ul {
    display: flex;
    flex-wrap: nowrap;
    padding: var(--size-relative-1) var(--nav-inline-space);
    font-size: var(--font-slze-fluid-0);
    justify-content: space-between;
    gap: calc(var(--size-fluid-1));

    &:first-child {
      padding-left: 0;
    }

    &:last-child {
      padding-right: 0;
    }
  }

  & li {
    list-style: none;
    display: flex;
    padding: 0;
    white-space: nowrap;
    white-space-collapse: collapse;
  }

  .link {
    display: flex;
    color: var(--text-2);
    font-weight: var(--font-weight-5);
    border-radius: var(--radius-2);
    border: var(--border-size-1) solid transparent;
    padding: var(--size-relative-2) var(--nav-inline-space);
    align-items: center;
    gap: var(--size-relative-2);

    @media (hover: hover) {
      &:hover {
        text-decoration: none;
        border-color: var(--accent-color-border);
        color: var(--accent-color-text);
      }
    }

    &.active {
      background: var(--accent-color-fill);
      color: var(--gray-1);
    }

    &:not(&.active) {
      .success {
        color: var(--green-6);
      }

      .working {
        color: var(--yellow-6);
      }

      .error {
        color: var(--red-6);
      }
    }
  }

  .icon-wrapper {
    font-size: var(--font-size-4);
  }

  .summary {
    align-items: center;
    display: flex;
    color: var(--text-2);
  }
}

.main-nav {
  display: grid;
  grid-template-rows: 100%;
  grid-template-columns: auto auto auto;
  justify-content: space-between;
  margin-inline: calc(0px - var(--nav-inline-space));
  width: 100%;

  @media screen and (width <=450px) {
    .dropdown {
      display: none;
    }
  }

  @media screen and (width > 450px) {
    .dropdown {
      display: flex;
    }
  }
}


/* -- GROCERY CATEGORY */

.grocery-category {
  margin-block: var(--size-6);
  position: relative;
  z-index: 1;

  & h4 {
    display: flex;
    gap: var(--size-2);
    align-items: center;
    margin-bottom: var(--size-2);

    .counter.all-done {
      color: var(--green-9);
    }

    >span {
      border-bottom: var(--border-size-2) solid transparent;

      &:focus-within {
        border-color: var(--accent-color);
      }
    }

    .delete-button {
      cursor: pointer;

      @media (hover: hover) {
        &:hover {
          color: var(--red-6);
        }
      }
    }

    & input {
      background: transparent;
      border: none;
      min-height: 1em;
      font-size: 1em;
      line-height: 1em;
      padding: 0;

      &:focus {
        outline: 0;
      }

      @supports (field-sizing: content) {
        field-sizing: content;
        max-width: 100%;
      }
    }
  }

  .category-body {
    height: auto;
    display: flex;
    flex-flow: column nowrap;
    transition: height 200ms var(--ease-elastic-in-out-3);
    margin-inline: calc(0px - var(--size-3));
    overflow-y: clip;
    overflow-x: visible;
    gap: var(--size-1);

    &.collapsed {
      height: 0;
      overflow: hidden;
      z-index: 0;
    }
  }
}


/* -- GROCERY ITEM */

.grocery-item {
  align-items: center;
  border-radius: var(--radius-2);
  column-gap: var(--size-1);
  display: grid;
  grid-template-columns: 2rem minmax(2rem, 100%) 1rem;
  padding: var(--size-2) var(--size-3);
  transition: var(--basic-hover-transition);
  min-height: 40px;
  width: 100%;

  &.item-form {
    background-color: var(--surface-2);
    box-shadow: var(--basic-shadow);
    align-items: center;
    position: relative;

    :is(textarea, input) {
      background: transparent;
      border: none;
      min-height: 1em;
      font-size: 1em;
      line-height: 1em;
      min-width: 1ch;

      &:focus {
        outline: 0;
      }
    }

    .grow-container {
      display: inline-flex;
    }

    .item-content {
      >span {
        &:focus-within {
          border-color: var(--accent-color);
        }

        align-items: center;
      }

      .item-validation-error+span {
        border-color: var(--error-bg);

      }
    }

    .item-validation-error {
      position: absolute;
      z-index: var(--layer-1);
      top: 44px;

      .error-message {
        background: var(--error-bg);
        border-radius: var(--radius-2);
        box-shadow: var(--shadow-2);
        color: var(--gray-0);
        font-size: 0.887em;
        margin-left: -1rem;
        padding: var(--size-1) var(--size-2);

        &:before {
          content: '';
          position: absolute;
          display: block;
          width: 0px;
          left: 1rem;
          top: 0;
          border: 8px solid transparent;
          border-top: 0;
          border-bottom: 8px solid var(--error-bg);
          transform: translate(-50%, calc(-100%));
        }
      }
    }

    &:last-child {
      .item-validation-error {
        top: -30px;

        .error-message {
          &:before {
            content: '';
            position: absolute;
            display: block;
            width: 0px;
            left: 1rem;
            bottom: 0;
            border: 8px solid transparent;
            border-bottom: 0;
            border-top: 8px solid var(--error-bg);
            transform: translate(-50%, calc(100%));
          }
        }
      }
    }
  }

  .item-quantity {

    & b {
      & input {
        /* TODO: For some reason element next to <b> is moving closer
        * when b has input
         * I dunno, man =( */
        padding-right: 4.6px;
      }
    }
  }

  @media (hover: hover) {
    &:hover {
      background-color: var(--surface-2);
      box-shadow: var(--basic-shadow);
    }
  }

  .item-content {
    display: flex;
    flex-flow: row wrap;
    column-gap: var(--size-3);
    margin-bottom: calc(0px - var(--border-size-2));

    >span {
      border-bottom: var(--border-size-2) solid transparent;
    }
  }

  .input-resize-container {
    max-width: 100%;
  }

  & input[type=text],
  & textarea {
    padding: 0;
    margin: 0;
  }

  & textarea {
    word-wrap: break-word;
    scrollbar-width: none;
    resize: none;
  }

  @supports (field-sizing: content) {

    & input[type=text],
    & textarea {
      field-sizing: content;
      max-width: 100%;
    }
  }

  & [role=checkbox] {
    aspect-ratio: var(--ratio-square);
    border-radius: var(--radius-2);
    border: var(--border-size-2) solid var(--gray-5);
    color: var(--gray-7);
    place-content: center;
    place-items: center;
    width: var(--size-4);

    & svg {
      visibility: hidden;
    }

    &.checked {
      background: var(--accent-color);
      border-color: var(--accent-color);
      color: var(--gray-0);

      & svg {
        visibility: visible;
      }
    }

    &.checked.check {
      background: var(--green-9);
      border-color: var(--green-9);

    }
  }


  .add-item-comment,
  .delete-button {
    cursor: pointer;
  }

  @media (hover: hover) {

    .add-item-comment,
    .delete-button {
      visibility: hidden;
      transition: var(--basic-hover-transition);
    }

    &:hover {

      .add-item-comment,
      .delete-button {
        visibility: visible;
      }
    }
  }

  .add-item-comment {
    font-size: 1.4em;

    @media (hover: hover) {
      opacity: 0.5;

      &:hover {
        opacity: 1;
      }
    }

  }

  .delete-button {
    @media (hover: hover) {
      &:hover {
        color: var(--red-6);
      }
    }

  }
}

.add-item-button {
  background: transparent;
  border: var(--border-size-1) dashed transparent;
  justify-content: flex-start;
  font-size: var(--font-size-3);
  padding: var(--size-2) var(--size-3);
  transition: all 0.2s var(--ease-in-out-2);
  min-height: 40px;

  @media (hover: hover) {
    &:hover {
      color: var(--accent-color);
      border-color: var(--accent-color);
    }
  }

}

/* -- COMPONENTS */
.chevron {
  transition: transform .1s var(--ease-in-out-3);

  &.open {
    transform: rotate(0.25turn);
  }


  @media (hover: hover) {
    &:hover {
      color: var(--accent-color);
    }
  }
}

.green {
  color: var(--green-9);
}

.dropdown {
  background: var(--surface-1);
  position: relative;
  padding: 0;
  display: flex;
  height: 100%;

  .summary {
    background: var(--surface-1);
    cursor: pointer;
    transition: all 0.1s var(--ease-in-out-1);

    @media (hover: hover) {
      &:hover {
        color: var(--accent-color);
      }
    }

  }

  & ul {
    font-size: var(--font-size--1);
    background-color: var(--surface-2);
    position: absolute;
    padding: var(--size-2) 0;
    z-index: var(--layer-3);
    box-shadow: var(--shadow-3);
    border-radius: var(--radius-2);
    transform: scale(0, 0) translate(-100%, -100%);
    overflow: hidden;
    /* TODO: need better solution */
    top: var(--size-7);

    transition:
      transform 0.05s var(--ease-in-3),
      opacity 0.05s var(--ease-in-3);

    @starting-style {
      opacity: 0;
      transform: scale(0);
    }

    & li {
      padding: var(--size-2) var(--size-4);
      min-width: max-content;
      cursor: pointer;

      @media (hover: hover) {
        &:hover {
          background-color: var(--surface-3);
        }
      }
    }
  }

  &.open {
    .summary {
      color: var(--accent-color);
    }

    & ul {
      display: block;
      transform: scale(1, 1) translate(0, 0);
    }
  }
}

.main-action {
  box-shadow: var(--shadow-4);
  font-size: var(--font-size-4);
  padding: var(--size-relative-3);
  position: fixed;
  bottom: var(--size-10);
  right: 2rem;
  z-index: var(--layer-2);

  @media screen and (width < 451px) {
    display: flex;
  }

  @media screen and (width > 450px) {
    display: none;
  }
}

.counter {
  font-size: var(--font-size-2);
  line-height: inherit;
  vertical-align: middle;
}

.end-shopping-button {
  display: flex;
  margin-inline: auto;
}

/* -- SETTINGS */

#settings-export-section {
  & button {
    margin-right: var(--size-3);
  }
}

.sync-settings-form {
  display: grid;
  gap: var(--size-5) var(--size-2);
  grid-template-areas:
    "title      title      close"
    "url-label  url-input  url-input"
    "room-label room-input room-input"
    "empty-left submit     empty-right";
  grid-template-columns: min-content auto min-content;
  grid-template-rows: repeat(4, auto);
  white-space: nowrap;


  & h3 {
    display: flex;
    width: 100%;
    justify-content: space-between;
    align-items: center;
    grid-area: title;
    margin-bottom: 0;

    & span {
      cursor: pointer;

      @media (hover: hover) {
        &:hover {
          color: var(--accent-color);
        }
      }
    }
  }

  >span {
    grid-area: close;
    align-self: baseline;
    justify-self: flex-end;
    font-size: var(--font-size-5);
    cursor: pointer;

    @media (hover: hover) {
      &:hover {
        color: var(--accent-color);
      }
    }

  }

  & label:first-of-type {
    grid-area: url-label;
  }

  & input:first-of-type {
    grid-area: url-input;
  }

  & label:last-of-type {
    grid-area: room-label;
  }

  & input:last-of-type {
    grid-area: room-input;
  }

  & button:last-of-type {
    grid-area: submit;
    justify-self: center;
  }

  & label {
    margin: var(--size-3) 0;
    display: flex;
    width: 100%;
    gap: var(--size-2);
    align-items: baseline;
    flex-grow: 1;

    & input {
      flex-grow: 1;
    }
  }
}
