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

body {
  font-family: 'Malgun Gothic', 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: #e0e0e0;
  background: #111827;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

#app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

/* ── 상단 바 ── */
.top-bar {
  background: #1e293b;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px 16px;
  gap: 8px 10px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.nav-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.nav-btn {
  background: rgba(99,102,241,.15);
  border: none;
  color: #a5b4fc;
  font-size: 13px;
  width: 32px; height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: rgba(99,102,241,.3); color: #fff; }
.nav-btn:active { background: rgba(99,102,241,.5); }
.view-title {
  font-size: 15px;
  font-weight: 700;
  color: #f1f5f9;
  white-space: nowrap;
}
.filter-select {
  padding: 5px 10px;
  background: rgba(99,102,241,.12);
  border: 1px solid rgba(99,102,241,.25);
  color: #cbd5e1;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  flex-shrink: 0;
  cursor: pointer;
}
.filter-select:focus {
  outline: 2px solid #6366f1;
  outline-offset: 1px;
  border-color: #6366f1;
}
.view-select {
  min-width: 44px;
  text-align: center;
}

.holiday-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: #94a3b8;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
}
.holiday-toggle input {
  accent-color: #ef4444;
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ── 검색 바 ── */
.search-bar {
  padding: 6px 16px 6px;
  background: #1e293b;
  flex-shrink: 0;
}
.search-input {
  width: 100%;
  padding: 8px 14px;
  background: #111827;
  border: 1px solid #334155;
  color: #e2e8f0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s;
}
.search-input:focus {
  outline: 2px solid #6366f1;
  outline-offset: -1px;
  border-color: #6366f1;
}
.search-input::placeholder { color: #64748b; }

/* ── 월별 헤더 ── */
.month-header {
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 700;
  color: #dce0f0;
  background: rgba(55, 71, 103, .9);
  border-bottom: 1px solid rgba(99,102,241,.15);
}

/* ── 일정 리스트 ── */
.event-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  background: #111827;
}
.event {
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,.04);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: background .12s;
}
.event:hover { background: rgba(99,102,241,.08); }
.event:active { background: rgba(99,102,241,.15); }
.event.sel {
  background: rgba(99,102,241,.2);
  border-left: 3px solid #6366f1;
  padding-left: 17px;
}
.event.readonly { opacity: 0.85; }
.event-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 72px;
  flex-shrink: 0;
}
.event-date {
  font-size: 15px;
  color: #94a3b8;
  white-space: nowrap;
  font-weight: 500;
}
.event-time {
  font-size: 14px;
  color: #8b9ab5;
  white-space: nowrap;
  margin-top: 2px;
}
.event.sel .event-date { color: #c7d2fe; font-weight: 600; }
.event.sel .event-time { color: #a5b4fc; }
.age-badge {
  font-size: 13px;
  color: #f59e0b;
  font-weight: 700;
  flex-shrink: 0;
  white-space: nowrap;
}
.event-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.event-title {
  font-size: 16px;
  font-weight: 600;
  color: #e2e8f0;
  word-break: break-word;
}
.event.sel .event-title { color: #fff; }
.event-location {
  font-size: 14px;
  color: #8b9ab5;
  margin-top: 2px;
}
.event.sel .event-location { color: #a5b4fc; }
.event-people {
  font-size: 13px;
  color: #8b9ab5;
}
.event.sel .event-people { color: #c4b5fd; }
.cat-badge {
  font-size: 13px;
  padding: 4px 12px;
  border-radius: 12px;
  flex-shrink: 0;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  letter-spacing: 0.3px;
}
.cat-birthday { background: linear-gradient(135deg, #f59e0b, #d97706); }
.cat-meeting { background: linear-gradient(135deg, #10b981, #059669); }
.cat-other { background: linear-gradient(135deg, #6366f1, #4f46e5); }
.cat-holiday { background: linear-gradient(135deg, #ef4444, #dc2626); }

.empty {
  padding: 60px 20px;
  text-align: center;
  color: #475569;
  font-size: 15px;
}

/* ── 액션 바 ── */
/* ── 캘린더 선택 + 새 일정 상단 바 ── */
.cal-top-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #1e293b;
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}
.cal-top-bar .filter-select { flex: 1; }
.cal-top-bar .action-btn.primary {
  flex: none;
  padding: 8px 18px;
  background: rgba(99,102,241,.25);
  border-radius: 8px;
  font-size: 14px;
}
.cal-top-bar .action-btn.primary:hover { background: rgba(99,102,241,.4); }

.stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: #c8d0e0;
  background: rgba(99,102,241,.08);
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.stats-note {
  font-size: 12px;
  font-weight: 400;
  color: #8b9ab5;
  margin-top: 2px;
}
.export-btn {
  margin-left: 12px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid #475569;
  border-radius: 4px;
  background: #334155;
  color: #e2e8f0;
  cursor: pointer;
}
.export-btn:active { background: #475569; }

.action-bar {
  display: flex;
  gap: 1px;
  background: #1e293b;
  border-top: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
  padding: 4px 8px;
  padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
}
.action-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 6px;
  cursor: pointer;
  border-radius: 8px;
  transition: background .12s, color .12s;
}
.action-btn:hover { color: #e2e8f0; background: rgba(99,102,241,.1); }
.action-btn:active { background: rgba(99,102,241,.2); }
.action-btn.primary { color: #a5b4fc; }
.action-btn.primary:hover { color: #c7d2fe; }
.action-btn.danger { color: #fca5a5; }
.action-btn.danger:hover { color: #fecaca; }
.action-btn.disabled,
.action-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.action-btn.disabled:hover,
.action-btn:disabled:hover {
  color: inherit;
  background: transparent;
}

/* ── 폼 ── */
.form-view {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}
.form-header {
  font-size: 17px;
  font-weight: 700;
  color: #f1f5f9;
  text-align: center;
  padding: 4px 0 20px;
}
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #94a3b8;
  margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  background: #1e293b;
  border: 1px solid #334155;
  color: #e2e8f0;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: 2px solid #6366f1;
  outline-offset: -1px;
  border-color: #6366f1;
}
.form-textarea {
  resize: vertical;
  min-height: 70px;
}
.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.form-check input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: #6366f1;
}

/* 날짜 행 */
.date-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.date-input {
  width: 72px !important;
  text-align: center;
}
.date-select {
  width: 80px !important;
}
.date-sep {
  font-size: 13px;
  color: #64748b;
  margin-right: 2px;
}
.weekday-label {
  font-size: 14px;
  font-weight: 600;
  color: #a5b4fc;
  margin-left: 4px;
}

/* 빠른 날짜 */
.quick-btns {
  display: flex;
  gap: 8px;
}
.quick-btn {
  padding: 7px 16px;
  background: #1e293b;
  border: 1px solid #334155;
  color: #94a3b8;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.quick-btn:hover { background: rgba(99,102,241,.15); color: #c7d2fe; border-color: #6366f1; }
.quick-btn:active { background: rgba(99,102,241,.25); }

/* 태어난 해 행 */
.birth-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.age-label {
  font-size: 13px;
  color: #a5b4fc;
  font-weight: 600;
}

/* 시간 행 */
.time-row {
  display: flex;
  gap: 12px;
}
.time-row .form-group { flex: 1; }
.time-inputs {
  display: flex;
  align-items: center;
  gap: 4px;
}
.time-select {
  width: 72px !important;
  text-align: center;
  padding: 10px 8px !important;
}
.time-inputs span {
  color: #64748b;
  font-weight: 700;
}

/* 음력 */
.lunar-row {
  margin-bottom: 12px;
}

/* ── 상태바 ── */
.status-bar {
  padding: 6px 20px;
  background: #1e293b;
  font-size: 12px;
  color: #8b9ab5;
  flex-shrink: 0;
  text-align: center;
}

/* ── 로딩 오버레이 ── */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .85);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #a5b4fc;
  font-size: 16px;
  font-weight: 600;
  z-index: 100;
}

/* ── 컨텍스트 메뉴 ── */
.ctx-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0,0,0,.4);
}
.ctx-menu {
  position: absolute;
  background: #1e293b;
  border: 1px solid rgba(99,102,241,.25);
  border-radius: 12px;
  padding: 6px 0;
  min-width: 190px;
  max-width: 260px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
.ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #cbd5e1;
  font-size: 14px;
  font-family: inherit;
  padding: 10px 18px;
  cursor: pointer;
  transition: background .1s;
}
.ctx-item:hover,
.ctx-item:focus {
  background: rgba(99,102,241,.15);
  color: #fff;
  outline: none;
}
.ctx-item.disabled,
.ctx-item:disabled {
  opacity: .35;
  cursor: default;
}
.ctx-item.disabled:hover,
.ctx-item:disabled:hover {
  background: none;
  color: #cbd5e1;
}
.ctx-sep {
  height: 1px;
  background: rgba(255,255,255,.08);
  margin: 4px 12px;
}

/* ── 스크롤바 커스텀 (데스크톱) ── */
.event-list::-webkit-scrollbar { width: 6px; }
.event-list::-webkit-scrollbar-track { background: transparent; }
.event-list::-webkit-scrollbar-thumb {
  background: rgba(99,102,241,.3);
  border-radius: 3px;
}
.event-list::-webkit-scrollbar-thumb:hover { background: rgba(99,102,241,.5); }

/* ── 폼 스크롤바 ── */
.form-view::-webkit-scrollbar { width: 6px; }
.form-view::-webkit-scrollbar-track { background: transparent; }
.form-view::-webkit-scrollbar-thumb {
  background: rgba(99,102,241,.3);
  border-radius: 3px;
}

/* ── 모바일 최적화 (≤430px) ── */
@media (max-width: 430px) {
  /* 일정 리스트 행 */
  .event {
    gap: 6px;
    padding: 10px 12px;
  }
  .event-left {
    min-width: 56px;
  }
  .event-date {
    font-size: 14px;
  }
  .event-time {
    font-size: 13px;
  }
  .event-title {
    font-size: 15px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .event-location {
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .cat-badge {
    font-size: 12px;
    padding: 3px 8px;
  }
  .month-header {
    padding: 10px 14px 4px;
    font-size: 13px;
  }

  /* 폼: 날짜 행 */
  .date-input {
    width: 60px !important;
  }
  .date-select {
    width: 96px !important;
  }

  /* 폼: 시간 행 */
  .time-row {
    gap: 6px;
  }
  .time-select {
    width: 64px !important;
  }
  .hasend-check {
    white-space: nowrap;
  }

  /* 폼 여백 */
  .form-view {
    padding: 16px 14px 80px;
  }
  .top-bar {
    padding: 8px 10px;
    gap: 6px;
  }
  .view-title {
    font-size: 13px;
  }
  .filter-select {
    padding: 4px 6px;
    font-size: 12px;
  }
  .view-select {
    min-width: 36px;
  }
  .cal-top-bar {
    padding: 6px 10px;
  }
  .holiday-toggle {
    font-size: 12px;
  }
  .holiday-toggle input {
    width: 14px;
    height: 14px;
  }
}
