/* 메이플 캘린더 — 메멘토 큐브 추천 화면(memento-cube.css)의 뼈대 위에 캘린더 전용 부분만 */

.cal-shell{
  width: min(1180px, calc(100% - 32px));
  --income: #3f8f4f;
  --expense: #c4533a;
  --cash: #3f7fb0;
}

html[data-theme="dark"] .cal-shell{
  --income: #7bc488;
  --expense: #e88a72;
  --cash: #7eb8d4;
}

/* 일정 색 */
.cal-c-orange{ --ev: #e8833a; }
.cal-c-green{ --ev: #5f9e4f; }
.cal-c-blue{ --ev: #3f8fc0; }
.cal-c-purple{ --ev: #8e6cc0; }
.cal-c-red{ --ev: #d0533a; }

/* ---------- 공통 버튼 ---------- */

.cal-btn{
  cursor: pointer;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--title);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
}

.cal-btn:hover:not(:disabled){
  background: var(--bg-sub);
}

.cal-btn:disabled{
  opacity: 0.55;
  cursor: wait;
}

.cal-btn.is-primary{
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.cal-btn.is-primary:hover:not(:disabled){
  background: var(--primary-hover);
}

.cal-btn.is-danger{
  border-color: var(--expense);
  background: transparent;
  color: var(--expense);
}

.cal-btn.is-danger-text{
  border-color: transparent;
  background: transparent;
  color: var(--expense);
  font-weight: 600;
}

.cal-btn.is-small{
  padding: 6px 12px;
  font-size: 13px;
}

.cal-btn-row{
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---------- 이달 요약 ---------- */

.cal-sum-title{
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 700;
  color: var(--title);
}

.cal-sum-row{
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.cal-sum-box{
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg-sub);
}

.cal-sum-label{
  font-size: 13px;
  color: var(--muted);
}

.cal-sum-num{
  font-size: 17px;
  font-weight: 800;
  color: var(--title);
  word-break: keep-all;
}

.cal-sum-box.is-income .cal-sum-num{ color: var(--income); }
.cal-sum-box.is-expense .cal-sum-num{ color: var(--expense); }
.cal-sum-box.is-cash .cal-sum-num{ color: var(--cash); }

.cal-sum-empty{
  margin-top: 12px;
}

/* ---------- 캘린더 ---------- */

.cal-layout{
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}

.cal-toolbar{
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.cal-month{
  margin: 0;
  min-width: 9.5em;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--title);
}

.cal-nav-btn,
.cal-today-btn{
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--title);
  font: inherit;
  font-weight: 700;
  border-radius: 10px;
}

.cal-nav-btn{
  width: 36px;
  height: 36px;
  font-size: 20px;
  line-height: 1;
}

.cal-today-btn{
  margin-left: auto;
  padding: 6px 14px;
  font-size: 14px;
}

.cal-nav-btn:hover,
.cal-today-btn:hover{
  background: var(--bg-sub);
}

.cal-weekdays,
.cal-grid{
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cal-weekdays{
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.cal-weekdays .is-sun,
.cal-cell.is-sun .cal-num{ color: #d0533a; }
.cal-weekdays .is-sat,
.cal-cell.is-sat .cal-num{ color: #3f7fb0; }

.cal-grid{
  gap: 4px;
}

.cal-cell{
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  min-width: 0;
  min-height: 96px;
  padding: 6px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  text-align: left;
}

.cal-cell:hover{
  border-color: var(--line);
  background: var(--bg-sub);
}

.cal-cell.is-other{
  opacity: 0.45;
}

.cal-cell.is-selected{
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary) inset;
}

.cal-num{
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--title);
}

.cal-cell.is-today .cal-num{
  align-self: flex-start;
  min-width: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff !important;
  text-align: center;
}

.cal-chips{
  display: grid;
  gap: 2px;
  min-width: 0;
}

.cal-chip{
  display: block;
  padding: 1px 6px;
  border-radius: 6px;
  border-left: 3px solid var(--ev);
  background: color-mix(in srgb, var(--ev) 14%, transparent);
  color: var(--title);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-chip-more{
  font-size: 11px;
  color: var(--muted);
  padding-left: 4px;
}

.cal-dots{
  display: none;
  gap: 3px;
  justify-content: center;
}

.cal-dot{
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--ev);
}

.cal-money{
  margin-top: auto;
  display: grid;
  justify-items: end;
  min-width: 0;
}

.cal-net{
  max-width: 100%;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.is-income{ color: var(--income); }
.is-expense{ color: var(--expense); }
.is-cash{ color: var(--cash); }

/* ---------- 선택한 날짜 ---------- */

.cal-day{
  position: sticky;
  top: 16px;
  display: grid;
  gap: 14px;
  padding: 16px;
  border-radius: 14px;
  background: var(--bg-sub);
}

.cal-day-title{
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--title);
}

.cal-today-tag{
  margin-left: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  vertical-align: 2px;
}

.cal-day-sec{
  display: grid;
  gap: 8px;
}

.cal-day-head{
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cal-day-head h4{
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}

.cal-add{
  cursor: pointer;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--primary);
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
}

.cal-add:hover{
  background: var(--primary-soft);
}

.cal-list{
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.cal-item{
  cursor: pointer;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  text-align: left;
}

.cal-item:hover{
  border-color: var(--line);
}

.cal-item-bar{
  align-self: stretch;
  flex: 0 0 4px;
  border-radius: 4px;
  background: var(--ev);
}

.cal-item-body{
  display: grid;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.cal-item-title{
  font-size: 14.5px;
  font-weight: 700;
  color: var(--title);
  overflow-wrap: anywhere;
}

.cal-item-time{
  margin-right: 6px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.cal-item-meta{
  font-size: 12.5px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.cal-item-amt{
  flex: 0 0 auto;
  max-width: 55%;
  font-size: 14px;
  font-weight: 800;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cal-entry.is-income .cal-item-amt{ color: var(--income); }
.cal-entry.is-expense .cal-item-amt{ color: var(--expense); }

.cal-cash-tag{
  padding: 0 6px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--cash) 15%, transparent);
  color: var(--cash);
  font-size: 11.5px;
  font-weight: 700;
  vertical-align: 1px;
}

.cal-empty{
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 13.5px;
}

.cal-day-total{
  margin: 0;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--muted);
  text-align: right;
}

/* ---------- 동기화·백업 ---------- */

.cal-tools{
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 24px;
}

.cal-tool{
  display: grid;
  align-content: start;
  gap: 12px;
}

.cal-tool-title{
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--title);
}

.cal-backup-at{
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--title);
}

.cal-backup-at.is-warn{
  color: var(--expense);
}

.cal-join{
  display: flex;
  gap: 8px;
}

.cal-join .mc-input{
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.cal-sync-status{
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--title);
}

.cal-sync-status.is-error{
  color: var(--expense);
}

.cal-sync-dot{
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--muted);
}

.cal-sync-dot.is-ok{ background: var(--income); }
.cal-sync-dot.is-error{ background: var(--expense); }
.cal-sync-dot.is-busy{
  background: var(--primary);
  animation: cal-blink 1s ease-in-out infinite;
}

@keyframes cal-blink{
  50%{ opacity: 0.3; }
}

.cal-code-box{
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 12px;
  background: var(--bg-sub);
}

.cal-code-label{
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.cal-code{
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--title);
  word-break: break-all;
}

.cal-code.is-masked{
  color: var(--muted);
  letter-spacing: 0.02em;
}

.cal-qr{
  width: 168px;
  padding: 6px;
  border-radius: 10px;
  background: #fff;
}

.cal-qr svg{
  display: block;
  width: 100%;
  height: auto;
}

/* ---------- 입력창 ---------- */

.cal-dialog{
  width: min(460px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: 0;
  border: none;
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-card);
}

.cal-dialog::backdrop{
  background: rgba(30, 20, 10, 0.45);
}

.cal-form{
  display: grid;
  gap: 12px;
  padding: 20px;
}

.cal-dialog-title{
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--title);
}

.cal-field{
  display: grid;
  gap: 4px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: none;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.cal-field em{
  font-style: normal;
  font-weight: 500;
}

.cal-field input[type="text"],
.cal-field input[type="date"],
.cal-field input[type="time"],
.cal-field select,
.cal-field textarea{
  width: 100%;
  min-width: 0;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-sub);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  color-scheme: light;
}

html[data-theme="dark"] .cal-field input,
html[data-theme="dark"] .cal-field select,
html[data-theme="dark"] .cal-field textarea{
  color-scheme: dark;
}

.cal-field input:focus,
.cal-field select:focus,
.cal-field textarea:focus{
  outline: none;
  border-color: var(--primary);
}

.cal-field textarea{
  resize: vertical;
}

.cal-field-row{
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.cal-seg{
  display: flex;
}

.cal-seg label{
  flex: 1;
  position: relative;
}

.cal-seg input{
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.cal-seg span{
  display: block;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}

.cal-seg input:checked + span{
  background: var(--card);
  color: var(--title);
  box-shadow: var(--shadow-soft);
}

.cal-seg input:focus-visible + span{
  outline: 2px solid var(--primary);
}

.cal-color-list{
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cal-color{
  position: relative;
  cursor: pointer;
}

.cal-color input{
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.cal-color span{
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--ev);
  border: 3px solid var(--card);
  box-shadow: 0 0 0 1px var(--line);
}

.cal-color input:checked + span{
  box-shadow: 0 0 0 2px var(--ev);
}

.cal-color input:focus-visible + span{
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.cal-color em{
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.cal-date{
  position: relative;
  display: block;
}

.cal-date input{
  color: transparent !important;
  cursor: pointer;
}

.cal-date input::-webkit-datetime-edit{
  opacity: 0;
}

.cal-date-text{
  position: absolute;
  left: 12px;
  right: 40px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-date-text.is-empty{
  color: var(--muted);
}

.cal-entry-fields{
  display: grid;
  gap: 12px;
}

.cal-krw-income img{
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
}

.cal-amount-preview{
  font-size: 13px;
  font-weight: 700;
  color: var(--title);
}

.cal-amount-preview.is-error{
  color: var(--expense);
}

.cal-dialog-actions{
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.cal-spacer{
  flex: 1;
}

.cal-ask{
  width: min(420px, calc(100% - 24px));
}

.cal-ask-msg{
  margin: 0;
  white-space: pre-line;
  font-size: 14.5px;
  line-height: 1.7;
}

.cal-ask .cal-dialog-actions{
  justify-content: flex-end;
}

/* ---------- 알림 ---------- */

.cal-toast{
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: 12px;
  background: #3a2e24;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-card);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.cal-toast.is-show{
  opacity: 1;
  transform: translate(-50%, 0);
}

.cal-toast.is-error{
  background: #a8432d;
}

/* ---------- 좁은 화면 ---------- */

@media (max-width: 860px){
  .cal-layout{
    grid-template-columns: 1fr;
  }

  .cal-day{
    position: static;
  }
}

@media (max-width: 600px){
  .cal-board{
    padding: 12px 8px;
  }

  .cal-grid{
    gap: 2px;
  }

  .cal-cell{
    min-height: 58px;
    padding: 4px 2px;
    align-items: center;
    border-radius: 8px;
  }

  .cal-cell.is-today .cal-num{
    align-self: center;
  }

  .cal-chips{
    display: none;
  }

  .cal-dots{
    display: flex;
  }

  .cal-money{
    justify-items: center;
  }

  .cal-net{
    font-size: 10px;
    letter-spacing: -0.03em;
  }

  .cal-month{
    min-width: 0;
    font-size: 18px;
  }

  .cal-sum-num{
    font-size: 15px;
  }

  .cal-field-row{
    grid-template-columns: 1fr;
  }
}
