/* ===== Base ===== */
:root {
  --bg: #f9fafb;
  --surface: #ffffff;
  --surface-2: #f3f4f6;

  --text: #1f2a24;
  --muted: #6b6f6c;

  --line: #e5e7eb;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.04);

  --brand: #6f8b6f; /* 세이지 그린 */
  --brand-2: #9fb09a;
  --chip: #f3f4f6;

  --radius: 16px;
  --radius-sm: 12px;

  --topbar-h: 64px;
  --max: 1200px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    "Apple SD Gothic Neo",
    "Noto Sans KR",
    "Malgun Gothic",
    Arial,
    sans-serif;
  color: var(--text);
  background: var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.topbar__left,
.topbar__right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.1rem;
}

.iconbtn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.iconbtn:hover {
  background: var(--surface-2);
}

.avatar {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  width: 38px;
  height: 38px;
  cursor: pointer;
}

/* ===== Search ===== */
.search {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px 12px;
  min-width: 240px;
}

.search__input {
  border: none;
  outline: none;
  background: transparent;
  width: 100%;
  padding: 6px;
  font-size: 14px;
}

.search__btn {
  border: none;
  background: transparent;
  cursor: pointer;
  opacity: 0.5;
}

/* ===== Layout ===== */
.layout {
  max-width: var(--max);
  margin: 20px auto 40px;
  padding: 0 14px;
  display: grid;
  grid-template-columns: 260px 1fr 280px;
  gap: 20px;
  align-items: start;
}

/* ===== Card 스타일 (공통) ===== */
.card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

/* ===== Sidebar ===== */
.sidecard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sidecard__head {
  background: var(--brand-2);
  padding: 24px 20px;
  color: #fff;
}

.sidecard__title {
  font-size: 1.1rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidelist {
  padding: 12px;
}

.sidelist__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 14px;
  color: var(--muted);
  transition: all 0.2s;
  margin-bottom: 4px;
}

.sidelist__item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidelist__item.is-active {
  background: #eff3ef;
  color: var(--brand);
  font-weight: 700;
}

/* ===== Calendar (Schedule View) ===== */
.calendar-container {
  display: flex;
  gap: 24px;
  background: #fcfdfc;
  border-radius: var(--radius-sm);
  padding: 10px;
}

.calendar-selected {
  flex: 0 0 140px;
  text-align: center;
  border-right: 1px solid var(--line);
  padding-right: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.cal-nav button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
}

#calYM {
  font-size: 0.9rem;
  font-weight: 700;
}

.selected-day-big {
  font-size: 4rem;
  font-weight: 900;
  color: var(--brand);
  line-height: 1;
}

.selected-day-text {
  color: var(--muted);
  font-size: 0.9rem;
}

.calendar-grid-wrapper {
  flex: 1;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.calendar-grid__wk {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding-bottom: 8px;
}

.calendar-grid__day {
  aspect-ratio: 1 / 1;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s;
}

.calendar-grid__day:hover {
  background: #f0f2f0;
}

.calendar-grid__day.is-today {
  color: var(--brand);
  background: #eff3ef;
}

.calendar-grid__day.is-selected {
  background: var(--brand);
  color: #fff;
}

.schedule-list-footer {
  margin-top: 20px;
  padding: 16px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-align: center;
}

/* ===== Memo View ===== */
.memo-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 20px;
}

.memo-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 500px;
  overflow-y: auto;
}

.memo-editor {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field__input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.field__input:focus {
  border-color: var(--brand);
}

.textarea {
  min-height: 300px;
  resize: none;
}

/* ===== Buttons ===== */
.btn {
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  border: none;
}

.btn--primary {
  background: var(--brand);
  color: #fff;
}

.btn--primary:hover {
  background: #5a735a;
}

.w-full {
  width: 100%;
}

/* ===== Login Panel ===== */
.panel__title {
  font-weight: 800;
  margin-bottom: 10px;
  display: block;
}
.login {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 240px 1fr;
  }
  .right {
    display: none;
  }
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  } /* 모바일에서는 햄버거 메뉴 로직 필요 */
  .calendar-container {
    flex-direction: column;
  }
  .calendar-selected {
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 0 0 20px;
    flex: none;
  }
  .memo-layout {
    grid-template-columns: 1fr;
  }
}

/* 추가 버튼 스타일 */
.btn--add {
  margin-top: 20px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  padding: 8px 16px;
}

/* 일정 입력 폼 */
.schedule-form {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
}

.form-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.form-btns {
  display: flex;
  gap: 8px;
}

.btn--save {
  background: var(--brand);
  color: #fff;
}
.btn--cancel {
  background: var(--chip);
}

.textarea--sm {
  min-height: 80px;
  margin-top: 8px;
}

/* [중요] 간략히 보기 모드일 때 스타일 */
.is-summary .calendar-grid-wrapper {
  display: none; /* 그리드 숨김 */
}

.is-summary .calendar-container {
  padding: 10px;
  justify-content: center;
}

.is-summary .calendar-selected {
  border-right: none;
  flex: 1;
  flex-direction: row; /* 가로 배열 (이미지 3번 참고) */
  align-items: center;
  gap: 20px;
}

/* ===== Dashboard Layout ===== */
.dashboard {
  margin-top: 10px;
}

.dashboard__row {
  display: grid;
  grid-template-columns: 1.8fr 1fr; /* 메모 갤러리를 더 넓게 */
  gap: 14px;
}

.card__subtitle {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

/* 최근 메모 갤러리 */
.memo-gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.memo-card {
  background: #fcfdfc;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  transition: transform 0.2s;
  cursor: pointer;
}

.memo-card:hover {
  transform: translateY(-3px);
  border-color: var(--brand);
}

.memo-card__title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--brand);
}

.memo-card__desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2; /* 두 줄만 표시 */
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 가계부 요약 */
.spending-box {
  padding: 10px 0;
  text-align: center;
}

.spending-amount {
  font-size: 24px;
  font-weight: 900;
  color: var(--text);
  margin-bottom: 12px;
}

.spending-bar-container {
  height: 10px;
  background: var(--chip);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 10px;
}

.spending-bar {
  height: 100%;
  background: var(--brand); /* 세이지 그린색 바 */
  border-radius: 999px;
}

.spending-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

/* 모바일 대응 */
/* ===== 모바일 전용 스타일 (860px 이하) ===== */
@media (max-width: 860px) {
  /* 1. 레이아웃: 1단으로 변경, 오른쪽 로그인 패널 숨김 */
  .layout {
    grid-template-columns: 1fr;
    padding: 0 10px;
  }
  .right {
    display: none;
  }

  /* 2. 상단바: 검색창 슬림화 및 오밀조밀함 해결 */
  .topbar {
    padding: 0 10px;
    gap: 8px;
  }
  .brand__name {
    font-size: 15px;
  }
  .search {
    min-width: 100px;
    flex: 1; /* 남는 공간을 검색창이 차지 */
    padding: 2px 8px;
  }

  /* 3. 사이드바: 왼쪽에서 나타나는 서랍장(Drawer)으로 변신 */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    background: var(--surface);
    z-index: 1000;
    transform: translateX(-110%); /* 왼쪽으로 숨기기 */
    transition: transform 0.3s ease;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.1);
    margin: 0;
    padding: 20px 10px;
    display: flex !important; /* 모바일에서도 보이게 함 */
    flex-direction: column;
  }

  /* 서랍장이 열렸을 때 상태 */
  .sidebar.is-open {
    transform: translateX(0);
  }

  /* 서랍장 내부 모바일 전용 로그인 영역 스타일 */
  .mobile-auth {
    margin-top: auto; /* 하단으로 밀기 */
    padding: 15px;
    background: #f8faf8;
    border-radius: 16px;
    border: 1px solid var(--line);
  }

  /* 어두운 배경 오버레이 */
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 999;
    display: none;
    backdrop-filter: blur(2px);
  }
  .sidebar-overlay.is-active {
    display: block;
  }
}

/* PC(861px 이상)에서는 햄버거 버튼 숨기기 (선택사항) */
@media (min-width: 861px) {
  #menuBtn {
    display: none;
  }
}

/* PC에서는 모바일 전용 인증 영역을 아예 안 보이게 함 */
#mobileAuthArea {
  display: none;
}

/* 모바일 화면(860px 이하)에서만 다시 보이게 함 */
@media (max-width: 860px) {
  #mobileAuthArea {
    display: block;
    margin-top: 20px;
    padding: 15px;
    border-top: 1px solid var(--line);
  }
}
