/* :root {
  --color-primary: #5ec576;
  --color-secondary: #ffcb03;
  --color-tertiary: #ff585f;
  --color-primary-darker: #4bbb7d;
  --color-secondary-darker: #ffbb00;
  --color-tertiary-darker: #fd424b;
  --color-primary-opacity: #5ec5763a;
  --color-secondary-opacity: #ffcd0331;
  --color-tertiary-opacity: #ff58602d;
  --gradient-primary: linear-gradient(to top left, #39b385, #9be15d);
  --gradient-secondary: linear-gradient(to top left, #ffb003, #ffcb03);
} */

:root {
  --color-primary: #88c273;
  --color-secondary: #889eaf;
  --color-tertiary: #f96666;
  --color-primary-darker: #729763;
  --color-secondary-darker: #506d84;
  --color-tertiary-darker: #dd5353;
  --color-primary-opacity: rgb(136, 194, 115, 0.4);
  --color-secondary-opacity: #ffcd0331;
  --color-tertiary-opacity: rgb(249, 102, 102, 0.4);
  --color-temporary: #ffcb03;
  --color-temporary-darker: #ffbb00;
  --gradient-primary: linear-gradient(to top left, #39b385, #9be15d);
  --gradient-secondary: linear-gradient(to top left, #ffb003, #ffcb03);
}

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

html {
  font-size: 62.5%;
  box-sizing: border-box;
}

body {
  font-family: 'Poppins', sans-serif;
  color: #444;
  background-color: #f3f3f3;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0;
}

/* Prevent flash of login screen on page refresh - hide modals initially */
body:not(.auth-checked) .modal,
body:not(.auth-checked) .modal--login,
body:not(.auth-checked) .overlay {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Loading state for initial page load */
.app-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #f3f3f3;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 1;
  transition: opacity 0.3s ease-out;
}

.app-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.app-loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #e0e0e0;
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* NAVIGATION */
nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 9rem;
  width: 100%;
  padding: 0 6rem;
  z-index: 1000;
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
}

.modal.hidden {
  display: none;
}

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
}

.overlay.hidden {
  display: none;
}

.nav__left {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.logo-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 6rem;
  height: 6rem;
  border-radius: 50%;
  border: 2px solid var(--color-primary);
  overflow: hidden;
  background-color: #fff;
}

.logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: all 0.3s;
}

.logo-container:hover {
  transform: scale(1.1);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(57, 179, 133, 0.3);
}

.nav__right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2rem;
  margin-left: auto;
}

.left-nav {
  flex: 1;
  text-align: left;
}

.right-nav {
  flex: 1;
  text-align: right;
}

.welcome {
  font-size: 2rem;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  /* Varmistaa että welcome-teksti on näkyvissä */
  display: block;
  visibility: visible;
}

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

.login__input {
  cursor: pointer;
  padding: 0.5rem 2rem;
  font-size: 1.6rem;
  font-family: inherit;
  text-align: center;
  width: 25rem;
  border-radius: 10rem;
  margin-right: 1rem;
  color: inherit;
  border: 2px solid var(--color-primary);
  transition: all 0.3s;
}

.login__input:hover,
.login__input:focus {
  outline: none;
  background-color: #eee;
  color: #777;
  border: 2px solid var(--color-primary-darker);
}

.login__input::placeholder {
  color: #aaa;
}

.login__input--user {
  width: 30rem;
}

.login__input--pin {
  width: 15rem;
}

.login__btn {
  border: 2px solid var(--color-primary);
  background: none;
  height: 4rem;
  width: 4rem;
  border-radius: 50%;
  font-size: 2.2rem;
  color: inherit;
  cursor: pointer;
  transition: all 0.3s;
}

.login__btn:hover,
.login__btn:focus,
.btn--sort:hover,
.btn--sort:focus {
  outline: none;
  color: #777;
  background-color: #eee;
  border: 2px solid var(--color-primary-darker);
}

.hidden {
  display: none !important;
}

/* Logout button styles */
.logout__btn {
  border: 2px solid var(--color-tertiary);
  padding: 0.5rem 2rem;
  font-size: 1.6rem;
  background-color: #fff;
  font-family: inherit;
  text-align: center;
  border-radius: 10rem;
  margin-right: 1rem;
  color: inherit;
  cursor: pointer;
  transition: all 0.3s;
  margin-left: 2rem;
}

.logout__btn:hover,
.logout__btn:focus {
  outline: none;
  background-color: #eee;
  border: 2px solid var(--color-tertiary-darker);
  transform: scale(1.02);
}

.btn--show-modal {
  border: none;
  padding: 0.8rem 2.5rem;
  font-size: 1.6rem;
  font-family: inherit;
  text-align: center;
  border-radius: 3rem;
  color: #333;
  background-color: var(--color-primary);
  cursor: pointer;
  transition: all 0.3s;
  border: 1px solid var(--color-primary);
}

.btn--show-modal:hover,
.btn--show-modal:focus {
  outline: none;
  color: #333;
  background-color: var(--color-primary-darker);
  border-color: var(--color-primary-darker);
  transform: scale(1.02);
}

/* Remove old nav__link--btn styles */
.nav__link--btn:link,
.nav__link--btn:visited,
.nav__link--btn:hover,
.nav__link--btn:active {
  text-decoration: none;
}

.nav__link--btn.hidden {
  display: none !important;
}
/* MAIN */
.app {
  position: relative;
  display: none;
  opacity: 0;
  transition: opacity 0.5s ease-in-out, grid-template-columns 0.3s ease;
  z-index: 5;
  min-height: 80vh;
  margin-bottom: 4rem;
}

/* Kun app on aktiivinen, näytetään se aina grid-elementtinä */
.app.active {
  display: grid !important;
  opacity: 1 !important;
  position: relative !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  width: min(95%, 190rem) !important;
  height: auto !important;
  min-height: 80vh !important;
  margin-bottom: 4rem !important;
  margin-top: 4rem !important;
  gap: 2rem !important;
  padding: 2rem !important;
  z-index: 999 !important; /* Extremely high z-index to ensure it's on top */
}

/* Yksinkertainen responsiivinen layout - alle 1025px käyttää yksi sarake */
@media (max-width: 1024px) {
  .app.active {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto auto auto auto auto auto auto;
    width: min(95%, 120rem) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    margin: 2rem 0 !important;
    padding: 2rem !important;
    gap: 2rem !important;
  }
  .movements,
  .operations-column,
  .balance,
  .search-container,
  .expense-summary,
  .budget-section,
  .logout-timer {
    grid-column: 1 / -1 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }
}

/* Desktop layout - yli 1024px käyttää kaksi saraketta */
@media (min-width: 1025px) {
  .app.active {
    grid-template-columns: 1.7fr 2fr !important;
    grid-template-rows: auto auto auto auto auto auto;
  }
  .movements {
    grid-column: 1;
    grid-row: 2;
  }
  .operations-column {
    grid-column: 2;
    grid-row: 2;
  }
  .balance {
    grid-column: 1 / -1;
    grid-row: 1;
  }
  .expense-summary__container {
    grid-column: 1 / -1;
    grid-row: 4;
  }
  .expense-summary {
    grid-column: 1 / -1;
    grid-row: 3;
  }
  .budget-section {
    grid-column: 1 / -1;
    grid-row: 5;
  }
  .user-controls {
    grid-column: 1 / -1;
    grid-row: 6;
  }
}
/* Aseta grid-alueet lapsielementeille */
.search-container {
  grid-column: 1;
  grid-row: 1;
  gap: 2rem;
}

.balance {
  grid-column: 2 / -1;
  grid-row: 1;
}

.movements {
  grid-column: 1;
  grid-row: 2;
}

.operations-column {
  grid-column: 2;
  grid-row: 2;
}

.expense-summary {
  grid-column: 1 / -1; /* Full width */
  grid-row: 3;
}

.logout-timer {
  grid-column: 1 / -1; /* Full width */
  grid-row: 5;
  padding: 0 0.3rem;
  /* margin-top: 1.9rem; */
  text-align: left;
  font-size: 1.25rem;
}

.timer {
  font-weight: 500;
}

.movements,
.operations-column {
  width: 100%;
  background-color: #fff; /* Tausta näkyy selkeämmin */
  border-radius: 1rem;
  padding: 2rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.balance {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.balance__label {
  font-size: 2.2rem;
  font-weight: 500;
  margin-bottom: -0.2rem;
}

.balance__date {
  font-size: 1.4rem;
  color: #888;
}

.balance__value {
  font-size: 3.5rem;
  font-weight: 500;
  /* Removing !important to allow dynamic color changes */
  color: #729763;
  transition: color 0.3s;
}

/* HEADER */
.header {
  position: fixed; /* Fixed sijaan absolute, jotta pysyy keskellä */
  top: 55%;
  left: 50%;
  transform: translate(-50%, -50%); /* Täydellinen keskitys */
  width: 90%;
  max-width: 120rem; /* Maksimi leveys suurille näytöille */
  min-height: auto;
  max-height: 90vh; /* Suhteellinen max-korkeus */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1; /* Lower z-index than app when active */

  /* Smooth transitions */
  transition: all 0.3s ease;
}

.header.hidden {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  position: absolute !important;
  z-index: -9999 !important;
  height: 0 !important;
  width: 0 !important;
  overflow: hidden !important;
  pointer-events: none !important;
  top: -9999px !important;
  left: -9999px !important;
}

.header__title.hidden {
  display: none;
}

.header__title {
  flex: 1;
  max-width: 115rem;
  display: grid;
  grid-template-columns: 3fr 2fr;
  row-gap: 3rem;
  align-content: center;
  justify-content: center;
  align-items: start;
  justify-items: start;
  position: relative;
}

h1 {
  font-size: 5.5rem;
  line-height: 1.35;
}

h4 {
  font-size: 2.4rem;
  font-weight: 500;
}

.header__img {
  width: 100%;
  grid-column: 2 / 3;
  grid-row: 1 / span 4;
  transform: translateY(-6rem);
  border: 2px solid var(--color-primary);
  border-radius: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.highlight {
  position: relative;
}

.highlight::after {
  display: block;
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  height: 100%;
  width: 100%;
  z-index: -1;
  opacity: 0.7;
  transform: scale(1.07, 1.05) skewX(-15deg);
  background-image: var(--gradient-primary);
}

/* Button efektit */
.login__btn:active {
  transform: scale(0.9);
}

/* Logout button active state */
.logout__btn:active {
  transform: scale(0.9);
}

/* Show modal button active state */
.btn--show-modal:active {
  transform: scale(0.9);
}

/* Update and delete buttons active state */
.form__btn:active {
  transform: scale(0.9);
}

footer.footer {
  position: relative;
  bottom: 0;
  left: 0;
  width: 100%;
  z-index: 1000;
}

/* Varmistetaan että nav pysyy näkyvissä */
@media (max-width: 770px) {
  nav {
    display: flex !important;
    visibility: visible !important;
    position: relative !important;
    z-index: 1000 !important;
  }
}

/* Landscape warning - näkyy vain vaakasuunnassa mobiililaitteilla */
.landscape-warning {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  color: white;
  text-align: center;
  padding: 2rem;
}

.landscape-warning i {
  font-size: 3rem;
  margin-bottom: 1rem;
  color: #ffd700;
}

.landscape-warning p {
  font-size: 1.2rem;
  margin: 0;
}

/* Näytä vain vaakasuunnassa mobiililaitteilla */
@media only screen and (max-width: 768px) and (orientation: landscape) and (max-height: 500px) {
  .landscape-warning {
    display: flex;
  }
}
