/* Global */
:root {
  --border: 1px solid black;
  --bg-transparent: hsla(0, 0%, 0%, 0%);
  --bg-hover: hsla(0, 0%, 0%, 10%);
  --bg-active: hsla(0, 0%, 0%, 20%);
  --transition: 0.3s ease;
  --radius: 10px;

  --color-bg: #fff;
  --color-text: #000;
  --color-success: #2d8f2d;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  flex-direction: column;
  width: 100%;
  font-family: sans-serif;
  color: var(--color-text);
}

/* Nav */
nav {
  display: flex;
  justify-content: center;
  padding: 1rem;
  width: 100%;
  text-align: center;
}

nav a {
  flex: 1;
  max-width: 200px;
  padding: 10px;
  text-align: center;
  border: var(--border);
  color: var(--color-text);
  background-color: var(--bg-transparent);
  text-decoration: none;
  transition: background-color var(--transition);
}

nav a:hover {
  background-color: var(--bg-hover);
}

nav a:active {
  background-color: var(--bg-active);
}

#userIcon {
  width: 40px;
  height: 40px;
  position: absolute;
  right: 55px;
  top: -55px;
}

/* Titles */
#titleHome,
#titlePost,
#titleEdit,
#titleAbout {
  font-size: 4rem;
  margin-top: 4rem;
}

/* Btns */
button,
#logoutBtn,
.card button,
#loginBox button,
#signupBox button,
#postBox button,
#buySection button,
#editBox button {
  display: inline-block;
  padding: 0.5rem 1rem;
  margin: 10px;
  background-color: var(--bg-transparent);
  color: var(--color-text);
  border: var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background-color var(--transition);
}

#shopping {
  margin-top: 50px;
  font-size: 1.1rem;
  font-weight: bold;
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  background: linear-gradient(
    270deg,
    red,
    orange,
    yellow,
    green,
    cyan,
    blue,
    violet,
    red
  );
  background-size: 600% 600%;
  animation: rainbow 4s linear infinite;
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
  transition: transform 0.2s;
}

#shopping:hover {
  transform: scale(1.05);
  box-shadow: 0 0 30px rgba(255, 255, 255, 0.4);
}

@keyframes rainbow {
  0% {
    background-position: 0% 50%;
  }
  100% {
    background-position: 100% 50%;
  }
}

button:hover,
#logoutBtn:hover,
.card button:hover,
#loginBox button:hover,
#signupBox button:hover,
#postBox button:hover,
#buySection button:hover,
#editBox button:hover {
  background-color: var(--bg-hover);
}

button:active,
#logoutBtn:active,
.card button:active,
#loginBox button:active,
#signupBox button:active,
#postBox button:active,
#buySection button:active,
#editBox button:active {
  background-color: var(--bg-active);
}

/* Home */
#mainHome {
  margin-top: 4rem;
}

#searchHome {
  width: 55vh;
  height: 3vh;
  font-size: 20px;
  text-align: center;
  border: var(--border);
  border-radius: var(--radius);
  margin-top: 50px;
}

/* Auth / Signup / Post boxes */
#boxes {
  display: flex;
  flex-direction: row;
}

#loginBox,
#signupBox,
#postBox,
#editBox {
  display: none;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.4s ease, transform 0.4s ease;
  flex-direction: column;
  margin: 30px 10px;
}

#editBox {
  display: flex;
  opacity: 1;
}

#btnBox,
#mainHome,
#headerHome,
#mainPost,
#headerPost,
#mainEdit,
#headerEdit,
#headerAbout {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

#btnBox {
  margin-top: -70px;
}

#mainEdit {
  margin-top: 4rem;
}

#btnBox {
  flex-direction: row;
}

/* show/hide animations */
.show {
  opacity: 1 !important;
  transform: scale(1) !important;
}

.hide {
  opacity: 0 !important;
  transform: scale(0.95) !important;
}

#error {
  margin: -2px 0;
  font-size: 15px;
  color: red;
}

form {
  display: flex;
  flex-direction: column;
}

form * {
  margin: 5px 0;
}

/* Market */
#headerMarket {
  display: none;
  justify-content: center;
  flex: 1;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

#searchMarket,
#filter {
  height: 3vh;
  font-size: 15px;
  border: var(--border);
  border-radius: var(--radius);
}

#searchMarket {
  width: 55vh;
}

#filter {
  margin: 0 10px;
  background-color: var(--bg-transparent);
  transition: background-color var(--transition);
  cursor: pointer;
}

#filter:hover {
  background-color: var(--bg-hover);
}

#filter:active {
  background-color: var(--bg-active);
}

#mainMarket {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1.5rem;
  padding: 2rem;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Cards */
.card {
  background: var(--color-bg);
  border: 1px solid #ddd;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
  transition: transform var(--transition), box-shadow var(--transition);
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.cardImage {
  width: 100%;
  height: 200px;
  background: #f3f3f3 center / cover no-repeat;
}

.cardContent {
  padding: 1rem;
}

.cardTitle {
  font-size: 1.2rem;
  font-weight: bold;
  margin: 0 0 0.5rem;
}

.cardPrice {
  font-size: 1.1rem;
  color: var(--color-success);
  margin-bottom: 1rem;
}

/* Post */
#imagesLabel {
  margin: 0;
  color: var(--color-text);
  align-self: center;
}

#preview {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 1rem;
  overflow-x: auto;
  scrollbar-width: thin;
}

#preview::-webkit-scrollbar {
  height: 8px;
}

#preview::-webkit-scrollbar-thumb {
  background-color: #ccc;
  border-radius: 4px;
}

#preview .image {
  flex: 0 0 200px;
  height: 200px;
  background: #f3f3f3 center / cover no-repeat;
  border-radius: 8px;
  border: 1px solid #ccc;
}

/* Template */
#mainItem {
  display: none;
  grid-template-columns: 1.2fr 2fr 1fr;
  gap: 2rem;
  padding: 2rem 4rem;
  background-color: #f8f8f8;
  min-height: 70vh;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Images */
#imagesItem {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 1rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  padding-bottom: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: #bbb #f0f0f0;
}

#imagesItem img {
  flex: 0 0 auto;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  object-fit: cover;
  transition: transform 0.2 ease;
  scroll-snap-align: center;
}

#imagesItem img:hover {
  transform: scale(1.03);
  cursor: pointer;
}

#imagesItem::-webkit-scrollbar {
  height: 8px;
}

#imagesItem::-webkit-scrollbar-thumb {
  background-color: #ccc;
  border-radius: 4px;
}

#imagesItem::-webkit-scrollbar-track {
  background-color: #f0f0f0;
}

/* Details section */
#detailsItem {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background-color: var(--color-bg);
  padding: 1.5rem 2rem;
  border-radius: 12px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

#titleItem {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

#descriptionItem {
  line-height: 1.5;
  color: #333;
  font-size: 1.1rem;
}

#conditionItem,
#locationItem {
  font-size: 0.95rem;
  color: #666;
}

/* Buy section */
#buySection {
  background-color: var(--color-bg);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
  height: fit-content;
  text-align: center;
}

#priceItem {
  font-size: 2rem;
  color: var(--color-success);
  margin-bottom: 1.5rem;
}

#buyBtn,
#cartBtn,
#editBtn,
#deleteBtn {
  width: 100%;
  padding: 0.8rem;
  font-size: 1.1rem;
  border: var(--border);
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 0.8rem;
  transition: background-color 0.2s ease;
}

/* Btn colors */
#buyBtn,
#editBtn,
#deleteBtn,
#cartBtn {
  background-color: var(--bg-transparent);
}

#buyBtn:hover,
#editBtn:hover,
#deleteBtn:hover,
#cartBtn:hover {
  background-color: var(--bg-hover);
}

#buyBtn:active,
#editBtn:active,
#deleteBtn:active,
#cartBtn:active {
  background-color: var(--bg-active);
}

/* Profile */
#userIcon {
  position: fixed;
  top: -58.5px;
  right: 25px;
  width: 45px;
  height: 45px;
  border-radius: 50%;
  background-image: url("./images/user.png");
  background-size: cover;
  background-position: center;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
}

#profileIcon {
  position: fixed;
  top: 15px;
  right: 25px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-image: url("./images/user.png");
  background-size: cover;
  background-position: center;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
}

#profileIcon:hover,
#userIcon:hover {
  transform: scale(1.05);
}

#mainProfile,
#mainHome,
#mainPost {
  width: 80%;
  max-width: 900px;
  margin: 80px auto;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  padding: 30px 40px;
}

#mainProfile {
  display: none;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

#mainProfile h1,
#mainHome h1,
#mainPost h1 {
  margin-bottom: 20px;
  color: black;
}

#mainProfile h2 {
  margin-top: 30px;
  margin-bottom: 10px;
  border-bottom: 2px solid #dfe6e9;
  padding-bottom: 5px;
  color: black;
}

#userData p {
  font-size: 1rem;
  margin: 5px 0;
}

#cart {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 15px;
  margin-top: 10px;
}

#cart a {
  text-decoration: none;
  color: inherit;
}

#balanceSection {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#balanceSection input {
  width: 150px;
  padding: 6px 8px;
  border: 1px solid #b2bec3;
  border-radius: 6px;
}

form input {
  padding: 8px;
  border: 1px solid #b2bec3;
  border-radius: 6px;
  width: 100%;
}

.buyAllBtn {
  display: block;
  margin: 20px auto 0;
  padding: 10px 20px;
}

#purchased {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 15px;
  margin-top: 10px;
}

.purchaseDate {
  font-size: 0.8em;
  color: gray;
}

.cartTotal {
  font-size: 1.2em;
  font-weight: bold;
  text-align: right;
  margin-top: 10px;
  margin-bottom: 10px;
}

.headerProfile {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.avatarProfile {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
}

/* RESPONSIVE DESIGN ADAPTATIONS    */

/* Large screens (desktops, >1200px) */
@media (min-width: 1200px) {
  body {
    font-size: 1rem;
  }

  #mainItem {
    grid-template-columns: 1.2fr 2fr 1fr;
    padding: 2rem 6rem;
  }
}

/* Medium screens (tablets, 768px–1199px) */
@media (max-width: 1199px) and (min-width: 768px) {
  nav a {
    font-size: 0.95rem;
    padding: 8px;
  }

  #titleHome,
  #titlePost,
  #titleEdit,
  #titleAbout {
    font-size: 3rem;
  }

  #mainItem {
    grid-template-columns: 1fr 1fr;
    padding: 2rem;
  }

  #profileIcon {
    width: 65px;
    height: 65px;
  }

  #userIcon {
    top: -10px;
    right: 0;
  }

  #mainProfile,
  #mainHome,
  #mainPost {
    width: 90%;
    padding: 20px 25px;
  }

  .card {
    border-radius: 10px;
  }

  .cardImage {
    height: 180px;
  }
}

/* Small screens (mobile, <768px) */
@media (max-width: 767px) {
  #headerHome,
  #headerPost {
    margin-top: -150px;
    padding-top: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
  }


  #headerPost {
    margin-top: -230px;
  }

  form button[type="reset"] {
    position: relative;
    right: 9px;
  }

  #btnBox {
    margin-top: -350px;
  }

  body {
    font-size: 0.9rem;
  }

  nav {
    flex-direction: column;
    padding: 0.5rem;
  }

  nav a {
    width: 100%;
    max-width: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  #userIcon,
  #profileIcon {
    width: 50px;
    height: 50px;
    top: 10px;
    right: 10px;
  }

  #titleHome,
  #titlePost,
  #titleEdit,
  #titleAbout {
    font-size: 2.2rem;
    margin-top: 2rem;
  }

  #searchHome,
  #searchMarket {
    width: 90%;
    font-size: 1rem;
  }

  #boxes {
    flex-direction: column;
    align-items: center;
  }

  #mainMarket {
    grid-template-columns: 1fr;
    padding: 1rem;
  }

  #mainItem {
    grid-template-columns: 1fr;
    padding: 1rem;
  }

  #detailsItem {
    padding: 1rem;
  }

  #buySection {
    padding: 1rem;
  }

  #mainProfile,
  #mainHome,
  #mainPost {
    width: 95%;
    padding: 20px;
  }

  .cardImage {
    height: 160px;
  }

  #cart {
    grid-template-columns: 1fr 1fr;
  }

  #purchased {
    grid-template-columns: 1fr 1fr;
  }

  form input {
    font-size: 0.95rem;
  }

  button,
  #logoutBtn,
  .card button {
    width: 100%;
    margin: 5px 0;
  }
}

/* Extra small screens (<480px) */
@media (max-width: 480px) {
  #titleHome,
  #titlePost,
  #titleEdit,
  #titleAbout {
    font-size: 1.8rem;
  }

  #userIcon {
    top: -8px;
  }

  #searchHome,
  #searchMarket {
    height: 1.8rem;
    font-size: 0.8rem;
    margin-top: 50px;
  }

  #filter {
    margin-top: 50px;
  }

  #mainProfile,
  #mainHome,
  #mainPost {
    padding: 15px;
  }

  #cart {
    grid-template-columns: 1fr;
  }

  #purchased {
    grid-template-columns: 1fr;
  }

  .cardImage {
    height: 140px;
  }

  #btnBox {
    gap: 15px;
  }

  form button[type="submit"] {
    position: relative;
    right: 9px;
  }

  #communicatorAbout {
    font-size: 0.8rem;
  }

  #shopping {
    width: 150px;
  }
}

/* Mobile menu toggle button */
#menuToggle {
  display: none;
  position: fixed;
  top: 15px;
  left: 15px;
  z-index: 1001;
  background: none;
  border: var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 1.5rem;
  cursor: pointer;
  transition: background-color var(--transition);
}

#menuToggle:hover {
  background-color: var(--bg-hover);
}

/* Hidden nav for mobile */
@media (max-width: 768px) {
  nav {
    position: fixed;
    top: 0;
    left: -100%;
    flex-direction: column;
    align-items: flex-start;
    justify-content: start;
    height: 45vh;
    width: 50%;
    max-width: 250px;
    background: var(--color-bg);
    border: var(--border);
    border-radius: 0 0 12px;
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
    padding-top: 60px;
    transition: left 0.3s ease;
    z-index: 1000;
  }

  nav a {
    width: 100%;
    text-align: left;
    padding: 15px 25px;
    border: none;
    border-bottom: var(--border);
    font-size: 1.1rem;
  }

  nav.show {
    left: 0;
  }

  #menuToggle {
    display: block;
    position: relative;
    width: 50px;
    height: 45px;
  }
}

#communicatorAbout {
  margin-top: 30px;
}
