body {
  margin: 0;
  touch-action: none;
}

main {
  width: 100%;
  height: calc(100% - 100px);
  display: flex;
  left: 0;
  top: 0;
  position: fixed;
  flex-direction: column;
  align-items: center;
  padding-top: 20px;
  box-sizing: border-box;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}

search {
  width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
}

search > * {
  width: 90%;
  max-width: 800px;
}

load {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #0093ff;
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0;
  top: 0;
  transform: translateY(0px);
  opacity: 1;
  transition: all 0.5s;
  z-index: 99;
  flex-direction: column;
  gap: 50px;
}

#login {
  width: 250px;
}

#login-redirect {
  background-color: white;
  color: #0093ff;
  border: 2px solid white;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: bold;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s;
}

#login-redirect:hover {
  background-color: #f0f8ff;
  transform: scale(1.05);
}

load.hidden {
  transform: translateY(100%);
  opacity: 0;
}

body {
  font-family: Arial, sans-serif;
  padding: 20px;
}

.search-container {
  margin-bottom: 10px;
  text-align: center;
}

.table {
  display: flex;
  flex-direction: column;
  border: 1px solid #ccc;
  border-radius: 5px;
  max-width: 600px;
  overflow: auto;
}

.row {
  display: flex;
  padding: 10px;
  border-top: 1px solid #eee;
  cursor: pointer;
}
/* 
.row:first-child {
  border-top: none;
  font-weight: bold;
  background-color: #f4f4f4;
} */

.row:hover:not(.header) {
  background-color: #f0f8ff;
}

.cell {
  flex: 1;
}

input[type="text"],
select {
  padding: 6px;
  width: 100%;
  max-width: 600px;
  box-sizing: border-box;
}

footer {
  position: fixed;
  width: 100%;
  height: 100px;
  left: 0;
  bottom: 0;
  background-color: #0093ff;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

footer img {
  width: 60px;
}

.out {
  display: none !important;
}

#profile {
  width: 80%;
  overflow-y: auto;
}

#profile fieldset {
  border: 1px solid gray;
  padding: 8px;
  margin: 5px;
  border-radius: 5px;
}

.main {
  width: 80%;
  height: 100%;
  overflow-y: auto;
}

#profile fieldset legend {
  color: gray;
}

#calendar {
  height: 100%;
}

#month {
  display: grid;
  grid-template-columns: repeat(7, calc(100% / 7));
  border: 1px solid black;
  overflow-y: auto;
  overflow-x: hidden;
  height: 95%;
}

.day {
  border: 1px solid black;
  width: 100%;
  /* height: 80px; */
}

#monthlabel {
  display: inline;
}

#calendar span {
  cursor: pointer;
}

button {
  background-color: #0093ff;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
  margin: 5px;
  margin-top: 10px;
}

.person-tag {
  display: inline-block;
  padding: 5px 10px;
  background-color: #f0f8ff;
  border-radius: 15px;
  margin-right: 5px;
  margin-top: 3px;
  cursor: pointer;
  border: #0093ff 1px solid;
}

.person-tag:hover {
  background-color: #e0f0ff;
}

.hidden {
  display: none !important;
}

#person_select_modal,
#add_person {
  width: 60%;
  display: flex;
  justify-content: center;
  flex-direction: column;
  border: 3px solid black;
  align-items: center;
  left: 50%;
  position: fixed;
  top: 50%;
  background-color: white;
  border-radius: 50px;
  box-sizing: border-box;
  padding: 20px;
  gap: 20px;
  transform: translate(-50%, -50%);
  box-shadow: black 10px 10px 20px;
  z-index: 100;
  max-height: 80%;
  overflow-y: auto;
}

.fam-id-span{
  border: 2px solid dodgerblue;
  margin: 10px;
  padding: 10px;
  width: 50%;
  border-radius: 5px;
}

.fam-id-span > .familyName{
  font-weight: bold;
}

#tree{
  overflow: hidden;
}

/* Role badges */
.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.8em;
  margin-left: 8px;
}

.role-badge.owner {
  background-color: #28a745;
  color: white;
}

.role-badge.editor {
  background-color: #ffc107;
  color: black;
}

.role-badge.viewer {
  background-color: #6c757d;
  color: white;
}

.manage-btn {
  display: block;
  margin-top: 8px;
  font-size: 0.9em;
  padding: 5px 10px;
}

/* Permissions modal */
#permissions_modal {
  width: 60%;
  display: flex;
  justify-content: center;
  flex-direction: column;
  border: 3px solid black;
  align-items: center;
  left: 50%;
  position: fixed;
  top: 50%;
  background-color: white;
  border-radius: 20px;
  box-sizing: border-box;
  padding: 20px;
  gap: 10px;
  transform: translate(-50%, -50%);
  box-shadow: black 10px 10px 20px;
  z-index: 100;
  max-height: 80%;
  overflow-y: auto;
}

#permissions_modal .modal-content {
  width: 100%;
  text-align: center;
}

#permissions_modal input[type="email"] {
  width: 60%;
  margin: 5px;
}

#permissions_modal select {
  width: auto;
  margin: 5px;
}

#permissions_modal ul {
  list-style: none;
  padding: 0;
}

#permissions_modal li {
  padding: 8px;
  border-bottom: 1px solid #eee;
}

#permissions_modal li button {
  background-color: #dc3545;
  padding: 3px 8px;
  font-size: 0.8em;
}

/* Filters Tab - Mobile First */
#filters {
  padding: 10px;
  box-sizing: border-box;
}

#filters h1 {
  text-align: center;
  margin: 0 0 15px 0;
  font-size: 1.5rem;
}

.filters-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.filter-section {
  background: #f8f9fa;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #e9ecef;
}

.filter-section h3 {
  margin: 0 0 8px 0;
  font-size: 0.9rem;
  color: #495057;
}

.filter-section select,
.filter-section input[type="number"] {
  width: 100%;
  padding: 10px;
  border: 1px solid #ced4da;
  border-radius: 5px;
  font-size: 1rem;
  box-sizing: border-box;
}

.age-range {
  display: flex;
  align-items: center;
  gap: 10px;
}

.age-range input {
  flex: 1;
  min-width: 0;
}

.age-range span {
  color: #6c757d;
  flex-shrink: 0;
}

.filter-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 5px;
}

.filter-actions button {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  margin: 0;
}

.secondary-btn {
  background-color: #6c757d;
}

.secondary-btn:hover {
  background-color: #5a6268;
}

.filter-results {
  margin-bottom: 20px;
}

.filter-results h3 {
  margin: 0 0 10px 0;
  font-size: 1rem;
  color: #495057;
}

#filter-table {
  max-height: 300px;
  overflow-y: auto;
}

.export-section {
  padding: 15px;
  background: #e7f3ff;
  border-radius: 8px;
  text-align: center;
}

.export-section h3 {
  margin: 0 0 10px 0;
  font-size: 1rem;
  color: #0056b3;
}

.export-section button {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  margin: 0;
}

/* Tablet and larger screens */
@media (min-width: 600px) {
  .filters-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
  }

  .filter-actions {
    grid-column: span 2;
    flex-direction: row;
    justify-content: center;
  }

  .filter-actions button {
    width: auto;
    min-width: 150px;
  }

  .export-section button {
    width: auto;
    min-width: 200px;
  }
}

/* Desktop screens */
@media (min-width: 900px) {
  .filters-container {
    grid-template-columns: repeat(3, 1fr);
  }

  .filter-actions {
    grid-column: span 3;
  }

  #filter-table {
    max-height: 400px;
  }
}

/* Calendar Tab - Mobile First */
#calendar {
  width: 95%;
  padding: 5px;
  box-sizing: border-box;
}

#calendar > span {
  font-size: 1.5rem;
  padding: 10px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#monthlabel {
  font-size: 1.2rem;
  min-width: 120px;
  text-align: center;
}

#month {
  font-size: 0.7rem;
}

.day {
  min-height: 60px;
  padding: 2px;
  box-sizing: border-box;
  overflow: hidden;
}

.day .person-tag {
  font-size: 0.6rem;
  padding: 2px 4px;
  margin: 1px;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Tree Tab - Mobile First */
#tree {
  width: 100%;
  padding: 10px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

/* Tree controls */
.tree-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.tree-search-container {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.tree-search-container input {
  width: 100%;
  padding: 10px;
  font-size: 1rem;
  border: 1px solid #ced4da;
  border-radius: 5px;
  box-sizing: border-box;
}

#tree-search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #ced4da;
  border-radius: 5px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  display: none;
}

#tree-root-name {
  font-weight: bold;
  color: #0056b3;
  padding: 8px 15px;
  background: #e7f3ff;
  border-radius: 20px;
  font-size: 1rem;
}

#tree_display {
  flex: 1;
  touch-action: none;
  border: 1px solid #ccc;
  border-radius: 5px;
  background: #fafafa;
}

/* Tablet and larger for calendar */
@media (min-width: 600px) {
  #calendar {
    width: 90%;
  }

  #month {
    font-size: 0.85rem;
  }

  .day {
    min-height: 80px;
    padding: 4px;
  }

  .day .person-tag {
    font-size: 0.75rem;
    padding: 3px 6px;
  }

  #monthlabel {
    font-size: 1.4rem;
  }
}

/* Desktop for calendar */
@media (min-width: 900px) {
  #calendar {
    width: 80%;
  }

  #month {
    font-size: 1rem;
  }

  .day {
    min-height: 100px;
    padding: 5px;
  }

  .day .person-tag {
    font-size: 0.85rem;
    padding: 5px 10px;
    display: inline-block;
  }
}

/* Tablet and larger for tree */
@media (min-width: 600px) {
  #tree {
    width: 95%;
  }

  .tree-search-container {
    max-width: 300px;
  }
}

@media (min-width: 900px) {
  #tree {
    width: 90%;
  }
}

/* Descendant filter */
.descendant-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.descendant-filter input[type="text"] {
  flex: 1;
  min-width: 150px;
}

#filter-descendant-name {
  font-weight: bold;
  color: #0056b3;
  padding: 5px 10px;
  background: #e7f3ff;
  border-radius: 15px;
}

.clear-btn {
  background: #dc3545;
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  padding: 0;
  margin: 0;
  cursor: pointer;
  font-size: 14px;
  line-height: 24px;
  min-width: 24px;
}

.search-dropdown {
  display: none;
  position: absolute;
  background: white;
  border: 1px solid #ced4da;
  border-radius: 5px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 50;
  width: calc(100% - 24px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.search-result-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid #eee;
}

.search-result-item:hover {
  background-color: #f0f8ff;
}

.search-result-item:last-child {
  border-bottom: none;
}

.filter-section {
  position: relative;
}