/* Base reset */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", Arial, sans-serif; line-height: 1.5; color: #111; background: #f7f7fb; }

/* Login */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-container { width: min(420px, 92vw); }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
.card { background: #fff; border: 1px solid #e6e6ef; border-radius: 14px; padding: 1.2rem; box-shadow: 0 2px 12px rgba(0,0,0,0.06); transition: box-shadow 0.3s ease; }
.card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
.field { display: grid; gap: .5rem; margin: 1rem 0; }
label { font-weight: 600; }
input[type="text"], input[type="password"], select { padding: .7rem .8rem; border: 1px solid #d2d2e6; border-radius: 10px; font-size: 1rem; background: #fff; transition: all 0.2s ease; }
input:focus, select:focus { outline: none; border-color: #1F4788; box-shadow: 0 0 0 3px rgba(31,71,136,0.15); }

/* [NEW] 읽기전용 입력 시각 힌트 */
input.readonly {
  background: #f1f3f9;
  color: #666;
  cursor: not-allowed;
}

.hint { color: #666; font-size: .85rem; }
.error { color: #b00020; min-height: 1.2rem; }
.btn { padding: .7rem 1rem; border-radius: 10px; border: 1px solid #d2d2e6; background: #fff; cursor: pointer; font-weight: 500; transition: all 0.2s ease; }
.btn:hover { background: #f8f9fc; border-color: #1F4788; }
.btn.primary { background: #1F4788; border-color: #1F4788; color: #fff; font-weight: 600; }
.btn.primary:hover { background: #163a6b; box-shadow: 0 2px 6px rgba(31,71,136,0.3); transform: translateY(-1px); }

.btn:disabled {
  background: #f0f1f6;
  color: #9aa0b4;
  border-color: #e1e3ef;
  cursor: not-allowed;
  opacity: .85;
}
.btn.primary:disabled {
  background: #9bb4d9;
  border-color: #9bb4d9;
  color: #ffffff;
  opacity: .7;
}

/* Settings > 개체관리: 삭제 버튼(관리자 전용) */
.btn.del-btn {
  background: #f44336;
  border-color: #d32f2f;
  color: #fff;
  font-weight: 700;
}
.btn.del-btn:hover { background: #d32f2f; transform: translateY(-1px); box-shadow: 0 2px 6px rgba(211, 47, 47, 0.4); }
.btn.del-btn:focus-visible { outline-color: #d32f2f; }
.btn:focus-visible { outline: 2px solid #1F4788; outline-offset: 2px; }
.btn-group { display: flex; gap: .6rem; }
.muted { color: #666; font-size: .9rem; margin-top: .6rem; }

/* App shell */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 2px solid #e6e6ef;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: #1F4788;
}
.logo { font-size: 1.4rem; }
.user-actions {
  display: flex;
  align-items: center;
  gap: .8rem;
}
.user-email {
  color: #555;
  font-size: .95rem;
  font-weight: 500;
}

.tabs {
  display: flex;
  gap: .4rem;
  background: #fff;
  border-bottom: 1px solid #e6e6ef;
  padding: .6rem 1rem;
  overflow: auto;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  position: sticky;
  top: 70px;
  z-index: 90;
}
#app-navigation { opacity: 0; transition: opacity 0.2s ease-in; }
#app-navigation.loaded { opacity: 1; }
.tab {
  display: inline-block;
  padding: .7rem 1.2rem;
  border-radius: 10px;
  text-decoration: none;
  color: #555;
  font-weight: 600;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}
.tab:hover {
  background: #f8f9fc;
  color: #1F4788;
}
.tab[aria-current="page"], .tab.active {
  background: #1F4788;
  color: #fff;
  box-shadow: 0 2px 6px rgba(31,71,136,0.3);
}
.tab:focus-visible { outline: 2px solid #1F4788; outline-offset: 2px; }

.content { padding: 1.2rem 1.5rem; }
.view h2 { margin-top: 0; }

/* Schedule */
.schedule-header { display: flex; justify-content: space-between; align-items: center; gap: .8rem; margin-bottom: .8rem; }
.schedule-left { display: flex; align-items: center; gap: .6rem; }
.month-label { margin: 0; font-size: 1.3rem; font-weight: 700; color: #1F4788; }
.schedule-wrap { background: #fff; border: 1px solid #e6e6ef; border-radius: 14px; padding: 1.2rem; box-shadow: 0 2px 12px rgba(0,0,0,0.06); transition: box-shadow 0.3s ease; }
.schedule-wrap:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.08); }

.calendar-view { display: grid; grid-template-rows: auto 1fr; }
.calendar-header { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; padding: 0; background: #e0e0e0; border: 1px solid #e0e0e0; color: #555; font-weight: 700; font-size: .95rem; }
.calendar-header > div { background: #f5f5f5; padding: 12px; text-align: center; }
.calendar-grid { position: relative; display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: 1fr; gap: 1px; background: #e0e0e0; border: 1px solid #e0e0e0; min-height: 0; }
.day-cell { border: none; padding: .6rem; background: #fff; display: flex; flex-direction: column; min-height: 120px; text-align: left; position: relative; }
.day-cell:hover { background: #fafafa; }
.day-head { display: flex; align-items: baseline; gap: .4rem; margin-bottom: 8px; min-height: 22px; }
.day-cell .day-num { font-weight: 700; color: #333; font-size: 1rem; display: inline-block; }
.holiday-note { font-weight: 700; font-size: 0.85rem; color: #d32f2f; }
.day-sat .day-num { color: #1976d2; }
.day-sun .day-num { color: #d32f2f; }
.day-holiday .day-num { color: #d32f2f !important; }
.day-cell .items { display: grid; gap: .25rem; overflow: visible; position: relative; z-index: 1; }
.item-line { font-size: .85rem; line-height: 1.2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 2px 4px; background: #f0f0f0; border-left: 3px solid #1F4788; border-radius: 2px; }
.more-line { color: #888; font-weight: 600; cursor: pointer; font-size: .75rem; padding: 2px 4px; background: #e8e8e8; border-radius: 2px; text-align: center; }
.more-line:hover { background: #d0d0d0; color: #555; }

/* 공통 일정 레이어 - calendar-grid 기준 absolute */
.common-events-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

/* 공통 일정 바 - 셀 경계를 넘어 이어짐 */
.common-event-bar {
  position: absolute;
  height: 20px;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: .8rem;
  font-weight: 600;
  color: white;
  display: flex;
  align-items: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: auto;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

/* Cards (관리카드) - centered & constrained */
.cards-search, .cards-table-wrap {
  background: #fff; border: 1px solid #e6e6ef; border-radius: 14px;
  padding: 1.2rem; box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  max-width: 1000px; margin: 0 auto 1rem;
  transition: box-shadow 0.3s ease;
}
.cards-search:hover, .cards-table-wrap:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}
.cards-table-wrap.slim { max-width: 800px; } /* used in settings subview */
.cards-search .row {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr)) auto; /* 필터 4칸(최소 120px) + 버튼영역(auto) */
  align-items: end;
  gap: .8rem;
}
.cards-search .actions {
  display: flex;
  gap: .6rem;
  justify-content: flex-end; /* 오른쪽 끝 정렬 */
}
.cards-search .field.small { margin: 0; }
/* 위치 입력칸 스타일 통일 */
.cards-search input[name="location"] {
  box-sizing: border-box;
  border: 1px solid #d2d2e6;
  border-radius: 10px;
  padding: .7rem .8rem;
  font-size: 1rem;
  background: #fff;
  width: 100%;
}
.table { width: 100%; border-collapse: collapse; background: #fff; }
.table th, .table td { border: 1px solid #e6e6ef; padding: .7rem .8rem; font-size: .95rem; }
.table th { background: #f8f9fc; text-align: left; font-weight: 600; }

/* Cards table widths */
.table.cards-table { table-layout: fixed; }
.table.cards-table th, .table.cards-table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: .7rem .8rem;
  border: 1px solid #e6e6ef;
  box-sizing: border-box;
}
/* 위치 칸 최소 너비 보장 */
.table.cards-table th:nth-child(6),
.table.cards-table td:nth-child(6) {
  min-width: 80px;
}
/* 작업(마지막) 칸은 버튼 2개가 들어가므로 표시 방식 조정 */
.table.cards-table td:last-child, .table.cards-table th:last-child { overflow: visible; text-overflow: clip; }
.table.cards-table td:last-child { display: flex; gap: .5rem; justify-content: flex-start; align-items: center; }
.table.cards-table td:last-child .btn { padding: .35rem .5rem; transition: all 0.2s ease; }
.table.cards-table tbody tr { transition: background-color 0.2s ease; }
.table.cards-table tbody tr:hover { background-color: #f8f9fc; }

/* Settings layout */
.settings-layout { display: grid; grid-template-columns: 220px minmax(0,1fr); gap: 1.2rem; }
.side-menu { background: #fff; border: 1px solid #e6e6ef; border-radius: 14px; padding: .8rem; height: fit-content; position: sticky; top: 64px; box-shadow: 0 2px 8px rgba(0,0,0,0.04); }
.side-title { font-weight: 800; color: #1F4788; margin: .2rem .4rem .6rem; }
.side-item { display: block; width: 100%; text-align: left; padding: .6rem .8rem; margin: .2rem 0; border-radius: 10px; background: transparent; border: 1px solid transparent; cursor: pointer; transition: all 0.2s ease; }
.side-item:hover { background: #f8f9fc; }
.side-item.active { background: #1F4788; color: #fff; border-color: #1F4788; }
/* [NEW] 버튼/링크 모두 동일한 글꼴 크기/색으로 강제 */
.side-menu .side-item,
.side-menu a.side-item,
.side-menu button.side-item {
  font-size: 1rem;
}
/* [NEW] 사이드 메뉴의 링크를 버튼/텍스트와 동일한 스타일로 */
.side-menu a.side-item {
  color: #333;
  text-decoration: none;
}
.side-menu a.side-item:visited { color: #333; }
.side-menu a.side-item:hover,
.side-menu a.side-item:focus { text-decoration: none; }
.side-menu a.side-item.active { color: #fff; }
.settings-content { background: #fff; border: 1px solid #e6e6ef; border-radius: 14px; padding: 1.2rem; box-shadow: 0 2px 8px rgba(0,0,0,0.04); transition: box-shadow 0.3s ease; }
.settings-content:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.06); }
.inline-search { display: flex; align-items: center; gap: .6rem; margin-bottom: .8rem; }
.inline-search input { width: 220px; }
.inline-search label { margin-right: .3rem; }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin: 0 0 1rem; }
.toolbar .grow { flex: 1 1 auto; }

/* Ensure hidden attribute is respected */
[hidden] { display: none !important; }

/* Responsive */
@media (max-width: 1024px) {
  .cards-search, .cards-table-wrap { max-width: 92vw; }
}
@media (max-width: 900px) {
  .settings-layout { grid-template-columns: 1fr; }
  .side-menu { position: static; }
}
@media (max-width: 640px) {
  .tabs { gap: .1rem; }
  .tab { padding: .5rem .7rem; font-size: .95rem; }
  .calendar-view { height: 70vh; }
}

/* Delete badge (개체코드 옆 작은 빨간 X 버튼) */
.x-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-left: 6px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: #f44336;
  border: 1px solid #d32f2f;
  border-radius: 50%;
  cursor: pointer;
  vertical-align: middle;
  transition: all 0.2s ease;
}
.x-badge:hover {
  background: #d32f2f;
  transform: scale(1.1);
  box-shadow: 0 2px 6px rgba(211, 47, 47, 0.4);
}

/* === Month Picker Popover === */
.popover.month-picker {
  position: absolute;
  background: #fff;
  border: 1px solid #e6e6ef;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  padding: 1rem;
  z-index: 1000;
  width: 220px;
}

.popover.month-picker .mp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.popover.month-picker .mp-header .icon-btn {
  border: none;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
  color: #333;
  transition: all 0.2s ease;
  padding: .2rem;
  border-radius: 4px;
}
.popover.month-picker .mp-header .icon-btn:hover {
  background: #f8f9fc;
  color: #1F4788;
}

.popover.month-picker .mp-title {
  font-weight: bold;
  font-size: 14px;
}

.popover.month-picker .months-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}

.popover.month-picker .month-btn {
  padding: 6px 4px;
  border: none;
  border-radius: 6px;
  background: #f8f9fc;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s ease;
}

.popover.month-picker .month-btn:hover {
  background: #e8f1ff;
  color: #1F4788;
}

.popover.month-picker .month-btn.active {
  background: #1F4788;
  color: #fff;
  font-weight: bold;
}

.popover.month-picker .mp-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.popover.month-picker .btn.small {
  padding: 4px 8px;
  font-size: 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: #eee;
}

.popover.month-picker .btn.small:hover {
  background: #ddd;
}

/* === Modal Styles for Objective === */
/* objectiveModal, objectiveDetailPopup 등 최상위 .modal 요소용 */
/* animal_detail.html의 .modal-backdrop > .modal과 구분하기 위해 :not() 사용 */
.modal:not(.modal-backdrop > .modal) {
  display: none;
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  justify-content: center;
  align-items: center;
}

.modal-content {
  background-color: #fff;
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  animation: modalFadeIn 0.3s ease;
}
@keyframes modalFadeIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid #e6e6ef;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.4rem;
  color: #111;
}

.close-btn {
  background: none;
  border: none;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  color: #666;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.close-btn:hover {
  background: #f8f9fc;
  color: #1F4788;
  transform: rotate(90deg);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .6rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid #e6e6ef;
}

.form-group {
  margin-bottom: 1.2rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: #333;
}

.form-control {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid #d2d2e6;
  border-radius: 10px;
  font-size: 1rem;
  background: #fff;
  transition: all 0.2s ease;
}

.form-control:focus {
  outline: none;
  border-color: #1F4788;
  box-shadow: 0 0 0 3px rgba(31, 71, 136, 0.15);
}

textarea.form-control {
  resize: vertical;
  font-family: inherit;
}

.btn.secondary {
  background: #fff;
  border-color: #d2d2e6;
  color: #333;
}

.btn.secondary:hover {
  background: #f8f9fc;
  border-color: #1F4788;
}

/* === Loading Indicator === */
.loading-indicator {
  position: fixed;
  top: 120px;
  right: 20px;
  background: #fff;
  border: 1px solid #e6e6ef;
  border-radius: 14px;
  padding: 1rem 1.2rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 9999;
  display: none;
  min-width: 220px;
  animation: slideInRight 0.3s ease;
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}
.loading-indicator.show { display: block; }
.loading-title { font-weight: 600; margin-bottom: 8px; font-size: 14px; }
.loading-progress { font-size: 13px; color: #666; }
.loading-bar {
  width: 100%;
  height: 4px;
  background: #e6e6ef;
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}
.loading-bar-fill {
  height: 100%;
  background: #1F4788;
  transition: width 0.3s ease;
  width: 0%;
}
.loading-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #e6e6ef;
  border-top-color: #1F4788;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
